Maybe a stupid idea

Mark McEahern mark at mceahern.com
Wed Dec 31 20:10:44 CET 2003


On Wed, 2003-12-31 at 11:49, sebb wrote:
> I'm kind of newbie to programming, but I thought of something and I
> want some opinions on that.
> 
> It's about a new instruction block to do some cycles.

Regarding the subject, I find it comforting to think that all ideas are
stupid.  Just like all questions are.  ;-)

Heh, I don't really know what you mean by cycle.  It'd be helpful to
know what problem you're trying to solve.  Anyway, consider this
admittedly pointless example:

#!/usr/bin/env python

import sys

def makecycle(doUp, doDown):
    def cycle(start, end):
        for i in range(start, end):
            yield i, doUp
        for i in range(end, start, -1):
            yield i, doDown
    return cycle

def doUp(i):
    sys.stdout.write('^')

def doDown(i):
    sys.stdout.write('v')

cycle = makecycle(doUp, doDown)
for i, func in cycle(1, 10):
    func(i)

Cheers,

// m






More information about the Python-list mailing list