I simply love how I can wrap line from csv file in custom CoffeeScript object just by declaring class like:
class Entry
constructor: ([@id, @description, @amount]) ->
and doing new Entry(line.split(','))I simply love how I can wrap line from csv file in custom CoffeeScript object just by declaring class like:
class Entry
constructor: ([@id, @description, @amount]) ->
and doing new Entry(line.split(','))>>> Entry = namedtuple("Entry", "id description amount")
>>> Entry(*line.split(','))
Entry(id='1', description='an entry', amount='99')
Can it inherit from something else?
Can something else inherit from Entry?
Won't named touple have some of its own methods that my methods could have collided with?
class Entry(namedtuple('Entry', ('id', 'description', 'amount')), SomethingElse):
def more_methods(self):
passYes, if you subclass it.
> Can something else inherit from Entry?
Yes, it can be subclassed.
>Won't named touple have some of its own methods that my methods could have collided with
Yes and no, it has the "index" and "count" methods any tuple should have, which can easily be overridden by specifying them as attributes in the second argument to the contructor, through reassignment during initialization or method overriding.