pylint style convention

Matt McCredie mccredie at gmail.com
Tue Jul 24 02:39:34 CEST 2007


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

I think pylint is expecting that any variables declared outside of a
function should be constants with special meanings (similar to #define or
enum values in c). So, I guess to get rid of that message you should do
something like this:

<code>
def main(args=None):
    if args is None:
        args = sys.argv

    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(args)

if "__main__" == __name__:
    sys.exit(main())
</code>

Here is an article by GvR that goes over main functions in python:
http://www.artima.com/weblogs/viewpost.jsp?thread=4829. You didn't really
ask for it, but I think it is good reading. His examples all use getopt
though, instead of optparse. I have come up with my own (probably overkill
for 99% of python scripts) template that uses optparse. If you really want
to see it let me know and I will send it to you.

Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070723/0370b316/attachment.html>


More information about the Python-list mailing list