From fafc79777d237b9d6ae7dc8c2745c7ad1434caf5 Mon Sep 17 00:00:00 2001 From: jayfiro Date: Fri, 15 Jun 2018 21:32:53 -0400 Subject: [PATCH 1/2] Fixed Box __repr__ and __str__ AttributeError Added weight=0 to __init__ parameters, self.weight = weight. --- palletier/box.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/palletier/box.py b/palletier/box.py index c11e04b..4cf0706 100644 --- a/palletier/box.py +++ b/palletier/box.py @@ -11,6 +11,7 @@ class Box: def __init__(self, dims, idx=None, pos=Coords(0, 0, 0), orientation=Dims(0, 0, 0), + weight=0, name=None, *args, traits=None): if idx is not None: self.idx = idx @@ -33,6 +34,7 @@ def __init__(self, dims, idx=None, self.dims = Dims(*dims) self.pos = pos self.orientation = orientation + self.weight = weight self.vol = 1 for dim in self.dims: self.vol *= dim From 75bc3936178378f271c3e815221e241d01a32226 Mon Sep 17 00:00:00 2001 From: Jose Figueroa Date: Mon, 18 Jun 2018 17:23:58 -0400 Subject: [PATCH 2/2] Removed the self.weight part on the __str__ and __repr__, and instead print out every element on self.traits with its corresponding value. --- palletier/box.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/palletier/box.py b/palletier/box.py index 4cf0706..ae40118 100644 --- a/palletier/box.py +++ b/palletier/box.py @@ -11,7 +11,6 @@ class Box: def __init__(self, dims, idx=None, pos=Coords(0, 0, 0), orientation=Dims(0, 0, 0), - weight=0, name=None, *args, traits=None): if idx is not None: self.idx = idx @@ -34,7 +33,6 @@ def __init__(self, dims, idx=None, self.dims = Dims(*dims) self.pos = pos self.orientation = orientation - self.weight = weight self.vol = 1 for dim in self.dims: self.vol *= dim @@ -44,8 +42,9 @@ def __eq__(self, other): def __repr__(self): repr_str = f'Box(idx={self.idx}, dims={self.dims}' - if self.weight != 0: - repr_str += f', weight={self.weight}' + if self.traits is not None: + for key in self.traits: + repr_str += f', {key}={self.traits[key]}' if self.name != 'NoName': repr_str += f'name={self.name}' if self.pos != Coords(0, 0, 0): @@ -57,8 +56,9 @@ def __repr__(self): def __str__(self): output = f'Box([{self.dims.dim1}, {self.dims.dim2}, {self.dims.dim3}]' - if self.weight != 0: - output += f', weight={self.weight}' + if self.traits is not None: + for key in self.traits: + output += f', {key}={self.traits[key]}' output += ')' return output