2016-08-26 22 views

答えて

1

:私は、最新の2ビーイングを次の関数にタプルの各要素を渡すのさまざまな方法を試してみました。その後、受信関数はそれらを再びタプルにモップできます(そうでないと!)。

これらの例は、物事を啓発する必要があります

>>> def foo(*f_args): 
...  print('foo', type(f_args), len(f_args), f_args) 
...  bar(*f_args) 
...  
>>> def bar(*b_args): 
...  print('bar', type(b_args), len(b_args), b_args) 
...  
>>> foo('a', 'b', 'c') 
('foo', <type 'tuple'>, 3, ('a', 'b', 'c')) 
('bar', <type 'tuple'>, 3, ('a', 'b', 'c')) 

、のbarを再定義し、argspecを破るみましょう:

>>> def bar(arg1, arg2, arg3): 
...  print('bar redefined', arg1, arg2, arg3) 
...  
>>> foo('a', 'b', 'c') 
('foo', <type 'tuple'>, 3, ('a', 'b', 'c')) 
('bar redefined', 'a', 'b', 'c') 
>>> foo('a', 'b') 
('foo', <type 'tuple'>, 2, ('a', 'b')) 
---> TypeError: bar() takes exactly 3 arguments (2 given) 
関連する問題