When creating programs and code in Python, the correct file extension for your code is .py.
There are a few other file extensions associated with Python files. In this article, we will discuss the four different Python file types and the file extensions for each of these file types.
File Extension for Python Source Code
As mentioned above, the file extension for your source code in Python is .py.
After writing your program, script, module, etc., saving your code with .py will allow the operating system to recognize this is a Python file.
File Extension for Compiled Python Bytecode
The second type of file associated with Python is compiled bytecode and the extension for compiled bytecode is .pyc.
Let’s say you create a module with Python source code. If you want to import that module, Python will build a .pyc file which contains the bytecode to make importing this module easier.
File Extension for Compiled Python Bytecode While Optimization is On
If you have optimizations turned on, i.e. with a command like “python -O test.py”, you will get a .pyo file when you run the code.
File Extension for Windows DLL file of Python Code
The final file extension which you should know about is the .pyd file extension. .pyd files are Windows DLL files.
DLL stands for Dynamic Link Library. These library files contain code to carry out a specific function for an application in the Windows operating systems.
Hopefully you’ve learned about the correct file extension for Python files and the difference between different file types in Python.
Leave a Reply