Last active
March 15, 2019 08:22
-
-
Save sarfarazahmad89/0e87731f9a4302adf819c1e56881ad2f to your computer and use it in GitHub Desktop.
My Python Gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** Filter, Lambda ** | |
There are probably 10 other better ways to do this, but this is for my personal reference. | |
mylst = ['dummy-2019.01', 'dummy-testindex', 'dummy-2019.02'] | |
def match_indices(index, regex): | |
return re.match(regex, index) | |
def match_indices_by_month_or_week(index): | |
return match_indices(index, '.*?\d{4}.\d{2}') | |
def match_indices_by_day(index): | |
return match_indices(index, '.*?\d{4}.\d{2}.\d{2}') | |
filter(match_indices_by_month_or_week, lst) | |
USING Lambda functions: | |
Becomes a one-liner | |
filter(lambda index: re.match('.*?\d{4}.\d{2}', index), lst) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you use the root logger, nested/buried deep inside loggers can be a pain. | |
List of them like, | |
import requests | |
import logging | |
for key in logging.Logger.manager.loggerDict: | |
print(key) | |
Source : https://stackoverflow.com/questions/11029717/how-do-i-disable-log-messages-from-the-requests-library |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment