简体   繁体   中英

Python: open a file *with* script?

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" how 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')

如果我没有大错,那就应该将文件名作为第一个参数传递给脚本sys.argv[1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM