inheriting file object

Jeremy jlconlin at lanl.gov
Wed Jul 6 14:35:23 EDT 2005


Jeremy Jones wrote:

> Something like this?  I put the following code in test_file.py:
> 
> class MyFile(file):
>     def doing_something(self):
>         print "in my own method"
> 
> 
> And used it like this:
> 
> In [1]: import test_file
> 
> In [2]: f = test_file.MyFile("foobar.file", "w")
> 
> In [3]: f.write("foo\n")
> 
> In [4]: f.doing_something()
> in my own method
> 
> 
> But do you really need to subclass file, or can you just use a file 
> instance in your class?
> 
> 
> Jeremy Jones  
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?
Thanks,
Jeremy




More information about the Python-list mailing list