python import 注意事项

Python 导入都有哪几种写法呢?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from xxx import yyy, zzz  //此处的yyy可能对应xx/yyy.py文件。 也有可能是xxx.py中的一个变量。 
from xxx import *
import xxx
import xxx as x

------
#!/bin/env pthon
""" 文件a.py"""
from xxx import yyy // 相当于声明了yyy变量,指向了xxx.py 中的yyy变量
yyy = 1 //此时yyy变量的指向就被改变了。指向了值1

"""文件b.py"""
from xxx import yyy
print(yyy)
Author: Chandler Kwok
Link: http://yoursite.com/2020/06/03/python-import-%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.