How to practice after the python file is written

Scripted programming

Copy the following code to the hello.py file:


print("Hello, Python!");


Execute the script with the following command:


$ python ./hello.pyhello,python


Use Python's own IDEL

Python comes with an IDE called IDLE.


v2-577901e9efd143405ad4f7a87983ce1b_720w.png


Content expansion:

Pyc file in Python practice

Introduction to pyc files

The .pyc file contains bytecode compiled from the python source file.

The Python parser tries to load the .pyc file before loading the .py. If it is the latest, there is no need to compile the Python source code file again.

The deletion of the .pyc file has no effect

The .pyc file is not large, because it can save the loading time of the python program, it will help to shorten the overall execution time

Method of generating pyc file

Run python -m helloworld.py directly

Use py_compile to generate pyc files python -c "import py_compile; py_compile.compile('helloworld.py')"

Compile all the py files in the directory


import compileallcompileall.compile_dir(r'/path')


This is the end of this article on how to practice python files after they are written. For more relevant python files how to practice content, please search for previous articles or continue to browse related articles below. Hope you will support you in the future!


Guess you like

Origin blog.51cto.com/14825302/2535609