#Python 读取txt时跳过第一行

时间: 2023-07-29 admin 互联网

#Python 读取txt时跳过第一行

#Python 读取txt时跳过第一行

这东西很简单啊…为啥每个都要写的那么长还定义什么num呢?
直接加一个:

next(f)

这就好了呀

附上读取某几列的txt代码

def ReadTxt(filename):
    f = codecs.open(filename, mode='r', encoding='utf-8')
    next(f) #这就跳过第一行了啊
    line = f.readline()
    list1 = []
    while line:
        a = line.split()
        b = a[1:]
        list1.append(b)
        line = f.readline()
    f.close()
    return list1

如有失误请指出,谢谢

以上