pylib.helper module

Helper objects.

Date

2020-01-01

class cd(new_path)[source]

Bases: object

Context manager for changing the current working directory

Parameters

new_path (string) – the directory to change into

Example

# enter the directory and run some code:
with cd("~/tmp"):
  # we are now in ~/tmp
  # code
# outside the context manager we are back where we started.
run_file(file_name)[source]

Run a file.

Inside a pythin interpreter it changes to the directory of the file and after excuting the file it changes back to the working directory before.

Parameters

file_name (string) – the file to execute

class timeit(description=None)[source]

Bases: contextlib.ContextDecorator

Meassure time for a function or code block.

Parameters

description (str) – description for the function or code block used for the print-out

Example

>>> with timeit('section_test'):
...   # code
section_test took 0.006 ms
@timeit('func')
def func():
  # code
>>> func()
func took 0.006 ms