convert string to list

Josef Meile jmeile at hotmail.com
Fri Oct 15 04:15:18 EDT 2004


Hi,

> #!/bin/bash
> script.py "['a', 'b', 'c']" "['d', 'e', 'f']"
> 
> 
> 
> #!/usr/bin/python
> import sys
> 
> arglist = []
> for arg in sys.argv[1:]:
>     arglist.append(eval(arg))
> 
> print arglist
> 
> 
Why not just:

script.py "a, b, c" "d, e, f"

Then:
 > arglist = []
 > for arg in sys.argv[1:]:
 >     arglist.append(arg.split(','))

Better than eval.

Regards,
Josef



More information about the Python-list mailing list