[Solved] Accessing a function from a module


EDIT: You’re actually not having a python issue but a bash one. You’re running your python script as if it were bash (hence the ‘from: can’t read from’), did you put #!/usr/bin/env python at the beginning of the file you’re running (not print_text.py, the other one)? You could alternatively call it that way: python myfile.py and it should work.

When you import a module, it is namespaced, so if you want to use anything that is from that module, you need to call it using the proper namespace. Here, you would call you echothis function using print_text.echothis.

Alternatively, if you want to include echothis in your main namespace, you can use the from print_text import echothis syntax.

0

solved Accessing a function from a module