iterating initalizations

Aaron Stepp stepp.aaron at gmail.com
Tue Dec 23 04:32:17 CET 2008


On Dec 22, 2008, at 10:15 PM, r wrote:

> I can't check you code because i don't have these modules but here is
> the code with proper indention
>
> import random
> from rtcmix import *
> from chimes_source import *
> from rhythmblock import *
> from pitchblock import *
> indexrand = random.Random()
> indexrand.seed(2)
> rhythm = rhythmBlock()
> pitch = pitchBlock()
>
> class pitchAndRhythm:
>    def __init__(self):
>        self.__abet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>    def listCreate(self, num):
>        if num > 25:
>            print "Oops.  This won't work"
>        else:
>            for a in range(num):
>                b = indexrand.randint(0, 3)
>                c = indexrand.randint(0, 7)
>                index = self.__abet[a]
>                index = [ ]
>                index = index.append(rhythm.rhythmTwist(b, c))
>
> take 2: notice the "(" and ")" around the arg to __init__


Thanks for the help so far, I think I'm starting to get a hang of the  
syntax.

I think I need to state my goal more clearly.

Instead of writing a long list of initializations like so:

A = [ ]
B = [ ]
...
Y = [ ]
Z = [ ]

I'd like to save space by more elegantly turning this into a loop.  If  
I need to just write it out, I guess that's ok... but it would be much  
cleaner.  I'm a composer, not a programmer, so some of this is quite  
above me.

I usually ask as a last resort, but I've been through the tutorial and  
didn't find this.  I've got a couple python books, but I'd like to  
finish this piece sooner than later.

Thanks!

AS




More information about the Python-list mailing list