【问题标题】:print function in python3.x?python3.x中的打印功能?
【发布时间】:2011-03-25 06:24:12
【问题描述】:

我想知道打印功能是如何工作的。但是在python3.2的源码中找不到打印功能!

在 python2.5 中打印一个整数(例如打印 100),将调用 int_print()。因为在创建 int 对象时,初始化 PyIntObject 的函数指针 - tp_print 指向 int_print():

printfunc tp_print;
/* We can't provide a full compile-time check that limited-API
   users won't implement tp_print. However, not defining printfunc
   and making tp_print of a different function pointer type
   should at least cause a warning in most cases. */
typedef int (*printfunc)(PyObject *, FILE *, int);

在python3.x中,所有整数都是PyLongObject的对象,但它初始化tp_print=NULL。而且print是一个不像python2.x的函数。 请在调用打印时告诉我,它是如何工作的!非常感谢!

【问题讨论】:

    标签: printing python-3.x


    【解决方案1】:

    我已经知道了!打印内置对象时,print() 会调用 builtin_print() 函数。

    builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
    

    【讨论】:

      猜你喜欢
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      相关资源
      最近更新 更多