convert string to list
Wolfram Kraus
kraus at hagen-partner.de
Wed Oct 13 11:06:50 EDT 2004
Jochen Hub wrote:
> Hi,
>
> I am a real beginner in Python and I was wondering if there is a way to
> convert a string (which contains a list) to a "real" list.
>
> I need this since I would like to give a list as an argument to my
> Python script from the bash:
>
> #!/usr/bin/python
> import sys
> argument1 = sys.argv[1]
> thelist = ???(argument1)
>
> and then call the script from the bash like this
>
> thescript.py ["A","B","C"]
>
> Thanks you,
> Jochen
If you are sure that the list always looks that way:
>>> l = '["A","B","C"] '
>>> l[1:-2].replace('"','').split(',')
['A', 'B', 'C']
HTH,
Wolfram
More information about the Python-list
mailing list