[Tutor] creating read only attributes
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Sat Nov 22 07:06:04 EST 2003
On Sat, 22 Nov 2003 14:15:58 +1300, you wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>
>Hi guys,
>
>
[snipped]
>
>I'm sure there's a way to do this in python, but I haven't found it yet.
>
Use properties -- look in the doc, under language reference,
customizing attribute access.
Then read this:
http://zephyrfalcon.org/labs/beginners_mistakes.html
I'll quote the important part:
"""
Mistake 2: writing "language X" code in Python
This is a mistake that is almost unavoidable. You come from, say,
Pascal, and try your hand at Python. The first code you write will
probably look like Pascal with a Python syntax. You are writing Pascal
code in Python.
Some notorious symptoms of "language X" code, and the languages that
may cause them:
- You're really paranoid about data hiding (some would call this
"encapsulation"), and/or write getters and setters for all object
attributes. (Java, C++, Delphi)
- You overuse properties (one of the shiny new features in Python
2.2). (Java, Delphi, maybe Visual Basic, C++?)
"""
With my best regards,
G. Rodrigues
More information about the Tutor
mailing list