r/Python • u/RickSore • Nov 14 '17
Senior Python Programmers, what tricks do you want to impart to us young guns?
Like basic looping, performance improvement, etc.
1.3k
Upvotes
r/Python • u/RickSore • Nov 14 '17
Like basic looping, performance improvement, etc.
5
u/ex4sperans Nov 14 '17
Do not create unnecessary lists. Most built-in functions accept generators as well. Do
all(item > 0 for item in iterable), notall([item ... ])Use virtualenv for every project (already has been said though).
If you faced extensive computations and/or nested looping on top of large lists/array, consider using numpy or numba.
NEVER do
from module import *.Study standard library.
pytest is your friend.
Use cProfile (or other profiler) regularly, optimize the bottlenecks.
Follow PEP8 (reasonably)
Do not use destructors, use
withblock insteadCreate custom exceptions, NEVER use
except Expection.Name your functions and variable properly. Python doesn't have static typing (well, latest versions have type annotations, but they aren't popular yet), so verbose names is a good practice.