Strommer
Strommer

Reputation: 323

How to pass implicit parameters

I am not sure if this is the right way to ask the question, but here it goes.

I have a class say

class T_shape(Shape):
    def __init__(self, center):
         coords = [Point(center.x - 1, center.y),
                   Point(center.x,     center.y),
                   Point(center.x + 1, center.y),
                   Point(center.x,     center.y + 1)]
    Shape.__init__(self, coords, 'yellow')
    self.center_block = self.blocks[1]

This class has been coded by someone else, I just wanted to ask what would be the right way to pass the parameters. Center is this case is tuple like (3,4). But when I try to pass it directly in this manner, it says 'tuple' object has no attribute 'x'.

Any help would be appreciated.

Upvotes: 0

Views: 1517

Answers (1)

I am not sure what kind of object center is, or T_shape constructor is expecting? But you can achieve with namedtuple.

from collections import namedtuple
center = namedtuple('center', ['x', 'y'], verbose=True)
center = center(x=3,y=4)
t_shape = T_Shape(center)

Upvotes: 2

Related Questions