IPython是怎么回事?操作员实际工作? [英] how does IPython's ? operator actually work?

查看:159
本文介绍了IPython是怎么回事?操作员实际工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我认为,为了在控制台应用程序中实现这样的功能,在函数名称的末尾附加问​​号会将它的文档字符串倒出,我可能会使用像元类一样的功能,其中在定义/导入时,我会复制所有模块成员名称并生成新的名称只是为了输入文档字符串。

So i was thinking that in order to implement such a feature in a console application , where appending a question mark at the end of a function name will pour out it's doc string , i would have probably used a feature like metaclasses , where upon definition/import , i'd duplicate all the module member names and produce new ones just for typing out doc strings.

然后我注意到你不需要实际调用辅助函数的括号和python实际上并不允许你在函数名的末尾添加一个问号....所以这是在python中完成的还是我只是在浪费时间试图弄清楚这一点?

Then i noticed that you don't need actual parenthesis to call the helper functions and python doesn't actually allow you to put a question mark at the end of the function name anyway.... So is this done in python or am i just wasting my time trying to figure this out?

提前致谢

推荐答案

这不是你的方式'重新想象。 ipython将您的命令提示输入作为一行文本读取,因此它有机会检查它是否以问号结尾,然后再将其传递给 eval (或其他) 。如果是的话,它会运行 help(name)而不是你输入的内容。

It's not done the way you're imagining. ipython reads your command prompt input as a line of text, so it has a chance to check if it ends with a question mark before it passes it on to eval (or whatever). If it does, it runs help(name) instead of what you typed.

AST看起来有点重 - 责任,但你可以通过检查模块代码来了解其工作原理。它为您提供了一个轻量级的解释器,如果需要,可以使用此类语法进行扩展。

AST looks a little heavy-duty, but you can get a feel for how this works by checking out the module code. It gives you a lightweight interpreter that you can extend with syntax of this sort if you want.

这篇关于IPython是怎么回事?操作员实际工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆