In the Python module, is a python file that ends with a. Py and contains Python object definitions and Python statements
Through the import statement, the syntax
Import Module1[,module2,module3,.....]
A module will only be imported once, no matter how many times you do import. This prevents the import module from being executed over and over.
From ... import statement, syntax
from module import fun1[,fun2,fun3 ....]
Case:
From support import Print_name,print_func
Print_name ("John Doe")
Search Path
When importing a module, the Python parser's search order for the module location is:
1. Current directory (the path to the current project)
2. If it is not in the current directory, Python searches for each directory under the shell variable Pythonpath (can view the environment variables of the computer's properties, if it cannot be hidden, you can enter the path directly in the C-drive window)
3. If none are found, Python will look at the default path. Under UNIX, the default path is typically/user/local/python
The module search path is stored in the Sys.path variable of the system module. The variable contains the current directory, Pythonpath, and the default directory determined by the installation process.
4. You can use the Sys.path.append () function
For example, the module to be called has a support.py file under E:\pyproject\append
Sys.path.append ("e:\\pyproject\\append") Import Support
Dir function
A list of strings in a sequence that contains functions defined in the module
import mathcontent=// get all the built-in functions for this reference
Globals () and locals () functions
Globals () is called in the function and returns the function to access the global name.
Locals () is called in a function that returns the name that the function can access in the function.
The return type of two functions is a dictionary, so the name can be obtained with the keys () function.
Reload () function syntax:
Reload (module_name) // You can use this function if you want to import the module Hearts
function notes
system-related information module: Import SYSSYS.ARGV is a list that contains all the command-line arguments. Sys.stdout Sys.stdin Sys.stderr respectively represents the standard input output, the error output of the file object. Sys.stdin.readline () reads a line from the standard input sys.stdout.write ("a"screen Output a sys.exit (exit_code) Exit program Sys.modules is a dictionary that represents all the available module Sys.platform in the system to get running operating system environment SYS.P Ath is a list that indicates all paths to find Module,package. Operating system-related calls and actions: Import Osos.environ A dictionary contains the mapping of environment variables os.environ["HOME"] can get the environment variable home value Os.chdir (dir) changes the current directory Os.chdir ('D:\\outlook'Note that Windows uses the Escape OS.GETCWD () to get the current directory Os.getegid () get the valid group ID os.getgid () get the Group ID os.getuid () Get the User ID Os.geteuid () To a valid user ID Os.setegid os.setegid () os.seteuid () Os.setuid () os.getgruops () Get user group Name list os.getlogin () get user login name O S.GETENV Get environment variable OS.PUTENV SET environment variable Os.umask set umask os.system (CMD) use system call, run cmd command built-in module (can be used directly without import) commonly used built-in functions: Help (obj) online, obj is any type callable (obj) to see if an obj can call repr (obj) like a function to get the representation string of obj, which can be used to reconstruct a copy of the object Eval_r ( STR) represents a valid Python expression that returns the expression dir (obj) to view the name hasattr visible in obj's name space (Obj,name) to see if there is a name in the name space of obj Getatt R (Obj,name) obtains a name SetAttr (Obj,name,value) in the name space of obj as a name in the name space of obj pointing to Vale, the object delattr (obj , name) removes a name VARs (obj) from the name space of obj to return an object name space. Use dictionary to indicate that locals () returns a local name space, using dictionary to represent globals () to return a global name space, using the dictionary representation of type (obj) to view an obj Type isinstance (obj,cls) View obj is not CLS instance Issubclass (SUBCLS,SUPCLS) View SUbcls is not supcls subclass ################## type conversion ################# #chr (i) converts an ASCII value into character ord (i) converts a character or Unicode character into ASCII numeric Oct (x) turns an integer x into an octal representation of the string hex (x) converts an integer x into a hexadecimal representation of the string str (obj) to get the string description of obj list (seq) convert a sequence to a list tuple (seq) converts a sequence into a tuple dict (), Dict (list) into a dictionaryint(x) into an integerLong(x) Convert to a long intergerfloat(x) convert to a floating-point number Complex (x) to the plural max ( ...) to find the minimum of min (...)
The Python module