[python] Lokalne premenne v try-except

Petr Prikryl PrikrylP na skil.cz
Středa Prosinec 7 11:40:08 CET 2005


Jan Janech
> Jaroslav Pachola wrote:
> >Jan Janech wrote:
[...]
> >>robim na jednu internetovu aplikaciu system, ktory mi  posiela mail pri
> >>kazdej chybe a system pokracuje dalej. Mam vsak otazku: da sa nejako
> >>zistit obsah lokalnych premennych v case chyby? chcel by som ich
> >>posielat serializovane ako prilohu mailu...  z tracebacku sa toho
> >>castokrat vela nedozviem.
[...]
> >treba takto?
> >
> >try:
> >    # nejaky kod
> >except:
> >    print locals() # nebo neco podobneho
> >    raise
[...]
> To by bolo prilis jednoduche :) V ramci bloku try mozu byt 
> volane fcie,  a chyba moze nastat v nich

Zkus si pohrát s modulem inspect. Zaměř se na 
metody stack() a trace():

  stack( [context]) 
  
     Return a list of frame records for the caller's
     stack. The first entry in the returned list
     represents the caller; the last entry represents
     the outermost call on the stack.
  
  trace( [context]) 
  
     Return a list of frame records for the stack
     between the current frame and the frame in which
     an exception currently being handled was raised
     in. The first entry in the list represents the
     caller; the last entry represents where the
     exception was raised.

Třeba z toho to potřebné vydoluješ.

pepr



Další informace o konferenci Python