How to use "while" within the command in -c option of python?
joshua.landau.ws at gmail.com
Mon Oct 15 23:24:08 CEST 2012
On 13 October 2012 17:38, Joshua Landau <joshua.landau.ws at 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.
> evaluable = sys.argv.encode("utf8").decode("unicode_escape")
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list