python sys模块sys.path使用方法示例
时间:2023-01-12 22:52:15
python sys模块包含了与python解释器和它的环境有关的函数,这个你可以通过dir(sys)来查看他里面的方法和成员属性
import sys
print dir(sys)
result:
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'getwindowsversion', 'hexversion', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'py3kwarning', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver']
import sys
print sys.path
result:
['C:\\Documents and Settings\\username\\My Documents\\Aptana Studio 3 Workspace\\Python_Test_Project\\src', 'C:\\Documents and Settings\\username\\My Documents\\Aptana Studio 3 Workspace\\Python_Test_Project\\src', 'C:\\Python27', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode', 'C:\\WINDOWS\\system32\\python27.zip']
里面有个 sys.path属性。他是一个list.默然情况下python导入文件或者模块的话,他会先在sys.path里找模块的路径。如果没有的话,程序就会报错。
所以我们一般自己写程序的话。最好把自己的模块路径给加到当前模块扫描的路径里,eg: sys.path.append('你的模块的名称'),这样程序就不会
因为找不到模块而报错。。
标签:python,sys模块,sys.path


猜你喜欢
Oracle 管道 解决Exp/Imp大量数据处理问题
2024-01-21 22:15:16
Python集合的增删改查操作
2023-09-30 00:48:18
python数字图像处理图像的绘制详解
2022-05-29 07:33:49

解决jupyter运行pyqt代码内核重启的问题
2022-01-29 21:28:40

python 如何查看pytorch版本
2021-02-05 05:38:59
python函数超时自动退出的实操方法
2021-09-11 07:07:45
oracle常用sql语句
2010-07-23 13:27:00
mycat在windows环境下的安装和启动
2024-01-17 08:07:14
Pytorch中.new()的作用详解
2023-12-11 10:28:54
用javascript实现select的美化
2007-05-11 16:50:00
pandas object格式转float64格式的方法
2022-05-26 15:58:53
Python实现ATM简单功能的示例详解
2021-07-17 12:06:46

基于jQuery 实现bootstrapValidator下的全局验证
2024-04-08 10:56:41
基于python 字符编码的理解
2021-02-04 09:53:25
[组图]手把手教你制作ASP留言本
2007-09-22 09:32:00

Go语言计算两个经度和纬度之间距离的方法
2024-04-29 13:06:04
Python使用Numpy模块读取文件并绘制图片
2022-03-11 07:11:58

常见SQL Server 2000漏洞及其相关利用
2007-10-01 14:45:00

ASP连接11种数据库语法总结
2007-09-29 12:07:00
由浅入深讲解python中的yield与generator
2022-08-14 06:26:11