[Tutor] back-quotes to print dictionary

Don Arnold Don Arnold" <darnold02@sprynet.com
Sat Apr 19 09:24:01 2003


----- Original Message -----
From: "reavey" <reavey@nep.net>
To: <tutor@python.org>
Sent: Saturday, April 19, 2003 7:39 AM
Subject: [Tutor] back-quotes to print dictionary


> I found this in instant python tutorial and I'm not sure how it's
> suposed to work?
> http://www.hetland.org/python/instant-python.php
> #!/usr/bin/env python
>
> class Basket:
>     def __init__(self, contents = None):
>         self.contents = contents or []
>
>     def add(self,element):
>         self.contents.append(element)
>
>     def print_me(self):
>         result = ""
>         for elem in self.contents:
>             result = result + " " +`element`
>         print "contains:" +result

You have a typo in print_me(). Although you're iterating through
self.contents using elem, you're appending `element` to the result. Change
one of them so they match and it should work.

HTH,
Don