python
主页 > 脚本 > python >

Python实现的在特定目录下导入模块功能的教程

2019-02-12 | 徐为波 | 点击:
本篇文章介绍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
>>>


原文链接:
相关文章
最新更新