Graham Ashton writes: > > --- libglade.py.orig Thu May 16 16:32:26 2002 > > +++ libglade.py Thu May 16 16:34:01 2002 > > @@ -11,6 +11,8 @@ > > class GladeXML(_gtk.GtkData): > > def __init__(self, filename=None, root=None, domain=None, _obj=None): > > if _obj: self._o = _obj; return > > + open(filename, 'r') ##raises an exception if file does not exist > > + close(filename) ## or is not readable > > I would have thought the intention of the code would be more apparent > (i.e. no need for comment) if you said something like (untested): > > if not os.path.exists(filename): > raise IOError, "No such file or directory: '%s'" % filename > > In general, if you can re-write your code to make the comment redundant, > it's usually a good idea.
You are so utterly and completely right. Furthermore, the patch I posted was totally bogus because "close(filename)" is not the way to close a file, it's "file_object.close()". I don't know how that patch made it past the rigorous testing of my QC department! Time to fire that QC engineer, I guess. ;-) I would like to withdraw this patch. I think an even better approach, which I will try to pursue, would be to catch any errors which occur while importing the Glade file, and turn them into exceptions. The problem of the file being missing or not having read permission is just one special case of a more general error reading/parsing the XML, which currently is not reported back to the user/developer in a very clear way... I think that it would be better to raise an exception than to just emit a complaint to stderr and continue. Opionions? _______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
