convert string to list

Michael Foord fuzzyman at gmail.com
Fri Oct 15 01:30:56 CEST 2004


Jochen Hub <jhub at gwdg.here_simple_one_dot.de> wrote in message news:<ckj5ie$tra$1 at gwdu112.gwdg.de>...
> 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


Other posters have mentioned difficulties with what the shell will do
to your command line. If you can get it as a single string - I've
written a module that will turn a string like that back into a list. I
use it for reading lists from config files. It will properly handle
the quotes etc.....

It's called listwuote and you can find it at
http://www.voidspace.org.uk/atlantibots/pythonutils.html#listquote

Regards,

Fuzzy



More information about the Python-list mailing list