with open之后输出的内容如何换行,用print就行

>>> with open('hello.txt','r') as f:
...     s=f.read()
...     s
...     print(s)
...
'1\t2\n3\t4\n5\t6'
1       2
3       4
5       6
>>>

在命令行直接输出f.read(),得到的结果是连续的,有\t制表符和\n换行符

输出print(f.read())就可以得到更清晰的结果

此外(如下:)  readlines()得到的结果是一个list

>>> with open(fpath,'r') as f:
...     s=f.readlines()
...     print(s)
...
['; for 16-bit app support\n', '[386Enh]\n', 'woafont=dosapp.fon\n', 'EGA80WOA.FON=EGA80WOA.FON\n', 'EGA40WOA.FON=EGA40WOA.FON\n', 'CGA80WOA.FON=CGA80WOA.FON\n', 'CGA40WOA.FON=CGA40WOA.FON\n', '\n', '[drivers]\n', 'wave=mmdrv.dll\n', 'timer=timer.drv\n', '\n', '[mci]\n']

 

你可能感兴趣的:(with open之后输出的内容如何换行,用print就行)