[Bf-python] __del__ hook

joe joeedh at gmail.com
Thu Aug 27 16:35:00 CEST 2009


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
>
>



More information about the Bf-python mailing list