SoFunction
Updated on 2024-10-29

python environment variables and import module import method (detailed)

1. Definitions

Modules: essentially files ending in .py (logically organizing python code) The essence of a module is that it implements a function The filename is the name of the module

Package: a folder with __init__.py; used to store module files

2、Import Module

import module name

form module name import *

from module name import module name as new name

3. Introducing the essence of the module

import module name ==== " Assign all the data in the module to the module name, the call requires module name. method name ()

from module name import method name == "Put the method into the current file and run it again, when you call it, you only need the method name () to run it.

Importing a package means executing the __init__.py file under the package.

Path Search

import sys,os

(__file__) # get the full name of the current file

() # Get the parent directory of the current object

()# Add the path of the current object to the first place

() # Add the current environment variable to the end of the environment variables

Above this python environment variables and import module import method (detailed) is all I have shared with you, I hope to give you a reference, and I hope you support me more.