Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python how to change ' from the string type

i have a list in python that looks like this ['a','b','c'] and i want it to look like ["a","b","c"]. I tried using some replace functions and looping the list and adding '"' before and after the element but its not working.
I receive the list from the import block in terraform as dictionary and also the replace function is not working there. I need it to look like this ["a","b","c"] because i want to generate another terraform file that will use that list for a variable but using ' in terraform for strings is not working.
How can i solve this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Sounds like you want to dump a list in json format.
Python has a module in its standard library for it.

import json

l = ['a', 'b']
print(l)
l_str = json.dumps(l)
print(l_str)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading