Why does printing html code as a string give hexadecimal numbers as output in python?

前端 未结 1 1142
醉酒成梦
醉酒成梦 2021-01-25 06:11

I wrote a Python code to modify my html contents. But on writing that again to the html file, I get weird hexadecimal numbers

import re

search=\"www.abc.com\"

         


        
相关标签:
1条回答
  • 2021-01-25 06:17

    When you truncated your file, you didn't actually seek back to position 0 in the file. The file position is still where it was, which is now past the end of the file.

    Writing to the file writes the text at the old file position, leaving everything before that point blank.

    The hex isn't caused by anything in the code you've posted. You've opened the file in a tool that's showing you the raw hex values of the bytes. This tool might be doing that because of all the null bytes.

    0 讨论(0)
提交回复
热议问题