I'm trying to debug a web app built by somebody else. The app is supposed to parse a text file containing lines that represent geographical waypoints in a comma-separated format. When viewed in a windows app like notepad++ or the web-based text viewer https://filehelper.com, the lines look like they should, i.e.:
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,,,,
but when I use 'cherrypy.log('line%s: %s' % (wpnum, line)) in a loop to display the lines in a linux terminal window, I get:
[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'
with the "b'" added to the beginning of each line.
so my question is - is Python's lines = file.readlines() function actually adding the "b'" to each line, or is this some artifact of the cherrypy.log() mechanism? Or, as the 1981 Memorex cassette tape commercial said, "Is it real, or is it Memorex?"
TIA,
Frank
b indicates bytes. i.e if the content is logged in as binary mode, then the 'b' will appear. If you want this 'b' to disappear, add the following line in your python code.
cherrypy.log(data.decode('utf-8'))