开发者

Python: open a file *with* script?

开发者 https://www.devze.com 2023-01-13 18:32 出处:网络
I have a python script bundled into a application (I\'m on a mac) and have the application set to be able to open .zip files. But when I say \"open foo.zip with bar.py\" h开发者_高级运维ow do I access

I have a python script bundled into a application (I'm on a mac) and have the application set to be able to open .zip files. But when I say "open foo.zip with bar.py" h开发者_高级运维ow do I access the file that I have passed to it?

Additional info: Using tkinter.

What's a good way to debug this, as there is no terminal to pass info to?


You should be using sys.argv[1]

task = sys.argv[1].decode('utf-8')
if task == u'uppercase':
    pass
elif task == u'openitems':
    item_paths = sys.argv[2:]
    for itempath in item_paths:
        itempath = itempath.decode('utf-8')


If I'm not greatly mistaken, it should pass the name of the file as the first argument to the script - sys.argv[1].

0

精彩评论

暂无评论...
验证码 换一张
取 消