为什么ironpythonsys.path与常规Python不一致?

2024-10-01 15:31:24 发布

您现在位置:Python中文网/ 问答频道 /正文

根据https://docs.python.org/2/library/sys.html#sys.path,sys.path中的第一项应该是最初由解释器调用的脚本的目录

我创建了一个简单的脚本,用于打印sys.path和sys.argv中包含的信息,并得到以下结果(注意,运行的两个脚本之间的唯一区别是/Python one有()用于打印,而/IronPython one没有:

System Info: 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] Copyright (c) 2001-2015 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.

Hello world!

Sys.Path:
 - c:\Users\220040509\workspace\ApplianceTools\Source\Scripts\Python
 - C:\Windows\system32\python34.zip
 - C:\Python34\DLLs
 - C:\Python34\lib
 - C:\Python34
 - C:\Python34\lib\site-packages

Sys.Argv:
 - <class 'str'> : Python/sysTest.py

System Info: 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] Copyright (c) 2001-2013 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.

Hello world!

Sys.Path:
 - c:\Users\220040509\workspace\ApplianceTools\Source\Scripts\IronPython
 - C:\Windows\system32\python27.zip
 - c:\Python27\DLLs
 - c:\Python27\lib
 - c:\Python27\lib\plat-win
 - c:\Python27\lib\lib-tk
 - c:\Python27
 - c:\Python27\lib\site-packages

Sys.Argv:
 - <type 'str'> : IronPython/sysTest.py

System Info: 2.7.5 (IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.18063 (32-bit)) Copyright (c) IronPython Team

Hello world!

Sys.Path:
 - IronPython/sysTest.py
 - c:\Users\220040509\workspace\ApplianceTools\Source\Scripts\IronPython
 - c:\Program Files (x86)\IronPython 2.7\Lib
 - c:\Program Files (x86)\IronPython 2.7\DLLs
 - c:\Program Files (x86)\IronPython 2.7
 - c:\Program Files (x86)\IronPython 2.7\lib\site-packages

Sys.Argv:
 - <type 'str'> : IronPython/sysTest.py

为什么IronPython的脚本文件(也是sys.argv[0])是sys.path[0]

(在gitbash中运行了这个命令,因此使用了\和/)


Tags: pathpy脚本libsysallprogramcopyright

热门问题