Python Day05 python environment variables and import module import

PHP中文网
Release: 2017-07-11 18:13:05
Original
1222 people have browsed it

1.Definition

Module: The essence is a file ending in .py (logically organizing python code). The essence of a module is to implement a function. The file name is the module name

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. Import module essence

import module name ===》 Assign all data in the module to the module name. The module name.method name () is required when calling.

from module name import method name ==》Put this method into the current file and run it once. When calling, you only need the method name () to run it

Importing a package is to execute the __init__.py file under the package

Path search

import sys,os

os.path.abspath(__file__) #Get the full name of the current file

os.path.dirname() #Get the parent directory of the current object

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

sys.path.append() # Add the current environment variable to the end of the environment variable

The above is the detailed content of Python Day05 python environment variables and import module import. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template