标签:atm style 提示 play random closed mod app module
import hm_01_测试模块1 import hm_02_测试模块2 hm_01_测试模块1.say_hello() dog = hm_01_测试模块1.Dog() print(dog) hm_02_测试模块2.say_hello() cat = hm_02_测试模块2.Cat() print(cat) print(hm_01_测试模块1.title) print(hm_02_测试模块2.title)
import hm_01_测试模块1 as DogModule import hm_02_测试模块2 as CatModule DogModule.say_hello() dog = DogModule.Dog() print(dog) CatModule.say_hello() cat = CatModule.Cat() print(cat) print(DogModule.title) print(CatModule.title)
from hm_01_测试模块1 import Dog from hm_02_测试模块2 import Cat # 如果两个模块,存在同名的函数,那么导入模块的函数,会覆盖掉先导入的函数 from hm_02_测试模块2 import say_hello from hm_01_测试模块1 import say_hello # 不需要使用模块调用类了 dog = Dog() print(dog) cat = Cat() print(cat) say_hello()
from hm_01_测试模块1 import Dog
from hm_02_测试模块2 import Cat
# 如果两个模块,存在同名的函数,那么导入模块的函数,会覆盖掉先导入的函数
# 统一写在顶部,可以使用别名as分别定义同名的函数
from hm_02_测试模块2 import say_hello as say_hello1
from hm_01_测试模块1 import say_hello as say_hello2
# 不需要使用模块调用类了
dog = Dog()
print(dog)
say_hello1()
say_hello2()
from import *(不建议使用)
函数重名没有任何的提示,出现问题不好排查
import random
rand = random.randint(1, 10)
print(random.__file__)
print(rand)
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\random.py
6
标签:atm style 提示 play random closed mod app module
原文地址:https://www.cnblogs.com/joycezhou/p/11402771.html