I'm reading tab separated values from strings into an object like this:
class Node(rect):
def __init__(self, line):
(self.id, self.x1, self.y1, self.x2, self.y2) = line.split('\t')
That works fine, but say I want to convert those x and y coordinates, which are read from the string line
, to floats. What is the most pythonic way to do this? I imagine something like
(self.id, float(self.x1), float(self.y1), float(self.x2), float(self.y2)) = line.split('\t')
which of course does not work. Is there an elegant way to do this or do I have to manually convert afterwards like self.x1 = float(self.x1)
?