我正在尝试调试其他人构建的 Web 应用程序。该应用程序应该解析一个文本文件,其中包含以逗号分隔格式表示地理航点的行。当在 Windows 应用程序(如 notepad++)或基于 Web 的文本查看器https://filehelper.com中查看时,这些行看起来应该如此,即:
name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc
"Abfaltersb Chp",Abfalter,,4645.518N,01232.392E,952.0m,1,,,,
"Admont Chp",Admont C,,4734.994N,01427.156E,628.0m,1,,,,
"Admont Stift Kir",Admont S,,4734.517N,01427.700E,646.0m,1,,,,
"Admonterhaus",Admonter,,4737.917N,01429.483E,1720.0m,1,,,,
"Aflenz Kirche",Aflenz K,,4732.717N,01514.467E,772.0m,1,,,,
但是当我在循环中使用'cherrypy.log('line%s: %s' % (wpnum, line))在 Linux 终端窗口中显示行时,我得到:
[09/Dec/2024:23:37:08] line1: b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n'
[09/Dec/2024:23:37:08] line2: b'"Abfaltersb Chp",Abfalter,,4645.518N,01232.392E,952.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08] line3: b'"Admont Chp",Admont C,,4734.994N,01427.156E,628.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08] line4: b'"Admont Stift Kir",Admont S,,4734.517N,01427.700E,646.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08] line5: b'"Admonterhaus",Admonter,,4737.917N,01429.483E,1720.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08] line6: b'"Aflenz Kirche",Aflenz K,,4732.717N,01514.467E,772.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08] line7: b'"Afritz Church",Afritz C,,4643.650N,01347.983E,710.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08] line8: b'"Aich Assac Chp",Aich Ass,,4725.480N,01351.460E,736.0m,1,,,,\r\n'
在每行的开头添加“b'”。
所以我的问题是 - Python 的 lines = file.readlines() 函数是否真的在每一行中添加了“b'”,或者这是 cherrypy.log() 机制的某种产物?或者,正如 1981 年 Memorex 磁带广告所说的那样,“它是真实的,还是 Memorex?”
短暂性脑缺血发作,
坦率
b 表示字节。即如果内容以二进制模式登录,则会出现 'b'。如果你想让这个 'b' 消失,请在你的 python 代码中添加以下行。
cherrypy.log(data.decode('utf-8'))