[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Classless Utilities?



I second the 'use a module' vote.

example...

m.py
class a:
   def __init__(self):
       print "init called!"
       self.x = 2


b = a()


p2.py import m

p1.py
import m
import p2


$ python p1.py init called!

So as you can see your class is constructed only once at the first import.


Yah!




On 5/13/06, Kris Schnee <kschnee@xxxxxxxxxx> wrote:
I was just thinking of revising my music/sound functions, which are thin
wrappers for Pygame's. One thing that struck me: I'd put most of the
code into a JukeBox class, so that to play a sound you'd have to create
an instance of it and pass a reference to it to any other object that
needed to be able to play sounds. The point of making the class was to
centralize the jukebox's data, eg. the set of loaded sounds. Otherwise
I'd have bunch of functions and variables lying around in the music
file, not linked to a particular object. It seems like the right thing
to do, for the sake of having any part of my program able to play sound
effects, but kind of inelegant. Thoughts?

Kris