Why does passing tuple as arg WITHOUT scattering work?

MRAB python at mrabarnett.plus.com
Wed Oct 21 00:26:32 CEST 2009


Alf P. Steinbach wrote:
> Hi all.
> 
> I'm just learning Python from scratch, on my own. Apologies if this 
> question is too newbie... Or perhaps answered in some FAQ (where?).
> 
> Here's my original code for simple starter program, using the 
> ActivePython implementation in Windows XP Prof, Python version is 2.6:
> 
> 
> <code>
> import Tkinter
> 
> window = Tkinter.Tk()
> window.title( "A fixed size ellipse..." )
> window.geometry( "350x200" )            # Client area size, not window 
> size.
> window.resizable( width = 0, height = 0 )
> 
> canvas = Tkinter.Canvas( window, bg = "white" )
> bbox = 2, 2, 347, 197                   # Pixel coors left, top, right, 
> bottom
> canvas.create_oval( bbox, fill = "PeachPuff" )
> canvas.pack()                           # Fill the entire client area, 
> please.
> 
> window.mainloop()                       # Process events until window is 
> closed.
> </code>
> 
> 
> It worked nicely, and I thought this code was fairly perfect until I 
> started studying the language reference.
> 
> It seems that formally correct code should apply the scatter operator to 
> the tuple, like this:
> 
> 
> canvas.create_oval( *bbox, fill = "PeachPuff" )
> 
> 
> And this /also/ works nicely!
> 
> I think it's this latter that is correct, and that the former just 
> worked by accident, due to e.g. the way that some C function parses 
> arguments or such?
> 
> But I'm unable to figure it out, so, what's correct (both? one?), and 
> assuming it's the latter that's correct, would the first version still 
> work in practice regardless of Python / Tkinter implementation?
> 
I've looked at the source in Tkinter.py. The positional arguments are
collected and then flattened into a tuple (tuples and lists are
'scattered').



More information about the Python-list mailing list