【python】dir()不能输出对象的全部属性方法。

2 篇文章 0 订阅
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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值