Terry Carroll wrote: > I would like to know the name of the shortcut (link, I think, in Unix > parlance) from which a python program is being invoked. I'd also like to > be able to access the directory where the shortcut lives.
You can set the command line arguments and working directory for a shortcut by opening the properties window on the shortcut, at least in Win2k. So for example in the properties for argc.py just add 'C:\\test\\argtest\\testdir\\argc.py to the "Target" field and set the "Start in" field to 'C:\\test\\argtest\\testdir' If arga.py imports any packages in argtest\ you will have to add that dir to sys.path somehow (many options for this). Kent > > Toy example: here's a directory structure: > > C:\ > test\ > argtest\ > arga.py > argb.py > testdir\ > argc.py > > arga.py contains: > > import sys,os > print "ARGS:", sys.argv > print "WD:", os.getcwd() > raw_input() # just to keep the window open > > argb.py and argc.py are both shortcuts to arga.py > > When I run arga.py (e.g., by double-clicking on it, I get, as expected: > > ARGS: ['C:\\test\\argtest\\arga.py'] > WD: C:\test\argtest > > > When I run argb.py, I get the same thing. I'd hoped (but didn't really > expect) sys.argv would be ['C:\\test\\argtest\\argb.py'] . > > When I run argc.py, same thing. In this case, I'd hoped sys.argv would be > ['C:\\test\\argtest\\testdir\\argc.py']; and os.getcwd() would have given > back 'C:\test\argtest\testdir'. > > Why do I care? > > Well, I'd like to set up a directory where the shortcut and all its > files will live. I'd hoped keying off of the shortcut name might be an > easy way to do this. > > I suspect I'm out of luck: my guess is that windows does all the lookup of > what the shortcut points to, and then launches the file pointed to; and by > the time Python gets control, the shortcut information is long gone. > Anyone know for sure? > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor