Re: [Tutor] Question about the "main" Python help list
I meant the Python-Help mailing list (http://mail.python.org/mailman/listinfo/python-help), which is described on the Python mailing list page (http://mail.python.org/mailman/listinfo) as "Expert volunteers answer Python-related questions." I guess I should have stated specifically what list I was referring to. Basically, the Python-Tutor list seems to be for people in the "beginner" or "initial learning" stage of Python, while the Python-Help list seems to be the general help list for people who are beyond the basics but who have some problem they can't solve on their own. I was hoping that there is a general Python help list that is not closed. Does anyone know if there is? Does anyone know why Python-Help Q&A are not made public? Joel > -Original Message- > From: tutor-bounces+joel=joelschwartz@python.org > [mailto:tutor-bounces+joelelschwartz@python.org] On > Behalf Of Stefan Behnel > Sent: Friday, December 03, 2010 11:43 PM > To: tutor@python.org > Subject: Re: [Tutor] Question about the "main" Python help list > > Joel Schwartz, 04.12.2010 08:19: > > I just went to sign up for the main Python help list and discovered > > that it is a "closed" list > > What (and where) is the "main Python help list"? > > Stefan > > ___ > 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
Re: [Tutor] Question about the "main" Python help list
Joel Schwartz, 04.12.2010 09:07: I meant the Python-Help mailing list (http://mail.python.org/mailman/listinfo/python-help), which is described on the Python mailing list page (http://mail.python.org/mailman/listinfo) as "Expert volunteers answer Python-related questions." I guess I should have stated specifically what list I was referring to. Basically, the Python-Tutor list seems to be for people in the "beginner" or "initial learning" stage of Python, while the Python-Help list seems to be the general help list for people who are beyond the basics but who have some problem they can't solve on their own. I was hoping that there is a general Python help list that is not closed. Does anyone know if there is? Sure, it's called "python-list" or as a newsgroup: "comp.lang.python". Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about the "main" Python help list
On 01/-10/-28163 02:59 PM, Joel Schwartz wrote: I meant the Python-Help mailing list (http://mail.python.org/mailman/listinfo/python-help), which is described on the Python mailing list page (http://mail.python.org/mailman/listinfo) as "Expert volunteers answer Python-related questions." I guess I should have stated specifically what list I was referring to. Basically, the Python-Tutor list seems to be for people in the "beginner" or "initial learning" stage of Python, while the Python-Help list seems to be the general help list for people who are beyond the basics but who have some problem they can't solve on their own. I was hoping that there is a general Python help list that is not closed. Does anyone know if there is? Does anyone know why Python-Help Q&A are not made public? Joel I think you're looking for comp.lang.python, which is a normal, subscribable list. it works just like python-tutor, except the latter is for beginners. Send Python-list mailing list submissions to python-l...@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to python-list-requ...@python.org You can reach the person managing the list at python-list-ow...@python.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
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. ;-) 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 To: Albert-Jan Roskam ; Python Mailing List 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:18PM >Subject: Re: [Tutor] Question on tkinterevent binding > > > > >I'llpaste the working code below. It's partially in Dutch, but hey, so is >Guidovan Rossem. ;-) > > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
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 > To: Albert-Jan Roskam ; Python Mailing List > > 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 > > > > I'll paste the working code below. It's partially in Dutch, but hey, so is > Guido van Rossem. ;-) > > > > ___ > 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
Re: [Tutor] Newline
"Steven D'Aprano" wrote >>> for i in (1, 2, 3): ... print(i, "spam", end="\n" if i==3 else "***") Ooooh! A new trick. I hadn't thought of using the conditional expression there but it makes a lot of sense. Definitely more fun and flexible than the old comma at the end of a print in v2 :-) Thanks for that, Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about the "main" Python help list
"Joel Schwartz" wrote My question: Is there a general Python help list that is open for all to see, in the same way that the Python Tutor list is open? There are many Python mailing lists and usenet newsgroups. They are all available to browse on gmane. (just short of 200 of them by my estimate) http://dir.gmane.org/index.php?prefix=gmane.comp.python Usually you will be best served by picking the most specific newsgroup for your topic and asking there. Take a look at the archive list to get an idea of how busy and current they are, also what the average turn-around time is for replies. You can subscribe to most of them as mailing lists or use a newsreader (eg Outlook Express or Thunderbird or GNUs etc) to access the gmane nntp feed HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question on tkinter event binding
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("", 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 To: Albert-Jan Roskam Cc: Patty ; Python Mailing List 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 mig
Re: [Tutor] Question on tkinter event binding
Evert Rol wrote: 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. I can't put my hands on the reference right now, but something like 99% of all software in the world is written purely for internal use and never gets distributed *at all*, let alone internationally. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question on tkinter event binding
Albert-Jan Roskam wrote: 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(). They have their uses, but yes, it's best to avoid them unless you need them. Let's see if we can avoid them :) 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 The classic solution for callbacks is to use lambda, but of course lambda is limited to a single expression and won't do the job here. So what you need is a factory function that returns a new function: handleDeletions[entryWidget] = make_deletion_handler() and the factory itself is defined something like this: def make_deletion_handler(): # Create a function. 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 # And return it. return handleDeletion If you move the factory outside of your createWidgets function, you will need to explicitly pass arguments entryWidget, content, etc. to the factory. Otherwise you can nest the factory inside createWidgets, at it will pick the variables up automatically. Hope this helps, -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newline
On 12/4/10, Alan Gauld wrote: > > "Steven D'Aprano" wrote > >> >>> for i in (1, 2, 3): >> ... print(i, "spam", end="\n" if i==3 else "***") > > Ooooh! A new trick. > I hadn't thought of using the conditional expression there but it > makes a lot of sense. > Definitely more fun and flexible than the old comma at the end of a > print in v2 :-) So is this a python3.x feature only? Is there an equivallent in 2.x? I had not realized if statements could be used in calling functions like that or that they could be arranged in that way, but I am sticking to python2 since most packages are still written for it. > > Thanks for that, > > Alan G. > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about the "main" Python help list
Next time you email tutor, start a new email msg instead of clearing out the contents of a reply to a different e-mail. When you do it like that it breaks threading, so all these emails are in the same thread as the "need help" one even though they aren't related to that e-mail. - Sent from a mobile device with a bad e-mail client. - On Dec 4, 2010, at 1:19 AM, "Joel Schwartz" wrote: > I just went to sign up for the main Python help list and discovered that it > is a "closed" list, in the sense that the answers to queries are kept > private between the questioner and the helpers, rather than shared with > everyone on the list. > > My question: Is there a general Python help list that is open for all to > see, in the same way that the Python Tutor list is open? Although the Tutor > list is great for getting started, it would also be very helpful to be able > to see answers to questions asked by Python programmers with more experience > and more sophisticated projects than those discussed on the Tutor list. > > I've been using the R programming language for a couple of years now and the > general R-help list is open for all to see and with searchable archives. It > is aninvaluable resource for learning advanced programming techniques > and sophisticated data analysis and management methods. Is there anything > similar for Python? > > Thanks, > Joel > > > ___ > 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
Re: [Tutor] Newline
Alex Hall wrote: On 12/4/10, Alan Gauld wrote: "Steven D'Aprano" wrote for i in (1, 2, 3): ... print(i, "spam", end="\n" if i==3 else "***") Ooooh! A new trick. I hadn't thought of using the conditional expression there but it makes a lot of sense. Definitely more fun and flexible than the old comma at the end of a print in v2 :-) So is this a python3.x feature only? Is there an equivallent in 2.x? I had not realized if statements could be used in calling functions like that or that they could be arranged in that way, but I am sticking to python2 since most packages are still written for it. Python has had "if" expressions (also known as the ternary operator) since Python2.5. You can write: true_value if condition else false_value anywhere that will accept an expression. E.g.: len("chicken" if today == tuesday else "fish") Since Python2.6, you can get the print function by using: from __future__ import print_function Note that there are TWO underscores at the start and end of "__future__", and that like all __future__ imports it must be the first executable line of your script or module. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newline
> >> ... print(i, "spam", end="\n" if i==3 else "***") > > > > I hadn't thought of using the conditional expression there but it > > makes a lot of sense. > So is this a python3.x feature only? Is there an equivallent in 2.x? I The end parameter of print is a Python 3 feature - only possible because print is now a function rather than a command. In Python two the only option was to add a comma at the end of the print statement qwhich suppressed the newline. But the end parameter allows you to add anything you like, not just newlines or a null.. Of course you can use string formatting in Python 2 to achieve similar results. The if construct is nothing to do with print, it is a standard conditional expression introduced in Python v2.5 or 2.6? As is true of any *expression* it can be used anywhere that a value is used. This is because every expression produces to a value. So in Python v2 we could simulate Steven's loop with: for n in range(3): s += "%d spam%s" % (n,"\n" if n==3 else "***") print s, # comma to avoid print adding its own \n... But the print(..., end=) version is much prettier IMHO. HTH, Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newline
On 12/4/10, Steven D'Aprano wrote: > Alex Hall wrote: >> On 12/4/10, Alan Gauld wrote: >>> "Steven D'Aprano" wrote >>> >>> for i in (1, 2, 3): ... print(i, "spam", end="\n" if i==3 else "***") >>> Ooooh! A new trick. >>> I hadn't thought of using the conditional expression there but it >>> makes a lot of sense. >>> Definitely more fun and flexible than the old comma at the end of a >>> print in v2 :-) >> So is this a python3.x feature only? Is there an equivallent in 2.x? I >> had not realized if statements could be used in calling functions like >> that or that they could be arranged in that way, but I am sticking to >> python2 since most packages are still written for it. > > > Python has had "if" expressions (also known as the ternary operator) > since Python2.5. You can write: > > true_value if condition else false_value How cool!! I never knew that. > > anywhere that will accept an expression. E.g.: > > len("chicken" if today == tuesday else "fish") > > Since Python2.6, you can get the print function by using: > > from __future__ import print_function > > Note that there are TWO underscores at the start and end of > "__future__", and that like all __future__ imports it must be the first > executable line of your script or module. > > > -- > Steven > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] PHP
For reasons of my work, of recent I have started aquiring php. Straightaway, i was impressed by one powerful property; the ability to imbed php into a html webpage, and switch into and out of php as needed, and let normal ssi and html and css work the rest of the time, outside of php. all I have to do is start the php block with # end the php block and continue in html. What a BLOODY shame we can't do that in python, which is otherwise awesome and superior in every way i can thus far evaluate. -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question on tkinter event binding
Hi Steven, Awesome, I've got it working now! Here's the code: http://pastebin.com/BQhW8piD (I also pasted it below this message). I tried your approach before but I abandoned it because I made a mistake in lines 16 (pass None for event) and 22 (I didn't use the parameters of the outer function as the arguments of the inner function. Thanks a lot for putting me back on the right track!! It's really working cool now and I was able to remove some unnecessary code (and I added some bells and whistles ;-)) Cheers!! Albert-Jan import Tkinter, time, sys # To be used in conjunction with the AutocompleteEntry class: # http://tkinter.unpythonic.net/wiki/AutocompleteEntry def createWidgets(veldnamen, termenlijst): root=Tk() for veldnaam in veldnamen: labelWidget=Tkinter.Label(root, text=veldnaam, takefocus=False) labelWidget.grid() # tcl names must start with a lowercase letter tclName = veldnaam[0].lower() + veldnaam[1:] entryWidget=Tkinter.Entry(root, name=tclName, highlightcolor="yellow") entryWidget.grid() makeDeletionHandler(event=None, widget=entryWidget, root=root, termenlijst=termenlijst) def makeDeletionHandler(event, widget, root, termenlijst): def handleDeletion(event, widget=widget, root=root, termenlijst=termenlijst): vensternaam = str(widget)[1:].capitalize() if vensternaam.startswith("*"): vensternaam = "*" + vensternaam[1:].capitalize() vensterinhoud = widget.get().strip() print "Name: %s -- Contents: %s" % (vensternaam, vensterinhoud) try: termenlijst[vensternaam].remove(vensterinhoud) widget.delete(0, END) widget.configure(bg = "green") #print termenlijst print "Deleted term '%s'" % vensterinhoud except KeyError: print "No such term '%s'" % vensterinhoud pass finally: delay = 0.5 if sys.platform.lower().startswith("win"): delay = delay * 1000 time.sleep(delay) # Windows: specify in ms!) widget.configure(bg = "white") widget.bind("", handleDeletion) return handleDeletion createWidgets(veldnamen = ["Naam", "*Postcode", "Adres", "*Organization name"], termenlijst = {"Naam": set(["Bill Gates", "Elvis Presley"]), "*Postcode": set(["2600AA", "8000BB"]), "Adres": set(["Street", "Avenue"]), "*Organization name": set(["CWI", "MIT"])}) ~~ 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: Steven D'Aprano To: Python Mailing List Sent: Sat, December 4, 2010 3:49:26 PM Subject: Re: [Tutor] Question on tkinter event binding Albert-Jan Roskam wrote: > 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(). They have their uses, but yes, it's best to avoid them unless you need them. Let's see if we can avoid them :) > 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 The classic solution for callbacks is to use lambda, but of course lambda is limited to a single expression and won't do the job here. So what you need is a factory function that returns a new function: handleDeletions[entryWidget] = make_deletion_handler() and the factory itself is defined something like this: def make_deletion_handler(): # Create a function. def handleDeletion(event, widget=entryWidget, root=root, termenlijst=termenlijst, content=content): actieveVenster = root.focus_get() actieveVensternaam = str(actieveVenster)[1:].capitalize() if actieveVensternaam.startswith("*"): actieveVensternaam = "*"+actieveVenste
Re: [Tutor] PHP
On 12/4/2010 2:27 PM, Kirk Bailey wrote: For reasons of my work, of recent I have started aquiring php. Straightaway, i was impressed by one powerful property; the ability to imbed php into a html webpage, and switch into and out of php as needed, and let normal ssi and html and css work the rest of the time, outside of php. all I have to do is start the php block with # end the php block and continue in html. What a BLOODY shame we can't do that in python, which is otherwise awesome and superior in every way i can thus far evaluate. Actually, you CAN do that with Python. Python Server Pages (PSP) and mod_python enable you to do this on an Apache server. ~Corey Richardson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PHP
> Straightaway, i was impressed by one powerful property; the ability to > imbed php into a html webpage, and switch into and out of php as needed, > and let normal ssi and html and css work the rest of the time, outside > of php. all I have to do is start the php block with > write code; > ?> # end the php block > and continue in html. What a BLOODY shame we can't do that in python, > which is otherwise awesome and superior in every way i can thus far evaluate. sure you can! however you have to use a web templating system, and there are many in Python (Mako, Genshi, Myghty, Kid, Cheetah, Jinja, Django templates, etc.). some examples here: Mako: http://www.makotemplates.org/docs/syntax.html#python-blocks Genshi: http://genshi.edgewall.org/wiki/Documentation/templates.html Myghty: http://www.myghty.org/docs/embedding.html it is not built-in to the language because Python is more general-purpose, so you have to import those packages to use them. hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PHP
On Sat, Dec 4, 2010 at 2:27 PM, Kirk Bailey wrote: > and continue in html. What a BLOODY shame we can't do that in python, > which is otherwise awesome and superior in every way i can thus far > evaluate. As someone mentioned, you CAN do that in Python. However, you'll find that mixing content and processing logic isn't considered a best practice. Embedding simple display logic into your presentational templates is fine (looping, if conditional then display this section, etc), but you'll want to avoid mixing complicated logic in with presentation - it makes maintenance/testing/reuse that much harder, even moreso when working on a team with different skill specialties. -- Brett Ritter / SwiftOne swift...@swiftone.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing in python 3.x
Alan, Perhaps this is a silly question (and possibly not strictly python-related) but I was under the impression that controlling exactly layout via html was kind of difficult and somewhat fragile. The latter perhaps less so as one could make some fairly concrete assumptions about the paper size being used in this situation. Is it common to use HTML for formatting printed reports?!? Could you give an example of how you'd control the layout of specific fields on a printed report? Thanks, Monte ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PHP
On Sat, Dec 4, 2010 at 12:44 PM, Brett Ritter wrote: > On Sat, Dec 4, 2010 at 2:27 PM, Kirk Bailey wrote: >> and continue in html. What a BLOODY shame we can't do that in python, >> which is otherwise awesome and superior in every way i can thus far >> evaluate. > > As someone mentioned, you CAN do that in Python. However, you'll find > that mixing content and processing logic isn't considered a best > practice. Embedding simple display logic into your presentational > templates is fine (looping, if conditional then display this section, > etc), but you'll want to avoid mixing complicated logic in with > presentation - it makes maintenance/testing/reuse that much harder, > even moreso when working on a team with different skill specialties. +1 on that point, which i failed to mention. :P separating the logic from the template adheres more the common best practice of using the MVC pattern. the template represents the "view," or the HTML template -- usually you want to keep this out of the hands of developers and give it to your designers (UX/UE/UI) folks. on the flip side, you want the controller (logic) to be the responsibility of the programmers. this segregation of duties enables for more agile development and creation of more accurate (and less confusing) unit-testing and faster and cleaner development overall. outside of the loops and conditionals mentioned, any real chunk of code embedded in a template i'd consider a special case or deployment issue (fewer approvals needed to push non-code, no need for server restart on static file pushes, etc.). cheers, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Python Web Development with Django", Addison Wesley, (c) 2009 http://withdjango.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Which non SQL Database ?
Hello all. Newbie question. Sorry. As part of my process to learn python I am working on two personal applications. Both will do it fine with a simple structure of data stored in files. I now there are lot of databases around I can use but I would like to know yoor advice on what other options you would consider for the job (it is training so no pressure on performance). One application will run as a desktop one,under Windows, Linux, Macintosh, being able to update data, not much, not complex, not many records. The second application, running behind web pages, will do the same, I mean, process simple data, updating showing data. not much info, not complex. As an excersice it is more than enough I guess and will let me learn what I need for now. Talking with a friend about what he will do (he use C only) he suggest to take a look on dBase format file since it is a stable format, fast and the index structure will be fine or maybe go with BD (Berkley) database file format (I hope I understood this one correctly) . Plain files it is not an option since I would like to have option to do rapid searches. What would do you suggest to take a look? If possible available under the 3 plattforms. Thanks in advance for your comments. Jorge Biquez ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Which non SQL Database ?
On Sat, Dec 4, 2010 at 5:42 PM, Jorge Biquez wrote: > Newbie question. Sorry. If it isn't you're on the wrong list :) > training so no pressure on performance). One application will run as a > desktop one,under Windows, Linux, Macintosh, being able to update data, not > much, not complex, not many records. The important details here are: simple data, low-volume. I'm assuming this is single-user (as in, each instance of your application has it's own DB) > The second application, running behind > web pages, will do the same, Is this multiple users, each accessing the same DB? That really changes what you are looking for. If you are dealing with single-user, or only a few users, I'd say look into SQLite - It uses SQL syntax but doesn't run as a server and stores the database as a single file. It's great to use in small projects because the syntax is the same as larger projects, and you can replace with a full-blown multi-user SQL DB if you ever need to without having to rework everything. It's also very simple to use. I believe SQLite (sqlite3) is part of the core library in recent Python versions, or available as a package for older pythons. Berkeley DB is pretty much interchangeable with SQLite in terms of functionality. I much prefer SQLite. If your web application intends to have multiple users interacting with the same data, neither is probably a good fit. -- Brett Ritter / SwiftOne swift...@swiftone.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor