Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个问题,我有一个歌曲播放列表,使用codecs.open(filename, encoding='utf8'). 播放列表文件中的每两行在第一行包含元数据,在第二行包含曲目文件名。
codecs.open(filename, encoding='utf8')
文件名是 unicode 格式,我遇到了一些由于标记错误或字符集不匹配而在名称中包含 \x85 字符的曲目标题。所以会有一个类似的元数据行'Title title \x85 title - artist,并且在使用 readline 读取文件时会错误地换行。
'Title title \x85 title - artist
我解决了这个问题。而不是调用file.readline,我将有一个包装 readline 的函数。最初我逐个字符地处理它,这很慢,但后来我过早地忘记了 readline 中断,并且可以通过进一步的调用将其构造成正确的行。
file.readline
def getline(_file): ln = '' while True: _ln = _file.readline() ln += _ln if not _ln: break; if _ln[-1] == '\n': break return ln
我认为我已经习惯了关于项目中 PHP 声明的相当自由的政策 - 我一直只是使用:
<? // here is my php code ?>
我只是在 FastCGI 下使用 PHP-FPM 设置了一个 nginx 服务器,现在它需要我明确声明:
<?php // here is my php code ?&