ET.find() takes exactly 2 arguments (3 given)

921 views Asked by At

I'm newbie in Python and getting the error

ET.find() takes exactly 2 arguments (3 given)

during the execution of

import xml.etree.ElementTree as ET

ns = {'conv_svc': 'http://schemas.com/serviceconvert'}            
jobTypesXml = self.__server_request(url, None)    
root = ET.fromstring(jobTypesXml)    
for job in root.find('conv_svc:GetJobTypesResult', ns):

My first question is: what type is deduced in the following initialization?

ns = {'conv_svc': 'http://schemas.com/serviceconvert'}            

Answering this I can go further to find out the error by myself! Thanks in advance!

1

There are 1 answers

2
roganjosh On

The find() method only takes a single argument so you cannot do whatever it is you're attempting (at least not with find()).

To answer your question, {'conv_svc': 'http://schemas.com/serviceconvert'} is a dictionary and would be interpreted as a single argument. If you are wondering about why the error states that you're passing 3 arguments (which you're not), it's because self is also counted as an argument to class methods.

class Testing(object):

    def __init__(self):
        self.a = 2

    def do_something(self, b):
        self.a += b

obj = Testing()
obj.do_something(2, 3) # Clearly passing only 2 arguments

Gives:

TypeError: do_something() takes exactly 2 arguments (3 given)

EDIT

Thanks to @ShreyashSSarnayak for pointing out that find() can take an optional extra argument in Python 3. The error message confirms that you are using Python 2, but perhaps reading some documentation associated with Python 3.