如何保持PEP8规则最多79个字符

时间:2014-04-01 14:44:39

标签: python

我有这段代码

elif key == "valid":
   print _("You should enter only one character from the alphabet without repeating it")

并且超过79个charqcters对抗PEP8。我试图找出如何在第79个字符之前拟合代码。问题是我在这个打印上有一个本地化,如果我把它分成两个单独的字符串:

elif key == "valid":
    print _("You should enter only one character from"
            "the alphabet without repeating it")

这打破了本地化。我正在寻找一种不同的方法来实现这一目标。

1 个答案:

答案 0 :(得分:1)

您尝试将字符串拆分为两行会更改字符串,因为您丢失了fromthe之间的空格。试试这个:

elif key == "valid":
    # Note the trailing space after 'from'
    print _("You should enter only one character from "
            "the alphabet without repeating it")

使用隐式字符串加入时,"a""b"相当于"ab",而不是"a b"