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

Where to include import statements referenced in module functions?

I’m working on my first project and am trying to figure out how something works. If I have a module that store some functions I will reference in my main program that depend on another module, where do I include the import statement?

For example:

# Title: func.py

import os

def my_function(path):
    if not os.path.isfile(path):
        parser.error(f'The file {path} does not exist.')

Do I include import os here, or can I simply have it in the main document?

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

>Solution :

You must import the module in the file that references the module. So if you have a file that somewhere calls os.path.isfile, you need to import os at the top of that file.

comment by larsks

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