Python特定目录下导入模块 Python实现的在特定目录下导入模块功能分析
徐为波 人气:0本文实例讲述了Python实现的在特定目录下导入模块功能。分享给大家供大家参考,具体如下:
方法1、在指定的目录下导入特定模块,(tab.py换行自动补齐语法模块)
root@kali:~# ls /root/python/ csvt01 csvtpy scan1.py scanhostport.py tab.py tab.pyc test.py root@kali:~# pwd /root root@kali:~# python Python 2.7.3 (default, Mar 14 2014, 11:57:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> import sys >>> sys.system('pwd') Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'system' >>> os.system('pwd') /root 0 >>> sys.path.append('/root/python/') >>> import tab >>>
方法2、可以直接在tab.py目录下直接导致
root@kali:~/python# ls csvt01 csvtpy scan1.py scanhostport.py tab.py tab.pyc test.py root@kali:~/python# python Python 2.7.3 (default, Mar 14 2014, 11:57:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tab >>>
希望本文所述对大家Python程序设计有所帮助。
加载全部内容