python - 交互式python解释器的欢迎信息来自哪里?
问题描述
python
在 Linux shell 上输入时,会打印欢迎消息:
[root@localhost ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
这些线是从哪里来的?它们是在编译或安装期间确定的吗?
我的系统上有另一个版本的python
可执行文件和一组库,但是当我输入它时python
,它也会显示与上面相同的欢迎消息。
谢谢,
更新:
我使用绝对路径来启动另一个版本的 python。刚刚发现欢迎信息与sys.version和sys.platform内容相同。但是如果我将其他版本的 python 复制到不同的 Linux 机器 B,并且仍然使用绝对路径来运行它。我明白了
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
此欢迎信息与机器 B 的 python 相同。
解决方案
编辑:C版源码类似: https ://github.com/python/cpython/blob/7e4db2f253c555568d56177c2fd083bcf8f88d34/Modules/main.c#L705
if (!Py_QuietFlag && (Py_VerboseFlag ||
(command == NULL && filename == NULL &&
module == NULL && stdin_is_interactive))) {
fprintf(stderr, "Python %s on %s\n",
Py_GetVersion(), Py_GetPlatform());
if (!Py_NoSiteFlag)
fprintf(stderr, "%s\n", COPYRIGHT);
}
它Py_GetVersion()
返回基于 MACRO 的版本
/* Version as a string */
#define PY_VERSION "3.7.0a0"
所以它是编译时间确定的,你可能有一个搞砸的PATH?
旧答案,实际上只是一个 python 模块
https://github.com/python/cpython/blob/7e4db2f253c555568d56177c2fd083bcf8f88d34/Lib/code.py#L214
if banner is None:
self.write("Python %s on %s\n%s\n(%s)\n" %
(sys.version, sys.platform, cprt,
self.__class__.__name__))
elif banner:
self.write("%s\n" % str(banner))
不确定这是否回答了您的问题,但知道仍然很有趣。
推荐阅读
- python - TensorFlow - 如何在不将它们添加到图形的情况下执行操作?
- math - 将 Sympy 表达式简化为变量的隐式函数
- android - Android Studio 在调试模式下运行仍然使用签名配置“发布”
- azure-container-instances - 我可以获取重新启动的 Azure 容器实例容器的先前实例的日志吗?
- tensorflow - LSTM 如何使用词嵌入进行文本分类,例如 Keras
- uwp - 联合身份 AAD 到 ADFS 重定向 | UWP 应用
- mysql - MySQL 双连接/数据透视表
- python - 如何在 Bokeh 中水平排列不同的小部件
- node.js - 将签名的 cookie 传递给 puppeteer
- wordpress - 如何在使用木材/树枝时使用 wordpress 主题自定义 API