[Tutor] droplet like behaviour in Python

bob gailer bgailer at gmail.com
Mon Aug 10 15:49:51 CEST 2009


Alan Gauld wrote:
> "pedro" <pedrooconnell at gmail.com> wrote
>> Well I made a script called droplet.py which looks like this:
>>
>> #!/usr/bin/env python
>> # encoding: utf-8
>> import sys
>> theFilePath = sys.argv[1]
>> print theFilePath
>>
>>
>> But when I try to drop something on it nothing happens. Sorry I guess 
>> there is something fundamental that I am missing.
>
> Sorry, obviously I was wrong. FWIW in XP I get python to start up but 
> there is no filename in argv. 

That depends on the file association settings for .py.
Start -> Settings -> Control Panel -> Folder Options -> File Types
Find py extension.
Click Advanced
Choose open
Click Edit
in my system I see "H:\Python30\python.exe" "%1" %*
which means fire up python.exe, pass the dropped file name as the first 
argument.

BTW a nice 1 python line version independent droplet:
#!/usr/bin/env python
# encoding: utf-8
input(__import__('sys').argv)


-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list