472,122 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

run a .py script with cmd line args

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

Aug 12 '08 #1
2 2291
On Aug 12, 2:20*pm, r <rt8...@gmail.comwrote:
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/pyt...ch/004360.html

You may also find the mimetypes module helpful:

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

Mike
Aug 12 '08 #2
En Tue, 12 Aug 2008 16:34:13 -0300, Mike Driscoll <ky******@gmail.com>
escribió:
On Aug 12, 2:20*pm, r <rt8...@gmail.comwrote:
>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/pyt...ch/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!)

--
Gabriel Genellina

Aug 13 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael | last post: by
2 posts views Thread by joe | last post: by
6 posts views Thread by Edd Dawson | last post: by
1 post views Thread by Eric | last post: by
3 posts views Thread by Robert Brinson | last post: by
3 posts views Thread by =?Utf-8?B?VGltIEE=?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.