On 13 October 2012 17:38, Joshua Landau <joshua.landau...@gmail.com> wrote:

> This here isn't a flaw in Python, though. It's a flaw in the command-line
> interpreter. By putting it all on one line, you are effectively saying:
> "group these". Which is the same as an "if True:" block, and some things
> like Reinteract even supply a grouping block like "build".
>
> That said, because some shells suck it would be nice if:
>
>> python -c "a=1\nif a:print(a)"
>
> worked (just for -c).
>
>
And, spurred on by another thread, this has become possible.

Make a file like so, install it if you wish.

import sys
> evaluable = sys.argv[1].encode("utf8").decode("unicode_escape")
> exec(evaluable)


This lets you do this:

python unicode_escape.py "a = []    ##\nfor x in range(100):    ##\n
>  a.append(x)    ##\n  a.append(x**2)    ##\nprint(a)"


It's ugly, but it works and only takes one line.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to