I have looked into passing command line arguments to python and can
send a specific pathname to python but ideally what i need is a
generic command that i can write to the registry that passes the
pathname of whichever file was doubled clicked!?!
am i asking too much/does it exist/is there an easier way to do this!!
CC
I did this by writing the path to me script or exe and added %1 to the
end, which basically means that my program can (or requires) a
parameter passed to it. Here's an example:
"C:\Program Files\PyMail\wxsendmail.exe" %1
That should work. Tested on Windows XP SP2 with Python 2.4/2.5.
Mike
I wrote a very simple script to test the idea:
import sys
for arg in sys.argv:
print arg
raw_input("Done") #Merely to slow the program down so i can see output
and then setup a file extension .xyz, placed it in the registry, can
get a .xyz file to work as a python script so the registry setup is
fine, but when i try and put the parameter to the above program and a
%1 (or even without) it gets the following error message from windows:
C:\...\hmm.xyz is not a valid Win32 application.
any suggestions??
Do you mean: when a file with "your extension" is double clicked on,
then Windows should pass the path of that file to "your application"
that is written in Python?
(snip)
Windows seems to be trying to execute your file.xyz as an application,
this means it hasn't associated your extension (.xyz) with your
application, instead .xyz is associated as an executable.
To associate your extension with your application, see:
http://msdn2.microsoft.com/en-us/library/bb776883.aspx
It's a bit advanced
NOT TESTED:
# Create or edit Registry Key: 'HKEY_CLASSES_ROOT\.xyz'
# Change the value for the key 'HKEY_CLASSES_ROOT\.xyz:' into 'MyApp'
# Create or edit Registry Key: 'HKEY_CLASSES_ROOT\MyApp\Shell\Open
\Command'
# Change Registry Key value for 'HKEY_CLASSES_ROOT\MyApp\Shell\Open
\Command' into: '"C:\pathtomyapp\myapp.py" "%1"'
Check an existing registry key, how they do it.
I think either I have misunderstood the situation, you misunderstood
your own situation, or you have expressed your situation incorrectly:
"it loads like a python file fine". What loads like a python file
fine? The python source or the data.xyz?
What did you put in data.xyz? Data to be fed to your python program or
python source code?
Aren't we trying to load the data.xyz to your python program? Or are
we trying to load data.xyz to python interpreter?
Anyway, try adding quotes around the "%1", to ensure that path that
contains spaces doesn't confuse the program
HKEY_CLASSES_ROOT\MyApp\Shell\Open\Command => "C:\pathtomyapp
\myapp.py" "%1"
And there are already "" around my %1 sign. It currently reads "C:\test
\test.py" "%1", where test.py is the short program that simply reads
the sys.argv that i posted further up.
> No you didnt misunderstand the situation, i think i have confused
> matters though!! When Ive got it working my program will read the data
> within the file. But obviously for it to do that it needs to know
> where the file is, hence the whole discussion. However to test things
After reading the thread I'm confused as well.
Try using an installer (like InnoSetup) to install your application. It can handle the .xyz registry stuff for you, among other things.
--
Gabriel Genellina