Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: inheriting file object

Thread Tools

Re: inheriting file object

Posts: n/a
harold fellermann wrote:
>>I don't know if I should be inheriting file or just using a file
>> How would I determine which one would be more appropriate?

> Inheritance is often refered to as an IS relation, whereas using an
> attribute
> is a HAS relation.
> If you inherit from file, all operations for files should be valif for
> your
> class also. Usually the file-operations would be directly inherited and
> not
> overwritten.
> However, if you don't want to expose all file functionalities, a HAS
> relation
> is more appropriate. if you plan to use your class as a file handle,
> e.g. for
> formatting output in a special way, I woould prefer to make the file an
> attribute:

> If you would tell as your use case, it would be easier to give you an
> advice.

That is an excellent explanation and the example is similar to what I
want to do. I have a file I want to look through and change if needed.
I think I will follow you suggestion and not inherit from the file object.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inheriting from Python list object(type?) Mangabasi Python 3 05-24-2007 09:05 AM
Inheriting str object Python 5 02-06-2007 11:25 AM
inheriting type or object? Fabiano Sidler Python 1 04-27-2006 10:09 PM
inheriting file object Jeremy Python 0 07-06-2005 04:58 PM
Inheriting from object Fuzzyman Python 16 07-03-2005 06:53 PM