3 ms·
I get where you're coming from, but those lines aren't equivalent (which may be why its confusing). "as" changes the name and can be used for both: import
by pfranz 3y ago
I get where you're coming from, but those lines aren't equivalent (which may be why its confusing). "as" changes the name and can be used for both:
import mpmath as mpmath_module
from mpmath import mp as mp_context
"import" and "from" always address modules (directories and files) from/import extracts objects from modules and "as" swaps out the name.
It's confusing because "from/import" reaches inside a package and Python uses the same delimiter for Namespaces/Modules, Classes, and Properties.
urllib.request.HTTPBasicAuthHandler.auth_header is Namespace.Module.Class.Property You have to use each one differently...but you just have to know. You get some small context clues based on capitalization or knowing the first thing at the top of the file is a Namespace or Module.