Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python Style Guide Questions - Contd.

Reply
Thread Tools

Python Style Guide Questions - Contd.

 
 
koranthala
Guest
Posts: n/a
 
      01-19-2009
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 _ ?
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-19-2009
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
 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      01-19-2009
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
 
Reply With Quote
 
Aahz
Guest
Posts: n/a
 
      01-23-2009
In article <>,
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Style Guide Questions koranthala Python 3 01-16-2009 07:28 AM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-24-2003 11:15 AM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-23-2003 07:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57