[Tutor] Read dictionary data in a specific order...
Alan Gauld
alan.gauld at btinternet.com
Sat Aug 25 10:26:54 CEST 2007
"Trey Keown" <trey at opmstech.org> wrote
> window_attrs_key_order = ["name", "title", "icon"]
> for (tag,val) in attrs.iteritems():
> for (tag,val) in attrs.iteritems():
> if tag in window_attrs_key_order:
> for tag in window_attrs_key_order:
> if tag == u"name":
> print "%s%s = Tk()" %(whitespace, val)
> print "***^^^%s^^^***" %val
> whatwindow = val
> if tag == u"title":
> print "%s%s.title(\"%s\")" % (whitespace, whatwindow, val)
> if tag == u"icon":
> print "%s%s.iconbitmap(\"%s\")" %(whitespace, whatwindow,
> val)
> """""""""""""""""""""""""""""""""""""
> attrs={u'title': u'example window title', u'name': u'SELF', u'icon':
> u'e.ico'}
> """""""""""""""""""""""""""""""""""""
> ......
> Example Window Title = Tk()
> ***^^^Example Window Title^^^***
> Example Window Title.title("Example Window Title")
> Example Window Title.iconbitmap("Example Window Title")
> SELF = Tk()
> ***^^^SELF^^^***
> SELF.title("SELF")
> SELF.iconbitmap("SELF")
> e.ico = Tk()
> ***^^^e.ico^^^***
> e.ico.title("e.ico")
> e.ico.iconbitmap("e.ico")
> """""""""""""""""""""""""""""""""""""
>
> why would you think that the program would do this?
Odd. I'd try a few things:
1) I'd make the keylist use unicode strings since thats what you
use elsewhere.
2) I'd put a debugging print statement in at the top of the for loop
to print out the tag values. That will show exactly what tag is set
to and prove that the loop is being executed and how often
3) change the name of tag in the inner loop since as it is you are
masking the name in the outer loop which is likely to cause
strange behaviour.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list