using dict for data attributes instead of self
From: Alexander Kervero (vegeta.z_at_gmail.com)
Date: 10/31/04
- Next message: Andrea Griffini: "Re: [OT] Re: "number-in-base" ``oneliner''"
- Previous message: Roger Binns: "Re: Multiple XML-RPC calls over the same connection?"
- Next in thread: Bengt Richter: "Re: using dict for data attributes instead of self"
- Reply: Bengt Richter: "Re: using dict for data attributes instead of self"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: python-list@python.org Date: Sun, 31 Oct 2004 03:52:10 -0400
Hi ,today i was reading diveinto python book,in chapter 5 it has a very
generic module to get file information,html,mp3s ,etc.
The code of the example is here :
http://diveintopython.org/object_oriented_framework/index.html
One thing that i have some doubs is this part :
class FileInfo(UserDict):
"store file metadata"
def __init__(self, filename=None):
UserDict.__init__(self)
self["name"] = filename
So why does he wants a dictionary-like base class if he never uses any
dictionary method,except for dict.clear which is not necesary.
--
could be done like this?
class FileInfo():
"store file metadata"
def __init__(self, filename=None):
UserDict.__init__(self)
self.name = filename
And the FileInfo subclasses could have the specific attributes that belongs
to each file type,for example mp3.
check the link to the full example.
--
The only reason is to have a base class with arbitrary attributes ? so it
can dinamicaly adquire attributes depending of its subclass or something
like that?
Is there a clearer way to do it? Is there any benefits of going this way
that i dont see?
Maybe this is just a dummy example to just show some functionality related
to the chapter? I am a bit confused.
- Next message: Andrea Griffini: "Re: [OT] Re: "number-in-base" ``oneliner''"
- Previous message: Roger Binns: "Re: Multiple XML-RPC calls over the same connection?"
- Next in thread: Bengt Richter: "Re: using dict for data attributes instead of self"
- Reply: Bengt Richter: "Re: using dict for data attributes instead of self"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]