0

I have a recursive function, that takes a new set() as argument. This is the function:

def attributes(node, set):
    set.add(node.tag)
    if not node.istext():
        for n in node.content:
            set = set.intersection(attributes(node, set()))
    return set

but I get this error:

error -> TypeError
'set' object is not callable
martineau
  • 119,623
  • 25
  • 170
  • 301

2 Answers2

5

You are overwriting the global builtin set with your local parameter. Just change it to

def attributes(node, my_set):
    ...
filmor
  • 30,840
  • 6
  • 50
  • 48
0

The problem is that your are using a datatype(set) reserved by Python itself and which you should not use as your variable name so change the name:

def attributes(node, the_set):
    the_set.add(node.tag)
    if not node.istext():
        for n in node.content:
            the_set = the_set.intersection(attributes(n, set()))
    return the_set
bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
Taufiq Rahman
  • 5,600
  • 2
  • 36
  • 44