Python Idioms and Gotchas

Use nested defs instead of lambda

Use list comprehension instead of map() and filter()

Use … instead of \ for multiline expressions

Use exec instead of execfile or reload

If you create an email program, do not name it email.py since that is the name of a module imported by the smtplib package

Use the global module index when naming a file to prevent accidentally overriding one you may need to import

If you delete the value at the current index from the list during a for loop, the next value will be skipped since it gets the index of the current item which has already been treated. Likewise, if you prepend a value into the list in front of the current index, the current value will be repeated again the next time through the loop. This can lead to nasty bugs that can be making a copy of the list before looping and doing all insertion and deletion assignment operations on it instead of the original

References

How to Write Pythonic Code
Intermediate and Advanced Software Carpentry in Python
On Writing Python One-Liners
Pythonic Design

Idiomatic Python Tutorial
Idiomatic Python Guidelines
Python Idioms Reference
Python Idioms Wiki
Python Idioms FAQ
Common Python Idioms
Python Idioms in Common Lisp
Hidden Features of Python

Python Gotchas
How not to Write Python
How not to write Python Code
Python Pitfalls

Python Performance Tips
Fast Python
Tweaking Python Scripts for Speed
Python Patterns – An Optimization Anecdote

Introduction to Python
Python Debugging
Python FAQ
Python Tricks
Design Patterns in Python
Python Snippets and Recipes

From scripting to object-oriented Python programming
How to change the User-Agent of Python’s urllib
Python for JavaScript Programmers
Python Interview Questions And Answers
Python in 1999 and now from a Perl perspective
Python Links

Study Notes

Set Class Methods
Tuple Class Methods
Interactive TTY Console CLI
Print Classes
Exception Classes
Mailbox Module
Exception Classes
Sequential File
Random Access File
Compressed Files
Python 3 primer, Part 1: What’s New
Python 3 primer, Part 2: Advanced Topics
Sending mail through GMail in Python
SMTPLib broken in Python 2.3
A Python & XML Companion
Using Python to create CLIs
Text Processing in Python
Morse Code Decoding With Python List Comprehensions
Simple Data Exchange with PHP

TrackBack URI

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.