[IPython-dev] Expanding $a to 'f1 f2' when $a is ['f1','f2']

Fernando Perez Fernando.Perez at colorado.edu
Wed Mar 16 17:18:43 EST 2005


Ville Vainio wrote:
> One often deals with lists of filenames when doing shellish stuff. It
> would be quite useful if you could use $flist in shell commands to say
> 'list of files', i.e. a list of file names separated by space. As it
> stands, it expands to the string representation of the list, which is
> almost never useful in shell commands. I've done
> 
> for f in junk:
>     rm $f
> 
> way too often lately, I'd just like to do 
> 
> rm $junk

Sorry, but the amount of special-casing that this would require is almost 
guaranteed to break somewhere.  Keep in mind that you can evaluate arbitrary 
code in $ expressions, so you can do:

rm ${' '.join(junk)}

Not the cleanest, but it works.

The problem is that I simply don't see a way to generically distinguish when 
$foo should be evaluated as a list joined on whitespace and when it should be 
treated as a list.  The $ evaluation mechanism is actually a full-blown 
generic interpolation module, Ka-Ping Yee's Itpl, from PEP-215:

http://www.python.org/peps/pep-0215.html

How do you propose such a mechanism do what you want in a generic, safe way? 
How can I determine when each kind of expansion to apply?  Unless a clean 
solution can be provided, this one stays as is.

Best,

f




More information about the IPython-dev mailing list