[Python-Dev] iterators and extended function call syntax (WAS: Replacement for print in Python 3.0) (original) (raw)

Steven Bethard steven.bethard at gmail.com
Sat Sep 3 19:06:48 CEST 2005


Nick Coghlan wrote:

I actually hope that extended function call syntax in Py3k will use iterators rather than tuples so that this problem goes away.

I suggested this a while back on the Python list: http://mail.python.org/pipermail/python-list/2004-December/257282.html

Raymond Hettinger brought up a few pretty valid complaints, the biggest of which is that a lot of code now expects *args to be sequences, not iterators. For example, the code you posted on the Wiki[1] would break:

def write(*args, **kwds):
    ...
    # may break if args iterator does not have a __len__
    if not args:
        return
    ...
    # will break unless "args = tuple(args)" precedes it
    stream.write(str(args[0]))
    for arg in args[1:]:
        stream.write(sep)
        stream.write(str(arg))

This code would have to be rewritten to use the iterator's .next() method and try/excepts for StopIterations. It's not particularly hard, but people would have to do some relearning about *args.

[1] http://wiki.python.org/moin/PrintAsFunction

STeVe

You can wordify anything if you just verb it. --- Bucky Katt, Get Fuzzy



More information about the Python-Dev mailing list