b=1
c=2
F = ('n'.join(open('C:\\Users\\Administrator\\Desktop\\ID.txt','r').readlines()[str(b):str(c)]))
运行结果报错
NameError: name 'b' is not defined
怎样才能将变量代入,不会出错
运行结果报这个:TypeError: slice indices must be integers or None or have an __index__ method
请问encoding='gbk'这个是什么意思?
追答使用gbk编码打开你的txt文件,如果你的txt文件编码是utf-8的,那么这里就需要修改为utf-8
追问F = ('n'.join(open('C:\\Users\\Administrator\\Desktop\\ID.txt','r', encoding='utf-8').readlines()[b:c]))
TypeError: 'encoding' is an invalid keyword argument for this function
还是报错了
直接写b和c 也报错了
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe0 in position 0: unexpected end of data
试试open('C:\\Users\\Administrator\\Desktop\\ID.txt','r').readlines().decode('gbk')
追问我的变量怎么带进去?
追答open('C:\\Users\\Administrator\\Desktop\\ID.txt','r').readlines().decode('gbk')[b:c]
追问额 还是有错AttributeError: 'list' object has no attribute 'decode'有没有联系方式私信一下吧