2

I have a python script which I can run from pythonwin on which I give the arguments. Is it possible to automate this so that when I just click on the *.py file, I don't see the script and it asks for the path in a dos window?

zombat
  • 92,731
  • 24
  • 156
  • 164
user150674
  • 97
  • 3
  • 10

4 Answers4

4

You're running on Windows, so you need an association between .py files and some binary to run them. Have a look at this post.

When you run "assoc .py", do you get Python.File? When you run "ftype Python.File", what do you get? If "ftype Python.File" points at some python.exe, your python script should run without any prompting.

Community
  • 1
  • 1
hughdbrown
  • 47,733
  • 20
  • 85
  • 108
3

Rename it to *.pyw to hide the console on execution in Windows.

Mark Rushakoff
  • 249,864
  • 45
  • 407
  • 398
  • I rename it to pyw but when i double click it nothing happens. And the file shows Python File(no console). – user150674 Aug 07 '09 at 16:54
  • Do you actually have a proper installation of Python? It should have automatically associated .py,.pyw with C:\PythonXX\Python.exe when you installed. – Mark Rushakoff Aug 07 '09 at 16:55
  • I have PythonWin Installed which includes everything. I tried the pyw too. It just creates the file but when i double click it nothing happens – user150674 Aug 07 '09 at 16:58
2

You can also wrap it in a batch file, containing:

c:\path to python.exe c:\path to file.py

You can then also easily set an icon, run in window/run hidden etc on the batch file.

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • didn't work...i created a batch file. I guess thats created giving the paths in a txt file and renaming it as *.bat – user150674 Aug 07 '09 at 17:05
  • Yes a batch file is just a text file with .bat What doesn't work ? What if you run the batch file form the command prompt? – Martin Beckett Aug 07 '09 at 17:21
  • ya it works in command prompt...but this time it gives a type error for 2 arguments...i give these arguments(i.e. paths ) when i run it from the PythonWin – user150674 Aug 07 '09 at 17:31
1

how does your script ask for or get its parameters? If it expects them from the call to the script (i.e. in sys.argv) and Pythonwin just notices that and prompts you for them (I think Pyscripter does something similar) you can either run it from a CMD window (commandline) where you can give the arguments as in

python myscript.py argument-1 argument-2

or modify your script to ask for the arguments itself instead (using a gui like Tkinter if you don't want to run from commandline).

Albert Visser
  • 1,124
  • 6
  • 5