annoying behavior

Christopher Barker Chris.Barker at noaa.gov
Wed Sep 29 15:22:52 EDT 2004


Patrick Maupin wrote:
> But, in Python, instances are "open".  This means that I can add
> attributes to a class instance at _any_ time 

Just to make it really clear what Patrick is saying:

#!/usr/bin/env python2.3

class foo:
     def __init__(self, host):
         self.f()
         self.r = True

     def f(self):
         if self.r:
             print "r is True"
         else:
             print "r is not True"


# now I'll add foo.r, before initialization:
foo.r = False

f = foo("1234")


and this runs just fine:

junk $ ./junk.py
r is not True

If you don't want a dynamic language, don't use Python!

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the Python-list mailing list