After reading chapter 18, I found that the first exercise, using *args to read all of the input parameters as a tuple, but in his practice only gave two variables to assign value, when the user is not clear about the definition of this function, it is possible to give too many variables into this function, then the following error occurs:
Valueerror:too Many values to unpack
So-called unpacking errors, too many values are given.
So in order to stop this situation, I trickery solved the next. Is that I changed the tuple to a list, and then made up 2 bits to go in.
It doesn't matter if he gives less variables, I can do it. may be too rubbing, and later have a good idea to make up.
def print_two (*args):
All_args = List (args) + [None,none] = all_args[0:2]
= Need_var print"arg1:%r, arg2:%r" %(ARG1,ARG2) Print_ Both (1,"hello", 3)
LPTHW Stupid Methodology Python Chapter 18