Skip to content Skip to sidebar Skip to footer

What Is The Jargon Of The Alias Variable After Import Module In Python?

There are lots of packages in Python ecosystem, like NumPy, Matplotlib. to simplify coding, we usually code this way import numpy as np np is an alias, or shortcut, or something e

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.


Solution 2:

You will not be wrong if you call it asname.

enter image description here


Post a Comment for "What Is The Jargon Of The Alias Variable After Import Module In Python?"