How do I tell PyLint “it's a variable, not a constant” to stop message C0103?

前端 未结 6 1994
闹比i
闹比i 2020-12-13 08:27

I have a module-level variable in my Python 2.6 program named \"_log\", which PyLint complains about:

C0103: Invalid name \"_log\" (should match (([A-Z_][A-Z         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-13 08:52

    Seems to me a bit of refactor might help. Pylint in looking at this as a module, so it would be reasonable not to expect to see variables at this level. Conversely it doesn't complain about vars in classes or functions. The following paradigm seems quite common and solves the issue:

    def main():
        '''Entry point if called as an executable'''
        _log = MyLog()  # . . .
    
    if __name__ == '__main__':
        main()
    

    This has the benefit that if you have some useful classes, I can import them without running your main. The __name__ is that of the module so the "if" fails.

提交回复
热议问题