Python Forum

Full Version: file extension for python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
python already uses .py and .pyc and .pyo ... are there any others:  i've started using these:

.pyi - insertable (not necessarily importable) snippets of code that can be useful to inserted while creating a .py file.

.pyd - insertable or importable files that are data being added to a program, such as a list of US states.

.pyt - insertable or importable files that are text being added to a program, such as different licenses.

your thoughts?

*** ducks behind the big blue couch ***
Hm... I would use some file name prefix or suffix. And I am doing it like that. The programs and the systems depend on file extension when it comes to text files. If the file is executable ( a script ), the shebang line will work regardless of the file extension. But this is valid for Linux/Unix systems. Don't know about Mac OS.
You forgot .pyw (though that may apply only to Windows).

Sounds like you're just reinventing the wheel and making life just a little more complicated.
I don't see the point to invent your own extensions. Who else, but you will know what they mean. Not to mention that
pyd - https://docs.python.org/3.6/faq/windows....e-as-a-dll
pyt -  http://desktop.arcgis.com/en/arcmap/10.3...lboxes.htm
this started for me when i had some files that were snippets of code i could insert into python code.  at first i used the extension .py for everything.  but that was getting them mixed up with python code that was suppose to be a complete command or module.  it first it seemed i needed to read each file to see if it began with #! which was making a lot of my commands big and complex.  at least the ones without #! were short so grep didn't need to read so much.  i started writing a command to detect these (the file command did not ... in some cases it said it was ascii text and in others it said it was python source) then got the idea of an extension (.pyi) as i could get emacs to recognize then that way a lot easier, and recognize them in big one-time commands a lot easier (for example, a one-time command to upload all python-insertable files to a specific location).  so, i started doing it that way.  i have solved similar issues with other things not involving python, before, with general good luck.  then i realized i had some files that were data or text assignments (can import) or quote encodings (inserted after a dangling assignment) and decided .pyi was not enough for these.  too bad Linux did not have meta-attributes for files.
It sounds like a database is what you need
there would be too much interfacing the database to other things ... i think extensions keeps it simple.