'How to get which file was opened with a .exe python program

So I am trying to create a program that would be able to read its own types of files

Imagine there is a file called hello.world

And you have a .exe program that you can open this file with.

This program is my python file, so what is actually the way of getting which file was opened with that .exe?



Solution 1:[1]

After a small discussion in the comments:

it is possible to use sys.argv to get the file path: getting file path from command line argument in python

filename = sys.argv[1]
print(filename)

if os.path.exists(fn):
    print os.path.basename(fn)
    # file exists

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nitlix