Python and common mistakes .

Python it very attractive for Rapid Application Development because is an interpreted, object-oriented, high-level programming language with dynamic semantics. This is not all.
If you search on the Internet articles about “python common mistakes”, you will find a whole series of articles that will disappoint you.
In this tutorial I present some of these mistakes to avoid a misconception about this programming language.
Let’s start with :

  1. Do not use or install old python or old python modules – use help and read the Python Enhancement Proposals (PEP) ;
  2. Incorrect indentation, tabs and spaces – never use tabs, only spaces (use 4 spaces for a tab);
  3. Scoping – Python decided to treat variables as global or local ( being an interpreted language is executed line-by-line and executed statement-by-statement) ;
  4. Copying – depends how  treat variables this can have many issues ( example mistakes when using Python dictionary) ;
  5. Using a mutable value as a default value – you to specify that a function argument is optional by providing a default value for it;
  6. Specifying parameters incorrectly for an exception block (example: to catch multiple exceptions in an except statement is to specify the first parameter as a tuple containing all exceptions to be caught) ;
  7. Modifying a list while iterating over it (example: deleting an item from a list or array while iterating over it) ;
  8. Confusing how Python binds variables in closures into a wrong way – (example: the expect the following output is wrong) ;
  9. Stop writing classes – is no need to use it.
  10. Using class variables incorrectly – class variables are internally handled as dictionaries and referred as Method Resolution Order (MRO) ;
  11. Creating circular module dependencies – the presence of a circular import can be a problem in Python importing modules;
  12. Name clashing with Python Standard Library modules – your code would be in conflict with the standard library module of the same name ;
  13. Do not confuse the concept of: error with mistakedepends on how you understand python language and output with development errors.

The subject of this tutorial is very complex, but it is more important if you go through it while developing the source code.


born 1976, Falticeni , Suceava , Romania
Posted in All, Programming, Python. Tagged with , , , .