如何使用注释PEP8一长串字符串

时间:2013-05-06 21:41:57

标签: python django pep8

带注释的行超过80个字符:

MIDDLEWARE_CLASSES = (
    'mydogslow.middleware.MyWatchdogMiddleware',
    'gattlib.djangomiddleware.SetRemoteAddrFromXRealIP',
    'i18n.middleware.SetLanguageMiddleware',
    'whitelabels.middleware.SetWhitelabelMiddleware', # after SetLanguageMiddleware
    'myaffiliateprogram.middleware.BlockReferringURLs',
)

我可以分解的最自然的方式是:

MIDDLEWARE_CLASSES = (
    'mydogslow.middleware.MyWatchdogMiddleware',
    'gattlib.djangomiddleware.SetRemoteAddrFromXRealIP',
    'i18n.middleware.SetLanguageMiddleware',
    'whitelabels.middleware.'
        'SetWhitelabelMiddleware', # after SetLanguageMiddleware
    'myaffiliateprogram.middleware.BlockReferringURLs',
)

不幸的是,悬挂缩进违反了PEP8。

提前感谢您向我展示如何打破这一阵容。

1 个答案:

答案 0 :(得分:9)

我只想移动评论:

MIDDLEWARE_CLASSES = (
    'mydogslow.middleware.MyWatchdogMiddleware',
    'gattlib.djangomiddleware.SetRemoteAddrFromXRealIP',
    'i18n.middleware.SetLanguageMiddleware',
    # This middleware needs to be after SetLanguageMiddleware
    'whitelabels.middleware.SetWhitelabelMiddleware',
    'myaffiliateprogram.middleware.BlockReferringURLs',
)