"SyntaxError: encoding issue: with BOM"



我正试图在django中运行一些cronjobs。

我有三个,其中两个运行完美。但第三个给了我错误:

../../monthly_abo_live.py", line 1
SyntaxError: encoding problem: with BOM

该文件的前2行是:

1. # -*- coding: utf-8 -*-
2. from django.core.management.base import BaseCommand, CommandError
3. ...

其他2个cronjobs与此相同。我被卡住了——为什么只有这个在抱怨?python似乎不支持utf-8?不可能,对吧?

根据本页:

http://legacy.python.org/dev/peps/pep-0263/

你有两个选择。。。

To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, such as:
    # coding=<encoding name>
or (using formats recognized by popular editors)
    #!/usr/bin/python
    # -*- coding: <encoding name> -*-

(注意:虽然以上是直接引用,但@tdelaney指出——我同意——应该使用#!/usr/bin/env python而不是固定路径#!/usr/bin/python。)

看起来您使用的是第二个选项的一部分,但没有包括所需的第一行(#!/usr/bin/python)。试着在"编码"行之前插入它,看看会发生什么。

最新更新