[Python的自由天空] 有人熟悉_io.TextIOWrapper这个类吗

发信人: z12366 (z12366), 信区: Python
标 题: 有人熟悉_io.TextIOWrapper这个类吗
发信站: 水木社区 (Fri Apr 27 01:37:02 2018), 转信

>>> os.chdir('/Users/macbookpro/Desktop')
>>> with open('demo.txt', 'w') as fp:
print(type(fp))
<class '_io.TextIOWrapper'>
>>> dir(fp)
['_CHUNK_SIZE', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', '_finalizing', 'buffer', 'close', 'closed', 'detach', 'encoding', 'errors', 'fileno', 'flush', 'isatty', 'line_buffering', 'mode', 'name', 'newlines', 'read', 'readable', 'readline', 'readlines', 'seek', 'seekable', 'tell', 'truncate', 'writable', 'write', 'writelines']

=======================================

貌似是文件句柄的类。
但是它前面加了一个单下划线,临时用一下的意思。

本来感觉fp在with语句退出后就自行销毁了,但是globals()显示它又是存在的——既然文件操作已经结束,还要文件指针有什么用?
--

※ 来源:·水木社区 http://www.newsmth.net·[FROM: 112.28.140.*]


from 水木社区 电脑技术区十大热门话题 https://ift.tt/2r26iCN
via IFTTT

评论

此博客中的热门博文

丰田将在 2019 东京车展上展出一台超迷你的都市型电动车

[数字家庭] [原创]北京联通IPTV的完美方案

英特尔将推出更多支持 e-SIM 的 modem