Problem with join in__str__() in class (newbie)
apt.shansen at gmail.com
Sun Aug 9 20:06:44 CEST 2009
> only the first topic is printed. If topics only contain a single topic I
> get this error:
> Traceback (most recent call last):
> File "C:\Users\fencer\workspace\Find Expert\src\find_expert.py", line 57,
> in <module>
> print experts
> File "C:\Users\fencer\workspace\Find Expert\src\find_expert.py", line 21,
> in __str__
> output += '\nKnown topics: %s' % (', '.join([str(x) for x in
> TypeError: iteration over non-sequence
> What did I do wrong?
It looks like, "if topics contains only a single topic", means:
self.topics = MyTopic
was done at some point. What you should do is make self.topics ALWAYS be a
list: even if it's only a list of one item.
So you do
when you add that one topic. That way self.topics is always a list.
Sometimes empty, sometimes containing one element, sometimes containing
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list