Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 一个文件中\n使用多少字节?_File_Python 3.x - Fatal编程技术网

File 一个文件中\n使用多少字节?

File 一个文件中\n使用多少字节?,file,python-3.x,File,Python 3.x,为什么它们都给我相同的输出:['\n',1345435 35tdgf\n',fggfsty tgds3st545'] 文件“t1.txt”: testcheckfdgddhd 1345435 35tdgf fggfsty tgds3st545 此代码 f=open("t1.txt","r+") f.seek(16) l=f.readlines() print(l) 这个密码呢 f=open("t1.txt","r+") f.seek(17) l=f.readlines()

为什么它们都给我相同的输出:['\n',1345435 35tdgf\n',fggfsty tgds3st545']

文件“t1.txt”:

testcheckfdgddhd  
1345435 35tdgf  
fggfsty tgds3st545  
此代码

 f=open("t1.txt","r+")
 f.seek(16)
 l=f.readlines()
 print(l)
这个密码呢

f=open("t1.txt","r+")
f.seek(17)
l=f.readlines()
print(l)
两者都提供相同的输出:
['\n',1345435 35tdgf\n',fggfsty tgds3st545']

这是为什么?

在Windows上,在文本模式下(与二进制模式相对)'r+b',\n写为\r\n,读为\r\n。在一种情况下,您碰巧正在查找\r,而在另一种情况下,您正在查找以下\n


切换到二进制模式以查看差异

十六进制编辑器对于回答这样的问题很有用。我推荐HxD。