Imports

ASnake Documentation

Table Of Contents

Summary:

Imports in ASnake, for now, are exactly the same as Pythons. Thus there are plenty of better resources than this page.

Regardless, an overview will be given.

Go here to get the list of the Python standard library, all other 3rd party modules (usually through PyPi) must be installed via pip or other tools (pipx, virtualenv).

Python import:

import followed by the module you wish to import, will include it within your code. Then you can specify what variable or function you need from it using an attribute.

import math
print math.pi
# result: 3.141592653589793

This will import the entire library. To just import one function, start with from followed by the module, then import, then the function or variable you desire.

from math import pi
print pi
# result: 3.141592653589793

Add an as after the import to nickname it as something else. This work for either method, but will modify either the library name or function/variable accordingly.

from math import pi as PIE
print PIE
# result: 3.141592653589793

import string as s
print s.ascii_lowercase
# result: abcdefghijklmnopqrstuvwxyz

ASnake Bug:

ASnake's support of Python's import is incomplete currently. It primarily fails when it comes to tuple imports with newlines:

from math import (pi, 
    sin)

This may get fixed soon, just be aware.

Scroll to top