Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't import functions/modules

I’m simply trying to import a function from another script. But despite import running successfully, the functions never enter my local environment.

The paths and files look like this:

project/__main__.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

project/script_a.py

from setup import script_b
x = ABC() # NameError: name 'ABC' is not defined
print(x)

project/setup/__init__.py

project/setup/script_b.py

def ABC():
    return "ABC"   

I’ve done this before and the documentation (officials and on here) is quite straightforward but I cannot grasp what I am failing to understand. Is the function running but never entering my environment?


I also tried using…

if __name__ == '__main__':
    def ABC():
        return "ABC"

…as script_b.

>Solution :

Import the functions inside the module:

from setup.script_b import ABC

Or call the function on the modules name like said in the comments

x = script_b.ABC() 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading