Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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__

like image 839
thlgood Avatar asked Mar 18 '26 07:03

thlgood


1 Answers

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()
like image 58
Martijn Pieters Avatar answered Mar 19 '26 19:03

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!