Enumming

John W. Baxter jwbnews at scandaroon.com
Mon Aug 21 19:35:23 EDT 2000


In article <m3zom6uwo6.fsf at greebo.nodomain.de>, Bernhard Herzog 
<herzog at online.de> wrote:

> Others have answered your question and I don't have to add anyting to
> that, so I'll pick the remaining nit:
> 
> "Larry Whitley" <ldw at us.ibm.com> writes:
> 
> > myList = []
> > for i in range( 10 ):
> >     myList.append( functionA(), funcationB(), functionC(), functionD(),
> > functionE() )
> 
> From Python 1.6 on the list's append method will only accept exactly one
> argument, so this will produce a TypeError. 
> 
> That it works now, despite being undocument, is a leftover from very
> early Python which had a different way to call C-methods.

Let me try that again (for some, my cancel will have worked, soon 
enough, and you'll think "*again?".  Starting with Python 1.6, we can say
myList.append( (functionA(), funcationB(), functionC(), 
functionD(),functionD()) )

But unfortunately that's not friendly now: it appends the tuple as one 
item:

>>> a = []
>>> a.append((1, 2, 3))
>>> a
[(1, 2, 3)]


To work with 1.5.2 and 1.6, the loop would need to be something like

     for i in range( 10 ):
        myList.append( functionA() )
        myList.append( functionB() )
        myList.append( functionC() )
        myList.append( functionD() )
        myList.append( functionE() )

Perhaps with a comment suggesting the single append for some future time 
when 1.5.2 and earlier versions do no matter.

-- 
John W. Baxter   Port Ludlow, WA USA  jwbnews at scandaroon.com



More information about the Python-list mailing list