After reading these:
Special use of args / kwargs
https://www.python.org/dev/peps/pep-3102/
What does ** (double star) and * (star) do for parameters?
https://docs.python.org/3.5/library/string.html#formatstrings
I want to be sure I understand well: str.format(*args, **kwargs)
if uniques
is a list of two integers such as [0, 0]
, which I would use for example in a loop with a condition to increment the first element and no condition to increment the second, with:
print('Task finished. {0!s} retrieved out of {1!s} tested'.format(*uniques))
I do have to use *uniques
because instead uniques
would be passed as a tuple to format. But if I do use
print('Task finished. {0.[0]} retrieved out of {0.[1]} tested'.format(uniques))
It raises value error: ValueError: Empty attribute in format string
. Using brackets around uniques
doesn't help. I don't really get why? Could someone please clarify?
In the first case, is the list unpacked then converted to a tuple, while in the second, it is not because the list can't be converted by format as a tuple right away, the same way format(uniques[0], uniques[1])
would? If I am right, why is that the case, since there's is a tuple(list)
function to do that and so, it is very simple?