Why does passing tuple as arg WITHOUT scattering work?
ethan at stoneleaf.us
Wed Oct 21 01:00:33 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:
>> import Tkinter
>> window = Tkinter.Tk()
>> window.title( "A fixed size ellipse..." )
>> window.geometry( "350x200" ) # Client area size, not window
>> 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,
>> window.mainloop() # Process events until window
>> is closed.
>> 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
Huh. I would have said 'gathered'. Must be my FoxPro days sneaking up
on me. *Shudder*
More information about the Python-list