bug in “django-admin.py makemessages” or xgettext call? -> “warning: unterminated string”

后端 未结 1 1824
梦谈多话
梦谈多话 2021-01-27 13:20

django-admin.py makemessages dies with errors \"warning: unterminated string\" on cases where really long strings are wrapped:

string = \"some          


        
1条回答
  •  情歌与酒
    2021-01-27 14:02

    I can think of two possibilities: you might have an extra space after your backslash at the end of the line; or you might be somehow ending up with the wrong line-ending characters in your source (e.g. Windows-style when your Python is expecting Unix-style, thus disabling the backslashes).

    Either way, I would take advantage of C-style automatic string concatenation:

    >>> string = ("some text "
    ...           "more text "
    ...           "and even more")
    >>> string
    'some text more text and even more'
    

    Alternatively, if you don't mind newlines ending up in there, use multi-line strings:

    >>> string = """some text
    ...             more text
    ...             and even more"""
    

    IMO these look much nicer, and are much less fragile when refactoring.

    Does this help?

    0 讨论(0)
提交回复
热议问题