首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

sys.stdout.write,返回的结果如何会有长度

2013-03-21 
sys.stdout.write,返回的结果怎么会有长度sys.stdout.write(abc)abc3不是应该返回adb吗?怎么后面还有一

sys.stdout.write,返回的结果怎么会有长度

sys.stdout.write("abc")
abc3
不是应该返回adb吗?怎么后面还有一个3
[解决办法]

引用:
abc是执行结果,3是write函数的返回值,估计是字串长度,交互模式会把语句的返回值打印出来,你用改用脚本方式执行就不会打印3出来...

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AM
D64)] on win32
Type "help", "co……


eee 
好久没做windows开发了
这个交互式 windows下有返回值?

>>> import sys
>>> sys.stdout.write("abc")
abc>>> 
>>> sys.stdout.write("abcd")
abcd>>> 

linux下如上输出
[解决办法]
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.write('abc')
abc>>>
[解决办法]
好像我说的有点简单了~,那就复杂一点吧~!(把所有的“~”换成空格)

1.~sys.stdout~是不一样的

在idle中是这样
>>>~sys.stdout
<idlelib.rpc.RPCProxy~object~at~0x00F3E290>
>>>~help(sys.stdout.write)
Help~on~MethodProxy~in~module~idlelib.rpc~object:

class~MethodProxy(builtins.object)
~
[解决办法]
~~Methods~defined~here:
~
[解决办法]
~~
~
[解决办法]
~~__call__(self,~*args,~**kwargs)
~
[解决办法]
~~
~
[解决办法]
~~__init__(self,~sockio,~oid,~name)
~
[解决办法]
~~
~
[解决办法]
~~----------------------------------
~
[解决办法]
~~Data~descriptors~defined~here:
~
[解决办法]
~~
~
[解决办法]
~~__dict__
~
[解决办法]
~~~~~~dictionary~for~instance~variables~(if~defined)
~
[解决办法]
~~
~
[解决办法]
~~__weakref__
~
[解决办法]
~~~~~~list~of~weak~references~to~the~object~(if~defined)


在cmd(shell)中是这样
C:\>python~-c~"import~sys;print(type(sys.stdout))"
<class~'_io.TextIOWrapper'>

C:\>python~-c~"import~sys;help(sys.stdout.write)"
Help~on~built-in~function~write:

write(...)

好像这里的help不够,那就F1~。15.2.3.4~~class~io.TextIOBase~
write(s)~
Write~the~string~s~to~the~stream~and~return~the~number~of~characters~written.




2.~MethodProxy~~在文件~Lib\idlelib\rpc.py~中~,他的定义是

class~MethodProxy(object):

~~~~def~__init__(self,~sockio,~oid,~name):
~~~~~~~~self.sockio~=~sockio
~~~~~~~~self.oid~=~oid
~~~~~~~~self.name~=~name

~~~~def~__call__(self,~*args,~**kwargs):
~~~~~~~~value~=~self.sockio.remotecall(self.oid,~self.name,~args,~kwargs)
~~~~~~~~return~value

sockio也同样在rpc.py中。~~我也就只能看到这里了。

############################以下是注释的部分
"""
我发现了一个问题,我该怎么找到~self.sockio.remotecall中的remotecall呢?
我想了一个最简单的方法,搜索def~remotecall。
还应该记录当前的函数,就像eclipse的call~hierarchy一样。
还应该给函数加上中文的名字(名字或许没必要,但是中文的注释就有必要了,
要能够显示在hierarchy中,如何做到呢?可以用overlay、可以新建buffer、可以临时跳转)
那就这样吧~!可以去看看ipython。
"""

[解决办法]
看起来2.x版应该是没有返回值,,,

热点排行