【发布时间】:2016-03-24 14:56:44
【问题描述】:
Python BDD 框架 Behave 在其 runner.py 中有如下代码
with open(filename) as f:
# -- FIX issue #80: exec(f.read(), globals, locals)
# try:
filename2 = os.path.relpath(filename, os.getcwd())
code = compile(f.read(), filename2, 'exec')
如您所见,open 没有提供任何字符集。根据其文档,locale.getpreferredencoding 用于此类情况。
但在 Windows 上,这个函数总是返回一个字节的字符集(所谓的“非 unicode 程序的字符集”)。拉丁文是 Windows-1252,西里尔文是 Windows-1251 等。
所以,UTF-8 py 文件总是被破坏。
我的问题是,如果不想使用 1 字节字符集,如何在 Windows 上使用非 ascii 步骤定义和 Behave?
【问题讨论】:
标签: python windows unicode python-behave