标签:handle name 程序 nbsp sha 文件名 fun add sel
from py文件名 import 类/函数
from 目录名.py文件名 import 类/函数
文件结构:
|-sub |-class_test.py |-test.py
class_test.py
class Dog:
def say_hello(self):
print(‘hello world‘)
@staticmethod
def say():
print(‘hello‘)
test.py
if __name__ == ‘__main__‘:
dog = Dog()
dog.say_hello()
Dog.say()
from module import class/function
外部引用包:
from 包名.module import class/function
外部则可以模糊导入:
from 包名.module import *
文件结构:
|-package_a |-__init__.py |-handle.py |-log.py |-data.py
log.py:
def log(fun):
def wrapper(*args, **kwargs):
print(‘call: %s‘ % fun.__name__)
return fun(*args, **kwargs )
return wrapper
handle.py:
@log
def add(x, y):
return x + y
if __name__ == ‘__main__‘:
print(add(1,2))
__init__.py:
__all__ = [‘handle‘, ‘log‘]
data.py
from package_a import * print(handle.add(10, 20))
标签:handle name 程序 nbsp sha 文件名 fun add sel
原文地址:https://www.cnblogs.com/itfenqing/p/10284353.html