Using command line args on Windows

K

k8

Hello-

I'm stuck on a Windows machine today and would love to fully play with
and test a simple python script. I want to be able to type "python
myscript myarg" somewhere. Is there anything out there to help me? My
main concern is playing with the myarg in the sys.argv list. I've been
mucking around with IDLE without much success.
 
L

Larry Bates

1) Start a command prompt window
(Start-Programs-Accessories-Command Prompt)
2) Change to directory where the python program is stored
(cd \<path-where-script-stored>)
3) Type python myscript.py myarg

-Larry Bates
 
D

Diez B. Roggisch

k8 said:
Hello-

I'm stuck on a Windows machine today and would love to fully play with
and test a simple python script. I want to be able to type "python
myscript myarg" somewhere. Is there anything out there to help me? My
main concern is playing with the myarg in the sys.argv list. I've been
mucking around with IDLE without much success.

Install cygwin. Don't confuse the cygwin python version with your
separately installed one, or don't install python via cygwin.

Regards,

Diez
 
D

Diez B. Roggisch

k8 said:
Thank you thank you thank you- The windows command line sol worked.

It sure does. But it sucks.. bad tab-completion, few tools, short
history, limited command-line-editing and so on. But if you want it the
hard way, it's your choice :)

Diez
 
F

Fredrik Lundh

k8 said:
I'm stuck on a Windows machine today and would love to fully play with
and test a simple python script. I want to be able to type "python
myscript myarg" somewhere. Is there anything out there to help me?

footnote: if you'd prefer to type "myscript myarg" instead, you might want
to check out this tool:

http://effbot.org/zone/exemaker.htm

</F>
 
D

Duncan Booth

Fredrik said:
footnote: if you'd prefer to type "myscript myarg" instead, you might
want to check out this tool:

http://effbot.org/zone/exemaker.htm

or even just do:

SET PATHEXT=.py;%PATHEXT%

and then "myscript myarg" will work for all scripts on your path without
compiling (if you don't set PATHEXT then "myscript.py myarg" will still
work, and tab completion means you don't generally need to type the .py for
scripts in the current directory).
 
T

Tim Roberts

Duncan Booth said:
or even just do:

SET PATHEXT=.py;%PATHEXT%

and then "myscript myarg" will work for all scripts on your path without
compiling (if you don't set PATHEXT then "myscript.py myarg" will still
work, and tab completion means you don't generally need to type the .py for
scripts in the current directory).

The downside to this is that there is a bug in the NT/2K/XP command
interpreter which will prevent redirecting from stdin in that case. That
is:

C:\Tmp>type x.py
import sys
print sys.stdin.readline()

C:\Tmp>echo 123 | python x.py
123

C:\Tmp>echo 123 | x.py
The process tried to write to a nonexistent pipe.

C:\Tmp>python x.py < x.py
import sys

C:\Tmp>x.py < x.py

C:\Tmp>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top