[Tutor] image
why the follwoing code report the error: Traceback (most recent call last): File "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Python23\Examples\AppB\text.py", line 24, in ? text.image_create(END, image=photo) File "C:\Python23\lib\lib-tk\Tkinter.py", line 2882, in image_create return self.tk.call( TclError: image "pyimage4" doesn't exist from Tkinter import * root = Tk() root.option_readfile('optionDB') root.title('Text') text = Text(root, height=26, width=50) scroll = Scrollbar(root, command=text.yview) text.configure(yscrollcommand=scroll.set) text.tag_configure('bold_italics', font=('Verdana', 12, 'bold', 'italic')) text.tag_configure('big', font=('Verdana', 24, 'bold')) text.tag_configure('color', foreground='blue', font=('Tempus Sans ITC', 14)) text.tag_configure('groove', relief=GROOVE, borderwidth=2) text.tag_bind('bite', '<1>', lambda e, t=text: t.insert(END, "I'll bite your legs off!")) text.insert(END, 'Something up with my banter, chaps?\n') text.insert(END, 'Four hours to bury a cat?\n', 'bold_italics') text.insert(END, 'Can I call you "Frank"?\n', 'big') text.insert(END, "What's happening Thursday then?\n", 'color') text.insert(END, 'Did you write this symphony in the shed?\n', 'groove') button = Button(text, text='I do live at 46 Horton terrace') text.window_create(END, window=button) photo=PhotoImage(file='img52.gif') text.image_create(END, image=photo) text.insert(END, 'I dare you to click on this\n', 'bite') text.pack(side=LEFT) scroll.pack(side=RIGHT, fill=Y) root.mainloop() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] click and line
> it works now. Hi Shi Mu, Can you describe how you fixed it? The only diff between the two programs that I see is that you repositioned the setting of the frame variable. # mumak:~ dyoo$ diff t1.txt t2.txt 6c6 < --- > frame = c 16c16 < frame = c --- > # What makes the "fixed" code suspicious is that the 'frame' variable is useless in the sense that it doesn't do anything. And even if it did do something, the fix --- moving a variable definition around --- doesn't make sense to me. *grin* Try changing it back and see if the problem recurs. (I suspect that your first version also worked, but that you may have forgotten to save your file before testing it.) Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] no error no result
On Sun, 6 Nov 2005, Shi Mu wrote: > when I read some python sample codes. > I found that several of them need "python -i" to run them or you will > not get any result though the program does not report any error. > I really can not understand it. Hi Shi Mu, Ok, let's compare-and-constrast. Can you show us an example of a program that doesn't get a result? Can you show us a different example of a program that does get a result? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] click and line
Danny, You are right. Thanks for your great patience and kindness. Shi On 11/7/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > > it works now. > > Hi Shi Mu, > > Can you describe how you fixed it? The only diff between the two programs > that I see is that you repositioned the setting of the frame variable. > > > # > mumak:~ dyoo$ diff t1.txt t2.txt > 6c6 > < > --- > > frame = c > 16c16 > < frame = c > --- > > > # > > What makes the "fixed" code suspicious is that the 'frame' variable is > useless in the sense that it doesn't do anything. And even if it did do > something, the fix --- moving a variable definition around --- doesn't > make sense to me. *grin* > > Try changing it back and see if the problem recurs. (I suspect that your > first version also worked, but that you may have forgotten to save your > file before testing it.) > > > Best of wishes! > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] geometry
any python code for middle school geometry teaching use? for instance, calculate the polygon area size, overlaid area size? Thanks. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Percentage
Hi all, What is the syntax if I want to work out what percentage 42 is out of 250? TIA, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Re; Geometry
If there's not code for geometry, let's write some!! What, precisely, are you looking for? Or, better yet, do you have the resources to have you students write the code after teaching them "just enough" python? I did that with a physics class a few years ago and the students loved it! --greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
Johan Geldenhuys <[EMAIL PROTECTED]> writes: > What is the syntax if I want to work out what percentage 42 is out of 250? If you want it as a factor to multiply / divide by something: perc = 42/250 If you want it to "read" as percentage: perc_100 = (42/250)*100 Sds, -- Jorge Godoy <[EMAIL PROTECTED]> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] geometry
Shi Mu wrote: > any python code for middle school geometry teaching use? > for instance, calculate the polygon area size, overlaid area size? You might be interested in PyGeo. I think it is more oriented toward visualization than calculation but it is definitely intended to aid in teaching geometry. http://pw1.netcom.com/~ajs/ Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
Johan Geldenhuys wrote: >Hi all, > >What is the syntax if I want to work out what percentage 42 is out of 250? > > Johan, You could try: percentage = (42 * 250)/100 This gives the answer 105. Cheers, F. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
I have it like that, just thought there could be another way. 8-) Jorge Godoy wrote: Johan Geldenhuys <[EMAIL PROTECTED]> writes: What is the syntax if I want to work out what percentage 42 is out of 250? If you want it as a factor to multiply / divide by something: perc = 42/250 If you want it to "read" as percentage: perc_100 = (42/250)*100 Sds, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
don't forget to use dot or converge into float.perc = 42./250or perc = float(42)/250otherwise:it is treated as integer.pujoOn 07 Nov 2005 11:50:05 -0200, Jorge Godoy <[EMAIL PROTECTED]> wrote: Johan Geldenhuys <[EMAIL PROTECTED]> writes:> What is the syntax if I want to work out what percentage 42 is out of 250?If you want it as a factor to multiply / divide by something: perc = 42/250If you want it to "read" as percentage:perc_100 = (42/250)*100Sds,--Jorge Godoy <[EMAIL PROTECTED]>___ Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
Wow, you gave 105% on this one. ;-) Frank Moore wrote: Johan Geldenhuys wrote: Hi all, What is the syntax if I want to work out what percentage 42 is out of 250? Johan, You could try: percentage = (42 * 250)/100 This gives the answer 105. Cheers, F. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
On 07 Nov 2005 11:50:05 -0200, Jorge Godoy <[EMAIL PROTECTED]> wrote: > Johan Geldenhuys <[EMAIL PROTECTED]> writes: > > > What is the syntax if I want to work out what percentage 42 is out of 250? > > If you want it as a factor to multiply / divide by something: > > perc = 42/250 Don't you need to specify one of these numbers as a float? >>> print 42/250 0 >>> print 42/250.0 0.168 I recall reading somewhere that all division would be 'true division' from >3.0 but this isn't the case in 2.x is it? > Jorge Godoy <[EMAIL PROTECTED]> S. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
Frank Moore <[EMAIL PROTECTED]> writes: > Johan, > > You could try: > > percentage = (42 * 250)/100 > > This gives the answer 105. And that sounds weird, doesn't it? 42 is smaller than 250, so I'd expect it to be less than 100% of the value... In fact, it is >>> 42.0/250 0.16801 >>> (42.0/250)*100 16.801 >>> I suspect the problem is due to the fact that Python does integer division by default: >>> 42/250 0 >>> So, how to make it generic? >>> a = 42 >>> b = 250 >>> a / b 0 >>> float(a)/b 0.16801 >>> One of the members has to be a floating point so that floating point division is performed instead of integer division. Be seeing you, -- Jorge Godoy <[EMAIL PROTECTED]> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
Steve Nelson <[EMAIL PROTECTED]> writes: > Don't you need to specify one of these numbers as a float? You do. My mistake and I haven't seen both corrections before sending my last message. :-) > I recall reading somewhere that all division would be 'true division' > from >3.0 but this isn't the case in 2.x is it? There was also some kind of "from future import true division method" but I don't remember where I found it. Oh! Found it! http://mail.python.org/pipermail/python-dev/2001-July/016174.html >>> from __future__ import division >>> 42 / 250 0.16801 >>> Be seeing you, -- Jorge Godoy <[EMAIL PROTECTED]> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Object instances
All right! That's penetrated. Thanks very much. ds ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
Pujo Aji <[EMAIL PROTECTED]> writes: > don't forget to use dot or converge into float. Or import division from __future__. >>> from __future__ import division >>> 42 / 250 0.16801 >>> -- Jorge Godoy <[EMAIL PROTECTED]> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
Johan Geldenhuys wrote: > Wow, you gave 105% on this one. ;-) > You're right. I misread the question and thought that you wanted 42% of 250. My mistake. Cheers, F. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Percentage
nice syntax. Cheers, pujo On 07 Nov 2005 12:18:44 -0200, Jorge Godoy <[EMAIL PROTECTED]> wrote: Pujo Aji <[EMAIL PROTECTED]> writes:> don't forget to use dot or converge into float. Or import division from __future__.>>> from __future__ import division>>> 42 / 2500.16801>>>--Jorge Godoy < [EMAIL PROTECTED]>___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] base64MIME module import error
I was just trying to make a simple cgi email form when I encountered this error. Traceback (most recent call last): File "/Users/eddie/Sites/python/email.py", line 4, in ? import smtplib File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/smtplib.py", line 49, in ? from email.base64MIME import encode as encode_base64 ImportError: No module named base64MIME It says it can not find the module base64MIME. I also tried importing the module from the command line and that worked fine. Any help is appreciated Eddie Sowden ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] base64MIME module import error
Eddie S wrote: > I was just trying to make a simple cgi email form when I encountered > this error. > > Traceback (most recent call last): > File "/Users/eddie/Sites/python/email.py", line 4, in ? > import smtplib > File > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/smtplib.py", > line 49, in ? > from email.base64MIME import encode as encode_base64 > ImportError: No module named base64MIME > > It says it can not find the module base64MIME. I also tried importing > the module from the command line and that worked fine. The problem is that your email.py module is shadowing the library email module. Python is looking for base64MIME in your module. Rename your email.py to something else and it should work. Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] geometry
| any python code for middle school geometry teaching use? | for instance, calculate the polygon area size, overlaid area size? | Thanks. | Yes, the module I refered to in response to the email with subject "Overlay" will handle these calculations. Again, see ( http://www.dezentral.de/warp.html?http://www.dezentral.de/soft/Polygon/ ). /c ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] base64MIME module import error
> The problem is that your email.py module is shadowing the library email > module. Python is looking for base64MIME in your module. Rename your email.py > to something else and it should work. > > Kent > > -- > http://www.kentsjohnson.com > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > Cheers that works better. That is the second time that has happened to me. (you would have thought I would have learned. Eddie ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] simple report writing?
Can someone suggest a specific tutorial strictly on report writing? I'm able to write reports fairly easily in Python. I know the stuff like str(round(x,2)) where x = 3.145678 will yield 3.14. What I'm looking for is to be able to control left and right justification, column by column while using string and numeric data of variable lengths so that my reports look much neater. Possibly a generalized def print_line(*x)? Thanks. RC _ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Easier way to access wxPython
Dear All, Just a note: When the next question about "which GUI for Python" comes around (and I should plead guilty to having asked a few times) I thought that the Dabo framework, which wraps wxPython in a nicer API would be worth pointing to. And even if the question didn't get asked, I thought people might like to know... http://daboenv.com/ HTH, Matt -- Dr. M. Williams MRCP(UK) Clinical Research Fellow Cancer Research UK +44 (0)207 269 2953 +44 (0)7834 899570 http://acl.icnet.uk/~mw http://adhominem.blogspot.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] simple report writing?
I have a list (x_list) of class data. How do I sort that list by a selected variable common to all members of the list? x_list.sort(key=x_list.v_name) # doesn't work becuase x_list can't see the individual items. RC _ Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Mono
Dear List, Slightly off topic, but could someone explain/ point me to a URL that explains how one might use Python with Mono (I guess it would be IronPython, rather than CPython), and what advantages it might give you (apart from a possible speed up of IronPython vs. CPython). I'm especially interested in the idea of being able to write different bits in different languages, and then run them all on Mono. Thanks, Matt -- Dr. M. Williams MRCP(UK) Clinical Research Fellow Cancer Research UK +44 (0)207 269 2953 +44 (0)7834 899570 http://acl.icnet.uk/~mw http://adhominem.blogspot.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simple report writing?
CPIM Ronin wrote: > Can someone suggest a specific tutorial strictly on report writing? > > I'm able to write reports fairly easily in Python. I know the stuff like > str(round(x,2)) where x = 3.145678 will yield 3.14. What I'm looking for is > to be able to control left and right justification, column by column while > using string and numeric data of variable lengths so that my reports look > much neater. Do you know about the string formatting operator %? http://docs.python.org/lib/typesseq-strings.html You might also be interested in this recipe which formats a table for output: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662 Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simple report writing?
CPIM Ronin wrote: > I have a list (x_list) of class data. How do I sort that list by a > selected variable common to all members of the list? > > x_list.sort(key=x_list.v_name) # doesn't work becuase x_list can't see > the individual items. Use import operator x_list.sort(key=operator.attrgetter('v_name')) Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Easier way to access wxPython
Matt Williams wrote: > Dear All, > > Just a note: When the next question about "which GUI for Python" comes > around (and I should plead guilty to having asked a few times) I thought > that the Dabo framework, which wraps wxPython in a nicer API would be > worth pointing to. > > http://daboenv.com/ Are there any examples or docs of using Dabo this way? I haven't downloaded Dabo but the info on the web site is pretty thin. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simple report writing?
I neglected to mention that the list x_list was created by x_list = [] and then a series of x_list.append(y), where y are class instances with a variety of variables, one of which I want to use as a sort key. >I have a list (x_list) of class data. How do I sort that list by a selected >variable common to all members >of the list? > >x_list.sort(key=x_list.v_name) # doesn't work becuase x_list can't see the >individual items. > >RC _ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Is Python a good choise for this project?
Hey, > > Python is capable of building such a system if thats what you mean. > Proivided high performance (real time rapid animation say) is not required > then it should perform adequately. Yes, performance is not a great concern. > But it will require quite a bit of > learning, > not just the core language but a GUI toolkit, and maybe the PyGame > framework too. > > graphics lib, like Pygame)? Other alternatives at this point are Java and > > C/SDL/Allegro. > > If you already know these environments and have built similar applications > in them you may be faster sticking with them. But if you have the time and > energy to learn a new language then Python offers the promise of more rapid > development in the future and easier maintenance. If you know Java you > might consider using Jython to write the core objects and Java to do the > GUI parts - Jython makes Python objects that are also valid Java objects > and vice versa. > I have experience with both Java and C. However using them will also involve some learning since I don't have much graphical animation experience (Java 2D if Java, SDL or Allegro if C). Since I got somewhat interested in Python's simplicity I added it to the possibility list because this would be an "excuse" to learn Python and Python's simplicity could help concentrate on the techniques and algorithms and less on the syntax. Java will probably be the choisen since I'm confortable with it and it can lead to less problems than C - the downsite is Java's heavy sintax. Jython seams interesting. Will check it. Thanks for your message. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mono
> Slightly off topic, but could someone explain/ point me to a URL that > explains how one might use Python with Mono (I guess it would be > IronPython, rather than CPython), and what advantages it might give you > (apart from a possible speed up of IronPython vs. CPython). I'm > especially interested in the idea of being able to write different bits > in different languages, and then run them all on Mono. Hi Matt, This is really specialized; I'd recommend checking with the IronPython folks on this one. http://lists.ironpython.com/listinfo.cgi/users-ironpython.com They're pretty active; I see some familiar faces like Liam in the archives there. *grin* I'd ask them, since they'd be most familiar with Python on Mono. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simple report writing?
Hi RC, >I have a list (x_list) of class data. So, a list of instances/classes then. You'll have to pass a custom function. def tSort(objA,objB): #assuming that objA.x & objB.x are the items to sort by, and are integers if objA < objB: result = -1 elif objA = objB: result = 0 elif objA > objB: #Would normally just do as an else #But being ultra explicit result = 1 return result x_list.sort(cmp=tSort) Regards, Liam Clarke -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of CPIM Ronin Sent: Tuesday, 8 November 2005 8:11 a.m. To: tutor@python.org Subject: [Tutor] simple report writing? I have a list (x_list) of class data. How do I sort that list by a selected variable common to all members of the list? x_list.sort(key=x_list.v_name) # doesn't work becuase x_list can't see the individual items. RC _ Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ A new monthly electronic newsletter covering all aspects of MED's work is now available. Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See http://news.business.govt.nz for more details. http://www.govt.nz - connecting you to New Zealand central & local government services Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simple report writing?
> >>Can someone suggest a specific tutorial strictly >>on report writing? >> >>to be able to control left and right justification, ... It doesn't sound like you need a tutorial per se, simply to spend some time with Pythons format strings - like C printf() Otherwise the only other advice I'd give is to read some general books on data transformations - something like Michael Jacksons classic JSP book maybe? (Try your local university library! or Amazons second hand service...) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Namespace Problem
Bob: Yes I did mean 'import' and yes there is more to the function. Here is the entire program. import socket import struct # data packet flags ABC = 1 DEF = 2 GHI = 4 JKL = 8 seq = 0 buf = 8192 # This is the max_packet_size defined in the SocketServer module addr = ('localhost', 12345) # Host and port used by the server def do_stuff(in_str): hdr = struct.pack('@2BH',ABC|DEF,seq,len(in_str)) newstr = hdr+in_str if(sock.sendto(newstr,addr)): response = sock.recv(buf) flags, retseq, dlen = struct.unpack('@2BH', response[:4]) print "flags: 0x%X, retseq: %u, dlen: %u" % (flags, retseq, dlen) response = response[4:] rsphdr=eval(response[:response.find(')')+1]) response = response[response.find(')')+2:] resptupl = (rsphdr, response) seq += 1 return resptupl sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) def_msg = "===Enter message to send to server==="; print "\n",def_msg # Send messages while (1): data = raw_input('>> ') if not data: break else: print "Sending message '",data,"'" ret_data = do_stuff(data) print "Got back: ", ret_data sock.close( ) Here is a trace of program execution. ===Enter message to send to server=== >> send some data Sending message ' send some data ' Traceback (most recent call last): File "./bgctest.py", line 40, in ? ret_data = do_stuff(data) File "./bgctest.py", line 15, in do_stuff hdr = struct.pack('@2BH',ABC|DEF,seq,len(in_str)) UnboundLocalError: local variable 'seq' referenced before assignment I can't figure it out. Barry > -Original Message- > From: bob [mailto:[EMAIL PROTECTED] > Sent: Friday, November 04, 2005 6:32 PM > To: Carroll, Barry; 'tutor@python.org' > Cc: Carroll, Barry > Subject: Re: [Tutor] Namespace Problem > > At 05:47 PM 11/4/2005, Carroll, Barry wrote: > >I have a function that makes use of several global variables: > > > >## > >Include struct > > Did you mean "import"? > > >ABC = 1 > >DEF = 2 > >xyz = 0 > >def do_stuff(in_str): > > hdr = struct.pack('@2BH',ABC|DEF,xyz,len(in_str)) > > newstr = hdr+in_str > > Works find for me. Is there anything else you are not showing us? > <> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Error message with testing Tkinter
Hi, I'm learning Tkinter with the following code on Mac OS X 10.4: from Tkinter import * from sys import stdout, exit widget = Button(None, text = 'Hello?', command=(lambda: stdout.write('Hello?\n') or exit())) widget.pack() widget.mainloop() I do successfully get a GUI with a button, but the problem is if I click the button, the GUI window hangs there with the following message message in the console: Hello? Traceback (most recent call last): File "/Users/gangc/Python_Scripting/test.py", line 7, in -toplevel- widget.mainloop() File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-tk/Tkinter.py", line 965, in mainloop self.tk.mainloop(n) File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-tk/Tkinter.py", line 1347, in __call__ raise SystemExit, msg SystemExit What am I missing? Any help will be highly appreciated, Joe Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Easier way to access wxPython
For wxPython - Wax is alright, Pythoncard is great. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Tuesday, 8 November 2005 8:31 a.m. Cc: Python Tutor Subject: Re: [Tutor] Easier way to access wxPython Matt Williams wrote: > Dear All, > > Just a note: When the next question about "which GUI for Python" comes > around (and I should plead guilty to having asked a few times) I > thought that the Dabo framework, which wraps wxPython in a nicer API > would be worth pointing to. > > http://daboenv.com/ Are there any examples or docs of using Dabo this way? I haven't downloaded Dabo but the info on the web site is pretty thin. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor A new monthly electronic newsletter covering all aspects of MED's work is now available. Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See http://news.business.govt.nz for more details. http://www.govt.nz - connecting you to New Zealand central & local government services Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Namespace Problem
Carroll, Barry wrote: > Bob: > > Yes I did mean 'import' and yes there is more to the function. Here is the > entire program. > > > import socket > import struct > > # data packet flags > ABC = 1 > DEF = 2 > GHI = 4 > JKL = 8 > seq = 0 > > buf = 8192 # This is the max_packet_size defined in the SocketServer module > addr = ('localhost', 12345) # Host and port used by the server > > def do_stuff(in_str): > hdr = struct.pack('@2BH',ABC|DEF,seq,len(in_str)) > newstr = hdr+in_str > if(sock.sendto(newstr,addr)): > response = sock.recv(buf) > flags, retseq, dlen = struct.unpack('@2BH', response[:4]) > print "flags: 0x%X, retseq: %u, dlen: %u" % (flags, retseq, dlen) > response = response[4:] > rsphdr=eval(response[:response.find(')')+1]) > response = response[response.find(')')+2:] > resptupl = (rsphdr, response) > seq += 1 The above statement binds a value to the name 'seq'. If a name is bound anywhere within a block, the compiler treats it as a local name and it will not be looked up in the global namespace. When the struct.pack() line is executed, seq is not bound in the local namespace and you get an error. The solution is to include 'global seq' in do_stuff(); this tells the compiler that seq should always be treated as a global name even though it is bound in the current block. This a little bit subtle because you are using seq += 1. Still this is binding a new value to seq and you need to declare it global. Kent > return resptupl > > sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > > def_msg = "===Enter message to send to server==="; > print "\n",def_msg > > # Send messages > while (1): > data = raw_input('>> ') > if not data: > break > else: > print "Sending message '",data,"'" > ret_data = do_stuff(data) > print "Got back: ", ret_data > > sock.close( ) > > > Here is a trace of program execution. > > > ===Enter message to send to server=== > >>>send some data > > Sending message ' send some data ' > Traceback (most recent call last): > File "./bgctest.py", line 40, in ? > ret_data = do_stuff(data) > File "./bgctest.py", line 15, in do_stuff > hdr = struct.pack('@2BH',ABC|DEF,seq,len(in_str)) > UnboundLocalError: local variable 'seq' referenced before > assignment > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error message with testing Tkinter
On Mon, 7 Nov 2005, Double Six wrote: > I'm learning Tkinter with the following code on Mac OS X 10.4: > > from Tkinter import * > from sys import stdout, exit > widget = Button(None, text = 'Hello?', command=(lambda: > stdout.write('Hello?\n') or exit())) > widget.pack() > widget.mainloop() > > I do successfully get a GUI with a button, but the problem is if I click > the button, the GUI window hangs there with the following message > message in the console: Hello, sys.exit() will raise a SystemExit exception when it's called, so the program is doing what you think it's doing. However, it looks like the mainloop() code from Tkinter doesn't expect to see that SystemExit. You probably want to call the quit() method of the graphical widgets instead: that'll get us out of the mainloop(). http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [OT] Mono
Hi Matt, The main advantage of IronPython is access to the .NET framework in Python. For most Python scripts I run, there is no speed advantage due to the overhead of loading the framework (but then, I have an old computer.) But, I like being able to poke .NET within a Python environment, as I didn't want to have to learn C# to just have a play. Because everything in .NET, whether from C# or VB.Net or C++ or IronPython, compiles down to Intermediate Language, you've got a wide community to draw 3rd party modules from. Downside is that IL isn't that nice to try and read, so if you didn't get the source, then it can be a bit of a black box scenario. But yeah. I'm very impressed with what little of the .NET framework I've seen. Avalon/WFP is the sane GUI library that Windows always needed. It's probably a bit simpler to use than Tkinter, but seems more powerful than wxWidgets. Of course, it's OS specific... (I also think that once IronPython is released properly, there'll be few reasons that pointy haired bosses could stop you using it. It's made by Microsoft, it's .NET (is that still an 'in' buzzword?), and it all turns into IL at the end.) That said, the main disadvantage is that it doesn't play well with CPython at all. The standard library is being ported across, bit by bit, but the chances of any 3rd party module working are slim. Anything that relies on C won't work, so it exists in great isolation from the rest of Python. i.e. I can import the os and popen2 modules, but i can't use any variant of popen(), as popen is built on a C function called pipe(). Also, .NET is a bit more... verbose. Here's a comparison of CPython and IronPython creating a subprocess and creating pipes to it. The .NET variant allows a little more flexibility in how the process is started (although I believe the CPython subprocess module would be a more accurate comparison, but I can't be bothered trying to understand it's docs), yet oddly enough has no way whereby stderr and stdout can be combined as per popen4(). Both the below code samples perform the exact same function. CPython - import os (procStdin, procStdOut, procStdErr ) = os.popen3("c:/window/system23/cmd.exe") #I think I got those around the right way. This is all from memory. IronPython - import System.Diagnostics #.NET library process = System.Diagnostics.Process() stInfObj = System.Diagnostics.StartInfo("c:/window/system23/cmd.exe") stInfObj.CreateNoWindow = True stInfObj.UseShellExecute = False stInfObj.RedirectStandardInput = True stInfObj.RedirectStandardOutput = True stInfObj.RedirectStandardError = True process.StartInfo = stInfObj process.Start() (procStdin, procStdOut, procStdErr) = (process.StandardInput, process.StandardOutput, process.StandardError) Liam Clarke-Hutchinson -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Danny Yoo Sent: Tuesday, 8 November 2005 8:45 a.m. To: Matt Williams Cc: Python Tutor Subject: Re: [Tutor] Mono > Slightly off topic, but could someone explain/ point me to a URL that > explains how one might use Python with Mono (I guess it would be > IronPython, rather than CPython), and what advantages it might give > you (apart from a possible speed up of IronPython vs. CPython). I'm > especially interested in the idea of being able to write different > bits in different languages, and then run them all on Mono. Hi Matt, This is really specialized; I'd recommend checking with the IronPython folks on this one. http://lists.ironpython.com/listinfo.cgi/users-ironpython.com They're pretty active; I see some familiar faces like Liam in the archives there. *grin* I'd ask them, since they'd be most familiar with Python on Mono. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor A new monthly electronic newsletter covering all aspects of MED's work is now available. Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See http://news.business.govt.nz for more details. http://www.govt.nz - connecting you to New Zealand central & local government services Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Does Pygame allow background images?
Hey all, Does Pygame allow background images (i.e. a hockey rink for a hockey game)? Thanks, Nathan Pinno ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does Pygame allow background images?
> Does Pygame allow background images (i.e. a hockey rink for a hockey game)? Sure... just check out the supplied chimp.py example, which has a message in the background, and two sprites on top of it. Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does Pygame allow background images?
Hi Nathan, Just create a surface the same size as your screen, and have a loop like so while True: Here's some rough code to add a background for that ball one I posted yesterday. Bear in mind that I can't check this at work. Lines with !! are new- import sys, pygame pygame.init() !!background = pygame.image.load("bckgrnd.bmp")#Pygame can handle other formats. !!backgrountRect = background.get_rect() !!size = (width, height) = background.get_size() #Returns size of image as (x, y) so game screen will be as big as background screen = pygame.display.set_mode(size) ball = pygame.image.load("ball.bmp") ballrect = ball.get_rect() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] !!screen.blit(background, backgroundRect) #instead of screen.fill() screen.blit(ball, ballrect) pygame.display.flip() That's very basic, but it should work. www.med.govt.nz -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nathan Pinno Sent: Tuesday, 8 November 2005 1:24 p.m. To: Tutor Mailing List Subject: [Tutor] Does Pygame allow background images? Hey all, Does Pygame allow background images (i.e. a hockey rink for a hockey game)? Thanks, Nathan Pinno A new monthly electronic newsletter covering all aspects of MED's work is now available. Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See http://news.business.govt.nz for more details. http://www.govt.nz - connecting you to New Zealand central & local government services Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does Pygame allow background images?
Oh dear, The full code would be (hopefully correct this time) import sys, pygame pygame.init() ball = pygame.image.load("ball.bmp") background = pygame.image.load("bckgrnd.bmp") ballrect = ball.get_rect() backgroundRect = background.get_rect() size = (width, height) = background.get_size() screen = pygame.display.set_mode(size) while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] screen.blit(background, backgroundRect) screen.blit(ball, ballrect) pygame.display.flip() Liam Clarke-Hutchinson -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Liam Clarke-Hutchinson Sent: Tuesday, 8 November 2005 3:06 p.m. To: 'Nathan Pinno'; Tutor Mailing List Subject: Re: [Tutor] Does Pygame allow background images? Hi Nathan, Just create a surface the same size as your screen, and have a loop like so while True: Here's some rough code to add a background for that ball one I posted yesterday. Bear in mind that I can't check this at work. Lines with !! are new- import sys, pygame pygame.init() !!background = pygame.image.load("bckgrnd.bmp")#Pygame can handle other formats. !!backgrountRect = background.get_rect() !!size = (width, height) = background.get_size() #Returns size of image as (x, y) so game screen will be as big as background screen = pygame.display.set_mode(size) ball = pygame.image.load("ball.bmp") ballrect = ball.get_rect() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] !!screen.blit(background, backgroundRect) #instead of screen.fill() screen.blit(ball, ballrect) pygame.display.flip() That's very basic, but it should work. www.med.govt.nz -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nathan Pinno Sent: Tuesday, 8 November 2005 1:24 p.m. To: Tutor Mailing List Subject: [Tutor] Does Pygame allow background images? Hey all, Does Pygame allow background images (i.e. a hockey rink for a hockey game)? Thanks, Nathan Pinno A new monthly electronic newsletter covering all aspects of MED's work is now available. Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See http://news.business.govt.nz for more details. http://www.govt.nz - connecting you to New Zealand central & local government services Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor A new monthly electronic newsletter covering all aspects of MED's work is now available. Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See http://news.business.govt.nz for more details. http://www.govt.nz - connecting you to New Zealand central & local government services Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Namespace Problem
Kent: Thank you for the explanation. This is a subtlety of Python that has tripped me up before. Barry > Date: Mon, 07 Nov 2005 16:26:39 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Namespace Problem > Cc: "'tutor@python.org'" > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > <> > > seq += 1 > > The above statement binds a value to the name 'seq'. If a name is bound > anywhere within a block, the compiler treats it as a local name and it > will not be looked up in the global namespace. When the struct.pack() line > is executed, seq is not bound in the local namespace and you get an error. > The solution is to include 'global seq' in do_stuff(); this tells the > compiler that seq should always be treated as a global name even though it > is bound in the current block. > > This a little bit subtle because you are using seq += 1. Still this is > binding a new value to seq and you need to declare it global. > > Kent > <> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TKinter Question
Just a quick TKinter question. Is it possible to have custom frames/widgets? In other words can I customize the way that the GUI looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I was just wondering if it was possible and if it is possible then where I might get some information on how to do it. Thank you very much, Rob. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] geometry
Because i am also teaching some introduction courses of programming in middle school, I prefer some 2D geometry codes. On 11/7/05, Chris or Leslie Smith <[EMAIL PROTECTED]> wrote: > > | any python code for middle school geometry teaching use? > | for instance, calculate the polygon area size, overlaid area size? > | Thanks. > | > > Yes, the module I refered to in response to the email with subject "Overlay" > will handle these calculations. > > Again, see ( > http://www.dezentral.de/warp.html?http://www.dezentral.de/soft/Polygon/ ). > > /c > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor