问题
I wonder how the Windows "Open file with..." feature works. Or rather, how would do if I write a program in python, compile a executable with py2exe and then want to be able to open certain files in that program by right-clicking and choose it in "Open with".
Is the file simply passed as an argument, like "CMD>C:/myapp.exe file"?
回答1:
Yep, the path to the file gets passed in as an argument and can be accessed via sys.argv[1]
.
回答2:
You can use more functionally argparse module
来源:https://stackoverflow.com/questions/15393202/windows-open-with-python-py2exe-application