gump-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject Re: Python Gump...
Date Sat, 26 Apr 2003 14:25:16 GMT
Adam Jack wrote:
> 	Try removing the line containing "try" and the lines starting with
> 	"finally" through the end of the file (unindenting the lines between
> 	where the try and finally lines originally where).
> 
> I just took the latest drop, and did this.
> 
>   #try:
>     f=open(dir.work+'/'+default.merge, 'w')
>     xmlize('workspace',workspace,f)
>   #finally:
>     # Since we may exit via an exception, close fp explicitly.
>   #  if f:
>   #    f.close()
> 
> I've tried commenting these out, followed by deleting them, same result each
> time.
> 
> F:\data\CommonsVersion\Gump\python>python gen.py
>   File "gen.py", line 78
>     f=open(dir.work+'/'+default.merge, 'w')
>     ^
> SyntaxError: invalid syntax
> 
> 	If the open fails, f is never assigned to, and the error you see is that
> 	f is undefined.  (thanks Samuele Pedroni fot the tip).
> 
> So is there no concept of "if undef f and f" in Python?

You didn't unindent the lines that you didn't comment out.

One can do "if 'f' in locals() and f: f.close()", but then you still 
won't see the exception tracebacek from the open.

- Sam Ruby



Mime
View raw message