import module1,mudule2...
模块名.函数名
import math #这样会报错 print(sqrt(2)) #这样才能正确输出结果 print(math.sqrt(2))
from 模块名 import 函数名1,函数名2....
from modname import name1[, name2[, ... nameN]]
from fib import fibonacci
from modname import *
In [1]: import time as tt
In [2]: time.sleep(1)
---------------------------------------------------------------------------
NameError Traceback (most recent call last) <ipython-input-2-07a34f5b1e42> in <module>()
----> 1 time.sleep(1)
NameError: name 'time' is not defined
In [3]: In [3]: In [3]: In [4]: In [4]: In [4]:
tt.sleep(1)
from time import sleep as sp
In [5]: --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-5-82e5c2913b44> in <module>()
----> 1 sleep(1)
NameError: name 'sleep' is not defined In [6]:
In [6]:
In [6]: sp(1)
In [7]:
├── setup.py
├── suba
│ ├── aa.py
│ ├── bb.py
│ └── __init__.py
└── subb
├── cc.py
├── dd.py
└── __init__.py
from distutils.core import setup setup(name="dongGe", version="1.0", description="dongGe's module", author="dongGe", py_modules=['suba.aa', 'suba.bb', 'subb.cc', 'subb.dd'])
. ├── build │ └── lib.linux-i686-2.7 │ │ │ │ │ │ │ │ ├── setup.py ├── suba │ ├── aa.py │ ├── bb.py │ └── __init__.py └── subb ├── cc.py ├── dd.py └── __init__.py
python setup.py sdist

from 模块名 import 模块名或者*
test.py
def add(a,b):
return a b
main.py import test result = test.add(11,22) print(result)
def add(a,b):
return a b
# 用来进行测试
ret = add(12,22)
print('int test.py file,,,,12 22=%d'%ret)import test result = test.add(11,22) print(result)