Python Headache

Discussion in 'Programming' started by amnezia, Oct 27, 2006.

  1. #1
    This is the first time is used python i keep getting the same error message and i have no idea why:

    
    import urllib
    import threading
    from mechanize import Browser
    
    class ImageGrabber(threading.Thread):
    
            def __init__(self,url,imgnum,searchterm):
    
                    self.url=url
                    self.imgnum=imgnum
                    self.searchterm=searchterm
                    threading.Thread.__init__(self)
    
            def run(self):
    
                    urllib.urlretrieve(self.url,'test')
    
    class ImageResults:
    
            def grabresults(query):
    
                    br=Browser()
                    response=br.open('http://images.google.co.uk/images?hl=en&q=%s&btnG=Search'%(self.query))
                    print response.read()
    
    i=ImageResults()
    i.grabresults('house')
    
    Code (markup):
    results it -> TypeError: grabresults() takes exactly 1 argument (2 given)
     
    amnezia, Oct 27, 2006 IP
  2. kiwwi

    kiwwi Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    class ImageResults:
    
            def grabresults([B]self,[/B] query):
    
                    br=Browser()
                    response=br.open('http://images.google.co.uk/images?hl=en&q=%s&btnG=Search'%(self.query))
                    print response.read()
    
    Code (markup):
    In Python, you have to have this self parameter on the first place of every object method (it is equivalent C++ this).
     
    kiwwi, Oct 31, 2006 IP