请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

5-2中,python3没有readinto方法

视频中是这样的,

buf = array.array('h', (0 for _ in range(n)))
f.readinto(buf)

然后我用这种方法解决了,请问有更好的方法吗?

buf = array.array('h', [])
buf.frombytes(f.read())


正在回答

2回答

buf.fromfile

0 回复 有任何疑惑可以回复我~
qq_蜜思丹海天_0 2018-01-05 15:47:54

array.fromfile(f, n)

Read n items (as machine values) from the file object f and append them to the end of the array.  If less than n items are available,EOFError is raised, but the items that were available are still inserted into the array. f must be a real built-in file object; something else with a read() method won’t do.


1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号