pythonsys模块sys.path使用方法示例
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了pythonsys模块sys.path使用方法示例,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1819字,纯文字阅读大概需要3分钟。
内容图文
![pythonsys模块sys.path使用方法示例](/upload/InfoBanner/zyjiaocheng/436/45c9bfb4eb324ce99fdf366c8032dbab.jpg)
代码如下:
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('你的模块的名称'),这样程序就不会
因为找不到模块而报错。。
内容总结
以上是互联网集市为您收集整理的pythonsys模块sys.path使用方法示例全部内容,希望文章能够帮你解决pythonsys模块sys.path使用方法示例所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。