[IPython-user] Notes on using ipython as a system shell ('pysh')

Prabhu Ramachandran prabhu_r at hathway.com
Wed Apr 14 03:43:43 CDT 2004


>>>>> "FP" == Fernando Perez <Fernando.Perez at colorado.edu> writes:

    >> I'm not adverse to a $prefix.  Other shells require something
    >> to distinguish literals from variables.  If ipython is a shell,
    >> I don't see why it shouldn't be able to do the same.  Python
    >> itself doesn't require the prefix because it has a highly
    >> constrained grammar.  When you're working in a system shell,
    >> every command could have its own syntax.

    FP> I agree with Daniel here, in that I simply don't see a clean
    FP> way to handle the two namespaces (filesystem and python
    FP> variables) without an explicit escaping mechanism.  I'd love
    FP> to hear a bit more detail from Prabhu, if you see a way out.
    FP> The problem is that we want to be able to set a variable:
[...]
    FP> For the above reasons, I honestly fail to see how to do
    FP> without an explicit interpolation symbol for expanding python
    FP> variables into commands meant to go to the system.  Obviously,
    FP> any code which is normal python would obey the regular python
    FP> syntax rules.

Yes, I see the problem.  I was only wishing aloud, and did not really
think about this issue.  So yes, I guess the $ is fine if its use is
unambiguous.

    >> To make it appear "pythonic", maybe variables could be wrapped
    >> with the dictionary variable interpolation "%(myvar)s" syntax,
    >> using the shell's globals() as the dictionary.  I haven't
    >> thought this through to its conclusion, and I'm not really
    >> advocating it, but it is pythonic, though also a bit perlish.
    >> E.g.,
    >> >  >> var = 'hello' echo %(var)s + ' world!'
    >> >  hello world!

    FP> -1.  A shell must value economy of typing above all.  I've
    FP> always hated %()s even in python programs for being too much
    FP> to type.  I also want to keep the user-visible behavior of
    FP> pysh as close to that of known shells as possible.

I agree with that.

    >> Although since the command arguments are always strings, I
    >> don't suppose the trailing "s" in "%(var)s" is needed.
    >>
    >> ...
    >> >  Also can pipes be handled?
    >> >
    >> >  >> ps uax | grep ipython | sort > /tmp/ps
    >>

    FP> Something like the above works even now, as long as you start
    FP> with !.  It's just a call to os.system(), and it would remain
    FP> so.  The difference is that pysh would keep stdout/err trapped
    FP> always into _ and _e for your convenience, so its calling
    FP> mechanism would actually be like what @sx does today, instead
    FP> of what ! does.

Cool!

cheers,
prabhu




More information about the IPython-user mailing list