convert string to list

Jochen Hub jhub at gwdg.here_simple_one_dot.de
Wed Oct 13 10:49:27 EDT 2004


>>
>>thescript.py ["A","B","C"]
> 
> 
> You can use eval for this.  Better, you could simply pass your list as a
> series of arguments from bash:

I tried with eval...simply using

thelist=eval(argv[1])

it didn't work :-(, I got the error message

   File "./findCenter.py", line 64, in ?
     print eval(sys.argv[1])
   File "<string>", line 0, in ?
NameError: name 'A' is not defined

> 
> #!/bin/bash
> myscript.py A B C

The problem is that I want to pass one or two lists to the script, so it 
should be able to distinguish between

thescript ["A","B"] ["C","D",E"]
thescript ["A","B","C"] ["D",E"]
thescript ["A","B","C","D",E"]



More information about the Python-list mailing list