It's my first time creating a class. I'm quite confused as to why the below code acts the way it does.
from collections import Iterable
from six import string_types
class Vols:
def __init__(self, name, recv=[], send=[]):
self.name = name
self.recv = recv
self.send = send
def assign_to(self, dest):
if isinstance(dest, Iterable) and not isinstance(dest, string_types):
for v in dest:
if isinstance(v, SyncVols):
self.send.append(v)
v.recv.append(self)
elif isinstance(dest, SyncVols):
self.send.append(dest)
dest.recv.append(self)
else:
raise TypeError("Destination must be object in class Vols or Iterable")
return
When I set
vol1 = Vols("vol1")
vol2 = Vols("vol2")
and run vol2.assign_to(vol1)
, it adds vol2
to vol2.recv
.
It adds itself to it's own recv
list. Why??? Is there something I'm missing with self
?
I tried adding an if/else statement to make sure dest != self
, but that didn't change anything.