Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make this one-liner work in DOS?

python -c "for x in range(1,10) print x"

I enjoy python one liners with -c, but it is limited when indentation is needed.

Any ideas?

like image 348
Luis Avatar asked Feb 19 '09 18:02

Luis


2 Answers

python -c "for x in range(1,10): print x"

Just add the colon.

To address the question in the comments:

How can I make this work though? python -c "import calendar;print calendar.prcal(2009);for x in range(1,10): print x"

python -c "for x in range(1,10): x==1 and __import__('calendar').prcal(2009); print x;"

As you can see it's pretty gross. We can't import before the loop. To get around this we check if x is at the first iteration in the loop, if so we do the import.

More examples here.

like image 163
Stephen Avatar answered Nov 15 '22 04:11

Stephen


Not a python script, but might help:

for /L %i in (1, 1, 10) do echo %i
like image 28
dirkgently Avatar answered Nov 15 '22 06:11

dirkgently