[Tutor] Design Question: File Object used everywhere
Luke Paireepinart
rabidpoobear at gmail.com
Fri May 14 07:35:41 CEST 2010
On Thu, May 13, 2010 at 11:49 PM, Jan Jansen <knacktus at googlemail.com> wrote:
> Hi there,
>
> I'm working on a code to read and write large amounts of binary data
> according to a given specification. In the specification there are a lot of
> "segments" defined. The segments in turn have defintions of datatypes and
> what they represent, how many of some of the data values are present in the
> file and sometimes the offset from the beginning of the file.
>
> Now I wonder, what would be a good way to model the code.
Personally I would just create a class that inherits from object (btw
I don't think you should have empty parenthesis after your classname,
I believe you should explicitly say object so it's clear what you're
inheriting from) and just implement the generic file object methods
(in this case read() and close() is probably all you'd need.)
that way you can pass it to other classes if you need to.
Basically the pythonic way is to make it as generic as possible and to
exploit duck typing so that other classes don't need to know how
you're actually implementing your reading/writing behind the scenes.
I'm not sure if that's acceptable (or even desirable) in this
particular situation though.
More information about the Tutor
mailing list