inheriting file object

Jeremy jlconlin at lanl.gov
Wed Jul 6 15:52:16 EDT 2005


harold fellermann wrote:
>>I don't know if I should be inheriting file or just using a file 
>>object.
>>  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.
Thanks,
Jeremy




More information about the Python-list mailing list