[IPython-dev] Expanding $a to 'f1 f2' when $a is ['f1','f2']
Fernando Perez
Fernando.Perez at colorado.edu
Thu Mar 17 13:28:50 EST 2005
Ville Vainio wrote:
> On Wed, 2005-03-16 at 15:18 -0700, Fernando Perez wrote:
>
>
>>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?
>
>
> 1. If it's just $junk (i.e. not ${junk})
>
> 2. not isinstance(junk, basestring)
>
> 3. iter(junk) does not raise TypeError
>
> -> Expand it as " ".join(junk)
OK, your proposal sounds very reasonable in principle. However, I'm afraid
that considering how the Itpl code is written, it's not that easy to do.
These strings with $ in them get fed wholesale to the itpl machinery, which
does the splitting on chunks at instantiation time, and then runs a fast
eval() loop over all chunks when str() is called.
I simply don't see a clean way to inject all this special-casing logic into
it, and I'm afraid it may break things (besides having a performance impact).
I really think the effort/benefit ratio is against this one, sorry.
Best,
f
More information about the IPython-dev
mailing list