[Tutor] back-quotes to print dictionary

Adrian Maier am@fx.ro
Sat Apr 19 09:36:01 2003


reavey (reavey@nep.net) a scris :
> I found this in instant python tutorial and I'm not sure how it's 
> suposed to work?

That little program doesn't work at all here :

Traceback (most recent call last):
  File "a.py", line 21, in ?
    b.print_me()
  File "a.py", line 13, in print_me
    result = result + " " +`element`
    NameError: global name 'element' is not defined


But if you replace:

             result = result + " " +`element`
with:
             result = result + " " + elem

then the program does exactly what it is expected to do:

contains: pear apple grape



If you backquote elem:       result = result+" "+`elem`   
then you'll get:

contains: 'pear' 'apple' 'grape'




Best wishes.

-- 
Adrian Maier
(am@fx.ro)