An example of how to make your function more flexible to handle a different number of return values. This means you won’t have to write the same code repeatedly if you are only changing the number of groups that are being returned.
def findMatches(string, regex) -> dict: """ This is a generic matching function. Warning! Your regex expression MUST use 'Named Groups' -> (:P<name>) or this function will return an empty dictionary :param string: The text you are searching :type string: str :param regex: The regular expression string you are using to search :type regex: str :returns: A dictionary of named key/value pairs.
[Read More]
Decoding Email Header and Contents
Using email.parser
and email.policy
along with policy.default
means that
you do not need to worry about character encoding as the modules will take care
of it automatically.
I forget where I saw it but I believe that policy.default will become the real
default in the future.
Current policy.compat32
is the module default.
Different String Padding Approaches
How to pad numbers in Python.
[Read More]
Generate QR Codes
Generate QR codes
[Read More]
Mock Python version for Testing
How to mock Python version
[Read More]