Violet
Violet

Reputation: 505

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?

Upvotes: 0

Views: 326

Answers (2)

pyfunc
pyfunc

Reputation: 66719

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

Upvotes: 1

Matthew Iselin
Matthew Iselin

Reputation: 10670

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

Upvotes: 0

Related Questions