[Bf-python] __del__ hook

Martin Poirier theeth at yahoo.com
Thu Aug 27 17:00:20 CEST 2009


datetime is being removed from the global namespace before your instance is.

As a rule, __del__ methods should never have dependencies outside of the instance itself and its class.

In any case, relying on __del__ for actions that you explicitly want to happen is bad for several reasons outline in the python doc.

http://docs.python.org/reference/datamodel.html#basic-customization

Can you elaborate more on why you wanted to use this method instead of a more explicit method call?

Martin

--- On Thu, 8/27/09, Rettig, Frank AGTHZA-DAE <rettifan at schaeffler.com> wrote:

> From: Rettig, Frank AGTHZA-DAE <rettifan at schaeffler.com>
> Subject: [Bf-python] __del__ hook
> To: bf-python at blender.org
> Received: Thursday, August 27, 2009, 9:19 AM
> 
> 
>  
>  
>  
> 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"
>  
> 
> -----Inline Attachment Follows-----
> 
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
> 


      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now
http://ca.toolbar.yahoo.com.



More information about the Bf-python mailing list