Last active
December 11, 2020 05:57
-
-
Save rmporsch/72c33765934a2ba411d4c75e1576f47e to your computer and use it in GitHub Desktop.
[Simple Python Recepies] Just some python recepies #python
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
# raw python | |
def batch(iterable, n=1): | |
l = len(iterable) | |
for ndx in range(0, l, n): | |
yield iterable[ndx:min(ndx + n, l)] | |
def chunks(lst, n): | |
"""Yield successive n-sized chunks from lst.""" | |
for i in xrange(0, len(lst), n): | |
yield lst[i:i + n] |
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
from setuptools import setup, find_packages | |
setup( | |
name="myapp", | |
version="0.1", | |
packages=find_packages(), | |
package_data={"myapp": ["configs/*.json"]}, | |
entry_points={ | |
"console_scripts": [ | |
"mls = myapp.__main__:run" #run is a function | |
] | |
} | |
) |
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
# Get all loggers in a system | |
import logging | |
loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict] | |
for lggg in loggers: | |
print(lggg.name, lggg.getEffectiveLevel()) |
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
def switch(value): | |
return { | |
"option1": 1, | |
"option2": 2 | |
}.get(value) | |
# with default value | |
def switch(value): | |
_default = 1 | |
return { | |
"option1": 1, | |
"option2": 2 | |
}.get(value, _default) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment