Search code examples
pythontypeerrorpython-importpython-module

TypeError: 'module' object is not callable in my simple program about python module


This is my Python module:

main.py
fib/
    __init__.py
    fib.py
    hello.py

fib.py defined function fib(), hello.py define function hello().

main.py is

from fib import *
hello()

__init__.py is

__all__ = ["fib", "hello"]

I write this code just for practice.Not for work

I run main.py it print:

Traceback (most recent call last):
  File "tes.py", line 5, in <module>
    hello()
TypeError: 'module' object is not callable

Why? I had list hello in __all__


Solution

  • You've imported the hello module with the from fib import * line, but you are not referencing the hello function in that module.

    Do this instead:

    from fib import *
    hello.hello()
    

    or this:

    from fib.hello import *
    hello()