TypeError: unbound method must be called with class instance 1st argument

Discussion in 'Python' started by Guest, Dec 21, 2006.

  1. Guest

    Guest Guest

    I'm a novice at Python, and found some code samples on how to use
    threads. My script is being run by a product that contains a Jython
    interpreter. Can someone please explain why I get the following error:

    Traceback (innermost last):
    File "/full/path/to/file/GenerateData.py", line 104, in ?
    File "/full/path/to/file/GenerateData.py", line 34, in __init__
    TypeError: unbound method must be called with class instance 1st
    argument


    Here are the important pieces of my GenerateData.py script. Note that
    "scriptinterface" is something provided by the product to allow my
    script to interface with it. Line 104 is the last line -- the one that
    creates a GenThread and calls start() on it.


    import sys

    # need this section otherwise the import random won't work
    if sys.path.count('/usr/local/lib/python2.2/') == 0:
    sys.path.append('/usr/local/lib/python2.2/')

    import random
    import time
    import threading

    from java.lang import String
    from jarray import array

    class GenThread(threading.Thread):
    def __init__(self, ipAddress, port):
    threading.Thread.__init__()
    self.ipAddress = ipAddress
    self.port = str(port)

    def run(self):
    #
    # code
    #

    GenThread(scriptinterface.getSnmpIPAddress(),
    scriptinterface.getSnmpPort()).start()
     
    Guest, Dec 21, 2006
    #1
    1. Advertisements

  2. Guest

    Matimus Guest

    The following line:
    threading.Thread.__init__()
    Should be written as:
    threading.Thread.__init__(self)
     
    Matimus, Dec 21, 2006
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    Thank you!
     
    Guest, Dec 21, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.