Please l will like to have a mentor how can I have it On Feb 14, 2017 09:53, <tutor-requ...@python.org> wrote:
> Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > > 1. Re: Access a .tcl file in python (Alan Gauld) > 2. Re: Q about .join() Thanks! (David Rock) > 3. Re: Fwd: Re: GUI for ANSI colors (Alan Gauld) > 4. Re: Q about .join() Thanks! (Alan Gauld) > 5. Re: Q about .join() Thanks! (Danny Yoo) > 6. Re: Q about .join() Thanks! (Peter Otten) > > > ---------- Forwarded message ---------- > From: Alan Gauld <alan.ga...@yahoo.co.uk> > To: tutor@python.org > Cc: > Date: Tue, 14 Feb 2017 01:17:39 +0000 > Subject: Re: [Tutor] Access a .tcl file in python > On 13/02/17 19:37, Lily ANTONY wrote: > > > I have a .tcl file.Does anyone know how to load a .tcl file in to > python?I > > need to call the .tcl file in > > a python program..Thanks! > > In general you can't run code for one language in a > program written in another language. (There are a few > exceptions, usually where one language is written in > the other). > > The nearest you can usually get is to execute the > Tcl program using the tcl interpreter (tclsh) from > the OS using a module like subprocess. > > However, Tcl and Python do have a connection via > the Tkinter module and you can call tcl code > using Tkinter like so(Python v3): > > import tkinter > tcl = tkinter.Tcl() > tcl.eval(""" > puts [expr 4+5] # or any other arbitrary tcl > """) > > So to execute a Tcl file you can read the contents > into a string and then execute that string. Note that > the return value will always be a string. > > HTH > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > > > ---------- Forwarded message ---------- > From: David Rock <da...@graniteweb.com> > To: "tutor@python.org" <tutor@python.org> > Cc: > Date: Mon, 13 Feb 2017 19:20:52 -0600 > Subject: Re: [Tutor] Q about .join() Thanks! > > > On Feb 13, 2017, at 12:34, SIJIA CHEN <schen...@wisc.edu> wrote: > > > > I find out that the outcome for using .join() on a dictionary is totally > different than it using on list or string. for example, > > > >>>> seq4 = {'hello':1,'good':2,'boy':3,'doiido':4} > >>>> print ':'.join(seq4) > > boy:good:doiido:hello > > So my question is why the outcome doesn't show sequentially as the same > sequence of the original seq4? What pattern do those "keys" of the > dictionary in the outcome show ? > > Dictionaries (in particular, their keys) are unordered. You can not rely > on them to be in a particular sequence. The reason for this, from a > practical perspective, is you are expected to ask for the specific key; you > should not care about the ordering. > > Lists, on the other hand, have a specific order by design so will always > be in the order they were created. > > What are you trying to do with join() on a dictionary in the first place? > Is there a specific outcome you are trying to get? It’s unlikely that > using join on a dictionary is what you actually want. > > — > David Rock > da...@graniteweb.com > > > > > > > ---------- Forwarded message ---------- > From: Alan Gauld <alan.ga...@yahoo.co.uk> > To: tutor@python.org > Cc: > Date: Tue, 14 Feb 2017 01:26:45 +0000 > Subject: Re: [Tutor] Fwd: Re: GUI for ANSI colors > On 14/02/17 00:58, Alan Gauld forwarded: > > > red = '\033[91m' > > yel = '\033[93m' > > blu = '\033[34m' > > grn = '\033[32m' > > These are indeed the ANSI codes for the colours but ANSI > codes only work in an ANSI terminal and GUIs are not > ANSI terminals. Instead they have their own ideas on > colours and you need to use those. They all support > the standard 16 colours used in ANSI however, so in > your case (for Tkinter at least) just use the names > 'red', 'yellow', 'blue' and 'green' > > > colors = [red, yel, blu, grn] > > colors = ['red', 'yellow', 'blue', 'green'] > > > > final_word = ''.join(choice(colors) + char for char in word) > > But again that won't work in a GUI, you need to use the GUIs > way of colouring. In Tkinter that's via tags as per my > previous post, reproduced here). > > > ############################### > > from Tkinter import * > > > > n = 0 > > top = Tk() > > t = Text(top, width=25, height=2) > > t.pack() > > > > # set up tags for the colors > > colors = ['red','blue','green'] > > for col in colors: > > t.tag_config(col, foreground=col) > > > > def addWords(): > > n = 0 > > for word in "Hello ", "bright ", "world ": > > t.insert(END,word,colors[n]) #use the color tags > > n +=1 > > > > You need to change the loop to iterate over the letters > instead of words and choose the tags at random. But that > should be fairly straightforward. > > > Button(top,text="Add words",command=addWords).pack() > > > > top.mainloop() > > ###################### > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > > > ---------- Forwarded message ---------- > From: Alan Gauld <alan.ga...@yahoo.co.uk> > To: tutor@python.org > Cc: > Date: Tue, 14 Feb 2017 01:31:57 +0000 > Subject: Re: [Tutor] Q about .join() Thanks! > On 13/02/17 18:34, SIJIA CHEN wrote: > > I find out that the outcome for using .join() on a dictionary is > > totally different than it using on list or string. > > Not really, it just looks like that :-) > > > > > >>> seq4 = {'hello':1,'good':2,'boy':3,'doiido':4} > > >>> print ':'.join(seq4) > > boy:good:doiido:hello > > So my question is why the outcome doesn't show sequentially > > That's because dictionaries are not stored sequentially and the > order of retrieval is not guaranteed - it can even change > during the execution of a program so you should never > depend on it. That's because dictionaries are optimised > for random access via the keys not to be iterated over. > > You can sort the keys and then pull the values and that will > give you a guaranteed order but simply printing the dictionary > (or joining it as you did) is not reliable. > > I've a vague memory that recent versions of Python may have > a special dictionary type that does return items in the order > they were inserted, but I may be mixing that up with > another language... Hopefully someone else can provide > a steer there. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > > > ---------- Forwarded message ---------- > From: Danny Yoo <d...@hashcollision.org> > To: Alan Gauld <alan.ga...@yahoo.co.uk> > Cc: Python Tutor Mailing List <tutor@python.org> > Date: Mon, 13 Feb 2017 18:10:10 -0800 > Subject: Re: [Tutor] Q about .join() Thanks! > > That's because dictionaries are not stored sequentially and the > > order of retrieval is not guaranteed - it can even change > > during the execution of a program so you should never > > depend on it. That's because dictionaries are optimised > > for random access via the keys not to be iterated over. > > Moreover, most implementations *deliberately* randomize their iteration > order to avoid a particular kind of hash collision attack out there in > the wild. See: > > https://en.wikipedia.org/wiki/Collision_attack > > https://arstechnica.com/business/2011/12/huge- > portions-of-web-vulnerable-to-hashing-denial-of-service-attack/ > > https://mail.python.org/pipermail/python-dev/2011-December/115116.html > > for some details. > > > > I've a vague memory that recent versions of Python may have > > a special dictionary type that does return items in the order > > they were inserted, but I may be mixing that up with > > another language... Hopefully someone else can provide > > a steer there. > > In Python, it's collections.OrderedDict: > > https://docs.python.org/3.6/library/collections.html# > collections.OrderedDict > > Other languages have similar libraries. Java has LinkedHashMap, for > example: > > https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html > > > Best of wishes! > > > > ---------- Forwarded message ---------- > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Cc: > Date: Tue, 14 Feb 2017 09:50:04 +0100 > Subject: Re: [Tutor] Q about .join() Thanks! > Danny Yoo wrote: > > > Moreover, most implementations *deliberately* randomize their iteration > > order to avoid a particular kind of hash collision attack out there in > > the wild. See: > > In CPython the hash() of a string may change between different runs to fend > off hash collision attacks, but that does not necessarily change the order > of iteration: > > In Python 3.4 for example both order and hash value change > > $ python3.4 -c 'd = dict.fromkeys("foo bar baz".split()); > print(hash("foo"), > *d)' > -1599197652882818545 baz bar foo > $ python3.4 -c 'd = dict.fromkeys("foo bar baz".split()); > print(hash("foo"), > *d)' > -7773300350121034240 foo bar baz > $ python3.4 -c 'd = dict.fromkeys("foo bar baz".split()); > print(hash("foo"), > *d)' > 4096077922251392823 baz bar foo > > In Python 3.6 on the other side the hash values still change, but > (insertion) order is preserved: > > $ python3.6 -c 'd = dict.fromkeys("foo bar baz".split()); > print(hash("foo"), > *d)' > 22453670082131454 foo bar baz > $ python3.6 -c 'd = dict.fromkeys("foo bar baz".split()); > print(hash("foo"), > *d)' > 4601604916521659267 foo bar baz > $ python3.6 -c 'd = dict.fromkeys("foo bar baz".split()); > print(hash("foo"), > *d)' > 5190466601789110813 foo bar baz > > So if the OP had used Python 3.6 she would have seen the behaviour she > expected. However, quoting > <https://docs.python.org/dev/whatsnew/3.6.html#new-dict-implementation> > > """ > The order-preserving aspect of this new [dict] implementation is considered > an implementation detail and should not be relied upon > """ > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > https://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor