[Tutor] Python structure advice ?
pythontut at pusspaws.net
Fri Dec 17 20:16:07 CET 2004
Kent Johnson wrote:
> Dave S wrote:
>> Dave S wrote:
>>> The 'remembering where is was' seems a continuous stumbling block
>>> for me. I have though of coding each module as a class but this
>>> seems like a cheat. I could declare copious globals, this seems
>>> messy, I could define each module as a thread & get them talking via
>>> queues, given this serious thought but heeded warning in previous
>>> posts. I have thought about returning an list of saved 'pointers'
>>> which would be re-submitted when the function is called. I don't
>>> know which way to turn.
>> Having written this email, it has put my thoughts in order, though it
>> seems a bit cheaty, wouldn't defining all modules that have to
>> remember their internal state as classes be the best bet ?
> Why do you say this is 'cheaty'? A class is basically a collection of
> data (state) and functions to operate on that state.
Sorry for the delay, real world work got in the way ...
Well I understand classes to be used when multiple instances are
required, I will only need one instance and as such it seemed a bit of a
cheat, The trouble is I now pretty well understand the tools, but don't
know how you guys use them in the real world.
> You might be interested in this essay:
I found this particularly usefull,
> It might well make sense to organize your program as a collection of
> cooperating classes, or maybe a collection of classes with a top-level
> function that stitches them all together.
Yes, this is the way I see things progressing, from 20,000ft this makes
a lot of sense.
> You might also want to learn about iterator classes and generator
> functions, they are a technique for returning a bit of data at a time
> while maintaining state. You might be able to structure your input
> stage as an iterator or generator.
I remeber iterators from 'learning python', I was concerned about
several modules all 'having a iterator' to the next, debuging would be
scary ! I think I will go the class route.
> Tutor maillist - Tutor at python.org
More information about the Tutor