def test_name(): assert 'youk' == name()
It’s much better to: 最好是这样做: - reference names through their module (fully qualified identifier) - 通过模块来引用名字 - import a long module using a shorter name (alias, recommend) - 把它import成更简短的名字,别名 - or explicitly import just the names your need. - 或者直接只import你要用的名字 Reference names through their module (fully qualified identifier) 通过模块来引用名字 import module module.name Or import a long module using a shorter name (alias) 或者是给一个有长名字的模块一个短的别名 import long_module_name as mod mod.name Or explicitly import just the names you need: 或者直接从模块中import你想要的名字 from module import name name Note that this form doesn’t lend itself to use in the interactive interpreter, where you may want to edit and “reload()” a module. 在交互式解释器中,你可能不能直接这样写,你要先’reload()’,如果你想要修改一个模块。
import module #imported module module.name('Niraj Rasal')
#import module frmo local directory import sys sys.path.append("/rhome/cjinfeng/software/ProgramPython/module/lib") from module import name import module2 #lib.module.sayHi() #lib.module.name() name() #print(lib.module.version) module2.sayHi2() #print(module2.version)