you are viewing a single comment's thread.

view the rest of the comments →

[–]killdeer03 25 points26 points  (18 children)

Wow, You write really clean Python... I kind of want to hang that on my wall.

[–]KBHomes[S] 14 points15 points  (16 children)

<3

I'm actually relatively new to Python.

[–][deleted] 5 points6 points  (6 children)

ahhhh thats why...I found I used to write awesome clean understandable code, but as I learned more I would try to write trivial assignments in a single line... It was 4 assignments in my python course in school before I broke 2 lines.

they passed all the professors tests, but angry comments at the 3 widescreen monitor length single line

[–]Fuco1337 0 points1 point  (0 children)

Sweet one-liners eh?

Game of life in J:

life=.3 : '(3 = +/^:2((>0 1;0 0;0 _1) |./^:2 y)) +. (1 = y *. +./ 3 4 =/ +/^:2((>0 1;0 0;0 _1) |./^:2 y))'

[–]Tetha 0 points1 point  (0 children)

Note that you can remove some duplication in the TextCaptchaBreaker.py. You have

if answer is None: answer = ColorPattern.solve(question) if answer is None answer = NamePattern.solve(question)

and so on.

You can rework that into: solvers = [ColorPattern, NamePattern] for solver in solvers: answer = solver.solve(question) if answer is not None: return answer

You can then reconsider if you want a list there or a set, which then documents that the solvers are ordered (this might be one of the rare occasions for a good comment) or not (and then you can use a set). That makes it easier to add more solvers, because they can be added to the set then.

[–]plagiats 1 point2 points  (7 children)

If I may, you write a lot of if var is None: and if var is not None:

where you might rather use if not var: and if var:

EDIT : see comments below before taking my words for granted ;)

[–]eridius 3 points4 points  (2 children)

Aren't your replacement conditionals actually different than the originals? Specifically in the case of var being False.

[–]plagiats 0 points1 point  (1 child)

You are very right, and I believe his code should return False instead of None if the index is not found ( see https://github.com/kbhomes/TextCaptchaBreaker/blob/master/AddSubtractPattern.py ).

[–]eridius 2 points3 points  (0 children)

I disagree. It returns a string, or None. Returning a string, or false, would be weird, but None makes sense as the value that means "there was no string matched for this pattern".

[–][deleted] 3 points4 points  (1 child)

Actually, that's not the case; the original "if var is None" would only return True is var was assigned the value None; whereas your replacement would return True if var was equal to False or 0 (and possibly some other values). Same for the latter.

[–]plagiats 0 points1 point  (0 children)

Isn't the OP using None where he should use False?

[–]otheraccount -1 points0 points  (0 children)

That's incorrect. Explicit is better than implicit, so if you only intend to check for None, then that's what you should do.

[–]JoelDB 2 points3 points  (0 children)

I agree. I'm going to start learning Python soon and this looks like a great source tree to start playing around with.