[Tutor] back-quotes to print dictionary
reavey
reavey@nep.net
Sat Apr 19 08:44:02 2003
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
when I run this I get
b = Basket()
b.add('pear')
b.add('apple')
b.add('grape')
Check add method
b.__dict__()
{contents:['pear','apple','grape']}
check print_me method
b.print_me()
contents: elementelementelement
I expect to see the contents of the dictionary [pear,apple,grape]. The
code knows there are three elements but it is not printing the elements?