[Bf-python] __del__ hook

Rettig, Frank AGTHZA-DAE rettifan at schaeffler.com
Thu Aug 27 17:02:14 CEST 2009


that helped,
thanks joe 

-----Ursprüngliche Nachricht-----
Von: bf-python-bounces at blender.org [mailto:bf-python-bounces at blender.org] Im Auftrag von joe
Gesendet: Donnerstag, 27. August 2009 16:35
An: Blender Foundation Python list
Betreff: Re: [Bf-python] __del__ hook

The namespace is messed up.  Attach datetime to the class, e.g.
self.datetime = datetime, in the __init__ function.

Joe

On Thu, Aug 27, 2009 at 7:19 AM, Rettig, Frank AGTHZA-DAE<rettifan at schaeffler.com> wrote:
> Dear list,
> I'am working on a import script for blender. The idea is to use the 
> __del__ hook to complete the import. The following script works fine 
> on my python interpreter, but if I use it from Blender I get:
>
> Exception NameError: "global name 'datetime' is not defined" in <bound 
> method X.
> __del__ of <__main__.X instance at 0x01FAD440>> ignored
>
> Any idea why the code doesn't run with blender?
>
> Best regards,
> Frank
>
>
> import datetime
> import time
>
> class X:
>      def __init__(self):
>          self._job_begin_time = datetime.datetime.now()
>          print "My job has started at %s " % self._job_begin_time
>
>      def __del__(self):
>          self._job_end_time = datetime.datetime.now()
>          print "My job has ended at %s " % self._job_end_time
>          print "Job took this much time: %s" % (self._job_end_time -
>                                                 self._job_begin_time )
>
>      def waste_some_time(self):
>       pass
>
> print "Starting job X"
> myX = X()
> myX.waste_some_time()
> print "Ending job X"
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
>
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python



More information about the Bf-python mailing list