Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

python - CPython编译成.so后,python print()输出元组(python print() output tuple after being CPython compiled into .so)

The python print() will only print its arguments like a tuple after this .py is CPython-compiled into a .so and being imported.

(将这个.py CPython编译成.so并导入后,python print()只会像元组一样打印其参数。)

How can it behave like it is a normal py file?

(它如何表现得像普通的py文件?)

The scenarios is like this.

(场景是这样的。)

Here is a function output() defined in mod4.py:

(这是在mod4.py中定义的函数output() :)

def output(a, b):
    print(a, b, str(a)+str(b))

I use following code to call output() :

(我使用以下代码来调用output() :)

import mod4
mod4.output(2, 3)

the output will be like:

(输出将是这样的:)

2 3 23

However, if I use CPython to compile mod4.py into mod4.cpython-37m-darwin.so, and the code above will generate output like:

(但是,如果我使用CPython将mod4.py编??译为mod4.cpython-37m-darwin.so,则上面的代码将生成如下输出:)

(2, 3, '23')

it looks just like a tuple of the arguments of print().

(它看起来就像是print()参数的元组。)

How can I get output() in .so outputs just like it in .py?

(如何在.so输出中获得与.py一样的output() ?)

  ask by Cuteufo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...