Q: Python module import not recognising functions I've been trying this for a few days without success. I've searched for, and read, many questions and answers here and elsewhere but am still scratching my head.  I'm an experienced programmer but new to Python.
Any help or guidance would be most appreciated.
Thanks in advance!!
I've created a simple module to import which contains 1 function:
def dd_print_func( par ):
   print ("Hello : ", par)
   return

I'm importing this into another module as shown here:
from inspect import getmembers, isfunction

try:
    print("import start")
    import dd_file_handler
    print("import end\n")
except ModuleNotFoundError:
    print("import fail 1\n")
except ImportError:
    print("import fail 2\n")
except:
    print("import fail 3\n")
else:
    print("Import worked\n\n")

print("before show functions imported")
print(getmembers(dd_file_handler, isfunction))
print("after show functions imported\n\n")

dd_file_handler.dd_print_func("Zara")
print("finished\n")

Here is the output I get when running the second module.
It imports the dd_file_handler module without a reported error.
The print(getmembers(dd_file_handler, isfunction)) shows only [].
Finally the call to dd_file_handler.dd_print_func fails and crashes the program.
import start
import end

Import worked


before show functions imported
[]
after show functions imported


Traceback (most recent call last):
  File "c:\Users\jason\Downloads\my_python_code\test_import_file_handler.py", line 21, in <module>
    dd_file_handler.dd_print_func("Zara")
AttributeError: module 'dd_file_handler' has no attribute 'dd_print_func'


A: I suspect you're not importing what you think you are. Ive copy pasted your code and it works.
my directory structure is:
stackOverflow/
--- main.py
--- dd_file_handler.py

in main.py:
from inspect import getmembers, isfunction

try:
    print("import start")
    import dd_file_handler
    print("import end\n")
except ModuleNotFoundError:
    print("import fail 1\n")
except ImportError:
    print("import fail 2\n")
except:
    print("import fail 3\n")
else:
    print("Import worked\n\n")

print("before show functions imported")
print(getmembers(dd_file_handler, isfunction))
print("after show functions imported\n\n")

dd_file_handler.dd_print_func("Zara")
print("finished\n")

in dd_file_handler.py
def dd_print_func( par ):
   print ("Hello : ", par)
   return


run command:
\stackOverflow> python main.py

output:
import start                                               
import end                                                 
                                                           
Import worked                                              
                                                           
                                                           
before show functions imported                             
[('dd_print_func', <function dd_print_func at 0x03485D30>)]
after show functions imported
                             
                             
('Hello : ', 'Zara')         
finished

after the import of dd_file_handler check that youre importing the right file with: dd_file_handler.__file__:
    print("import start")
    import dd_file_handler
    print(dd_file_handler.__file__)
    print("import end\n")

should print /stackOverflow/dd_file_handler.py or you've edited the dd_file_handler.py file and forgot to save it xD
