import 與 from...import 在 python 用 import 或者 from...import 來導入相應的模塊。 將整個模塊(somemodule)導入,格式為: import somemodule 從某個模塊中導入某個函數,格式為: from somemodule import somefunction 從某個模塊中導入多個函數,格式為: from somemodule import firstfunc, secondfunc, thirdfunc 將某個模塊中的全部函數導入,格式為: from somemodule import * 導入整個塊 import sys print ('命令行參數為:') for i in sys.argv: print (i) print ('\n python 路徑為',sys.path) 導入具體的模塊 直接運行: #!/usr/bin/python # -*- coding: UTF-8 -*- from sys import argv,path print('path:',path) 交互模式: >>> from sys import argv,path >>> print('path:',path) path: ['', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\Lib\\idlelib', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\python36.zip', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\DLLs', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\lib', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\lib\\site-packages'] |
|