Return a dictionary of Regex Matches
Posted on January 12, 2021
| 1 minutes
| 151 words
| Bas-Man
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. The key value is derived \
from (:P<name>)
:returns: None is returned if No match is found.
:rtype: dict
:rtype: None
"""
matcher = re.compile(regex, re.UNICODE)
match = matcher.match(string)
if match:
matches = dict()
for key in match.groupdict():
matches[key] = match.group(key)
return matches
# No Matches
return None
Decoding Email Header and Contents
Posted on October 15, 2020
(Last modified on November 2, 2020)
| 1 minutes
| 52 words
| Bas-Man
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
Posted on July 7, 2020
| 1 minutes
| 60 words
| Bas-Man
How to pad numbers in Python.
[Read More]Generate QR Codes
Posted on July 7, 2020
| 1 minutes
| 51 words
| Bas-Man
Generate QR codes
[Read More]Mock Python version for Testing
Posted on July 7, 2020
| 0 minutes
| 0 words
| Bas-Man
How to mock Python version
[Read More]Custom Corporate Holidays with holidays package
Posted on May 9, 2025
| 2 minutes
| 393 words
| Bas-Man
I am currently working on a newish personal project. My plan is to create a Python version of a Google Script app
that I am running. I wanted to find a way to determine if a given date is a national holiday. This requires taking into account that National Holidays that fall on a Sunday are moved to the following Monday or to
Tuesday if Monday is already a National Holiday. I also needed to support adding Company holidays. This is important as
it impacts some calculations. Enter the Python package: holidays
[Read More]Google API Gmail LINE Notifications Part 7
Posted on February 12, 2021
| 2 minutes
| 306 words
| Bas-Man
Final part in a series of articles on implementing a notification system using Gmail and Line Bot.
[Read More]Google API Gmail LINE Notifications Part 6
Posted on February 8, 2021
| 4 minutes
| 789 words
| Bas-Man
Part 6 in a series of articles on implementing a notification system using Gmail and Line Bot.
[Read More]Google API Gmail LINE Notifications Part 5
Posted on February 4, 2021
| 3 minutes
| 531 words
| Bas-Man
Part 5 in a series of articles on implementing a notification system using Gmail and Line Bot.
[Read More]Google API Gmail LINE Notifications Part 4
Posted on February 3, 2021
| 3 minutes
| 513 words
| Bas-Man
Part 4 in a series of articles on implementing a notification system using Gmail and Line Bot.
[Read More]