Search code examples
pythonpython-3.xoopgetattr

getattr with two tuples after it


I am working with a code base which contains a line which I really can't understand:

x, x, z = getattr(ReceiveFile, maxsizes)(input, args)

So if it didn't have the second tuple at the end it would be just

x, y, z = ReceiveFile.maxsizes

How do I interpret that tuple at the end (input, args) ? I can't that easily run this code and play with a debugger to come to an understanding..


Solution

  • Given a string value for the maxsizes variable:

    maxsizes = "abc"
    

    the following

    x, x, z = getattr(ReceiveFile, maxsizes)(input, args)
    

    is equivalent to:

    x, x, z = ReceiveFile.abc(input, args)
    

    Or in words: The object ReceiveFile has a method with the name maxsizes (which is ReceiveFile.abc) which is called with the arguments input and args. The parentheses do not denote a tuple, but a function call.