Recommendations (or best practices) to define functions (or methods)

Gabriel Genellina gagsl-py at yahoo.com.ar
Mon Jan 8 18:22:00 CET 2007


At Monday 8/1/2007 10:25, vizcayno wrote:

>However, what happens when the error is due to data error. Or when the
>program is reading many files to save data into a database and one or
>two files have problems with data format. I would like to keep the
>program running (using exception in a controlled way) for the remaining
>good files and prepare a log about the failed files. How to keep the
>same function for a program that runs in batch, or on-line or in  the
>web? Giving the simple example I put, I would like to find more
>guidelines.

Deal with the exception at a higher level. In your example, you have 
some files to be processed:

for fname in filenames:
    do_something_with(fname)

==>

for fname in filenames:
     try:
         do_something_with(fname)
     except StandardError, E:
         log_error(E)


-- 
Gabriel Genellina
Softlab SRL 


	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the Python-list mailing list