Sibbs Gambling
Sibbs Gambling

Reputation: 20355

Problems in calling module function in Python?

I have a segmenting.py module in a package called processing.

I am trying to call a function in the module in my main. It is extremely simple.

In main.py

from processing import segmenting

segmenting.test()

In segmenting.py

def test():
    print 'succeed'

However, I end up with errors as follows:

>>> from processing import segmenting
>>> 
>>> segmenting.test()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'test'
>>> 

Where went wrong?

Upvotes: 0

Views: 70

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 601529

The most likely cause is that you didn't restart your interactive interpreter after editing (and saving!) segmenting.py. Modules are imported only once and cached. If you edit the source code and then run the import statement again, the module is simply retrieved from the cache and doesn't pick up your changes. See also the reload() built-in.

Upvotes: 2

Related Questions