What Is The Jargon Of The Alias Variable After Import Module In Python?
Solution 1:
Importing is a form of name binding; names in the current namespace are bound to imported objects.
The import
statement documentation calls it an identifier, but identifiers are names. Importing an object always binds to an identifier, but the as <identifier>
syntax lets you specify an alternate name to use instead of the default.
When parsing Python syntax into an Abstract Syntax Tree (which is what the CPython compiler does, and you can do with the ast
module), then the resulting Import
and ImportFrom
nodes have 1 or more names
, each an object of the ast.alias
type:
| Import(alias* names)
| ImportFrom(identifier? module, alias* names, int? level)
and the alias
type has a name
and an asname
value, both identifiers, and asname
is optional:
-- import name with optional 'as' alias.
alias = (identifier name, identifier? asname)
So they are just names, variables, and because they differ from the default for those imports, it's fine to call them aliases.
Post a Comment for "What Is The Jargon Of The Alias Variable After Import Module In Python?"