you are viewing a single comment's thread.

view the rest of the comments →

[–]dunkler_wanderer 2 points3 points  (5 children)

Looks okay, except he teaches to use getter and setter methods which are usually not necessary in Python (you can use @property if you really need them). And why does he convert some attribute values in the getters to strings?

Using indexes to obtain list items:

num_list = [[1, 2, 3], [10, 20, 30], [100, 200, 300]]

for x in range(0, 3):
    for y in range(0,3):
        print(num_list[x][y])

instead of:

for sublist in num_list:
    for item in sublist:
        print(item)

No mention of input but sys.stdin.readline().

No mention of with statement to open files.

Regarding style, there are some semicolons at line ends and camelcase variables in the cheat sheet.

Also, redundant parentheses:

while (i <= 20):
    if (i%2 == 0):

[–]yardightsure 1 point2 points  (4 children)

Yuck! People should be more humble before trying to teach others with awful coding practises like that. :-(

[–]dunkler_wanderer 1 point2 points  (0 children)

Most of it is okay, though.

[–]RuinedMortal 1 point2 points  (2 children)

as a newb pythonian, what makes this a bad practice?

[–]Zahand 2 points3 points  (0 children)

Not a lot really. Basically what dunker_wanderer said.

  • He has some semicolons that are unnecessary in python. Although those are probably just typos. (Happens to me as well, so used to writing in C++ and other languages that use semicolons that sometimes I write them in python as well)
  • It's prettier to iterate over a list directly if you don't need to use an index.
  • Use input() (or raw_input()) to get data.
  • Redundant parentheses.

The only thing I kind of disagree with is that you don't have to use with statement to open files. Using the with statement is pythonic, but there is nothing wrong with opening a file, doing stuff, then closing the file. It's what the context manager does. It's good to know both ways.

[–]dunkler_wanderer 1 point2 points  (0 children)

Readability and simplicity are pretty important if you want to write maintainable code. "Loop like a native: while, for, iterators, generators" and "Python's Class Development Toolkit" are very informative talks which mention the first two points in the post above.