What are some common mistakes to avoid when writing Python code?
• Don't use underscore prefixes for private methods. In Python, "underscores do not provide meaningful privacy".
• Avoid mutating arguments. Mutating arguments can cause issues when the function is called multiple times.
• Don't use long imports. Import specific classes and functions rather than importing entire modules.
• Avoid default arguments for mutable objects. Default arguments are evaluated once at definition time.
• Don't use catch-all statements except for statements. Catch specific exceptions wherever possible.
• Don't reuse variables without rebinding. Reusing variable names can confuse.
• Avoid using list comprehensions that cause side effects. List comprehensions should be side effect free.
• Avoid using " ... " to continue lines. Instead, split the logic across multiple lines.
• Don't equate None with Boolean False. Use None to check for None explicitly.
• Avoid catching bare except exceptions. Catch specific exceptions whenever possible.
• Avoid datetime.now() and time.time() in performance critical code. They are not monotonic.
• Don't use init.py files for importing. Import modules directly instead.
• Avoid conditional imports. Import all dependencies at the top of the module.