【python】dir()不能輸出對象的全部屬性方法。

import os
res=os.popen('ipconfig')

dir(res)輸出的方法是不全的,

可以明確res的類型是

<os._wrap_close at 0x2a0ddb7dcc0>

更明確的是

{'_stream': <_io.TextIOWrapper name=4 encoding='cp936'>,
 '_proc': <subprocess.Popen at 0x2a0ddbf89e8>,
 '__dir__': 1}

且該對象擁有read,readlines等io操作方法,但這些方法dir()無法獲取到,但hasattr可以驗證這些方法的存在。

抽象基類

繼承

抽象方法

Mixin方法和屬性

IOBase

 

filenoseek, 和 truncate

closeclosed__enter____exit__flushisatty__iter____next__readablereadlinereadlinesseekabletellwritable 和 writelines

RawIOBase

IOBase

readinto 和 write

繼承 IOBase 方法, read, 和 readall

BufferedIOBase

IOBase

detachreadread1, 和 write

繼承 IOBase 方法, readinto, 和 readinto1

TextIOBase

IOBase

detachreadreadline, 和 write

繼承 IOBase 方法, encodingerrors, 和 newlines

更多關於該抽象基類的說明:

https://docs.python.org/zh-cn/3/library/io.html#io.TextIOWrapper

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章