Get the App
SLTechnology News&Howtos  ›  Development  › 

How the Python interpreter reads the source file

Shulou Source: shulou.com Published: 2022-06-03 17:38:48 11月13日 Update

This article mainly introduces the Python interpreter how to read the source file, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Description

1. When the Python interpreter reads the source file, it first defines some special variables.

2. Set some special variables, such as _ _ name__, and execute all the code found in the file.

The Python interpreter uses the code as the value of the _ _ name__ variable, that is, the value of the _ _ name__ variable is _ _ main__.

Example

# Suppose this is foo.py. Print ("before import") import math print ("before functionA") def functionA (): print ("Function A") print ("before functionB") def functionB (): print ("Function B {}" .format (math.sqrt (100)) print ("before _ name__ guard") if _ name__ = ='_ main__': functionA () functionB () print ("after _ name__ guard") Thank you for reading this article carefully I hope the article "how the Python interpreter reads the source file" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Interpreters interpreters articles source files special code variables values values interests at the same time examples documents more friends knowledge editing industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL Docker Apple Shulou Tech Info