Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring class object with PEP 8 standard in Python (pylint error) [duplicate]

I am trying to declare an object in Python. I am using Visual Studio Code with the basic pylint setup in it. Here is a snip of some code I have.

class MyLogging:
    """A class to initialize and run the logging commands using built in logging functions."""
    def __init__(self):
    etc...

my_can_logger = MyLogging()

Pylint keeps giving me an error that my_can_logger is named incorrectly.

[pylint] C0103:Invalid constant name "my_can_logger"

But I don't want it to be a constant! I want it to be an object. Is there some rule that I am missing? I looked at the PEP-8 styling guide, and I seem to be following their convention pretty well.

Thanks in advance

like image 212
Punchki Avatar asked Jan 29 '26 12:01

Punchki


1 Answers

pylint thinks it's a constant because it's a module level variable. Just ignore pylint, it's being stupid. Using a module level object for the logger is a common pattern in Python.

Better linters such as flake8 or pyflakes won't give you these complaints.

like image 80
wim Avatar answered Jan 31 '26 01:01

wim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!