Skip to content
Advertisement

Python 3.10 read from playlist file, wrong first character of first line

File: main_nested.aimppl

JavaScript

File: read_playlist_file.py

JavaScript

Output:

JavaScript

Expected output:

JavaScript

As you can see in the first line there is no # print.

This file was created from python3.10. Maybe you can’t reproduce this problem. Maybe it’s a utf-bom character issue.

This code works:

JavaScript

What’s the problem with the first code, and what it’s the appropriate solution?

Advertisement

Answer

“Maybe it’s a utf-bom character issue.” Yes, that’s it. You can check your file with e.g. hexdump -c on the command line. The first 3 bytes should be 0xEF, 0xBB, 0xBF if it’s a utf8-with-BOM file.

“what it’s the appropriate solution?” What you did is exactly right. encoding='utf_8_sig' is for utf8-with-BOM files.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement