python interactive mode_Python中“inspect”和“interactive”命令行标志之间的区别

根据

pythonrun.c对应的Py_InspectFlag和Py_InteractiveFlag使用如下:

int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */

/* snip */

static void

handle_system_exit(void)

{

PyObject *exception, *value, *tb;

int exitcode = 0;

if (Py_InspectFlag)

/* Don't exit if -i flag was given. This flag is set to 0

* when entering interactive mode for inspecting. */

return;

/* snip */

}

如果“inspect”标志为true,Python不会在SystemExit上退出.

int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */

/* snip */

/*

* The file descriptor fd is considered ``interactive'' if either

* a) isatty(fd) is TRUE, or

* b) the -i flag was given, and the filename associated with

* the descriptor is NULL or "" or "???".

*/

int

Py_FdIsInteractive(FILE *fp, const char *filename)

{

if (isatty((int)fileno(fp)))

return 1;

if (!Py_InteractiveFlag)

return 0;

return (filename == NULL) ||

(strcmp(filename, "") == 0) ||

(strcmp(filename, "???") == 0);

}

如果“interactive”标志为false并且当前输入未与终端关联,则python不会打扰进入“交互”模式(unbuffering stdout,打印版本,显示提示等).

-i选项打开两个标志.如果PYTHONINSPECT环境变量不为空,则“inspect”标志也会打开(参见main.c).

基本上它意味着如果您设置PYTHONINSPECT变量并运行您的模块然后python不会退出SystemExit(例如,在脚本的末尾)并显示交互式提示而不是(允许您检查您的模块状态(因此“检查”) “国旗的名称)).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值