run a .py script with cmd line args

R

r

i have a python text editor program(script) that i would like to run
when a user clicks on .txt files.
how do i run my script from windows,
and send the filename to my script, so that my script can do:

if len(sys.argv) > 1:
try:
self.LoadFile(sys.argv[1]) # load text into editor
except:
pass
 
M

Mike Driscoll

i have a python text editor program(script) that i would like to run
when a user clicks on .txt files.
how do i run my script from windows,
and send the filename to my script, so that my script can do:

if len(sys.argv) > 1:
    try:
         self.LoadFile(sys.argv[1])  # load text into editor
    except:
        pass


The following thread explains one way to do it:

http://mail.python.org/pipermail/python-win32/2006-March/004360.html

You may also find the mimetypes module helpful:

http://docs.python.org/lib/module-mimetypes.html

Mike
 
G

Gabriel Genellina

i have a python text editor program(script) that i would like to run
when a user clicks on .txt files.
how do i run my script from windows,
and send the filename to my script, so that my script can do:

if len(sys.argv) > 1:
    try:
         self.LoadFile(sys.argv[1])  # load text into editor
    except:
        pass


The following thread explains one way to do it:

http://mail.python.org/pipermail/python-win32/2006-March/004360.html

Instead of directly writing to the Windows registry, you can also execute
these two commands:

assoc .foo=Foo.File
ftype Foo.File=c:\path\to\python.exe c:\path\to\script.py "%1" %*

They work on every non-prehistoric Windows version...

(replace foo with the desired extension - I would *NOT* use txt!)
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top