Is is possible to rewrite this code:
def function(obj):
    obj.attrib = 8
    return obj
So the set of the attribute and the return line appears in only one line? Something like:
def function(obj):
    return obj.attrib = 8 # of course, this does not work
You could do this:
def function(obj):
    return setattr(obj, 'attrib', 8) or obj
This works because built-in function setattr returns None.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With