convert string to list

Cliff Wells clifford.wells at
Wed Oct 13 14:15:01 CEST 2004

On Wed, 2004-10-13 at 14:03 +0200, 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
> ["A","B","C"]

You can use eval for this.  Better, you could simply pass your list as a
series of arguments from bash:

#!/bin/bash A B C

import sys
thelist = sys.argv[1:]


Cliff Wells <clifford.wells at>

More information about the Python-list mailing list