Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: for-loop on cmd-line

Reply
Thread Tools

Re: for-loop on cmd-line

 
 
D'Arcy J.M. Cain
Guest
Posts: n/a
 
      10-11-2012
On Thu, 11 Oct 2012 13:24:22 +0200
Gisle Vanem <(E-Mail Removed)> wrote:

> Hello list. I'm a newbie when it comes to Python.
>
> I'm trying to turn this:
>
> def print_sys_path():
> i = 0
> for p in sys.path:
> print ('sys.path[%2d]: %s' % (i, p))
> i += 1
>
> into a one-line python command (in a .bat file):


Is "one liner" an actual requirement or is the requirement to run it
from the command line?

python -c "
import sys
i = 0
for p in sys.path:
print('sys.path[%2d]: %s' % (i, p))
i+=1
"

I don't know if this works on Windows or not.

--
D'Arcy J.M. Cain <(E-Mail Removed)> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
IM: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments