Python跨文件调用函数实例:
# main.py
import supportlibrary
s = supportlibrary.say
s.nema("at","SB")
s.hello()
s.saytime()
# supportlibrary.py
import time
class say:
def nema(a,b):
print("{0} say:{1}".format(a,b))
def hello():
print("hello world")
def saytime():
print(time.time())
请放在同个目录下,supportlibrary.py不能编译!(此项目不做解释,自行理解)
code china 项目
使用方法
运行main
简单实例+说明
# main.py
import supportlibrary# 引入函数文件
s = supportlibrary.say# 将supportlibrary.say简化为s
s.hello()# 执行函数hello
# supportlibrary.py
class say:# 定义say类
def hello():# 定义hello函数
print("hello world")# 打印hello world