|
入门帖子啊,多谢前辈大侠指点!
学习的脚本是Python2.x系列的,Python2.7的脚本:
import sys
class MyLog(object):
def __init__(self, file_obj = sys.stdout):
self.file_obj = file_obj
def log(self, s):
print >> self.file_obj, s
if __name__ == '__main__':
log_obj = MyLog()
log_obj.log('hello world 3')
运行结果:
hello world 3
尝试修改为Python3.7的脚本:
import sys
class MyLog(object):
def __init__(self, file_obj = sys.stdout):
self.file_obj = file_obj
def log(self, s):
print(s, self.file_obj)
if __name__ == '__main__':
log_obj = MyLog()
log_obj.log('hello world 3')
运行结果:
hello world 3 <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
问题: 为啥后面有一坨字符串 <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
需要怎么修改才能正常显示hello world 3?
|
|