Re: [Tutor] printing in python 3.x
"Rance Hall" wrote But shop owner wants to do something nicer with the customer receipts. He is talking shop logos and pdf files. The simplest technique is probably to generate an HTML file and then get the OS to print that for you via the default browser. Google keeps bringing up ReportLib and the python imaging library, but neither have a 3.x compatible version yet. THats much harder work IMHO than using an HTML file as a template. Shop owner is talking about eventually being able to save customer check in tickets and check out tickets on a web site where clients can log in and check on their work. And HTML woyuld definitely be easier here! My thought is that this is perfect for PDF files, but they aren't available on 3.x yet. Well you could hand crank them, they are just text files after all. But HTML is much easier to generate by hand! I looked at word integration and openoffice integration and they dont look ready for 3.x yet either. The Pywin32 and ctypes modules all work on Python 3 so you could use COM integration, or even WSH. But HTML stioll gets my vote. 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
[Tutor] Question on tkinter event binding
Hi, I'm trying to make a small improvement on a data entry program and it is literally giving me a headache. I would appreciate your help or suggestions. The actual program uses Autocomplete entry widgets [1], which is a subclass of the Tkinter Entry widget. The sample code below uses a simple Entry widget, for the sake of simplicity. The autocompletions are recorded in a dictionary of the form {entry name: set()}. The problem is that entries with typos cannot be deleted, so wrong autocomplete suggestions ("Bbbilly Gates") are given until the end of time. My solution: I want to bind each entry widget to the Delete key, which makes it possible to remove the typo-entry from the set of entries. I am using an ' expanded event handler' [2] to do the event binding. The sample code below creates two entry widgets. The problem is that the entry contents is not retrieved correctly. If I fill the 2nd entry with some text, then hit 'Del' , it shows the content of the *first* entry. Also, I would like to isolate the event handler into its own function, not as a function within a function, but I'm not quite sure how. [1] http://tkinter.unpythonic.net/wiki/AutocompleteEntry [2] http://www.daniweb.com/code/snippet306072.html from Tkinter import * def createWidgets(veldnamen): root=Tk() termenlijst = {"Naam": set(["Bill Gates", "Elvis Presley"]), "*Postcode": set(["2600AA", "8000NN"])} handleDels = {} for veldnaam in veldnamen: # tcl names must start with lowercase letter entryWidget=Entry(root, name=veldnaam[0].lower() + veldnaam[1:]) entryWidget.grid() def handleDel(event, widget=entryWidget, root=root, termenlijst=termenlijst): vensternaam = str(root.focus_get())[1:].capitalize() # ... and back to uppercase if vensternaam.startswith("*"):# mandatory fields start with '*' in my program. vensternaam = "*" + vensternaam[1:].capitalize() vensterinhoud = entryWidget.get() print "Naam", vensternaam # entry name print "Inhoud", vensterinhoud # entry contents try: termenlijst[vensternaam].remove(vensterinhoud) # here's where the typo is removed except KeyError: pass # user tries to delete a term that doesn't exist in the termenlijst. handleDels[entryWidget] = handleDel # do all the bindings (is this where it goes wrong??) for entryWidget, handleDel in handleDels.iteritems(): entryWidget.bind("", handleDel) print handleDels print termenlijst createWidgets(["Naam", "*Postcode"]) Thanks again for having a look at this. 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? ~~ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Finally finished my currency exchange program
I've finally finished my currency exchange program thanks to help from this list and another list. It updates the exchange rates via an xml feed etc. Feedback on it would be appreciated please: http://www.dinksoftware.com/astute_currency_analyzer.php Dink ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finally finished my currency exchange program
sadly you didn't take into account Linux users On 12/3/10, Eddie wrote: > I've finally finished my currency exchange program thanks to help from this > list and another list. It updates the exchange rates via an xml feed etc. > > Feedback on it would be appreciated please: > http://www.dinksoftware.com/astute_currency_analyzer.php > > Dink > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finally finished my currency exchange program
"Eddie" wrote in message news:aanlktimxrajnbvj9egx4diqbwrb1ltfa9quv2fdeq...@mail.gmail.com... I've finally finished my currency exchange program thanks to help from this list and another list. It updates the exchange rates via an xml feed etc. If you wrote it in Python why only Windows support? Virtually all Python GUI toolkits are portable across platforms, one of the biggest advantages of Python... And the core functions are surely just basic Python code? Seems like a missed opportunity. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finally finished my currency exchange program
On Fri, Dec 3, 2010 at 8:07 AM, Alan Gauld wrote: > > "Eddie" wrote in message > news:aanlktimxrajnbvj9egx4diqbwrb1ltfa9quv2fdeq...@mail.gmail.com... > > I've finally finished my currency exchange program thanks to help from >> this >> list and another list. It updates the exchange rates via an xml feed etc. >> > > If you wrote it in Python why only Windows support? > > Virtually all Python GUI toolkits are portable across platforms, one of > the biggest advantages of Python... And the core functions are surely > just basic Python code? > > Seems like a missed opportunity. > > Alan G. > > Since this is a python tutor group, I figured you might have had earlier discussions here about the coding of this project. But I didn't find anything. hmm? Why did you decide to make this a desktop application, and not a website application? I'm guessing that you may have published it for Windows only because of issues around the installation process. I haven't tried creating any sort of install packages in Windows, or Linux, so I am completely in the dark about those things. But, by putting the application on the web, install issues disappear, and you might get more hits on your site. -- Joel Goldstick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finally finished my currency exchange program
I didn't find any of his previous questions as well - Looks like he just registered on this list to try and promote his product. Sneaky! On Fri, Dec 3, 2010 at 2:21 PM, Joel Goldstick wrote: > > On Fri, Dec 3, 2010 at 8:07 AM, Alan Gauld wrote: > >> >> "Eddie" wrote in message >> news:aanlktimxrajnbvj9egx4diqbwrb1ltfa9quv2fdeq...@mail.gmail.com... >> >> I've finally finished my currency exchange program thanks to help from >>> this >>> list and another list. It updates the exchange rates via an xml feed >>> etc. >>> >> >> If you wrote it in Python why only Windows support? >> >> Virtually all Python GUI toolkits are portable across platforms, one of >> the biggest advantages of Python... And the core functions are surely >> just basic Python code? >> >> Seems like a missed opportunity. >> >> Alan G. >> >> Since this is a python tutor group, I figured you might have had earlier > discussions here about the coding of this project. But I didn't find > anything. hmm? > > Why did you decide to make this a desktop application, and not a website > application? I'm guessing that you may have published it for Windows only > because of issues around the installation process. I haven't tried creating > any sort of install packages in Windows, or Linux, so I am completely in the > dark about those things. But, by putting the application on the web, > install issues disappear, and you might get more hits on your site. > > > -- > Joel Goldstick > > > ___ > 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] permutations?
Thanks, everyone! While I do not understand the function provided a few messages back, it works perfectly. The rest of the responses were very interesting. I need to try, yet again, to really understand list comprehensions, possibly the most difficult topic I have yet come across, along with the colon when used in lists. Thanks again to all! On 12/2/10, Steven D'Aprano wrote: > Alan Gauld wrote: >> >> "Alex Hall" wrote >> >>> Alright, I have it working. Now the problem is that it does not throw >>> out reversals. I tried to do this myself with a couple loops, but I >>> get index errors. My total list of permutations is called l. >>> >>> for i in range(0, len(l)): >>> r=l[i]; r.reverse() >> >> You don''t need to specify the 0, its the default. >> But you don't need to use indexing either. >> >> for r,i in enumerate(l): r.reverse() >> >>> for j in range(0, len(l)): >>> print l[j], r, i, j >> >> Here you are comparing the reversed item to every item in the >> list, including the ones you have already reversed, including the >> item itself. So you will always find a match when i==j... >> >> Using the in operator and list slicing would be easier >> >> if r in l[i:]: l.remove(r) >> >> but... >> >>> if r==l[j]: l.remove(r) >> >> Its never a good idea to remove items from a list you are iterating >> over, its like the old cartoon of the guy cutting down the tree branch >> he is sitting on. > > You can cut off the branch you're sitting on so long as you remember to > cut on the correct side :) > > Back in Ancient Days when dinosaurs walked the earth, and I programmed > in Pascal, computers didn't have much memory, and were slow. > Consequently it wasn't practical to make a copy of a list if you wanted > to delete a few items. The only practical way to modify lists was to > modify them in place, and if you needed to delete items, you had to work > backwards. It took me a while to break myself of the habit of doing this: > > for i in range(len(mylist)-1, -1, -1): > if mylist[i] == "something": > del mylist[i] > > (Note that you only need to work backwards if you're *deleting* entries, > not if you replace them with something else.) > > This is still a useful technique to have in your toolbox, but generally > speaking the above is better written as: > > mylist = [x for x in mylist if x != "something"] > > > If you really need to modify the list in place, and not just re-bind the > name "mylist" to the new list, then one tiny change will do it: > > mylist[:] = [x for x in mylist if x != "something"] > > > > -- > 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] floats
I have a float variable that is very long. >>> float_a = 1.16667 However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. >>> float_a = 1.16667 >>> print "%.2f" % float_a 1.17 I tried the following: >>> float_b = "%.2f" % float_a >>> float_b '1.17' >>> type(float_b) This doesn't work because it yields a string. Any suggestions? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] floats
you have two options 1) either type cast like float_b = float(etcetc) 2) use round method which available inbuilt On Sat, Dec 4, 2010 at 12:22 AM, Christopher Spears wrote: > > I have a float variable that is very long. > > >>> float_a = 1.16667 > > However, I want to pass the value of float_a to float_b, but I want the > float to be accurate to two decimal points. > > >>> float_a = 1.16667 > >>> print "%.2f" % float_a > 1.17 > > I tried the following: > > >>> float_b = "%.2f" % float_a > >>> float_b > '1.17' > >>> type(float_b) > > > This doesn't work because it yields a string. > > Any suggestions? > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] floats
On 12/3/2010 1:52 PM, Christopher Spears wrote: I have a float variable that is very long. float_a = 1.16667 However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. float_a = 1.16667 print "%.2f" % float_a 1.17 I tried the following: float_b = "%.2f" % float_a float_b '1.17' type(float_b) This doesn't work because it yields a string. Any suggestions? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor float_b = float(float_b) That takes the string and makes it a float. ~Corey Richardson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] floats
On 12/3/2010 10:52 AM Christopher Spears said... I have a float variable that is very long. float_a = 1.16667 However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. float_a = 1.16667 print "%.2f" % float_a 1.17 I tried the following: float_b = "%.2f" % float_a float_b '1.17' type(float_b) This doesn't work because it yields a string. Any suggestions? If you want control over the precision I'd use the decimal module. >>> x 1.1666 >>> y = decimal.Decimal("%.2f" % x) >>> y Decimal('1.17') >>> Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] floats
On Fri, Dec 3, 2010 at 1:52 PM, Christopher Spears wrote: float_a = 1.16667 > > However, I want to pass the value of float_a to float_b, but I want the float > to be accurate to two decimal points. Use the built-in round() function, like this: >>> a = 1.16667 >>> print a 1.16667 >>> b = round(a, 2) >>> print b 1.17 -- Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] floats
"Christopher Spears" wrote I have a float variable that is very long. float_a = 1.16667 Thats not really very long! However, I want to pass the value of float_a to float_b, but I want the float to be accurate to two decimal points. float_a = 1.16667 print "%.2f" % float_a 1.17 Rounding issues will give you all sorts of issues here. However if you really want to round it up or down to 2 digits then the round() function is what you want. But I'd be interested in why you need to lose precision like that, it's not that common a requirement. Usually controlling the presentation is sufficient (and preferred). float_b = "%.2f" % float_a float_b '1.17' type(float_b) This doesn't work because it yields a string. It works in that it returns a string representation of what you want. It doesn't produce a float because *string formatting* can only produce strings. 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] floats
On Fri, Dec 3, 2010 at 1:52 PM, Christopher Spears wrote: > > I have a float variable that is very long. > > >>> float_a = 1.16667 > > However, I want to pass the value of float_a to float_b, but I want the > float to be accurate to two decimal points. > > >>> float_a = 1.16667 > >>> print "%.2f" % float_a > 1.17 > > I tried the following: > > >>> float_b = "%.2f" % float_a > >>> float_b > '1.17' > >>> type(float_b) > > > This doesn't work because it yields a string. > > Any suggestions? > This would be good to read: http://docs.python.org/tutorial/floatingpoint.html If you have: float_a = 1.7 and do round(float_a, 2) you get: round(1.16667, 2) 1.1699 I don't think that is what you want, but since floating point arithmetic is done in binary there are rounding errors. You might want to look at the decimal module > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Joel Goldstick ___ 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
Aaahhh, got it! Peace! I did two things wrong: (1) I didn't use a tcl StringVar() to get the entry widget contents (2) I didn't consistently close the menus generated by previous attempts to run the program, which led to inconsistent results. I'll paste the working code below. It's partially in Dutch, but hey, so is Guido van Rossem. ;-) Even so, I'd be happy to hear suggestions for improvement or simplification. I'd love to chop the code up into smaller, more comprehensible bits. 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() 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 handleDeletions[entryWidget] = handleDeletion for entryWidget, handleDeletion in handleDeletions.iteritems(): entryWidget.bind("", handleDeletion) 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: Albert-Jan Roskam To: Python Mailing List Sent: Fri, December 3, 2010 11:19:02 AM Subject: [Tutor] Question on tkinter event binding Hi, I'm trying to make a small improvement on a data entry program and it is literally giving me a headache. I would appreciate your help or suggestions. The actual program uses Autocomplete entry widgets [1], which is a subclass of the Tkinter Entry widget. The sample code below uses a simple Entry widget, for the sake of simplicity. The autocompletions are recorded in a dictionary of the form {entry name: set()}. The problem is that entries with typos cannot be deleted, so wrong autocomplete suggestions ("Bbbilly Gates") are given until the end of time. My solution: I want to bind each entry widget to the Delete key, which makes it possible to remove the typo-entry from the set of entries. I am using an ' expanded event handler' [2] to do the event binding. The sample code below creates two entry widgets. The problem is that the entry contents is not retrieved correctly. If I fill the 2nd entry with some text, then hit 'Del' , it shows the content of the *first* entry. Also, I would like to isolate the event handler into its own function, not as a function within a function, but I'm not quite sure how. [1] http://tkinter.unpythonic.net/wiki/AutocompleteEntry [2] http://www.daniweb.com/code/snippet306072.html from Tkinter import * def createWidgets(veldnamen): root=Tk() termenlijst = {"Naam": set(["Bill Gates", "Elvis Presley"]), "*Postcode": set(["2600AA", "8000NN"])} handleDels = {} for veldnaam in veldnamen: # tcl names must start with lowercase letter entryWidget=Entry(root, name=veldnaam[0].lower() + veldnaam[1:]) entryWidget.grid() def handleDel(event, widget=entryWidget, root=root, termenlijst=termenlijst): vensternaam = str(root.focus_get())[1:].capitalize() # ... and back to uppercase if vensternaam.startswith("*"):# mandatory fields start with '*' in my program. vensternaam = "*" + vensternaam[1:].capitalize() vensterinhoud = entryWidget.get() print "Naam", vensternaam # entry name print "Inhoud", vensterinhoud # entry contents try: termenlijst[vensternaam].remove(vensterinhoud) # here's where the typo is removed except KeyError: pass # user tries to delete a ter
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
Re: [Tutor] Question on tkinter event binding
On Fri, 3 Dec 2010, Albert-Jan Roskam wrote: I'm trying to make a small improvement on a data entry program and it is literally giving me a headache. Followed shortly thereafter with: On Fri, 3 Dec 2010, Albert-Jan Roskam wrote: Aaahhh, got it! Peace! ... I'll paste the working code below. It's partially in Dutch, but hey, so is Guido van Rossem. ;-) Once again proving the Zen of Python: >>> import this The Zen of Python, by Tim Peters . . . There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] print problem
hi I have a file and it is in chunks: I want to be able to select the number that follows 'Elution: ' where the line startswith (TITLE)(say 72.958) and check if it is larger than my choice of number (say 71.4). If it is then I want to print chunk from BEGIN LINE to END LINE separated by one empty line. I wrote the following script, when executed in IDEL or python mode, it works. however I use python test_script_test.py , I get name error: could you please help me whats wrong here. thanks Command line mode: $ python test_script_test.py Traceback (most recent call last): File "test_script_test.py", line 14, in newk = dat[mystartl:myfinish] NameError: name 'myfinish' is not defined In python mode: >>> f1 = open('test','r') >>> da = f1.read().split('\n') >>> dat = da[:-1] >>> mytimep = 71.4 >>> for i in range(len(dat)): ... if dat[i].startswith('BEGIN LINE'): ... mystartl = i ... if dat[i].startswith('END LINE'): ... myfinish = i ... if dat[i].startswith('Title'): ... col = dat[i].split(',') ... x= float(col[2].split()[1]) ... if x > mytimep: ... newk = dat[mystartl:myfinish] ... for x in newk: ... print x ... BEGIN LINE MYMASS=643.973587067287 CHARGE=2+ Title=File:xyx, sample= Cyst 7 band 7 (sample number 8), Elution: 72.958 to 73.198 min, Period: 1 132.4082 0.0323 133.0418 0.2596 136.0618 0.3276 138.0482 0.546 140.4848 0.0499 140.7096 0.0333 END LINE BEGIN LINE MYMASS=643.973587067287 CHARGE=2+ Title=File:xyx, sample= Cyst 7 band 7 (sample number 8), Elution: 72.958 to 73.198 min, Period: 1 132.4082 0.0323 133.0418 0.2596 136.0618 0.3276 138.0482 0.546 140.4848 0.0499 140.7096 0.0333 my file: BEGIN LINE MYMASS=643.973587067287 CHARGE=2+ Title=File:xyx, sample= Cyst 7 band 7 (sample number 8), Elution: 72.958 to 73.198 min, Period: 1 132.4082 0.0323 133.0418 0.2596 136.0618 0.3276 138.0482 0.546 140.4848 0.0499 140.7096 0.0333 END LINE BEGIN LINE MYMASS=643.973587067287 CHARGE=2+ Title=File:xyx, sample= Cyst 7 band 7 (sample number 8), Elution: 72.958 to 73.198 min, Period: 1 132.4082 0.0323 133.0418 0.2596 136.0618 0.3276 138.0482 0.546 140.4848 0.0499 140.7096 0.0333 END LINE ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finally finished my currency exchange program
Its Windows only as that is what I am more comfortable with and I don't use Linux (tried and not had much luck with it really). Yes, the installer is Windows only. Also, No, I didn't just register on thsi list, I've been registered on this list for years. Dink On 4 December 2010 01:54, Evans Anyokwu wrote: > I didn't find any of his previous questions as well - > Looks like he just registered on this list to try and promote his product. > Sneaky! > > > > On Fri, Dec 3, 2010 at 2:21 PM, Joel Goldstick > wrote: > >> >> On Fri, Dec 3, 2010 at 8:07 AM, Alan Gauld wrote: >> >>> >>> "Eddie" wrote in message >>> news:aanlktimxrajnbvj9egx4diqbwrb1ltfa9quv2fdeq...@mail.gmail.com... >>> >>> I've finally finished my currency exchange program thanks to help from this list and another list. It updates the exchange rates via an xml feed etc. >>> >>> If you wrote it in Python why only Windows support? >>> >>> Virtually all Python GUI toolkits are portable across platforms, one of >>> the biggest advantages of Python... And the core functions are surely >>> just basic Python code? >>> >>> Seems like a missed opportunity. >>> >>> Alan G. >>> >>> Since this is a python tutor group, I figured you might have had earlier >> discussions here about the coding of this project. But I didn't find >> anything. hmm? >> >> Why did you decide to make this a desktop application, and not a website >> application? I'm guessing that you may have published it for Windows only >> because of issues around the installation process. I haven't tried creating >> any sort of install packages in Windows, or Linux, so I am completely in the >> dark about those things. But, by putting the application on the web, >> install issues disappear, and you might get more hits on your site. >> >> >> -- >> Joel Goldstick >> >> >> ___ >> 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 > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print problem
Please post the exact contents of "test_script_test.py", don't paraphrase, don't abbreviate. A good place to post code snippets are here: http://pastebin.com/ That said, I'll try to put down some of the troubleshooting thought process you should be having. Firstly, the error message is telling you that on line 14 of your module on the line saying "newk = dat[mystartl:myfinish]", that "mystartl" is not defined. So then you should be asking yourself "how can it happen that the program can get to this point and 'mystartl' not be set?". Which should lead on to "OK, let's see where mystart is in fact being set, and see if there's conditions attached to that which may explain the behaviour". Which should lead to you looking back in the code and spotting the lines that says: ... if dat[i].startswith('BEGIN LINE'): ... mystartl = i OK, so: "mystartl" is *only* set if dat[i].startswith('BEGIN LINE') is false. So then the implication would be that dat[i] doesn't start with 'BEGIN LINE' when run from the prompt, so the next question would be why that is? The implication would be that it wasn't read from the file. So then implication is that the file "test" that your script reads is not what you think it is when you run the file from the prompt. HTH, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Newline
Hello everybody, I'm new to the mailing list so I'm pretty sure I'll have lots of questions:) It's a very basic question I have and everybody might look at this question and say, "Wow, she reallly doesn't get it?" But oh well. Here's my question: I'm in Chapter 2 of my Python Programming Third Editition book. I've gotten to the section of the chapter where it talks about a "newline character. Exactly what is a newline character? I keep reading the same section of the book and I'm just not really understanding. Here's the code that the book uses to explain the newline character: print("Here", end=" ") print("it is...") The book says that I can specify that a space be the final character printed instead of a newline. In the first print() statement I specify that a space be the final string printed. So the text "Here" appears but no newline character. The next print() statement prints the text "it is"..." right after the space following the final "e" in the "Here" text. You do it by passing a space to the end parameter of the print() function with the code end" ". My Operating System is Windows 7 and the Python version is 3.1.3. That's it. Thanks to anybody who responds to my question. -- *Ava Durand* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newline
Hello Ava/Ashley On 4 December 2010 01:47, Ashley Blackwell wrote: > Exactly what is a newline character? Not all characters used to encode information are printable/displayable characters like the letters in the alphabet or numerals or punctuation and symbols. There's several "special" characters that have special meanings and represent other things. A "newline character" is such a character. It is character 13 in the ASCII character set (which is a well known encoding standard that define a mapping between bytes of data and characters. See here: http://www.asciitable.com/ ) It's meaning is "start a new line" instead of encoding "a" or "z" or "#" or whatever. > I keep reading the same section of the book and I'm just not really > understanding. Here's the code that the book uses to explain the newline > character: > > print("Here", end=" ") > print("it is...") > > The book says that I can specify that a space be the final character > printed instead of a newline. In the first print() statement I specify that > a space be the final string printed. So the text "Here" appears but no > newline character. The next print() statement prints the text "it is"..." > right after the space following the final "e" in the "Here" text. You do it > by passing a space to the end parameter of the print() function with the > code end" ". > So, what this is trying to explain is that by default Python appends a newline character to the end of whatever it's been told to print. This has the effect of normally puttig successive print statements on successive lines. However, you can override this behaviour and tell Python to use another character as its "end" character to append to whatever is printed, by specifying the "end" parameter. If you for example replace this with space e.g. " " then as you can see when you execute the 2 print statements they end up on one line, seperated by thace space, instead of being on 2 seperate lines. Does that help? Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newline
Ava: On an old typewriter when you slapped that mechanical arm two separate but related things happened. 1) the page advanced to the next line of text. 2) the carriage was returnedt to the beginning of the line of text. If you were careful about the way you slapped that mechanical arm, you could get the page to advance without moving the carriage to the beginning of the line. You would get stair stepped output like this Now in the computing world, these two separate but related things can sometimes still be dealt with individually. strictly speaking a newline character is the command to move down to the next line. and a return character is the command to go to the beginning of the line. On Windows, by convention the newline command does both. So you likely won't see the return command much. But there is one, and it is used on most non-windows systems. as to your specific question, I've never actually tried to specify a new line character like you have demonstrated. I just use the "\n" sequence to make my new lines happen where I want. On Fri, Dec 3, 2010 at 7:47 PM, Ashley Blackwell wrote: > Hello everybody, I'm new to the mailing list so I'm pretty sure I'll have > lots of questions:) > > It's a very basic question I have and everybody might look at this > question and say, "Wow, she reallly doesn't get it?" But oh well. Here's my > question: I'm in Chapter 2 of my Python Programming Third Editition book. > I've gotten to the section of the chapter where it talks about a "newline > character. Exactly what is a newline character? I keep reading the same > section of the book and I'm just not really understanding. Here's the code > that the book uses to explain the newline character: > > print("Here", end=" ") > print("it is...") > > The book says that I can specify that a space be the final character printed > instead of a newline. In the first print() statement I specify that a space > be the final string printed. So the text "Here" appears but no newline > character. The next print() statement prints the text "it is"..." right > after the space following the final "e" in the "Here" text. You do it by > passing a space to the end parameter of the print() function with the code > end" ". > > My Operating System is Windows 7 and the Python version is 3.1.3. That's it. > Thanks to anybody who responds to my question. > > -- > Ava Durand > > ___ > Tutor maillist - tu...@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
On 12/3/10, Ashley Blackwell wrote: > Hello everybody, I'm new to the mailing list so I'm pretty sure I'll have > lots of questions:) That is what the list is for. :) > > It's a very basic question I have and everybody might look at this > question and say, "Wow, she reallly doesn't get it?" But oh well. Here's my > question: I'm in Chapter 2 of my Python Programming Third Editition book. > I've gotten to the section of the chapter where it talks about a "newline > character. Exactly what is a newline character? I keep reading the same > section of the book and I'm just not really understanding. Here's the code > that the book uses to explain the newline character: > > print("Here", end=" ") > print("it is...") > > The book says that I can specify that a space be the final character printed > instead of a newline. In the first print() statement I specify that a space > be the final string printed. So the text "Here" appears but no newline > character. The next print() statement prints the text "it is"..." right > after the space following the final "e" in the "Here" text. You do it by > passing a space to the end parameter of the print() function with the code > end" ". > > My Operating System is Windows 7 and the Python version is 3.1.3. That's it. > Thanks to anybody who responds to my question. A newline character is just a character telling the computer to move to the next line. Understand that all characters, from basic letters (a, b, c, ...) to strange characters that you never see are represented by numbers. For example, the letter a is 97, b is 98, and so on. A space character is 32. A newline has a number as well, since it is, after all, just another character. Instead of using numbers, though, Python (like most programming languages) lets you use what I believe are called escape sequences (someone correct me here). Basically, putting a backslash (\) followed by a letter will sometimes represent a character. \t is tab, for example. In this case, try passing \n to your function (remember to put it in quotes, since it is still a string!) and see if that does it. I hope this makes some sense. > > -- > *Ava Durand* > -- 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] Newline
Ashley Blackwell wrote: Hello everybody, I'm new to the mailing list so I'm pretty sure I'll have lots of questions:) It's a very basic question I have and everybody might look at this question and say, "Wow, she reallly doesn't get it?" But oh well. Here's my question: I'm in Chapter 2 of my Python Programming Third Editition book. I've gotten to the section of the chapter where it talks about a "newline character. Exactly what is a newline character? Text (say, in a word processor, or in source code) is made up of characters. Some characters are visible, like letters and digits. Some characters are invisible "whitespace". The most obvious one is the space character, which you get by pressing the spacebar. A little less obvious is the "newline" character, which you get by pressing the Enter key. The newline is special, because it instructions your word processor or text editor to start a new line. Duh! :-) Anyway, the point is that when you're dealing with text, there is an "invisible" newline at the end of each line. That's how your program knows that it is the end of a line! The print() function automatically adds a newline by default: >>> s = "Nobody expects the Spanish Inquisition!" # no newline >>> print(s) # automatically adds a newline Nobody expects the Spanish Inquisition! >>> If the string already includes a newline, you get a blank line: >>> s = "Nobody expects the Spanish Inquisition!\n" # \n = newline >>> print(s) Nobody expects the Spanish Inquisition! >>> Notice the blank line between the printed string and the next prompt (>>>)? print() adds a newline because that's nearly always what you want: >>> for i in (1, 2, 3): ... print(i, "spam") ... 1 spam 2 spam 3 spam but sometimes you want to print on the same line: >>> for i in (1, 2, 3): ... print(i, "spam", end="***") ... 1 spam***2 spam***3 spam***>>> Notice that because there's no newline printed at all, the prompt >>> ends up on the same line as the output! There are ways around that. Here's one: >>> for i in (1, 2, 3): ... print(i, "spam", end="\n" if i==3 else "***") ... 1 spam***2 spam***3 spam >>> 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 Sat, Dec 4, 2010 at 3:04 AM, Rance Hall wrote: > Ava: > > On an old typewriter when you slapped that mechanical arm two separate > but related things happened. > > 1) the page advanced to the next line of text. > 2) the carriage was returnedt to the beginning of the line of text. > > If you were careful about the way you slapped that mechanical arm, you > could get the page to advance without moving the carriage to the > beginning of the line. > > You would get > stair stepped > output like this > > Now in the computing world, these two separate but related things can > sometimes still be dealt with individually. > > strictly speaking a newline character is the command to move down to > the next line. > > and a return character is the command to go to the beginning of the line. > On Windows, by convention the newline command does both. > So you likely won't see the return command much. > But there is one, and it is used on most non-windows systems. As a matter of fact, on windows, a newline is encoded in binary as a carriage return (CR, ASCII code 13) followed by a linefeed (LF, ASCII code 10). The carriage return is the "return to beginning of line," and the linefeed is the "move one line down" that you mention. So in effect just the ASCII "newline" character *doesn't* do both. However, python is smart, so when you tell it to print a "\n" escape character, it prints out both a linefeed and a carriage return on windows systems (most other programming languages do this as well). Most older operating systems that predate Unix used this CR+LF convention as well, because their printing was done on teletypes that functioned much like actual typewriters. However, you're very unlikely to come across these systems today, apart from Windows. Unix systems don't use the carriage return at all, so just a newline character suffices there to move to the beginning of the next line. Mac OS (up to version 9, IIRC) actually used just a carriage return, no newline. Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print problem
Hs Hs wrote: hi I have a file and it is in chunks: I want to be able to select the number that follows 'Elution: ' where the line startswith (TITLE)(say 72.958) and check if it is larger than my choice of number (say 71.4). If it is then I want to print chunk from BEGIN LINE to END LINE separated by one empty line. I wrote the following script, when executed in IDEL or python mode, What is "python mode"? Do you mean the interactive interpreter? it works. however I use python test_script_test.py , I get name error: could you please help me whats wrong here. $ python test_script_test.py Traceback (most recent call last): File "test_script_test.py", line 14, in newk = dat[mystartl:myfinish] NameError: name 'myfinish' is not defined In python mode: f1 = open('test','r') da = f1.read().split('\n') dat = da[:-1] mytimep = 71.4 for i in range(len(dat)): ... if dat[i].startswith('BEGIN LINE'): ... mystartl = i ... if dat[i].startswith('END LINE'): ... myfinish = i ... if dat[i].startswith('Title'): ... col = dat[i].split(',') ... x= float(col[2].split()[1]) ... if x > mytimep: ... newk = dat[mystartl:myfinish] ... for x in newk: ... print x This can fail because myfinish doesn't get defined until you see a line "END LINE". So if you have a file like this: BEGIN LINE <= defines "mystart" Title ...<= tries to use "mystart" and "myfinish" END LINE <= defines "myfinish" the call to dat[mystartl:myfinish] fails because there is no myfinish. The reason it works in IDLE and the Python interactive interpreter is that you must have already defined a myfinish variable previously. Your code does way too much work manually instead of letting Python handle it. If you want to read lines from a file, just read them from a file. This should be close to what you want: f1 = open('test','r') mytimep = 71.4 flag = False collected = [] # Hold collected lines as you see them. for line in f1: line = line.rstrip() # strip whitespace from the end of the line if line == "BEGIN LINE": flag = True # start processing continue # but not *this* line, start at the next line if line == "END LINE": flag == False if flag: # process the line if line.startswith('Title'): col = line.split(',') x = float(col[2].split()[1]) if x > mytimep: collected.append(line) for line in collected: print line -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Need Help!
Hello I am totally new to python and our last assignment is that we have to create a Gui Application game similar to Hangman. The game allows the user to guess a movie title from hints and allows the player to also guess a letter in the title. Right now I just have the GUI set up. Whatever help you guys can give me will be apperciated. I will attach my Driver and GUI file to this email. from Tkinter import * class Game(Frame): def __init__(self,master): Frame.__init__(self,master) self.grid() self.create_components() def create_components(self): welcome= Label(self, text = "Guess the movie", font=("Guess the movie", 16)).grid(row = 0,column=1) Tries = Label(self, text = "# of tries left").grid(row = 2, column = 0) self.input_field1=Entry(self) count = 5 self.input_field1.insert(0,count) self.input_field1.grid(row = 3, column = 0) Guess_a_letter= Label(self, text = "Guess a Letter").grid(row = 2, column = 2) self.input_field2=Entry(self) self.input_field2.grid(row = 3, column = 2) self.Submitguess = Button(self, text="submit letter").grid(row=3, column=3) Hint = Label(self, text = "Hint:").grid(row = 4, column = 1) self.input_field3=Entry(self) self.input_field3.grid(row = 5, column = 1) Guess_The_Movie = Label(self, text = "Guess the movie").grid(row = 6, column = 0) self.input_field4=Entry(self) self.input_field4.grid(row = 7, column = 0) self.Submit = Button(self,text="Submit Guess").grid(row=8,column=0) self.Play_Again=Button(self,text="Play Again").grid(row=9,column=1) self.Reset = Button(self,text="Reset").grid(row = 7, column = 2, columnspan=1,sticky = E+W) def Gamelist(self): gamelist=set(open('Projectdatafile.txt')) Game_set= [i.split(",") for i in gamelist] from Tkinter import Tk from project_classes import Game root= Tk() root.title("Guess the Movie") root.geometry("500x500") application = Game(root) root.mainloop() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need Help!
On Sat, Dec 4, 2010 at 7:08 AM, wrote: > > Hello I am totally new to python and our last assignment is that we have to > create a Gui Application game similar to Hangman. The game allows the user > to guess a movie title from hints and allows the player to also guess a > letter in the title. Right now I just have the GUI set up. Whatever help you > guys can give me will be apperciated. I will attach my Driver and GUI file > to this email. > I'm sorry, you seem to have forgotten to ask your question. If you're unsure of how to do so, this guide might be of some help: http://www.catb.org/~esr/faqs/smart-questions.html We all like to help out people who have specific, good questions. We generally don't like to do someone's homework for them. If we did, how would they learn? So: with what are you having trouble and what have you tried? Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need Help!
tgreen...@aol.com wrote: Hello I am totally new to python and our last assignment is that we have to create a Gui Application game similar to Hangman. The game allows the user to guess a movie title from hints and allows the player to also guess a letter in the title. Right now I just have the GUI set up. Whatever help you guys can give me will be apperciated. I will attach my Driver and GUI file to this email. Did you have a question, or would you just like us to do your assignment for you? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question about the "main" Python help list
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
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