TypeError: unbound method PrintInput() must be called with test instance as first argument (got test instance instead)

Diez B. Roggisch deets at nospam.web.de
Sun Oct 16 13:06:44 EDT 2005


arotem wrote:
> Hi,
> 
> I am trying to call an unbound method (PrintInput) with the object
> instance as the first argument but getting the following error:
> "TypeError: unbound method PrintInput() must be called with test
> instance as first argument (got test instance instead)"
> 
> Below is the sample code (test) for this purpose (two files).
> 
> Any help is greatly appreciated.

The problem is your circular import. When test.py is invoked, it imports 
  input_file.py, which in turn imports test, creating a class bound to 
the name test.test. Then the rest of test is interpreted, creating a 
__main__.test. While both are based on the same code, they are two 
different instances of classes.

To fix this, put your test-class in a separate module, and import that 
from both input_file.py and test.py

Diez



More information about the Python-list mailing list