I have written a class in python that implements __str__(self)
but when I use print on a list containing instances of this class, I just get the default output <__main__.DSequence instance at 0x4b8c10>
. Is there another magic function I need to implement to get this to work, or do I have to write a custom print function?
Here's the class:
class DSequence:
def __init__(self, sid, seq):
"""Sequence object for a dummy dna string"""
self.sid = sid
self.seq = seq
def __iter__(self):
return self
def __str__(self):
return '[' + str(self.sid) + '] -> [' + str(self.seq) + ']'
def next(self):
if self.index == 0:
raise StopIteration
self.index = self.index - 1
return self.seq[self.index]