小编bka*_*e56的帖子

Python unicode在写入文件时转换为ASCII

我正在编写一个脚本来浏览音乐库并打印一个带有专辑名称日期的.txt文件......然后编号轨道.它完美地工作,直到导入的标签(作为unicode)到达( - ).然后我得到一个:

  File "C:/Users/Brian/Python files/CDinfoRF2.py", line 51, in music_album_info
    mfile.write(header)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 18: ordinal not in range(128).
Run Code Online (Sandbox Code Playgroud)

代码:

#!usr/bin/env python
__author__ = 'Brian Kane'

"""This scripts takes a path argument to the root directory of the music files (mp3 here) and
   writes various information about the disc to a text file which is named by the artist"""

import io
import os
from os.path import *
import string
from mutagen.mp3 import MP3
from …
Run Code Online (Sandbox Code Playgroud)

python unicode converter non-ascii-characters

1
推荐指数
1
解决办法
284
查看次数

标签 统计

converter ×1

non-ascii-characters ×1

python ×1

unicode ×1