python 2到3迁移错误“;“读入”;方法
我转换了一个巨大的文件,是我在Python2.7.3中编写的,现在我想升级到Python3+(我有3.5)python 2到3迁移错误“;“读入”;方法,python,python-2to3,Python,Python 2to3,我转换了一个巨大的文件,是我在Python2.7.3中编写的,现在我想升级到Python3+(我有3.5) 到目前为止我所做的: 安装了python解释器3.5+ 已将环境路径更新为从python3+文件夹读取 升级了numpy,熊猫 我使用Python2to3.py-wviterbi.py将其转换为版本3+ 我有错误的部分 import sys import numpy as np import pandas as pd # Counting number of lines in the
import sys
import numpy as np
import pandas as pd
# Counting number of lines in the text file
lines = 0
buffer = bytearray(2048)
with open(inputFilePatheName) as f:
while f.readinto(buffer) > 0:
lines += buffer.count('\n')
我的错误是:
AttributeError: '_io.TextIOWrapper' object has no attribute 'readinto'
这是第一个错误,我无法继续查看是否存在任何其他错误。我不知道读入的等效命令是什么您是否尝试过将open(inputFilePatheName,'rb')作为f:?我现在做了,它说'lines+=buffer.count('\n')`类型错误:需要类似于对象的字节,而不是'str'。我的输入文件是一个文本文件/您是否尝试过
'rt'
或只是'r'
而不是'rb'
模式?谢谢,我有很多东西需要更改,因此,我认为最好在py3中重写代码