CLICK ME
yes, even hidden code blocks!
print("hello world!")| # check packages in python | |
| # the python packaging is sometimes hard to understand, in that way it often helps to see what python | |
| # thinks about you packages | |
| # (this code is written and tested with python 3.6) | |
| import pkgutil | |
| def inspect_package(name): |
| # Once in a while you really would need case switching: this is how to best do it in python: | |
| def positive_handler(x): | |
| print("the number {} is positive".format(x)) | |
| def zero_handler(x): | |
| print("the number {} is zero".format(x)) | |
| def negative_handler(x): | |
| print("the number {} is negative".format(x)) |
| """ | |
| This is a simple example on how to wrap functions in python: | |
| - it uses inspect and wraps from functools | |
| (this is built for python 3.6, you can copy this into a Jupyter notebook and execute!) | |
| """ | |
| # -------------------------------------------------------------------------- | |
| # Define the wrapper for logging the function | |
| # -------------------------------------------------------------------------- |
| """ | |
| This is a simple example on how to use vars() in python: | |
| vars() is for getting the variables from objects that have a __dict__ | |
| (this is built for python 3.6, you can copy this into a Jupyter notebook and execute!) | |
| """ | |
| # vars is for getting variables from an objects __dict__ |
| """ | |
| This is a simple example on how to set up logging in python | |
| (this is built for python 3.6, you can copy this into a Jupyter notebook and execute!) | |
| A good source for logging is the Hitchhikers guide to Python: http://docs.python-guide.org/en/latest/writing/logging/ | |
| Another good article on logging: https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/ | |
| """ | |
| # first you have to import the library | |
| import logging |
| ''' | |
| In this example I will show you how to read and write yaml configuration files in python | |
| (this is built for python 3.6, you can copy this into a Jupyter notebook and execute!) | |
| Background Information: | |
| ----------------------- | |
| yaml is a configuration language: | |
| - see this link for a good introduction on what is possible with yaml: https://learnxinyminutes.com/docs/yaml/ | |
| In python you need pyyaml to write and read yaml files: |