全部博文(695)
分类: Python/Ruby
2015-12-04 13:47:07
原文地址:import 与from import 的区别 作者:yfjelley
1 2 3 4 5 6 7 8 9 10 | import sys print('================Python import mode=========================='); print ('The command line arguments are:') for i in sys.argv: print (i) print ('\n The python path',sys.path) from sys import argv,path#导入特定的成员 print('================python from import===================================') print('path:',path) |
1 | print(sys.path)['D:/xx/PythonSERVER/python31/Code', 'D:\\xx\\PythonSERVER\\python31\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python31.zip', 'D:\\xx\\PythonSERVER\\python31\\DLLs', 'D:\\xx\\PythonSERVER\\python31\\lib', 'D:\\xx\\PythonSERVER\\python31\\lib\\plat-win', 'D:\\xx\\PythonSERVER\\python31', 'D:\\xx\\PythonSERVER\\python31\\lib\\site-packages'] |
1 2 3 4 5 6 | import syss Traceback (most recent call last): File "D:/xxx/xxx/xx/Code/test.py", line 19, in <module> import syss ImportError: No module named syss |
1 2 3 4 5 6 7 8 9 | #!/user/bin/python #Filename:mymodel.py version = '1.0' def sayHello(): print ('Hello world') def modelName(): return __name__#返回它自己的名称 #end of model 以上语句注意: |
1 2 3 4 5 6 7 8 9 10 11 | import sys,mymodel sys.path.append('D:/xx/PythonSERVER/python31/Code')#提供搜索路径 print(__name__) #此处打印主模块的名称:__main__ mymodel.sayHello() print('Version',mymodel.version) print('Model Name',mymodel.modelName())#打印被导入模块的名称: mymodel 我们使用from..import... print('======================from.....import=====================================') from mymodel import * print(__name__) #此处打印主模块的名称:__main__ sayHello() print('Version',version) print('Model Name',modelName()) #打印被导入模块的名 称: mymodel |