Python Style Guide Questions - Contd.
Diez B. Roggisch
deets at nospam.web.de
Mon Jan 19 09:26:10 EST 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
More information about the Python-list
mailing list