620 copied = self.copy()
621
622 # We only need to shift x0 because x1 is computed from x0 using dx
623 copied.__x0 = copied.__x0 + shift624 return copied
625
626 def copy(self):
620 copied = self.copy()
621
622 # We only need to shift x0 because x1 is computed from x0 using dx
623 copied.__x0 = copied.__x0 + shift624 return copied
625
626 def copy(self):
600 copied.__shape = self.shape - 2 * self.num_ghost
601 # We "push x0 inside the grid"
602 copied.__x0 = copied.__x0 + self.num_ghost * self.dx
603 copied.__num_ghost = np.zeros_like(copied.shape)604 return copied
605
606 def shifted(self, shift):
599 # lower and upper ghostzones
600 copied.__shape = self.shape - 2 * self.num_ghost
601 # We "push x0 inside the grid"
602 copied.__x0 = copied.__x0 + self.num_ghost * self.dx603 copied.__num_ghost = np.zeros_like(copied.shape)
604 return copied
605
599 # lower and upper ghostzones
600 copied.__shape = self.shape - 2 * self.num_ghost
601 # We "push x0 inside the grid"
602 copied.__x0 = copied.__x0 + self.num_ghost * self.dx603 copied.__num_ghost = np.zeros_like(copied.shape)
604 return copied
605
Accessing a protected member (a member prefixed with _
) of a class from outside that class is not recommended, since the creator of that class did not intend this member to be exposed. If accesing this attribute outside of the class is absolutely needed, refactor it such that it becomes part of the public interface of the class.
class Rectangle(object):
def __init__(self, height, width):
self._height = height
self._width = width
r = Rectangle(4, 8)
area = r._height * r._width
class Rectangle(object):
def __init__(self, height, width):
self._height = height
self._width = width
def area():
return self._height * self._width
r = Rectangle(4, 8)
area = r.area()