Problem with join in__str__() in class (newbie)
MRAB
python at mrabarnett.plus.com
Sun Aug 9 14:10:08 EDT 2009
Fencer wrote:
> jon rascal wrote:
>>
>> You're turning your list into a string -- try this:
>> ', '.join([str(x) for x in self.topics])
>
> Thanks for your quick reply, unfortunately it didn't quite work for me.
> Say topics contain two topics: polemics, and the parthenon I get this
> output:
> e2:Carla
> Known topics: t5:Polemics
>
> 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[1]
> 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
> self.topics]))
> TypeError: iteration over non-sequence
>
> What did I do wrong?
>
Try printing self.topics. It should always be a list of topics.
More information about the Python-list
mailing list