Did you know you can create QR codes in Linux console?
echo hello | qrencode -t ansiutf8
Did you know you can create QR codes in Linux console?
echo hello | qrencode -t ansiutf8
Today I have added support for config files with stocks
https://github.com/koss822/misc/tree/master/Python/yahoo-scraper
{
"stocks": [
{
"name": "iShares SP500",
"symbol": "CSSPX.MI",
"currency": "eurczk",
"count": 1
}
}
This is a simple code preview how to use ChainMap to combine multiple config files into one with precedence. Attaching also Jupyter Notebook.
from collections import ChainMap
from pprint import pprintlocal_config = {
"user": "localuser",
"pass": "localpass",
"host": "localhost"
}global_config = {
"user": "globaluser",
"pass": "globalpass",
"host": "globalhost",
"timeout": 15
}config = ChainMap(local_config, global_config)
pprint(config)for k,v in config.items():
print(f"{k}:{v}")
Sometimes you need to initialize dictionary before you use it, for this reason you can use dict() subclass defaultdict(). This is how you would do it normally.
# counter for cars by vendor
cars = dict()
if 'ferrari' not in cars:
cars['ferrari'] = 1
else:
cars['ferrari'] += 1
but with default dict this scenario is far easier
# counter for cars by vendor
from collections import defaultdict
cars = defaultdict(int)
cars['ferrari'] += 1
Always remember that defaultdict takes as parameter callable (function) not default value.
I am preparing course for Python beginners and I was thinking how to do something they can try on their own computers quickly and immediately see results.
I would like to use Google Colab but when you want to present some results you usually want some graphical way for it containing images etc. And what is a better tip than HTML.
Here is a quick tip how to use HTML in your Jupyter Notebook.
from IPython.core.display import display, HTMLdisplay(HTML('<h1>Hello, world!</h1>'))