Python best practices
fantascienza.net
Python best practices
1–10 of 41 posts
Re: Python best practices
#2Re: Python best practices
#3> x=5 || x = 5
Noooo. That first one is backwards. Extraneous spaces annoy me to no end. Makes it a pain to search for things too.
On the other hand, using newlines to break things up at commas for example, is great. But that's not applicable here.
> class fooclass: ... || class Fooclass(object): ...
Is this a joke?
> d = dict() || frequences = {}
How can you say that longer names are always better? (Is that part of the message here?) Usually most variables are throw-away so using short names should be the most common case. Similar to mathematics.
> # Use iter* methods when possible
This should mention that thread-safety is probably the most directly relevant use case for the non-iterable methods.
> # coding: latin
Better to use this:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-Re: Python best practices
#4My comments: > x=5 || x = 5 Noooo. That first one is backwards. Extraneous spaces annoy me to no end. Makes it a pain to search for things too. On the other hand, using newlines to break things up at commas for example, is great. But that's not applicable here. > class fooclass: ... || class Fooclass(object): ... Is this a joke? > d = dict() || frequences = {} How can you say that longer names are always better? (Is…
Re: Python best practices
#5My comments: > x=5 || x = 5 Noooo. That first one is backwards. Extraneous spaces annoy me to no end. Makes it a pain to search for things too. On the other hand, using newlines to break things up at commas for example, is great. But that's not applicable here. > class fooclass: ... || class Fooclass(object): ... Is this a joke? > d = dict() || frequences = {} How can you say that longer names are always better? (Is…
>>> def f(l=[]):
... l.append(0)
... print l
...
>>> f()
[0]
>>> f()
[0, 0]
>>> f()
[0, 0, 0]
Unless you 1) actually want the appearance of a 'static' local variable or 2) are really careful to make a copy of the mutable before messing around with it, you'll get yourself into trouble.Re: Python best practices
#6My comments: > x=5 || x = 5 Noooo. That first one is backwards. Extraneous spaces annoy me to no end. Makes it a pain to search for things too. On the other hand, using newlines to break things up at commas for example, is great. But that's not applicable here. > class fooclass: ... || class Fooclass(object): ... Is this a joke? > d = dict() || frequences = {} How can you say that longer names are always better? (Is…
It is recommended in the "official" python style guide to surround the assignment operator with a single space: http://www.python.org/dev/peps/pep-0008/
Re: Python best practices
#7My comments: > x=5 || x = 5 Noooo. That first one is backwards. Extraneous spaces annoy me to no end. Makes it a pain to search for things too. On the other hand, using newlines to break things up at commas for example, is great. But that's not applicable here. > class fooclass: ... || class Fooclass(object): ... Is this a joke? > d = dict() || frequences = {} How can you say that longer names are always better? (Is…
> Extraneous spaces annoy me to end. It is recommended in the "official" python style guide to surround the assignment operator with a single space: http://www.python.org/dev/peps/pep-0008/
i = i + 1
submitted += 1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)
Who writes like that?? I very strongly disagree.Re: Python best practices
#8Earlier quoted context omitted.
> Extraneous spaces annoy me to end. It is recommended in the "official" python style guide to surround the assignment operator with a single space: http://www.python.org/dev/peps/pep-0008/
And look how complicated they make it. Sometimes spaces, sometimes not, how confusing. And tell me that their "Use spaces around arithmetic operators" example doesn't make you want to puke: i = i + 1 submitted += 1 x = x * 2 - 1 hypot2 = x * x + y * y c = (a + b) * (a - b) Who writes like that?? I very strongly disagree.
Re: Python best practices
#9My comments: > x=5 || x = 5 Noooo. That first one is backwards. Extraneous spaces annoy me to no end. Makes it a pain to search for things too. On the other hand, using newlines to break things up at commas for example, is great. But that's not applicable here. > class fooclass: ... || class Fooclass(object): ... Is this a joke? > d = dict() || frequences = {} How can you say that longer names are always better? (Is…
Is this a joke?
No... it is generally recommended that class names are capitalized, and any classes you create are supposed to inherit from object. This mainly comes into effect when using super().
In Python 3K, I'm pretty sure that all classes will inherit from object without having to explicitly say it.
Re: Python best practices
#10Biased but interesting. Seems to me that there are only two examples of 'strange' here the 'while( )' and the regex. Interesting thing about regex---python itself uses perl compatible regex, so throw that item on the trash heap. As for the other its shorthand for grab a file from the command line, open it, Feed each line(\n terminated) to $_(could just as easily been a declared variable, but $_ is always there) and p…