Importing Stuff

Importing functions and variables in Fate is similar to Python. One can either import an entire module as a single variable, or can cherry-pick individual properties. In all cases, the imported items can be aliased locally.

Importing Entire Modules

When an entire module is imported, it will be stored as a single local Object variable whose name (unless aliased) is the last component of its module path.

import dir.subdir.module1  # will import as 'module1'

import dir.subdir.module1, dir.subdir.module2

import dir.subdir.module1 as myModule  # will import as `myModule`

import dir.subdir.module1 as mod1,
       dir.subdir.module2 as mod2

When you've imported an entire module, you have to address its functions or variables via membership paths:

import dir.subdir.module1 as myModule
myModule.myFunction('Hello')

Cherry-Picking Items

When cherry-picking, only the imported items will be placed in the local scope, the module itself will be discarded.

from dir.subdir.module1 import myVariable

from dir.subdir.module1 import myVariable as myVar

from dir.subdir.module1 import myVariable, myFunction as function1
function1('Hello')

Exporting Stuff

What can you import something if nobody is exporting stuff? Fate allows you to easily export any symbol that you can declare. In the case of Functions and Assignments, you simply prefix the statement with the export keyword.

export def someExportedFunction()
  # I'm exported
end

# both a and b are exported
export let a = 100, b = 200

You can also explicitly export any variable previously declared:

def someFunction
  # I'll be exported
end

let a = 100, b = 200

export someFunction as someExportedFunction, a, b

You can also immediately export things that are imported.

export import test as assert

You can also export everything that's be declared up until this point by exporting `all`.

export all

results matching ""

    No results matching ""