Why don't people like lisp?

Jon S. Anthony j-anthony at rcn.com
Thu Oct 23 19:16:25 EDT 2003


Brian Kelley <bkelley at wi.mit.edu> writes:

> I choose a bad example on abusing the C-implementation.  The main
> thrust of my argument is that you don't need macros in this case,
> i.e. there can be situations with very little tradeoff.
> 
> class SafeFileWrapper:
>     def __init__(self, f):
>         self.f = f
> 
>     def write(self, data):
>         try: self.f.write(data)
>         except:
>          self.f.close()
> 	self.f = None
>          raise
> 
>      def close():
>          if self.f:
>             self.f.close()
>     ...
> 
> Now the usage is:
> 
> f = SafeFileWrapper(open(...))
> print >> f, "A couple of lines"
> f.close()
...
> I still have to explicitly close the file though when I am done with

It's just this sort of monotonous (yet important) book keeping (along
with all the exception protection, etc.) that something like
with-open-file ensures for you.


/Jon




More information about the Python-list mailing list