Summarizing my comments on the question, you can follow the steps below to achieve what you are asking:
- Use
sys.argv
to access the command line arguments. For example the following script will just print all the arguments given to it:
import sys
print("Given arguments: ", str(sys.argv))
Let's name it myprogram.py
.
You can then call it (I think) with: python myprogram.py arg1 arg2 arg3
and it will run and print the command line arguments.
Notice that the first argument (sys.argv[0]
) is the script's path. So arg1
would be sys.argv[1]
, arg2
would be sys.argv[2]
and so on.
I am saying to use sys.argv
because as far as I remember double clicking a file with an extension which has a default opening program, will open that program with the file path as an argument.
- Next step is to package your python script to an executable. This has been already asked and answered for example here (which is a duplicate, where you can follow the question which came before it to see even more examples). I used PyInstaller to test it (and on Windows OS). My command was like:
pyinstaller myprogram.py
... and it generated some folders and files. Specifically the folder dist\myprogram
contained the executable along with its dependencies. You can then run your program by double clicking on it in the dist\myprogram
folder. It should pop a CLI window, printing the arguments (ie only the program's path, since we called it without any other) and immediately exit. Or you can open a CLI window and run it with a command like:
myprogram argument1 argument2 argumentN
(supposing your current working directory is dist\myprogram
) and it will indeed print the arguments.
Finally you have to set it up as the program which by default opens files with .ccp
extension. On Windows 10, you can do this via:
- Open up File Explorer.
- Find a file with
.ccp
extension (or create one).
- Right click on it.
- Click on Properties on the dialog that pops up.
- Go to General tab (if you are not already there) on the dialog that pops up.
- On the Open with: section there is a button which reads Change. Click it.
- Select More apps at the bottom of the dialog.
- Make sure you have the Always use this app to open .ccp files checkbox selected.
- Scroll to the bottom of the dialog and click on the blue text which prompts for manually selecting the default app, which in turn pops up a file chooser. I am not running on English language so it is a bit difficult to translate it exactly (I followed some online pages to actually see the default translation for the previous steps).
- Select your executable as the default.
- Confirm your choices by selecting Ok, Apply or anything else required.
Then you will also be able I think to change this extention later via:
Settings --> Apps --> Default Apps --> Choose default apps by file type.
Some references:
- PyInstaller website and introductory manual.
- Official page for step 3.
- Unofficial page for step 3, a lot more detailed.