pylint style convention

  • Thread starter Mick Charles Beaver
  • Start date
M

Mick Charles Beaver

Hello,

I've been looking into using PyLint on some of my programs, just as a
best practices kind of thing.

Here's a snippet:
#======================================================================
if __name__ == '__main__':
parser = optparse.OptionParser(usage='usage: %prog [OPTIONS]')
parser.add_option('-c', '--config',
action='store',
type='string',
dest='configFilename',
help='config file containing defaults')
(options, args) = parser.parse_args()
#======================================================================

Now, PyLint reports the following convention warnings:
C:158: Invalid name "parser" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
C:170: Invalid name "options" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
C:170: Invalid name "args" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)

Which style convention is it referring to? Should these really be all
caps?

Thank you,
Mick
 
M

Michael Hoffman

Mick said:
Hello,

I've been looking into using PyLint on some of my programs, just as a
best practices kind of thing.

Here's a snippet:
#======================================================================
if __name__ == '__main__':
parser = optparse.OptionParser(usage='usage: %prog [OPTIONS]')
parser.add_option('-c', '--config',
action='store',
type='string',
dest='configFilename',
help='config file containing defaults')
(options, args) = parser.parse_args()
#======================================================================

Now, PyLint reports the following convention warnings:
C:158: Invalid name "parser" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
C:170: Invalid name "options" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
C:170: Invalid name "args" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)

Which style convention is it referring to? Should these really be all
caps?

There's a style convention that global constants at file scope are
defined in all caps.

Personally, I do all my optparsing in a special function rather than in
the __name__ == '__main__' block.
 
B

Ben Finney

Here's a snippet:

pylint is reporting line numbers. Can you show us line numbers for
this snippet?
#======================================================================
if __name__ == '__main__':
parser = optparse.OptionParser(usage='usage: %prog [OPTIONS]')
parser.add_option('-c', '--config',
action='store',
type='string',
dest='configFilename',
help='config file containing defaults')
(options, args) = parser.parse_args()
#======================================================================

Now, PyLint reports the following convention warnings:
C:158: Invalid name "parser" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
C:170: Invalid name "options" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
C:170: Invalid name "args" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)

These warnings are for line 158 and line 170, which covers a range of
13 lines. Your code snippet is only 8 lines long. So at least one of
those two lines that have warnings reported are not in the code you've
shown to us.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top