本文实例讲述了Python实现的在特定目录下导入模块功能。分享给大家供大家参考,具体如下:
方法1、在指定的目录下导入特定模块,(tab.py换行自动补齐语法模块)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
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目录下直接导致
1
2
3
4
5
6
7
8
|
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程序设计有所帮助。
原文链接:https://blog.csdn.net/xwbk12/article/details/72353805