Skip to content

Instantly share code, notes, and snippets.

@rmporsch
Last active December 11, 2020 05:57
Show Gist options
  • Save rmporsch/72c33765934a2ba411d4c75e1576f47e to your computer and use it in GitHub Desktop.
Save rmporsch/72c33765934a2ba411d4c75e1576f47e to your computer and use it in GitHub Desktop.
[Simple Python Recepies] Just some python recepies #python
# 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]
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
]
}
)
# 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())
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