10 most common mistake that python developer make
hello friends,today i am going to saw you 10 most common mistake that python developer make.
1.misusing expression as default for function arguments
A common mistake is to think that the optional argument will be set to the specified default expression each time the function is called without supplying a value for the optional argument
2. using class variable incorrectly
class variable are internally handle as dictionaries and follow what is often referred to as method resolution order(MRO)
3.specifying parameter for incorrectly for an exception block
python facilitates as to not specify the exception with the except statement. it allow as to declare multiple exceptions with the except clause.
4. Misunderstanding python scope rules
python scope resolution is based on what is know as the LEGB rule, which is shorthand for local, inclosing ,globle, built-in.
5. modifying a list while iterating over it
python incorporates a number of elegant programming paradigm which, when used properly, can result in significantly simplified and streamlined code.
6. confusing how python blind in closures
python's late blinding behavior which say that the value for variable used in closures are looked up at the time the inner function is called.
7. Creating circular module dependencies
circular dependency occurs when two or more modules depend on each other. circular importance are the result of bad designs. a deeper analysis of the program could have concluded that the dependency isn't actually required, or that the depended functionality can be moved to different modules that wouldn't content the circular reference.
8. Name clashing with python standard library module
Be exercised to avoid using the same name as those in the python standard library modules. it's way easier for you to change the name of module within your package than it is to file a python enhancement proposal(PEP) to request a name change upstream and to try and get their approved.
9. Failing to address differences between python two and python 3
in python 3, the exception object is not accessible beyond the the scope of except block hence, in python 2 we can. so to avoid this issue is to maintain a reference to the exception object outside the scope of the except block so that it remain accessible.
10. Misusing the _del__ method
_del_ is a destrutor method which is called as soon as all reference of the object are deleted i.e when an object is garbage collected. in order to ensure correct cleanup of the object add an a explicit close(), or similar, method.possibly make the object a context manager. the _del_ method should just cal close.
0 Comments