code_junkie

What does “pythonic” mean

Nov 13th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. $ python
  2. Python 2.5.3 (r253:67856, Dec 19 2008, 16:52:52)
  3. [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import this
  6. The Zen of Python, by Tim Peters
  7.  
  8. Beautiful is better than ugly.
  9. Explicit is better than implicit.
  10. Simple is better than complex.
  11. Complex is better than complicated.
  12. Flat is better than nested.
  13. Sparse is better than dense.
  14. Readability counts.
  15. Special cases aren't special enough to break the rules.
  16. Although practicality beats purity.
  17. Errors should never pass silently.
  18. Unless explicitly silenced.
  19. In the face of ambiguity, refuse the temptation to guess.
  20. There should be one-- and preferably only one --obvious way to do it.
  21. Although that way may not be obvious at first unless you're Dutch.
  22. Now is better than never.
  23. Although never is often better than *right* now.
  24. If the implementation is hard to explain, it's a bad idea.
  25. If the implementation is easy to explain, it may be a good idea.
  26. Namespaces are one honking great idea -- let's do more of those!
  27.  
  28. if isinstance(x, someclass):
  29. x.somemethod()
  30. else:
  31. print "an error has occurred!"
  32.  
  33. if hasattr(x, somemethod):
  34. x.somemethod()
  35. else:
  36. print "an error has occurred!"
  37.  
  38. try:
  39. x.somemethod()
  40. except AttributeError:
  41. print "an error has occurred!"
Add Comment
Please, Sign In to add comment