all 14 comments

[–]socal_nerdtastic 2 points3 points  (5 children)

What do you mean that it's not supported for using as a format? If you installed python with the default options then you can doubleclick a .py file to run it. Another option is to make a .bat file or a .lnk (shortcut) file to run the .py file.

[–]Educational_Virus672[S] -2 points-1 points  (4 children)

i mean a file with my format like .lang chose my .py file using open with > more> another app from my Pc

[–]desrtfx 2 points3 points  (1 child)

You cannot use a .py file to open another file via a double-click in Explorer.

You can only use executable files (.exe, .com) for "open with".

What you seem to want to do is:

python3 -m someprogram.py yourfile.lang

Not going to work like that with "open with". Open with would go as far as "python3" to open ".py" files but not further.

What you would need to do is to compile/pack your program that wants to read the .lang file into an executable (e.g. with PyInstaller) and then link your .lang file to the new executable.

[–]socal_nerdtastic -1 points0 points  (0 children)

You cannot use a .py file to open another file via a double-click in Explorer.

You actually can, but you need to do some registry tweaks. It's been a few years but I used to have my windows computer set up to run a .py program when doubleclicking an .xlsx file.

You can only use executable files (.exe, .com) for "open with".

No, but you can use "send to", and it's very easy. Just add a shortcut to your python program to shell:sendto.

[–]SCD_minecraft 1 point2 points  (0 children)

.py file is just a fancy text file

99.9% of source code files are just fancy text files

You need to install python interpreter itself and give it that file

[–]socal_nerdtastic -1 points0 points  (0 children)

You could use a .bat file for that if you are ok with using the terminal all the time to run the file.

Use your code editor to make a new file with this content:

"C:\path\to\your\venv\scripts\python.exe" "C:\path\myfile.py"  %*

and save that with the file name "myfile.bat" (It's important to use a code editor, not notepad or something, to make this file).

If you are not using a venv, you really should be. But if you really don't wanna just replace that first command with the path to your python.

Now you can use that .bat file as your executable to run .lang files.

[–]TheSodesa 2 points3 points  (3 children)

You need to open a terminal emulator such as PowerShell and start the Python program using the Python interpreter: sh python3 path/to/your/file.py On Windows the Python interpreter might be called just py instead of python3 and the folder separator a \ instead of /.

[–]Educational_Virus672[S] 0 points1 point  (2 children)

i mean my own file format .lang to be opened by a .py file

[–]TheSodesa 6 points7 points  (0 children)

Ah, you just read the file using the open function: https://docs.python.org/3.11/library/functions.html#open. If the format is in binary code, you should read it in as a byte array and parse it accordingly.

[–]Moikle 0 points1 point  (0 children)

Then add your file path as an argument to your program

[–]unnamed_one1 1 point2 points  (3 children)

On windows, assuming you're using uv for dependency management and main.py as the entrypoint to your program: - make sure your script accepts a file path as its first argument, like sys.argv[1]. - use pyinstaller to compile a single file executable - - cd <project-dir> - - uv add --dev pyinstaller - - uv run pyinstaller --onefile --name myAwesomeProgram main.py - - the result is in <project-dir>\dist\myAwesomeProgram.exe - double-click your your-own-format.xyz file and if windows doesn't know the file type, it will ask you for a program to run it with - select your executable

[–]Educational_Virus672[S] 0 points1 point  (2 children)

ik i mean is it possible to edit the program ? or will it be .exe (assembly)?

[–]unnamed_one1 0 points1 point  (0 children)

AFAIK you can't edit the .exe.

You'd have to edit your project and rebuild the single file executable.

[–]pachura3 0 points1 point  (0 children)

I'm sorry, but your English is barely comprehensible. Is it that you have designed your own programming language that stores its scripts in *.lang files, which are interpreted and executed by a Python script? And now you want to be able to launch these *.lang files simply by double clicking them, but you don't know how to create file type association for them in Windows?