Class or Modules?

David Konsumer konsumer at toughtechs.com
Mon Aug 23 18:20:17 CEST 2004


I'm writing a game to learn more about python, and I've done a little
bit of programming in puthon so far, that were very small projects
(single source file) shell scripts, little gui's, and the like. Now that
I'm working on something larger, I'm not sure how to go about it.

My question is: Which should I use for multiple source files in a large
project, classes or modules?

Here is an example of my sturcture

main
  input
  video

input and video need to get/set data from the others that needs to be
persistant (like if I set video.x in main or video, input needs to see
it the same way) and run functions from the others.

So the way I tried to achieve this uses classes (which I'm fairly sure
is BAD, it just doesn't seem right) was this:

import input,video,events,gui,gameplay,player
class main:
  def __init(self)__:
    input=input.Input(self)
    video=video.Video(self)
    (more like that)

and then in other files:

class input:
  def __init__(self,engine):
    self.engine=engine

class Video:
  def __init__(self,engine):
    self.engine=engine

(more like that)

Is there a better way to do this?




More information about the Python-list mailing list