Folgende Definition:
class X( object ):
def f( self, x, *args ):
print x % args
X().f( None, '%s %s', 'a', 'b' )
sollte dann
a b
ausdrucken. Stattdessen:
TypeError: not enough arguments for format string
Aendere ich die Definition in:
class X( object ):
def f( self, x, *args ):
print args
print type( args )
dann ergibt obiger Aufruf:
(('a', 'b'),)
<type 'tuple'>
Um Klarheit zu verschaffen:
class X( object ):
def f( self, x, *args ):
print args
print type( args )
print args[0]
print type( args[0] )
print m % args[0]
Obiger Aufruf:
(('a', 'b'),)
<type 'tuple'>
('a', 'b')
<type 'tuple'>
a b
???
Ich dachte immer, *args ergaebe ein Tupel der
Elemente, kein Tupel eines Tupels der Elemente?
Oder habe ich etwas uebersehen?
O'Brien
*verwirrt*
class X( object ):
def f( self, x, *args ):
print x % args
X().f( None, '%s %s', 'a', 'b' )
sollte dann
a b
ausdrucken. Stattdessen:
TypeError: not enough arguments for format string
Aendere ich die Definition in:
class X( object ):
def f( self, x, *args ):
print args
print type( args )
dann ergibt obiger Aufruf:
(('a', 'b'),)
<type 'tuple'>
Um Klarheit zu verschaffen:
class X( object ):
def f( self, x, *args ):
print args
print type( args )
print args[0]
print type( args[0] )
print m % args[0]
Obiger Aufruf:
(('a', 'b'),)
<type 'tuple'>
('a', 'b')
<type 'tuple'>
a b
???
Ich dachte immer, *args ergaebe ein Tupel der
Elemente, kein Tupel eines Tupels der Elemente?
Oder habe ich etwas uebersehen?
O'Brien
*verwirrt*