Techletter #101 | November 30, 2024
What is the difference between *args and **kwargs in python?
In Python, you can write functions that accept any number of arguments or keyword arguments by using a special syntax.
To get infinite arguments, use *args and for infinite keyword arguments, use **kwargs.
The āargsā and ākwargsā words are not important. Thatās just convention. You could have called them *bill and **ted and it would work the same way. The key here is in the number of asterisks.
Link: https://python101.pythonlibrary.org/chapter10_functions.html#args-and-kwargs
Asynchronous programming in python
The asynchronous programming is not as straight as in Node.js. If you are into python after writing a lot of code in node, you feel why this simple concept is not so simple in Python. It may be because the python was not designed to be asynchronous, the asynchronous way of writing code was introduced in the Python 3.4 and has evolved a lot after that.
Links:
https://sunscrapers.com/blog/python-async-programming-basics/
https://realpython.com/async-io-python/
Exceptions in Python
List of common exceptions are:
Exception, AttributeError, IOError, ImportError, IndexError, KeyError, KeyboardInterrupt, NameError, OSError, SyntaxError, TypeError, ValueError, ZeroDivisionError.
- ExceptionĀ (this is what almost all the others are built off of)
- AttributeErrorĀ - Raised when an attribute reference or assignment fails.
- IOErrorĀ - Raised when an I/O operation (such as a print statement, the built-in open() function or a method of a file object) fails for an I/O-related reason, e.g., āfile not foundā or ādisk fullā.
- ImportErrorĀ - Raised when an import statement fails to find the module definition or when aĀ from … importĀ fails to find a name that is to be imported.
A complete explanation of this can be found here:
Link: https://python101.pythonlibrary.org/chapter7_exception_handling.html#common-exceptions
Python Dependency management
Managing dependencies become hard as project grows.
The key reason for adopting good dependency management practices isĀ reproducibility. Reproducibility means we can follow a set of steps and always get exactly the same result.
As soon as a single step in the chain of instructions is not reproducible, the behavior of code becomes non-deterministic.
Below is the link for in depth article about dependency management in Python