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
  • 112,593
  • 23
  • 157
  • 280

2 Answers2

5

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

def attributes(node, my_set):
    ...
filmor
  • 28,551
  • 4
  • 47
  • 46
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
  • 72,252
  • 6
  • 79
  • 103
Taufiq Rahman
  • 5,436
  • 2
  • 35
  • 43