.py file
A plain text file whose name ends in .py, holding Python source code that the interpreter can run or import.
In more detail
Running python3 name.py executes the file as a program; import name loads it as a module. Idle, editors and the py launcher all recognise the ending. The file name, without .py, becomes the module name, so it should follow the rules for identifiers.
Example
python3 hello.pyRelated terms
- file extension — The part of a file name after the last dot, such as .py or .txt, that tells programs what kind of file it is.
- module — A file of code whose functions, classes and variables other files can use by importing it.
- source code — The human-readable text of a program, as written in a programming language and saved in a file.
Taught in
- Editors, IDEs And Shells — Hands-on Python: Complete Video Course & Book
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- First Run, And Fixing A Broken Install — Hands-on Python: Complete Video Course & Book
- Input, And Numbers Versus Digits — Hands-on Python: Complete Video Course & Book
- The String Format Method — Hands-on Python: Complete Video Course & Book
- Packages, And Your Own Library — Hands-on Python: Complete Video Course & Book
- Interpreter, Compiler, And What Counts As Syntax — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Your Own Modules And Packages — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep