[Tutor] Object attributes surviving deletion

Kent Johnson kent37 at tds.net
Fri Jun 27 00:59:37 CEST 2008


On Thu, Jun 26, 2008 at 6:30 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "Shrutarshi Basu" <technorapture at gmail.com> wrote
>
>>  def parse_display(self ):
>>
>>      try:
>>          gram = Grammars(10, 10, self.pc_map, self.hard_rules)
>>          gram.database = {}
>
> How is gram.database defined? Is it an instance attribue or
> a class attribute? If you have
>
> class Grammars:
>    database = {}
>    def __init__(....): ....
>
> instead of
>
> class Grammars:
>    def __init__(....):
>         self.database = {}
>          ....
>
> Then database will be shared by all instances of Grammars

No, the assignment
  gram.database = {}
will always (at least absent any extra magic) create an instance attribute.

Kent


More information about the Tutor mailing list