>>> os.chdir('/Users/macbookpro/Desktop')
>>> with open('demo.txt', 'w') as fp:
print(type(fp))
>>> 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()显示它又是存在的——既然文件操作已经结束,还要文件指针有什么用?