473,513 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2331
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1664
by: Michael | last post by:
What's the perfered method of passing command-line args throughout a Python program given that globals don't seem to really exist? I thought of writing them out to a python file and then importing...
2
2646
by: joe | last post by:
Hello, I have the following commands: testb -s <size> testb -s <size> -o <input file> testb -s <size> -o <codes> How do i split the commands so that all three are valid. And how do i check...
2
2816
by: Norman | last post by:
Hello All, I have a large WSH Javascript script that I want to convert to .Net Javascript. How do I accomplish the same functionality as - var args = WScript.Arguments; within the .Net...
6
2920
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd...
1
1298
by: Eric | last post by:
How do I enter my command line args with .Net? I know on 6.0 you went to project -> properties and on one of the tabs you could enter your args. I can't find this anywhere on .Net
3
8150
by: Robert Brinson | last post by:
I'm writing one of my first WinForm apps; everything else has been WebForms up to this point. However, having come from a background of Java, C++, and Perl, I'm having trouble understanding how...
10
2218
by: David B | last post by:
I am writing a console App with VB 2005 where I accept a text file as input, parse it and insert the text data into an SQL table. I have written the code correctly as well as I can tell because it...
3
2086
by: =?Utf-8?B?VGltIEE=?= | last post by:
I want the user to be able to select a group of files in windows explorer, right click, open with - my application and have my application put all of the file names onto the clipboard. It seems...
3
1995
by: smitty1e | last post by:
Just a fun exercise to unify some of the major input methods for a script into a single dictionary. Here is the output, given a gr.conf file in the same directory with the contents stated below: ...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.