Python Style Guide Questions - Contd.

Discussion in 'Python' started by koranthala, Jan 19, 2009.

  1. koranthala

    koranthala Guest

    Hi,
    I have some more questions about python code styling.
    1. Global Variables: In my code, I am using some global variables.
    Now, when I ran PyLint, it raised convention errors mentioning that
    they should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that
    mentioned. Please let me know whether that is the usual styling
    mechanism which is used.
    2. I have many loops wherein I define a variable as just a counter.
    for x in range(counter):
    do_something()
    Please note that I am not using x anywhere in the program.
    Pylint again raises warnings saying that the variable should be
    used.
    Should I disregard it or use the default variable _ ?
    for _ in range(counter):
    do_something()
    pylint does not raise errors for those. Are there any issues in
    using _ ?
     
    koranthala, Jan 19, 2009
    #1
    1. Advertising

  2. koranthala wrote:

    > Hi,
    > I have some more questions about python code styling.
    > 1. Global Variables: In my code, I am using some global variables.
    > Now, when I ran PyLint, it raised convention errors mentioning that
    > they should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that
    > mentioned. Please let me know whether that is the usual styling
    > mechanism which is used.


    I adopted that convention, however I don't know if it is "official". I'd
    consider it good style though.

    > 2. I have many loops wherein I define a variable as just a counter.
    > for x in range(counter):
    > do_something()
    > Please note that I am not using x anywhere in the program.
    > Pylint again raises warnings saying that the variable should be
    > used.
    > Should I disregard it or use the default variable _ ?
    > for _ in range(counter):
    > do_something()
    > pylint does not raise errors for those. Are there any issues in
    > using _ ?


    Nope, using _ is perfectly fine for variables you don't care about. Another
    example is e.g.

    foo, bar, _ = ("a", "b", "c")

    Diez
     
    Diez B. Roggisch, Jan 19, 2009
    #2
    1. Advertising

  3. On Mon, 19 Jan 2009 05:50:54 -0800, koranthala wrote:

    > Hi,
    > I have some more questions about python code styling. 1. Global
    > Variables: In my code, I am using some global variables.
    > Now, when I ran PyLint, it raised convention errors mentioning that they
    > should be CAPITAL_ALPHABETS. Now, in PEP 8, I did not see that
    > mentioned. Please let me know whether that is the usual styling
    > mechanism which is used.


    PEP8 doesn't mention constants at all. The all caps naming for constants
    is a convention in several languages.

    > 2. I have many loops wherein I define a variable as just a counter.
    > for x in range(counter):
    > do_something()
    > Please note that I am not using x anywhere in the program. Pylint
    > again raises warnings saying that the variable should be
    > used.
    > Should I disregard it or use the default variable _ ? for _ in
    > range(counter):
    > do_something()
    > pylint does not raise errors for those. Are there any issues in
    > using _ ?


    Pylint doesn't barf on `dummy` either. The point is having a name that
    makes clear at the head of the loop, that the reader doesn't have to
    bother looking for places where the value will be used because it is
    clear from the name that the value won't be used at all.

    BTW pylint is very configurable, you can dump the default configuration
    and find out which names are "allowed" by default and of course define
    your own set of "value doesn't matter" names.

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Jan 19, 2009
    #3
  4. koranthala

    Aahz Guest

    In article <-berlin.de>,
    Marc 'BlackJack' Rintsch <> wrote:
    >
    >PEP8 doesn't mention constants at all.


    Not true anymore. ;-)
    --
    Aahz () <*> http://www.pythoncraft.com/

    Weinberg's Second Law: If builders built buildings the way programmers wrote
    programs, then the first woodpecker that came along would destroy civilization.
     
    Aahz, Jan 23, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hermit Dave
    Replies:
    0
    Views:
    488
    Hermit Dave
    Jan 13, 2004
  2. Christian Seberino
    Replies:
    21
    Views:
    1,768
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    1,081
    Steve Lamb
    Oct 23, 2003
  4. koranthala

    Python Style Guide Questions

    koranthala, Jan 16, 2009, in forum: Python
    Replies:
    3
    Views:
    355
    koranthala
    Jan 16, 2009
  5. Laphan

    ASP Time Out Issues Contd.

    Laphan, Jul 24, 2003, in forum: ASP General
    Replies:
    1
    Views:
    142
    Ray at
    Jul 25, 2003
Loading...

Share This Page