Hello,

I`m starting to learn python, and I hava a very good background in Java
and C/C++ programming. I was reading Dive into python chapter about
OO and I saw that in python we can do the following:

class Person:
    pass

joe = new Person()
joe.name = "Joe"
joe.age = 13

It seems that it is possible to add attributes to any object instance
in run time, as in _javascript_. It seems to me that it can be a source
of errors. One that come in my mind is the follwing:

class Person:
    name = ""

joe = new Person()
joe.nome = "Joe"

The code above adds an attribute called nome,  but the programmer may think it's name.

What is the real interest of this feature ? Is there a way to block this kind of error ?

Thanks,

Miguel
--
Miguel Galves - Engenheiro de Computação
Já leu meus blogs hoje?
Para geeks http://log4dev.blogspot.com
Pra pessoas normais
http://miguelgalves.blogspot.com

"Não sabendo que era impossível, ele foi lá e fez..."
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to