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 :
- Do not use or install old python or old python modules – use help and read the Python Enhancement Proposals (PEP) ;
- Incorrect indentation, tabs and spaces – never use tabs, only spaces (use 4 spaces for a tab);
- Scoping – Python decided to treat variables as global or local ( being an interpreted language is executed line-by-line and executed statement-by-statement) ;
- Copying – depends how treat variables this can have many issues ( example mistakes when using Python dictionary) ;
- Using a mutable value as a default value – you to specify that a function argument is optional by providing a default value for it;
- 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) ;
- Modifying a list while iterating over it (example: deleting an item from a list or array while iterating over it) ;
- Confusing how Python binds variables in closures into a wrong way – (example: the expect the following output is wrong) ;
- Stop writing classes – is no need to use it.
- Using class variables incorrectly – class variables are internally handled as dictionaries and referred as Method Resolution Order (MRO) ;
- Creating circular module dependencies – the presence of a circular import can be a problem in Python importing modules;
- Name clashing with Python Standard Library modules – your code would be in conflict with the standard library module of the same name ;
- Do not confuse the concept of: error with mistake – depends 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.