When I want to know about a attribute (e.g.: myAttrib) of an object, I
should use the specific method (e.g.: getMyAttrib).
Considering that this attribute is always another object (everything is an
object in Python), what should getMyAttrib do?
1) Return the object
2) Return a copy of the object
How do I return a copy of the object?
Thanks for all.
.. Facundo
.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .
.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .
.. . . . . . . . . . . . . . .
ADVERTENCIA
La información contenida en este mensaje y cualquier archivo anexo al mismo,
son para uso exclusivo del destinatario y pueden contener información
confidencial o propietaria, cuya divulgación es sancionada por la ley.
Si Ud. No es uno de los destinatarios consignados o la persona responsable
de hacer llegar este mensaje a los destinatarios consignados, no está
autorizado a divulgar, copiar, distribuir o retener información (o parte de
ella) contenida en este mensaje. Por favor notifíquenos respondiendo al
remitente, borre el mensaje original y borre las copias (impresas o grabadas
en cualquier medio magnético) que pueda haber realizado del mismo.
Todas las opiniones contenidas en este mail son propias del autor del
mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones
Personales S.A. o alguna empresa asociada.
Los mensajes electrónicos pueden ser alterados, motivo por el cual
Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación
cualquiera sea el resultante de este mensaje.
Muchas Gracias. 2 1320
In article <ma*********************************@python.org> , Batista, Facundo: This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.
When I want to know about a attribute (e.g.: myAttrib) of an object, I should use the specific method (e.g.: getMyAttrib).
Considering that this attribute is always another object (everything is = an object in Python), what should getMyAttrib do?
1) Return the object 2) Return a copy of the object
I do not think there is a definite rule regarding this. However,
whichever one it does, you should probably document it :o)
How do I return a copy of the object?
You can use the copy module to create either a shallow or deep copy.
Batista, Facundo wrote: When I want to know about a attribute (e.g.: myAttrib) of an object, I should use the specific method (e.g.: getMyAttrib).
Its not really considered "pythonic" to access attributes through
getters and setters. Instead, you can access them directly: class Foo:
.... def __init__(self, val):
.... self.a = val
.... foo = Foo(4) print foo.a
4 foo.a = 6 print foo.a
6
If you need to to other processing of the data for the data (ie, if you
wanted to give a copy), you can use the __getattr__ and __setattr__
methods.
Considering that this attribute is always another object (everything is an object in Python), what should getMyAttrib do?
1) Return the object 2) Return a copy of the object
How do I return a copy of the object?
try looking at: import copy help(copy)
HTH,
-Dan Thanks for all.
. Facundo
[snip] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nicolas Lehuen |
last post by:
Hi,
I hope this is not a FAQ, but I have trouble understanding the behaviour of
the super() built-in function. I've read the excellent book 'Python in a
Nutshell' which explains this built-in...
|
by: Ares Lagae |
last post by:
Could someone please tell me what the behaviour of the following code
snippet is, according to the C++ standard ?
--------------------------------------------------------------------------
...
|
by: Frederick Gotham |
last post by:
If we look at a programming language such as C++: When an updated Standard
comes out, everyone adopts it and abandons the previous one.
It seems though that things aren't so clear-cut in the C...
|
by: subramanian100in |
last post by:
Program 1:
---------------
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |