Hi Evert, I actually wanted the var names to be in English, but apparently the people who came up with the coding convention did not agree with me on this. Then again, the Zen of Python states that (1) readability counts and that (2) practicality beats purity. Most of the time, I'm 120% sure the code doesn't leave Holland. If it inadvertently does, Ctrl-H is my friend. It's impractical to overgeneralize one's applications. Let's say I have a list of all the medical specialisms we have here in N. I really wouldn't know all the exact English equivalents. My manager wouldn't like it if I spent my time doing all the translations. Besides, doesn't it with the current political climate to have dutch-only code? ;-) [Note: We had a landslide win of a xenophobic, right-wing party during the last elections]
Meanwhile, I tinkered a bit more with the code. I used exec() to isolate the event handler function. It works and it's better, but I think it could be still better. I'm not so fond of eval() and exec(). from Tkinter import * def createWidgets(veldnamen): root=Tk() termenlijst = {"Naam": set(["Bill Gates", "Elvis Presley"]), "*Postcode": set(["2600AA", "8000BB"]), "Adres": set(["Street", "Avenue"])} handleDeletions = {} for veldnaam in veldnamen: labelWidget=Label(root, text=veldnaam, takefocus=False) labelWidget.grid() # tcl names must start with a lowercase letter tclName = veldnaam[0].lower() + veldnaam[1:] content = StringVar() entryWidget=Entry(root, name=tclName, textvariable=content) entryWidget.grid() exec(doHandleDeletion()) handleDeletions[entryWidget] = handleDeletion for entryWidget, handleDeletion in handleDeletions.iteritems(): entryWidget.bind("<Shift-Delete>", handleDeletion) def doHandleDeletion(): func = \ """def handleDeletion(event, widget=entryWidget, root=root, termenlijst=termenlijst,content=content): actieveVenster = root.focus_get() actieveVensternaam = str(actieveVenster)[1:].capitalize() if actieveVensternaam.startswith("*"): actieveVensternaam = "*" + actieveVensternaam[1:].capitalize() vensterinhoud = content.get().strip() print "Name: %s -- Contents: %s" % (actieveVensternaam, vensterinhoud) try: termenlijst[actieveVensternaam].remove(vensterinhoud) actieveVenster.delete(0, END) print "Deleted term '%s'" % vensterinhoud except KeyError: print "No such term '%s'" % vensterinhoud pass""" return func createWidgets(["Naam", "*Postcode", "Adres"]) Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ________________________________ From: Evert Rol <evert....@gmail.com> To: Albert-Jan Roskam <fo...@yahoo.com> Cc: Patty <pa...@cruzio.com>; Python Mailing List <tutor@python.org> Sent: Sat, December 4, 2010 2:10:04 PM Subject: Re: [Tutor] Question on tkinter event binding > Hi Patty, > > As far as books are concerned, I actually prefer (programming) books in the >English language. Although the Dutch don't do it as much as e.g. the French or >the Germans, I hate it when technical terms are translated into Dutch in a >somewhat artificial way ("Computer" is "Ordinateur" in French and "Rechner" in >German [although "Computer" is also OK]; in Dutch it's simply "Computer") . It >also makes it harder to find additional info on the internet. In addition, >books >in the English language are usually far cheaper than those in Dutch. > > As far as programming itself is concerned, I find it slightly more readable > to >use Dutch variable and function names. The risk of name clashes is also >virtually absent! In my office we have a coding convention which states that >Dutch names should be used. I must confess, however, I don't always >consistently >follow the convention. One example are getter and setter methods. It's just >clearer to use 'get' and 'set' in the method name. When I download software, >I >use then 'as-is'. I might translate code snippets so it blends better with the >rest of the code. If I send snippets to e.g. this mailing list, I usually >translate the variable names + comments --only this time I was a bit lazy. ;-) I tend to follow this piece of advice from PEP 8: "Python coders from non-English speaking countries: please write your comments in English, unless you are 120% sure that the code will never be read by people who don't speak your language." It's about comments, but applies just as well to variable names etc. If output strings are eg Dutch, that's only the non-English part, and I might even make use of some "translation" library (ie, English strings, which get replaced by the appropriate strings upon a language settings. I know Django uses this system). It has such a huge advantage when, for example, asking questions on a list like this. Albert-Jan may occasionally translate his problems, but there's no guarantee that that wouldn't masquerade the actual problem. I actually find it a bit weird that a (programming?) company has a coding convention for non-English names; makes it harder if you want to hire non-Dutch speaking employees, distribute software (& code) internationally etc. Cheers, Evert > > Cheers!! > Albert-Jan > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > All right, but apart from the sanitation, the medicine, education, wine, > public >order, irrigation, roads, a fresh water system, and public health, what have >the >Romans ever done for us? > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > From: Patty <pa...@cruzio.com> > To: Albert-Jan Roskam <fo...@yahoo.com>; Python Mailing List <tutor@python.org> > Sent: Fri, December 3, 2010 11:39:28 PM > Subject: Re: [Tutor] Question on tkinter event binding > > Hello Albert-Jan: > I am glad you made the comment below. I was fascinated with the fact that > your >code was partly in English/Python and also in Dutch. I am a linguist so have >great interest in bilingualism. How does this work in practice? I mean as a >programmer, with native language other than English, do you download or buy >English language software programs and work with them as-is? Do you have >translated tutorials to help you learn? If you had a Dutch language software >program and created your own program so that everything is totally in Dutch, >and >you wanted to communicate with English language email group :) How would you >do >that? Or would you try and find a Dutch language resource? > > Besides that, I am definitely saving your code segments for the future. > Thanks >for sharing. > > Patty > ----- Original Message ----- > From: Albert-Jan Roskam > To: Albert-Jan Roskam ; Python Mailing List > Sent: Friday, December 03, 2010 12:18 PM > Subject: Re: [Tutor] Question on tkinter event binding > > <stuff snipped> > > I'll paste the working code below. It's partially in Dutch, but hey, so is >Guido van Rossem. ;-) > > <stuff snipped> > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor