Imagine that there's a Python library states
, in which there is a script for each of the 50 states, named after those state abbreviations.
al.py
ak.py
...
or.py
...
wi.py
wy.py
This certainly isn't the best way to structure code. But given that it exists, and given that or
is a reserved keyword, is there a reasonable way to write a caller for Oregon that includes the statement
from states import or
Or does the library have to change their naming convention to something a bit better, like the full state name.
You can't import or
directly, even when doing from... import... as
. Instead, you will need to use the function-based import mechanism supplied in importlib
. This will work:
import importlib
_or = importlib.import_module('states.or')
and you can refer to the module as _or
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With