Fix Python – How to dynamically load a Python class

Given a string of a Python class, e.g. my_package.my_module.MyClass, what is the best possible way to load it?
In other words I am looking for a equivalent Class.forName() in Java, function in Python. It needs to work on Google App Engine.
Preferably this would be a function that accepts the FQN of the class as a string, and returns a reference to….

Fix Python – What’s the correct way to sort Python `import x` and `from x import y` statements?

The python style guide suggests to group imports like this:

Imports should be grouped in the following order:

standard library imports
related third party imports
local application/library specific imports

However, it does not mention anything how the two different ways of imports should be laid out:
from foo import bar
import foo

There are m….

Fix Python – ModuleNotFoundError: What does it mean __main__ is not a package?

I am trying to run a module from the console. The structure of my directory is this:

I am trying to run the module p_03_using_bisection_search.py, from the problem_set_02 directory using:
$ python3 p_03_using_bisection_search.py

The code inside p_03_using_bisection_search.pyis:
__author__ = ‘m’

from .p_02_paying_debt_off_in_a_year import compu….

Fix Python – Sibling package imports

I’ve tried reading through questions about sibling imports and even the
package documentation, but I’ve yet to find an answer.
With the following structure:
├── LICENSE.md
├── README.md
├── api
│   ├── __init__.py
│   ├── api.py
│   └── api_key.py
├── examples
│   ├── __init__.py
│   ├── example_one.py
│   └── example_two.py
└── tests
│   ├── __in….

Fix Python – Relative imports – ModuleNotFoundError: No module named x

This is the first time I’ve really sat down and tried python 3, and seem to be failing miserably. I have the following two files:

test.py
config.py

config.py has a few functions defined in it as well as a few variables. I’ve stripped it down to the following:
config.py
debug = True

test.py
import config
print (config.debug)

I also have an __in….