brainpy.tools module

AST-to-Code

ast2code(ast_node[, indent, line_length])

Decompiles an AST into Python code.

Code Tools

copy_doc(source_f)

code_lines_to_func(lines, func_name, ...[, ...])

get_identifiers(expr[, include_numbers])

Return all the identifiers in a given string expr, that is everything that matches a programming language variable like expression, which is here implemented as the regexp \b[A-Za-z_][A-Za-z0-9_]*\b.

indent(text[, num_tabs, spaces_per_tab, tab])

deindent(text[, num_tabs, spaces_per_tab, ...])

word_replace(expr, substitutions[, exclude_dot])

Applies a dict of word substitutions.

is_lambda_function(func)

Check whether the function is a lambda function.

get_main_code(func[, codes])

Get the main function _code string.

get_func_source(func)

change_func_name(f, name)

New Dict

DictPlus(*args, **kwargs)

Python dictionaries with advanced dot notation access.

class brainpy.tools.DictPlus(*args, **kwargs)[source]

Python dictionaries with advanced dot notation access.

For example:

>>> d = DictPlus({'a': 10, 'b': 20})
>>> d.a
10
>>> d['a']
10
>>> d.c  # this will raise a KeyError
KeyError: 'c'
>>> d.c = 30  # but you can assign a value to a non-existing item
>>> d.c
30
copy() a shallow copy of D[source]
setdefault(key, default=None)[source]

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

Name Checking

check_name(name, obj)

get_name(type)

Other Tools

size2num(size)