Day 429
Python imports
Python ‘No module named’ error; ‘package’ is not a package - Stack Overflow TL;DR Beware of conflicting filenames.
I keep getting bitten by this - if I have a folder called something
and inside it something called something.py
and want to import something from the folder, it will take something
to mean something.py
instead of the folder.
Quoting the most helpful answer:
I was using the same name for both a sub-package (directory) and a module (file) within it.
For example I had this:
/opt/mylib/myapi /opt/mylib/myapi/__init__.py /opt/mylib/myapi/myapi_creds.py # gitignored file for user/pass /opt/mylib/myapi/myapi.py # base module, load creds and connect /opt/mylib/myapi/myapi_dostuff.py # call myapi.py and do work
The script ‘myapi.py’ imports credentials from myapi_creds.py via this statement:
from myapi.myapi_creds import my_user, my_pass Testing the module 'myapi.py' resulted in this error: $ ./myapi.py Traceback (most recent call last): File "./myapi.py", line 12, in <module> from myapi.myapi_creds import my_user, my_pass File "/opt/mylib/myapi/myapi.py", line 12, in <module> from myapi.myapi_creds import my_user, my_pass ModuleNotFoundError: No module named 'myapi.myapi_creds'; 'myapi' is not a package
The solution was to rename
myapi.py
tomyapi_base.py
so it’s name does not collide with the sub-package name.
Markdown code in quotes
Is there a way to put code blocks in block quotes? - Meta Stack Overflow
TL;DR Code is indented four spaces, but inside a quote (>
) they have to be indented five spaces.
English - dingbat
dingbat - Wiktionary - crazy person - typographical ornament (like arrows) - small device/gadget the correct term for which is forgotten/unknown
Scipy normality test
scipy.stats.normaltest — SciPy v1.4.1 Reference Guide - function returns amongst other things p-value that the sample comes from a normal distribution.
Meaning of buffer_size=
in dataset.shuffle()
It affects how random the shuffle is. A buffer size of 1 would not shuffle at all, one bigger than the dataset would be perfect. It’s basically the size of the randomly created bucket from which we pick the next element.