Piet van Oostrum wrote:
[snip]
Thanks for your detailed reply!
- Fencer
--
http://mail.python.org/mailman/listinfo/python-list
> Fencer (F) wrote:
>F> Also, notice the code I've commented out. If I can get the join above to
>F> work (with your help) my next question is how to present the known experts
>F> in a comma separated list with only expert_id and name? I can't use the
>F> normal __str__() method (the one I'm
MRAB wrote:
Try printing self.topics. It should always be a list of topics.
Ah, yes, that made me find a bug when I was creating the Expert objects:
the lists of known topics were not created properly. I should have
posted more code I suppose! Thanks for the help, this problem has now
been s
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 t
>
> 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
>print experts[1]
> File "C:\Users\fencer\workspace\Find Expert\src\find_expert
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:Polem
output += '\nKnown topics: %s' % (', '.join(str(self.topics)))
Your problem is here.
self.topics is a list of topic instances: but you're calling str() on the
list itself to turn the LIST itself into a string. Compare:
>>> x = [1,2,3]
>>> x
[1, 2, 3]
>>> str(x)
'[1, 2, 3]'
Now, after str(se
> def __str__(self):
> output = '%s:%s' % (self.expert_id, self.name)
> output += '\nKnown topics: %s' % (', '.join(str(self.topics)))
You're turning your list into a string -- try this:
', '.join([str(x) for x in self.topics])
--
http://mail.python.org/mailman/listinfo/python-list
Hello, I've written two classes. One class describes experts: experts
has a unique ID and a name. An expert knows topics and other experts. A
topic is described by my other class and includes a unique ID and a
name. Now I have a problem with the __str__ method in my Expert class:
def __str__(s