Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61741
| Date | 2013-12-12 18:59 +0000 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Python Script |
| References | <89929063-4c26-4e97-8f28-c53f1c538d1d@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4012.1386874770.18130.python-list@python.org> (permalink) |
On 12/12/2013 18:05, Amimo Benja wrote:
> I have an issue with a Python script that I will show as follows:
> http://codepad.org/G8Z2ConI
>
> Assume that you have three (well defined) classes: AirBase and VmNet,
> . VmNet has got a method that is called recursively each time an HTTP
> response is received. The variable recordTuple needs to be built
> independently for each instance of VmNet that is created. However,
> the mentioned variable is being overwritten across every instance, so
> if you try to get it from vmnet_instance_y, you would get exactly the
> same than retrieving it from vmnet_instance_x.
>
> • What is the code issue? I need to use this script in a project and
> I don't know how to proceed.
>
> Actually, the script aims to follow the principle don't repeat
> yourself (DRY). As you may notice, VmNet and AirBase does not have
> def __init__(self), so self.recordTupleBase does not probably exist.
> Additionally, many other subclasses, similar to VmNet, can implement
> the recursive method using that recordTupleBase.
>
> * I will gladly appreciate any help thanks....
>
This line:
recordTuple = AirBase.recordTupleBase
makes recordTuple refer to the same object as AirBase.recordTupleBase
and AirBase.recordTupleBase is an attribute of the class AirBase itself.
You're re-using the same object. That's why it's being overwritten.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python Script Amimo Benja <amimobenja08@gmail.com> - 2013-12-12 10:05 -0800
Re: Python Script Gary Herron <gary.herron@islandtraining.com> - 2013-12-12 10:35 -0800
Re: Python Script Amimo Benja <amimobenja08@gmail.com> - 2013-12-12 22:21 -0800
Re: Python Script Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-13 08:38 +0000
Re: Python Script Terry Reedy <tjreedy@udel.edu> - 2013-12-12 13:55 -0500
Re: Python Script Amimo Benja <amimobenja08@gmail.com> - 2013-12-12 22:21 -0800
Re: Python Script MRAB <python@mrabarnett.plus.com> - 2013-12-12 18:59 +0000
Re: Python Script Amimo Benja <amimobenja08@gmail.com> - 2013-12-12 22:26 -0800
csiph-web