简体   繁体   English

Python:使用*脚本打开文件?

[英]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. 我将python脚本捆绑到一个应用程序中(我在Mac上),并将该应用程序设置为能够打开.zip文件。 But when I say "open foo.zip with bar.py" how do I access the file that I have passed to it? 但是,当我说“用bar.py打开foo.zip”时,如何访问传递给它的文件?

Additional info: Using tkinter. 附加信息:使用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] 您应该使用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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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