Error handling in file generation (Pythonic way: with / decorators?)

2007-08-29 Thread xavim
Hi everyone,

I am writing a small tool that generates a file from a list of
sources.
The function dictgen(dictfile, *sources) takes a list of sources path
and an open file object and does the processing.

I am having some problems with how to do proper error handling.
One of the requirements is that the destination file should not be
created if there is any error in the processing.

I have come out with the following code::

dictfile = file(dictpath, 'w')
try:
try:
dictgen(dictfile, *sources)
finally:
dictfile.close()
except error, e:
os.remove(dictpath)
sys.exit(str(e))
except:
os.remove(dictpath)

but it appears to me as somewhat ugly.  Is there any more Pythonic
way to abstract this kind of error handling?  Maybe 'with' or
decorators could be useful here?

Thanks,
Xavi

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error handling in file generation (Pythonic way: with / decorators?)

2007-08-29 Thread xavim
On Aug 29, 10:58 am, xavim <[EMAIL PROTECTED]> wrote:
> (...)
> try:
> (...)
> except:
> os.remove(dictpath)

This should read::

try:
(...)
except:
os.remove(dictpath)
raise

Sorry.

-- 
http://mail.python.org/mailman/listinfo/python-list


Python training in Barcelona, Spain?

2007-03-16 Thread xavim
Hi!

I work for a company located in Barcelona, Spain, and we are
looking for an on-site introductory Python training.  The
audience would consist of about 10 developers with Java
background.  The training should be taught in Spanish.

Does anyone knows of a company or individual that could
deliver such training?

Thanks!
Xavi

-- 
http://mail.python.org/mailman/listinfo/python-list