Re: [Tutor] Another Quick Question
> I’m one of the people new to Python who has started going through a > beginner’s book to learn the basics of the language (“Python > Programming for the Absolute Beginner”). In the second chapter the > author (Michael Dawson) illustrates the use of escape sequences with, > among other things, the “\a” to sound the system bell. However, when > I run the little program myself, the program runs but I get no sound – > all is get is the word BEL in while letters on a blue background. > I’ve turned the volume up all the way and still no sound. I know the > speakers on my laptop work because I just finished my daily session > trying to learn a little Spanish which involves sound. > > > > I went to the language reference which also seems to indicate I should > get a sound with exactly what the author is saying. The exact line > is: > > > > print “\a” I think that the bell referred to is the sound played by the speaker inside the case and has nothing to do with sound cards, speakers etc. Norman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for suggestions
Haven't look at the code in detail, but it would be great exercise to write a web gui for this game like the one for Tick-Tack-Toe. Any suggestions where to start with something like this? Johan PS: Fun to play. ->Terry<- wrote: >-BEGIN PGP SIGNED MESSAGE- >Hash: SHA1 > > >I have written a small peg game using Pygame. >This is the first working version. I have a >request and a couple of perhaps silly questions. > >To anyone willing to take the time to have a >look at the code and offer any advice or >suggestions, I would be much appreciative. >I'm looking for code suggestions rather than >game-play suggestions, although I'm open to >any help. > >I haven't got my head really wrapped around the >OO stuff, so I'm thinking rewriting it using >classes would make a good project to learn >with. Is this the sort of thing that one would >use classes for? Or is is better left as >simple as possible? > >Now here is the perhaps silly question. Is >something like this need to have a license? >What I mean is, as I play with and improve >this game and want to share it with others, >should I choose a license and add the legal >stuff with the distributed product? > >I have learned so much reading this list. I >hope I've asked my questions right. > >The game appears to also work on Windows also, >but does require you to have Pygame installed. >It was written on Slackware with Python 2.4.1 > >The code: > >http://members.socket.net/~tvbare/pypeg/pypeg.py> > >And the images: > >http://members.socket.net/~tvbare/pypeg/board.png> >http://members.socket.net/~tvbare/pypeg/peg.png> > >Cheers, >- -- > Terry > > >"Be who you are and say what you feel, because those > who mind don't matter and those who matter don't mind." > -- Dr. Seuss >-BEGIN PGP SIGNATURE- >Version: GnuPG v1.2.7 (GNU/Linux) > >iD8DBQFDeCyyQvSnsfFzkV0RAqnBAJ9TEwpP7gmUPt06ZWCS/vUJ9lLSXACbBhFl >NxIKZYKxi4OK9vR13HYP7IA= >=gYkg >-END PGP SIGNATURE- > >___ >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] Another Quick Question
> I went to the language reference which also seems to indicate I should get > a > sound with exactly what the author is saying. The exact line is: > > print "\a" Escape characters are terminal settings so you need to be running in a terminal. Start up a command window and run the program there it should work. Running in IDLE or PythonwIn, which are windows environments, won't work. HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Inheriting from parent object
I want to create a property that will inherit it's value from the same property in it's parent object, but will check it's parent's propety everytime it is called. But that can be over-ridden, and I don't have to know what the objects parent is. For example: object.x = 3 object.subobject.x = inherit() print object.subobject.x #prints 3 object.x = 4 print object.subobject.x #prints 4 object.subobject.x = 5 print object.subobject.x #prints 5 What could I put in the inherit() function that would look for the same property of it's parent and return that, whilst keeping it as general as possible? Thanks Ed ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python / OS X recommendations
Hello, I am looking for some advice about Python resources for the Mac OS X (Tiger) platform. I have done some googling and found some good stuff (Python IDE, MacPython), Just wondering if there is anything I am missing. I tried downloading the activestate python tool, but i cant seem to install it. Thanks, Ben. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python / OS X recommendations
Benjamin, > I am looking for some advice about Python resources for the Mac OS X Can you tell us what background you have? Are you a MacOS programmer? Have you used Objective C or Java to build a Mac application for example? Do you already know Cocoa? There are loads of general MacOS programming sites which could be useful depending what your background is. THe obvious starting point is the Apple Developer site... http://developer.apple.com/ > missing. I tried downloading the activestate python tool, but i cant > seem to install it. I may be wrong but I thought ActiveState targeted Windows, do they have any MacOS tools? Which tool did you try to load? Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for suggestions
> To anyone willing to take the time to have a > look at the code and offer any advice or > suggestions, I would be much appreciative. I'm wondering if you can condense this: if sel1 == 1 and sel2 == 4: # This seems really ugly... if state[1] == 1: return 2 elif sel1 == 1 and sel2 == 6: if state[2] == 1: return 3 Into this: sel={(1,4): (1,3), (1,6): (2,2), etc.} if state[ sel[(sel1,sel2)][0] ] == 1: return sel[(sel1,sel2)][1] Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for suggestions
->Terry<- wrote: > To anyone willing to take the time to have a > look at the code and offer any advice or > suggestions, I would be much appreciative. > I'm looking for code suggestions rather than > game-play suggestions, although I'm open to > any help. A couple of notes after a quick look: - As you note, def check_valid_jump(sel1, sel2) is really ugly. When I have code like this I look for a way to drive it from a table instead of a bunch of if/elif statements full of magic numbers. In this case it looks like you have one condition for each state. The conditions and results could be put in a list whose index is the state and whose values are the test values for sel1 and sel2. You would have a table that looks like this: jump_table = [ (1, 1, 4, 2),# (state # sel1 and sel2 values to check for state, return value) (2, 1, 6, 3), # etc for all the tests ] Then check_valid_jump() becomes def check_valid_jump(sel1, sel2): for st, sel1value, sel2value, result in jump_table: if sel1 == sel1value and sel2 == sel2value: if state[st] == 1: return result break return 0 - get_button() could be similarly simplified, only you don't even need a table, you are just returning the number of the peg_coords that was clicked. This should work: def get_button(click): for i, peg in peg_coords: if click in peg: return i+1 return 0 > > I haven't got my head really wrapped around the > OO stuff, so I'm thinking rewriting it using > classes would make a good project to learn > with. Is this the sort of thing that one would > use classes for? Or is is better left as > simple as possible? I'm a believer in "as simple as possible". One of the strengths of Python is that you don't *have* to use classes if they are not called for. Maybe there is some benefit in using classes in your program, for example a peg class might simplify it, I'm not sure. This essay talks about some of the reasons you might want to introduce classes into a program: http://personalpages.tds.net/~kent37/blog/stories/15.html Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python / OS X recommendations
Benjamin James wrote: > Hello, > > I am looking for some advice about Python resources for the Mac OS X > (Tiger) platform. I have done some googling and found some good stuff > (Python IDE, MacPython), Just wondering if there is anything I am > missing. You might be interested in PyObjC which lets you write Cocoa programs in Python. http://pyobjc.sourceforge.net/ Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] tkFileDialog.Directory
Hello! I want to learn Tkinter and try to build a small File search dialog. Tkinter is nice, but here is a problem where I am stuck: I want to allow the dialog's user to pick a directory. The widget for this is tkFileDialog.Directory. But when I start the Directory-Window, it is possible move the focus back to my File Search dialog. Thus it is possible but not wanted to create several "Pick directory" windows. I tried to make the Directory instance modal by calling .grab_set() but this raises an attribute error. Here is a minimal example: --- snip --- import Tix from Tkconstants import * from tkFileDialog import Directory class FileSearchBase: def __init__(self, root): self.root = root self.top = None self.title= "File Search" def open(self): if not self.top: self.create_widgets() else: self.top.deiconify() self.top.tkraise() self.top.grab_set() def close(self, event=None): if self.top is not None: self.top.grab_release() self.top.withdraw() def create_widgets(self): top = Tix.Toplevel(self.root) top.resizable(0,0) top.bind("", self.close) top.protocol("WM_DELETE_WINDOW", self.close) top.wm_title(self.title) self.top = top pickButton= Tix.Button(top, text = 'Pick..', command = self.pick_dir) pickButton.grid(row= 0, column=1) def pick_dir(self): dir_dlg= Directory() #dir_dlg.grab_set() # AttributeError: grab_set #self.top.wait_window(dir_dlg) # AttributeError: _w dir= dir_dlg.show() print dir if __name__ == '__main__': root = Tix.Tk() root.title("File Search Demo") widget = FileSearchBase(root) searchButton = Tix.Button(root, text = 'Show search dialog', command = widget.open) searchButton.pack(padx = 8, pady = 8) root.mainloop() --- snip --- The above example allows to create several Directory dialogs. On the other hand, if I start the Directory dialog from the root window (from the Tix.Tk() instance), everything works fine. The following example works: --- snip --- import Tix from Tkconstants import * from tkFileDialog import Directory def pick_dir(): dir_dlg= Directory() dir= dir_dlg.show() print dir if __name__ == '__main__': root = Tix.Tk() root.title("File Search Demo") pickButton = Tix.Button(root, text = 'Choose Directory', command = pick_dir) pickButton.pack(side = 'bottom') root.mainloop() --- snip --- Would be nice if someone could help me with the first example... Kind regards, Karsten. -- Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko! Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for suggestions
->Terry<- wrote: > Now here is the perhaps silly question. Is > something like this need to have a license? > What I mean is, as I play with and improve > this game and want to share it with others, > should I choose a license and add the legal > stuff with the distributed product? Just a quick note about this. If you are planning to distribute casually maybe it doesn't matter. But for more formal distribution (e.g. a permanent web site) you do your readers a favor by explicitly stating the terms under which they can use your code. Absent a license, honest users must contact you before they can use your programs. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] question about serial coms
Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Any TurboGears users out there?
I just stumbled across TurboGears: http://www.macdevcenter.com/pub/a/mac/2005/11/08/turbogears.html Its based on CheryPy which consistently gets good reviews but adds SQL access and XML templates. Sounds interesting, possibly even a Zope rival for the medium sized as opposed to massive site.. Is anyone on the list using it? Or even looked at it? Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: > Hey there, > i am developing on a linux computer with the serial module. Now, i > already am able to recieve info from a serial RS232 device and process > everything ok. What i need to do now is write to the serial device, but > i also need to be able to not interrupt the script that is reading from > it. > I guess my question is, do i have to interrupt the reading script to > write to the same RS232 device ? > and if so, how do i do that? > > thanks, > shawn > > ___ > 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] Any TurboGears users out there?
Alan Gauld wrote: > I just stumbled across TurboGears: > > http://www.macdevcenter.com/pub/a/mac/2005/11/08/turbogears.html > > Its based on CheryPy which consistently gets good reviews but adds SQL > access and XML templates. Sounds interesting, possibly even a Zope rival > for the medium sized as opposed to massive site.. > > Is anyone on the list using it? Or even looked at it? I have looked at it to the extent of getting through the tutorial and a little more playing. It looks very promising to me. CherryPy, SQLObject and mochikit all have good reputations and TG seems to do a good job of gluing them together. Kid (the template engine) is not as mature as the others but it seems to work OK. I used CherryPy 1 for a small work project. It was very easy to build the web site. I found the built-in webserver lacking in some of the basics like a usable request log but I think this has been fixed in CP 2. Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
Yeah, i am using pyserial, i think, in debian its called python serial and i use import serial to get things going. Really easy, just wanted to know about this stuff before i start scrambling this like so many eggs. i will not be using two different scripts, but likely two threads in the same script. not sure i really get what select() is all about great link by the way, thanks. shawn On Mon, 2005-11-14 at 12:35 -0600, Hugo González Monteverde wrote: > Hi Nephish, > > Are you using pyserial or rolling your own? Normally you can write and > read to the /dev/ttySXX file at the same time; since they're special > files, not ordinary files, the driver handles that. > > Handling both writing and reading in your program's flow control is a > wholly different matter, though. You might need to use select() to > avoid blocking. > > Are you using two completely different scripts for reding and writing? > > There is some valuable info, if not about python, in the Serial > Programming howto, at: > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > Hugo > > nephish wrote: > > Hey there, > > i am developing on a linux computer with the serial module. Now, i > > already am able to recieve info from a serial RS232 device and process > > everything ok. What i need to do now is write to the serial device, but > > i also need to be able to not interrupt the script that is reading from > > it. > > I guess my question is, do i have to interrupt the reading script to > > write to the same RS232 device ? > > and if so, how do i do that? > > > > thanks, > > shawn > > > > ___ > > 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] Any TurboGears users out there?
* Alan Gauld <[EMAIL PROTECTED]> [051114 09:26]: > I just stumbled across TurboGears: > > http://www.macdevcenter.com/pub/a/mac/2005/11/08/turbogears.html > > Its based on CheryPy which consistently gets good reviews but adds SQL > access and XML templates. Sounds interesting, possibly even a Zope rival > for the medium sized as opposed to massive site.. > > Is anyone on the list using it? Or even looked at it? I have downloaded it, but have not yet done any testing. I'm interested in investigating AJAX features, which I believe it supports. I hope to do some testing in the next couple of days, time permitting. tj > Alan G > Author of the learn to program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Tim Johnson <[EMAIL PROTECTED]> http://www.alaska-internet-solutions.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TurboGears - and some issues
Dear Alan, I haven't used it, but I've looked through it, and it looks v. interesting. One of the things I like is that it glues lots of different bits together (I came across it while looking at SQLObject), and so benefits from their advances. I was a bit surprised that you hadn't come across it before, as in general you seem to be one of the core team on the list (in that you tend to answer rather than ask most questions). This got me thinking about how we stay up with different, and new, python projects. I tend to look at the Daily Python URL, as well as some Technorati and del.icio.us tagged sites/blogs. Where else do other people look? Matt ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TurboGears - and some issues
Matt Williams wrote: > This got me thinking about how we stay up with different, and new, > python projects. I tend to look at the Daily Python URL, as well as some > Technorati and del.icio.us tagged sites/blogs. Where else do other > people look? The main places I hear about new stuff are Planet Python Python Cookbook CheeseShop python-announce The first three have RSS feeds, the last is a mailing list. See my blogroll for URLs and a complete list of blogs I read: http://personalpages.tds.net/~kent37/blog/ and of course there's comp.lang.python if you have the time for it... Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Inheriting from parent object
> I want to create a property that will inherit it's value from the same > property in it's parent object, but will check it's parent's propety > everytime it is called. But that can be over-ridden, and I don't have > to know what the objects parent is. Ed you are using a lot of OOP terminology here to decribe something that looks decidedly non OOP. Can you clarify exactly what you mean by the terms: object, property, inherit and parent. Also can you describe the problem you are trying to solve rather than the solution you think you need? It may be that there is a simpler paradigm you can use. I'm not sure I really understand what you are trying to achieve. > object.x = 3 > object.subobject.x = inherit() > print object.subobject.x #prints 3 > object.x = 4 > print object.subobject.x #prints 4 > object.subobject.x = 5 > print object.subobject.x #prints 5 object it the built-in object class that provides new-style classes, is that theone you are using here? Or is it just a generic name for illustration? Is object an instance or a class? > What could I put in the inherit() function that would look for the > same property of it's parent and return that, whilst keeping it as > general as possible? I also don't understand what the inherit() function is supposed to do. You provide it with no context in which to operate. Unless it relies on hard coded global variables there is no way it can know about object, subobject or x. Normal OOP inheritance relies on creating instances from classes, but you don't appear to want to do that, it looks more like you are building some kind of containment lattice. I think I need more background. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: > Hey there, > i am developing on a linux computer with the serial module. Now, i > already am able to recieve info from a serial RS232 device and process > everything ok. What i need to do now is write to the serial device, > but i also need to be able to not interrupt the script that is reading > from it. > I guess my question is, do i have to interrupt the reading script to > write to the same RS232 device ? > and if so, how do i do that? > > thanks, > shawn > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ 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] Inheriting from parent object
if you want to copy object just use: import copy newobj = copy.deepcopy(objparent) or just create object which has direct correlation with the parent like: newobj = objparent Cheers, pujo On 11/14/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > I want to create a property that will inherit it's value from the same> property in it's parent object, but will check it's parent's propety > everytime it is called. But that can be over-ridden, and I don't have> to know what the objects parent is.Ed you are using a lot of OOP terminology here to decribesomething that looks decidedly non OOP. Can you clarify exactly what you mean by the terms: object, property, inherit and parent.Also can you describe the problem you are trying to solve rather thanthe solution you think you need? It may be that there is a simpler paradigm you can use. I'm not sure I really understand what youare trying to achieve.> object.x = 3> object.subobject.x = inherit()> print object.subobject.x #prints 3> object.x = 4 > print object.subobject.x #prints 4> object.subobject.x = 5> print object.subobject.x #prints 5object it the built-in object class that provides new-style classes,is that theone you are using here? Or is it just a generic name for illustration? Is object an instance or a class?> What could I put in the inherit() function that would look for the> same property of it's parent and return that, whilst keeping it as> general as possible? I also don't understand what the inherit() function is supposed to do.You provide it with no context in which to operate.Unless it relies on hard coded global variables there is noway it can know about object, subobject or x. Normal OOP inheritance relies on creating instances from classes,but you don't appear to want to do that, it looks more like youare building some kind of containment lattice. I think I need morebackground. Alan GAuthor of the learn to program web tutorhttp://www.freenetpages.co.uk/hp/alan.gauld___ 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] TurboGears - and some issues
Matt Williams wrote: > This got me thinking about how we stay up with different, and new, > python projects. I tend to look at the Daily Python URL, as well as some > Technorati and del.icio.us tagged sites/blogs. Where else do other > people look? One more - Dr Dobbs Python-URL (not the same as Daily Python URL). Subscribe here: http://www.ddj.com/topic/pythonurl/ Kent -- http://www.kentsjohnson.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 21, Issue 60
I have spent quite a bit of time looking at TurboGears. I have not used it in any production sense. Recently, there has developed a new TurboGears app which you may not have run across yet, but is very interesting in itself. It's called Catwalk. http://www.checkandshare.com/catwalk/download.html I have hacked it to give it access to other databases I have stored in MySQL and have started a generic version of it to display the MySQL database itself. Seems very cool. Steve > Message: 9 > Date: Mon, 14 Nov 2005 18:12:42 - > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: [Tutor] Any TurboGears users out there? > To: "Python Tutor list" > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > I just stumbled across TurboGears: > > http://www.macdevcenter.com/pub/a/mac/2005/11/08/turbogears.html > > Its based on CheryPy which consistently gets good reviews but adds SQL > access and XML templates. Sounds interesting, possibly even a Zope rival > for the medium sized as opposed to massive site.. > > Is anyone on the list using it? Or even looked at it? > > Alan G > Author of the learn to program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > -- > > Message: 11 > Date: Mon, 14 Nov 2005 13:37:36 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Any TurboGears users out there? > Cc: Python Tutor list > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Alan Gauld wrote: > > I just stumbled across TurboGears: > > > > http://www.macdevcenter.com/pub/a/mac/2005/11/08/turbogears.html > > > > Its based on CheryPy which consistently gets good reviews but adds SQL > > access and XML templates. Sounds interesting, possibly even a Zope rival > > for the medium sized as opposed to massive site.. > > > > Is anyone on the list using it? Or even looked at it? > > I have looked at it to the extent of getting through the tutorial and a > little more playing. It looks very promising to me. CherryPy, SQLObject and > mochikit all have good reputations and TG seems to do a good job of gluing > them together. Kid (the template engine) is not as mature as the others but > it seems to work OK. > > I used CherryPy 1 for a small work project. It was very easy to build the web > site. I found the built-in webserver lacking in some of the basics like a > usable request log but I think this has been fixed in CP 2. > > Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] tkFileDialog.Directory
On Mon, 14 Nov 2005 14:42:27 +0100 (MET) [EMAIL PROTECTED] wrote: > Hello! > I want to learn Tkinter and try to build a small File search dialog. Tkinter > is nice, but here is a problem where I am stuck: > > I want to allow the dialog's user to pick a directory. The widget for this > is tkFileDialog.Directory. But when I start the Directory-Window, it is > possible move the focus back to my File Search dialog. Thus it is possible > but not wanted to create several "Pick directory" windows. I tried to make > the Directory instance modal by calling .grab_set() but this raises an > attribute error. Here is a minimal example: > Hi Karsten, I guess the tkFileDialog.Directory class isn't intended to be used directly. Try tkFileDialog.askdirectory() instead. If there are problems with the grab state, try passing "parent=self.top" to askdirectory(). I hope this helps Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TurboGears - and some issues
TurboGears sounds pretty good. But, from the write up, TurboGears appears to be for MAC only. Or am I misreading the write up? Terry ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TurboGears - and some issues
> The main places I hear about new stuff are > Planet Python > Python Cookbook > python-announce I know of them but rarely look. > CheeseShop New one on me! > The first three have RSS feeds, But I didn't know that... > and of course there's comp.lang.python if you have the time for it... And there's the rub. If I'm not busy I try to scan c.l.p but mostly its just too busy. Nonetheless its my primary source of new stuff, its fairly easy to scroll down lookling for subjects beginning [Ann:] However I have to say I'm pretty conservative when it comes to Python addons. I don't use many and I only look for them when I have a specific need. I only found the TurboGears stuff because someone asked about MacOS resources and Apple were highlighting TG on the developer page... It caught my interest because I'm exploring JSP/Tomcat and Struts just now for my day job, so anything related to Web frameworks... Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: > Ive worked on a similar application. I used one thread to read from the > serial port and another one to handle the writes. > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González > Monteverde > Sent: Tuesday, 15 November 2005 7:36 a.m. > To: nephish > Cc: tutor > Subject: Re: [Tutor] question about serial coms > > Hi Nephish, > > Are you using pyserial or rolling your own? Normally you can write and read > to the /dev/ttySXX file at the same time; since they're special files, not > ordinary files, the driver handles that. > > Handling both writing and reading in your program's flow control is a wholly > different matter, though. You might need to use select() to avoid blocking. > > Are you using two completely different scripts for reding and writing? > > There is some valuable info, if not about python, in the Serial Programming > howto, at: > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > Hugo > > nephish wrote: > > Hey there, > > i am developing on a linux computer with the serial module. Now, i > > already am able to recieve info from a serial RS232 device and process > > everything ok. What i need to do now is write to the serial device, > > but i also need to be able to not interrupt the script that is reading > > from it. > > I guess my question is, do i have to interrupt the reading script to > > write to the same RS232 device ? > > and if so, how do i do that? > > > > thanks, > > shawn > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] new topic draft
I've just added an incomplete draft copy of my latest tutorial topic on using the Operating System from Python. The material that's there discusses the role of the OS and looks at file handling usng os/os.path/shutil etc. http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm If anyone would like to take a look and provide feedback on general direction/depth etc that'd be greatly appreciated. TIA, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
I believe that the drivers take care of that, however, I did use locks to make sure that there were no conflicts. In the listener thread I had something along the lines of: Acquire lock readline() from the ser port Release lock And in the sender thread, Acquire lock send msg over ser port Release lock Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 10:47 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: > Ive worked on a similar application. I used one thread to read from the > serial port and another one to handle the writes. > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Hugo González Monteverde > Sent: Tuesday, 15 November 2005 7:36 a.m. > To: nephish > Cc: tutor > Subject: Re: [Tutor] question about serial coms > > Hi Nephish, > > Are you using pyserial or rolling your own? Normally you can write and read > to the /dev/ttySXX file at the same time; since they're special files, not > ordinary files, the driver handles that. > > Handling both writing and reading in your program's flow control is a wholly > different matter, though. You might need to use select() to avoid blocking. > > Are you using two completely different scripts for reding and writing? > > There is some valuable info, if not about python, in the Serial Programming > howto, at: > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > Hugo > > nephish wrote: > > Hey there, > > i am developing on a linux computer with the serial module. Now, i > > already am able to recieve info from a serial RS232 device and > > process everything ok. What i need to do now is write to the serial > > device, but i also need to be able to not interrupt the script that > > is reading from it. > > I guess my question is, do i have to interrupt the reading script > > to write to the same RS232 device ? > > and if so, how do i do that? > > > > thanks, > > shawn > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > ___ > 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] TurboGears - and some issues
"Terry Kemmerer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > TurboGears sounds pretty good. But, from the write up, TurboGears > appears to be for MAC only. > Or am I misreading the write up? The writeup I posted was Mac focused but the project itself is multi platform. The downloads page has links to Windows, Mac and Linux/Unix versions. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] new topic draft
> -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of Alan Gauld > > > I've just added an incomplete draft copy of my latest tutorial topic > on using the Operating System from Python. The material that's > there discusses the role of the OS and looks at file handling > usng os/os.path/shutil etc. > > http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm > > If anyone would like to take a look and provide feedback on > general direction/depth etc that'd be greatly appreciated. Thanks for that Alan. I always seem to get myself into difficulty with the os.walk routine, but you explained it brilliantly there. Have to admit, I couldn't be bothered to read the "So What is the Operating System" bit tho cos as you say on the page, we don't need to know it. Now if we were C programmers maybe .. :) Thanks again, Nick . ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
ok, lock is something you wrote yourself ? i can't find it in the docs. However, i think i can essentially build the same thing. the serial module i use is pyserial. pyserial.sourceforge.net. the docs are a wee bit on the sparce side. But i think i can pull it off. Thanks for your help. shawn On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: > I believe that the drivers take care of that, however, I did use locks to > make sure that there were no conflicts. > > In the listener thread I had something along the lines of: > > Acquire lock > readline() from the ser port > Release lock > > And in the sender thread, > > Acquire lock > send msg over ser port > Release lock > > Cheers > Hans > > -Original Message- > From: nephish [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 15 November 2005 10:47 a.m. > To: Hans Dushanthakumar > Cc: Hugo González Monteverde; tutor > Subject: RE: [Tutor] question about serial coms > > well thats encouraging, did you have to do anything special to prevent an > error when trying to read or write at the same time ? > > thanks > sk > > > On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: > > Ive worked on a similar application. I used one thread to read from the > > serial port and another one to handle the writes. > > > > -Original Message- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > > Behalf Of Hugo González Monteverde > > Sent: Tuesday, 15 November 2005 7:36 a.m. > > To: nephish > > Cc: tutor > > Subject: Re: [Tutor] question about serial coms > > > > Hi Nephish, > > > > Are you using pyserial or rolling your own? Normally you can write and read > > to the /dev/ttySXX file at the same time; since they're special files, not > > ordinary files, the driver handles that. > > > > Handling both writing and reading in your program's flow control is a > > wholly different matter, though. You might need to use select() to avoid > > blocking. > > > > Are you using two completely different scripts for reding and writing? > > > > There is some valuable info, if not about python, in the Serial Programming > > howto, at: > > > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > > > > Hugo > > > > nephish wrote: > > > Hey there, > > > i am developing on a linux computer with the serial module. Now, i > > > already am able to recieve info from a serial RS232 device and > > > process everything ok. What i need to do now is write to the serial > > > device, but i also need to be able to not interrupt the script that > > > is reading from it. > > > I guess my question is, do i have to interrupt the reading script > > > to write to the same RS232 device ? > > > and if so, how do i do that? > > > > > > thanks, > > > shawn > > > > > > ___ > > > Tutor maillist - Tutor@python.org > > > http://mail.python.org/mailman/listinfo/tutor > > > > > ___ > > 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] question about serial coms
Lock() is provided by the threading module. see http://docs.python.org/lib/module-threading.html & http://docs.python.org/lib/lock-objects.html Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 11:23 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms ok, lock is something you wrote yourself ? i can't find it in the docs. However, i think i can essentially build the same thing. the serial module i use is pyserial. pyserial.sourceforge.net. the docs are a wee bit on the sparce side. But i think i can pull it off. Thanks for your help. shawn On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: > I believe that the drivers take care of that, however, I did use locks to > make sure that there were no conflicts. > > In the listener thread I had something along the lines of: > > Acquire lock > readline() from the ser port > Release lock > > And in the sender thread, > > Acquire lock > send msg over ser port > Release lock > > Cheers > Hans > > -Original Message- > From: nephish [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 15 November 2005 10:47 a.m. > To: Hans Dushanthakumar > Cc: Hugo González Monteverde; tutor > Subject: RE: [Tutor] question about serial coms > > well thats encouraging, did you have to do anything special to prevent an > error when trying to read or write at the same time ? > > thanks > sk > > > On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: > > Ive worked on a similar application. I used one thread to read from the > > serial port and another one to handle the writes. > > > > -Original Message- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > > Behalf Of Hugo González Monteverde > > Sent: Tuesday, 15 November 2005 7:36 a.m. > > To: nephish > > Cc: tutor > > Subject: Re: [Tutor] question about serial coms > > > > Hi Nephish, > > > > Are you using pyserial or rolling your own? Normally you can write and read > > to the /dev/ttySXX file at the same time; since they're special files, not > > ordinary files, the driver handles that. > > > > Handling both writing and reading in your program's flow control is a > > wholly different matter, though. You might need to use select() to avoid > > blocking. > > > > Are you using two completely different scripts for reding and writing? > > > > There is some valuable info, if not about python, in the Serial Programming > > howto, at: > > > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > > > > Hugo > > > > nephish wrote: > > > Hey there, > > > i am developing on a linux computer with the serial module. Now, > > > i already am able to recieve info from a serial RS232 device and > > > process everything ok. What i need to do now is write to the > > > serial device, but i also need to be able to not interrupt the > > > script that is reading from it. > > > I guess my question is, do i have to interrupt the reading script > > > to write to the same RS232 device ? > > > and if so, how do i do that? > > > > > > thanks, > > > shawn > > > > > > ___ > > > Tutor maillist - Tutor@python.org > > > http://mail.python.org/mailman/listinfo/tutor > > > > > ___ > > 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] TurboGears - and some issues
Alan Gauld wrote: >> CheeseShop > > New one on me! CheeseShop is formerly known as PyPI, the Python Package Index. It's a central repository for Python add-ons. http://www.python.org/pypi > If I'm not busy I try to scan c.l.p but mostly its > just too busy. Nonetheless its my primary source of new stuff, its > fairly easy to scroll down lookling for subjects beginning [Ann:] If that's all you want from c.l.p it's easier to subscribe to python-announce and the cheeseshop feed. > > However I have to say I'm pretty conservative when it comes to Python > addons. I don't use many and I only look for them when I have a specific > need. Maybe we should start a thread of favorite addons. For me, Jason Orendorff's path module is definitely #1 on the list, probably followed by Fredrik Lundh's ElementTree. http://www.jorendorff.com/articles/python/path/ http://effbot.org/zone/element-index.htm > I only found the TurboGears stuff because someone asked about > MacOS resources and Apple were highlighting TG on the developer page... > It caught my interest because I'm exploring JSP/Tomcat and Struts just > now for my day job, so anything related to Web frameworks... You have my deepest sympathy :-) Maybe you could use TurboGears instead. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Another Quick Question - Thanks again
Thanks to all those who responded to my plea regarding how to make my laptop’s bell ring with the print “\a” command. The secret turned out to be, as a couple of you suggested, that it won’t work in the Python window environment. It works fine if I just double click the .py file in Windows Explorer or use the “Run” command. You live and learn. Thanks again. Steve ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to convert between type string and token
hello all when i run the code : # -*- coding: cp1256 -*-from nltk.tagger import *from nltk.corpus import brownfrom nltk.tokenizer import WhitespaceTokenizer # Tokenize ten texts from the Brown Corpustrain_tokens = []xx=Token(TEXT=open('fataha2.txt').read())WhitespaceTokenizer().tokenize(xx)for l in xx: train_tokens.append(l)#Initialise and train a unigram taggermytagger = UnigramTagger(SUBTOKENS='WORDS')for tok in train_tokens: mytagger.train(tok)#Once a UnigramTagger has been trained, the tag() method can be used to tag new text: text_token = Token(TEXT="ÇáÍãÏ ááå ÑÈ ÇáÚÇáãíä")WhitespaceTokenizer(SUBTOKENS='WORDS').tokenize(text_token)mytagger.tag(text_token)print 'The first example : Using Unigram Tagger the reseults are : 'print acc = tagger_accuracy(mytagger, train_tokens)print ' With Accuracy :Accuracy = %4.1f%%,' % (100 * acc) i got the following error : Traceback (most recent call last): File "F:\MSC first Chapters\unigramgtag1.py", line 14, in -toplevel- for tok in train_tokens: mytagger.train(tok) File "C:\Python24\Lib\site-packages\nltk\tagger\__init__.py", line 324, in train assert chktype(1, tagged_token, Token) File "C:\Python24\Lib\site-packages\nltk\chktype.py", line 316, in chktype raise TypeError(errstr)TypeError: Argument 1 to train() must have type: Token (got a str) please i want a help on how to recover this error , in other words how can i convert between type string and token , as im still new in python thanks in advance Yahoo! FareChase - Search multiple travel sites in one click. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Do I have to initialize TKInter before I can use it?
Hey all, Do I have to initialize TKInter before I can use it, and if so, how would I go about doing that? Thanks, Nathan Pinno ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
ok, i think i got it. Thanks so much. let you know how it turns out. shawn On Tue, 2005-11-15 at 11:27 +1300, Hans Dushanthakumar wrote: > Lock() is provided by the threading module. > see > http://docs.python.org/lib/module-threading.html > & > http://docs.python.org/lib/lock-objects.html > > Cheers > Hans > > > -Original Message- > From: nephish [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 15 November 2005 11:23 a.m. > To: Hans Dushanthakumar > Cc: Hugo González Monteverde; tutor > Subject: RE: [Tutor] question about serial coms > > ok, lock is something you wrote yourself ? > i can't find it in the docs. However, i think i can essentially build the > same thing. > the serial module i use is pyserial. pyserial.sourceforge.net. > the docs are a wee bit on the sparce side. But i think i can pull it off. > Thanks for your help. > > shawn > > > On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: > > I believe that the drivers take care of that, however, I did use locks to > > make sure that there were no conflicts. > > > > In the listener thread I had something along the lines of: > > > > Acquire lock > > readline() from the ser port > > Release lock > > > > And in the sender thread, > > > > Acquire lock > > send msg over ser port > > Release lock > > > > Cheers > > Hans > > > > -Original Message- > > From: nephish [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, 15 November 2005 10:47 a.m. > > To: Hans Dushanthakumar > > Cc: Hugo González Monteverde; tutor > > Subject: RE: [Tutor] question about serial coms > > > > well thats encouraging, did you have to do anything special to prevent an > > error when trying to read or write at the same time ? > > > > thanks > > sk > > > > > > On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: > > > Ive worked on a similar application. I used one thread to read from the > > > serial port and another one to handle the writes. > > > > > > -Original Message- > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > > > Behalf Of Hugo González Monteverde > > > Sent: Tuesday, 15 November 2005 7:36 a.m. > > > To: nephish > > > Cc: tutor > > > Subject: Re: [Tutor] question about serial coms > > > > > > Hi Nephish, > > > > > > Are you using pyserial or rolling your own? Normally you can write and > > > read to the /dev/ttySXX file at the same time; since they're special > > > files, not ordinary files, the driver handles that. > > > > > > Handling both writing and reading in your program's flow control is a > > > wholly different matter, though. You might need to use select() to > > > avoid blocking. > > > > > > Are you using two completely different scripts for reding and writing? > > > > > > There is some valuable info, if not about python, in the Serial > > > Programming howto, at: > > > > > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > > > > > > > Hugo > > > > > > nephish wrote: > > > > Hey there, > > > > i am developing on a linux computer with the serial module. > > > > Now, > > > > i already am able to recieve info from a serial RS232 device and > > > > process everything ok. What i need to do now is write to the > > > > serial device, but i also need to be able to not interrupt the > > > > script that is reading from it. > > > > I guess my question is, do i have to interrupt the reading > > > > script > > > > to write to the same RS232 device ? > > > > and if so, how do i do that? > > > > > > > > thanks, > > > > shawn > > > > > > > > ___ > > > > Tutor maillist - Tutor@python.org > > > > http://mail.python.org/mailman/listinfo/tutor > > > > > > > ___ > > > 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] Do I have to initialize TKInter before I can use it?
On 15/11/05, Nathan Pinno <[EMAIL PROTECTED]> wrote: > > Hey all, > > Do I have to initialize TKInter before I can use it, and if so, how would I > go about doing that? Generally, you need to create a Tkinter.Tk object before you create any other Tkinter objects. Are you having problems? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Converting a List/Tuple to delimited string
Dear John, Thanks for your explanation. It is quite amazing, I had completely misunderstood what the join function was all about. An example in "Learning Python" which was something like "".join(L) , had led me to think it was a string concatenation function that extended the length of a string. Even when reading the manual my prejudice had interpreted the following as still being just that. My subconscious had skipped over the second sentence. "join(seq) Return a string which is the concatenation of the strings in the sequence seq. The separator between elements is the string providing this method. " Fortunately my new Python instinct suggested what I was doing was not quite right, and thank you for correcting my misunderstanding. This Tutor service is an invaluable help for us lonely new to Python programmers. Thanks, Roy PS Despite this glitch I would still recommend Learning Python. Message: 5 Date: Mon, 14 Nov 2005 17:11:16 +1300 From: John Fouhy <[EMAIL PROTECTED]> Subject: Re: [Tutor] Converting a List/Tuple to delimited string To: Tutor Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1 On 14/11/05, Roy Bleasdale <[EMAIL PROTECTED]> wrote: > I have a list of strings and wanted to output them as a single delimited > string. > > Eg > > ('ab','cd','ef') becomes "ab:cd:ef" You almost had it ... What about: >>> lst = ['ab', 'cd', 'ef'] >>> ':'.join(lst) 'ab:cd:ef' In general, foo.join(lst) (where foo is a string) is equivalent to: def join(foo, lst): if not lst: return '' s = lst[0] for item in lst[1:]: s += foo + item return s -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How do you read this mailing list ?!?
It's a little confusing for me, are there some special programs for reading mailing lists or you use just basic mail client ? __ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Do I have to initialize TKInter before I can use it?
Nathan Pinno wrote: > Hey all, > > Do I have to initialize TKInter before I can use it, and if so, how > would I go about doing that? > > Thanks, > Nathan Pinno Btw, your question would be a little more user-friendly if you don't post HTML, and don't post embedded images as well! (Not everyone has an email reader that renders HTML and graphics. And for those people, your email looks like a dogs dinner!) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to convert between type string and token
On Mon, 14 Nov 2005, enas khalil wrote: > hello all [program cut] Hi Enas, You may want to try talking with NTLK folks about this, as what you're dealing with is a specialized subject. Also, have you gone through the tokenization tutorial in: http://nltk.sourceforge.net/tutorial/tokenization/nochunks.html#AEN276 and have you tried to compare your program to the ones in the tutorial's examples? Let's look at the error message. > File "F:\MSC first Chapters\unigramgtag1.py", line 14, in -toplevel- > for tok in train_tokens: mytagger.train(tok) > File "C:\Python24\Lib\site-packages\nltk\tagger\__init__.py", line 324, in > train > assert chktype(1, tagged_token, Token) > File "C:\Python24\Lib\site-packages\nltk\chktype.py", line 316, in chktype > raise TypeError(errstr) > TypeError: > Argument 1 to train() must have type: Token > (got a str) This error message implies that each element in your train_tokens list is a string and not a token. The 'train_tokens' variable gets its values in the block of code: ### train_tokens = [] xx=Token(TEXT=open('fataha2.txt').read()) WhitespaceTokenizer().tokenize(xx) for l in xx: train_tokens.append(l) ### Ok. I see something suspicious here. The for loop: ## for l in xx: train_tokens.append(l) ## assumes that we get tokens from the 'xx' token. Is this true? Are you sure you don't have to specifically say: ## for l in xx['SUBTOKENS']: ... ## The example in the tutorial explicitely does something like this to iterate across the subtokens of a token. But what you're doing instead is to iterate across all the property names of a token, which is almost certainly not what you want. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to convert between type string and token
> Ok. I see something suspicious here. The for loop: > > ## > for l in xx: > train_tokens.append(l) > ## > > assumes that we get tokens from the 'xx' token. Is this true? Are you > sure you don't have to specifically say: > > ## > for l in xx['SUBTOKENS']: > ... > ## Hi Enas, I'm taking python-list again out of CC: my apologies to the others for not catching that sooner. Enas, please do not crosspost to multiple mailing lists. You have been doing this since at least June: http://mail.python.org/pipermail/python-list/2005-June/287371.html http://mail.python.org/pipermail/tutor/2005-June/039351.html http://mail.python.org/pipermail/tutor/2005-July/039642.html http://mail.python.org/pipermail/python-list/2005-July/289505.html http://mail.python.org/pipermail/tutor/2005-October/042155.html http://mail.python.org/pipermail/python-list/2005-October/303805.html If you crosspost, we at Tutor won't be able to see responses that go to python-list, and visa-versa. The end result clutters both lists and isn't friendly to either community. Please read: http://www.gweep.ca/~edmonds/usenet/ml-etiquette.html and try to change your habits in this area. Anyway, just as a concrete example of this: ## >>> from nltk.tokenizer import * >>> text_token = Token(TEXT='hello world this is a test') >>> text_token.keys() ['TEXT'] >>> WhitespaceTokenizer().tokenize(text_token) >>> text_token.keys() ['TEXT', 'SUBTOKENS'] >>> text_token['SUBTOKENS'] [, , , , , ] >>> type(text_token['SUBTOKENS'][0]) ## Do you understand this code, or is there something here that you're not familar with? Good luck to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
I have been working with pyserial. One question I have is this. I have a loop that writes to the serial port and then waits about 500ms and then reads from the serial port. The first thing read from the serial port is ALWAYS the data written to the serial port... I must be missing something obvious, but I thuoght the two buffers were separate... Here is the code I'm using if that helps: while i == 0: line = parmfile.readline() line = string.rstrip(line) #print line if line == "": i = 1 break else: ser.write(line + "\r") #ser.write("\r\n") print "Sending: " + line time.sleep(1) data_in = ser.read(100) print "Response: " + data_in time.sleep(.2) print "Closing Serial Port\n" ser.close() -Joe --- nephish <[EMAIL PROTECTED]> wrote: > ok, i think i got it. Thanks so much. > let you know how it turns out. > shawn > > > On Tue, 2005-11-15 at 11:27 +1300, Hans > Dushanthakumar wrote: > > Lock() is provided by the threading module. > > see > > http://docs.python.org/lib/module-threading.html > > & > > http://docs.python.org/lib/lock-objects.html > > > > Cheers > > Hans > > > > > > -Original Message- > > From: nephish [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, 15 November 2005 11:23 a.m. > > To: Hans Dushanthakumar > > Cc: Hugo González Monteverde; tutor > > Subject: RE: [Tutor] question about serial coms > > > > ok, lock is something you wrote yourself ? > > i can't find it in the docs. However, i think i > can essentially build the same thing. > > the serial module i use is pyserial. > pyserial.sourceforge.net. > > the docs are a wee bit on the sparce side. But i > think i can pull it off. Thanks for your help. > > > > shawn > > > > > > On Tue, 2005-11-15 at 10:58 +1300, Hans > Dushanthakumar wrote: > > > I believe that the drivers take care of that, > however, I did use locks to make sure that there > were no conflicts. > > > > > > In the listener thread I had something along the > lines of: > > > > > > Acquire lock > > > readline() from the ser port > > > Release lock > > > > > > And in the sender thread, > > > > > > Acquire lock > > > send msg over ser port > > > Release lock > > > > > > Cheers > > > Hans > > > > > > -Original Message- > > > From: nephish [mailto:[EMAIL PROTECTED] > > > Sent: Tuesday, 15 November 2005 10:47 a.m. > > > To: Hans Dushanthakumar > > > Cc: Hugo González Monteverde; tutor > > > Subject: RE: [Tutor] question about serial coms > > > > > > well thats encouraging, did you have to do > anything special to prevent an error when trying to > read or write at the same time ? > > > > > > thanks > > > sk > > > > > > > > > On Tue, 2005-11-15 at 09:29 +1300, Hans > Dushanthakumar wrote: > > > > Ive worked on a similar application. I used > one thread to read from the serial port and another > one to handle the writes. > > > > > > > > -Original Message- > > > > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > > > > Behalf Of Hugo González Monteverde > > > > Sent: Tuesday, 15 November 2005 7:36 a.m. > > > > To: nephish > > > > Cc: tutor > > > > Subject: Re: [Tutor] question about serial > coms > > > > > > > > Hi Nephish, > > > > > > > > Are you using pyserial or rolling your own? > Normally you can write and read to the /dev/ttySXX > file at the same time; since they're special files, > not ordinary files, the driver handles that. > > > > > > > > Handling both writing and reading in your > program's flow control is a wholly different matter, > though. You might need to use select() to avoid > blocking. > > > > > > > > Are you using two completely different scripts > for reding and writing? > > > > > > > > There is some valuable info, if not about > python, in the Serial Programming howto, at: > > > > > > > > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > > > > > > > > > > Hugo > > > > > > > > nephish wrote: > > > > > Hey there, > > > > > i am developing on a linux computer with > the serial module. Now, > > > > > i already am able to recieve info from a > serial RS232 device and > > > > > process everything ok. What i need to do now > is write to the > > > > > serial device, but i also need to be able to > not interrupt the > > > > > script that is reading from it. > > > > > I guess my question is, do i have to > interrupt the reading script > > > > > to write to the same RS232 device ? > > > > > and if so, how do i do that? > > > > > > > > > > thanks, > > > > > shawn > > > > > > > > > > > ___ > > > > > Tutor maillist - Tutor@python.org > > > > > > http://mail.python.org/mailman/listinfo/tutor > > > > > > > > > > ___ > > > > Tutor maillist - Tutor@python.org > > > > http://mail.python.org/mailman/listinfo/tutor > > > > > > > ___ > Tutor maillist -
Re: [Tutor] question about serial coms
oh yeah, i will need this too! sk On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe wrote: > I have been working with pyserial. One question I have > is this. I have a loop that writes to the serial port > and then waits about 500ms and then reads from the > serial port. The first thing read from the serial port > is ALWAYS the data written to the serial port... I > must be missing something obvious, but I thuoght the > two buffers were separate... > > Here is the code I'm using if that helps: > > while i == 0: > line = parmfile.readline() > line = string.rstrip(line) > #print line > if line == "": > i = 1 > break > > else: > > ser.write(line + "\r") > #ser.write("\r\n") > print "Sending: " + line > > > > time.sleep(1) > data_in = ser.read(100) > print "Response: " + data_in > time.sleep(.2) > > > print "Closing Serial Port\n" > ser.close() > > > > -Joe > > > --- nephish <[EMAIL PROTECTED]> wrote: > > > ok, i think i got it. Thanks so much. > > let you know how it turns out. > > shawn > > > > > > On Tue, 2005-11-15 at 11:27 +1300, Hans > > Dushanthakumar wrote: > > > Lock() is provided by the threading module. > > > see > > > http://docs.python.org/lib/module-threading.html > > > & > > > http://docs.python.org/lib/lock-objects.html > > > > > > Cheers > > > Hans > > > > > > > > > -Original Message- > > > From: nephish [mailto:[EMAIL PROTECTED] > > > Sent: Tuesday, 15 November 2005 11:23 a.m. > > > To: Hans Dushanthakumar > > > Cc: Hugo González Monteverde; tutor > > > Subject: RE: [Tutor] question about serial coms > > > > > > ok, lock is something you wrote yourself ? > > > i can't find it in the docs. However, i think i > > can essentially build the same thing. > > > the serial module i use is pyserial. > > pyserial.sourceforge.net. > > > the docs are a wee bit on the sparce side. But i > > think i can pull it off. Thanks for your help. > > > > > > shawn > > > > > > > > > On Tue, 2005-11-15 at 10:58 +1300, Hans > > Dushanthakumar wrote: > > > > I believe that the drivers take care of that, > > however, I did use locks to make sure that there > > were no conflicts. > > > > > > > > In the listener thread I had something along the > > lines of: > > > > > > > > Acquire lock > > > > readline() from the ser port > > > > Release lock > > > > > > > > And in the sender thread, > > > > > > > > Acquire lock > > > > send msg over ser port > > > > Release lock > > > > > > > > Cheers > > > > Hans > > > > > > > > -Original Message- > > > > From: nephish [mailto:[EMAIL PROTECTED] > > > > Sent: Tuesday, 15 November 2005 10:47 a.m. > > > > To: Hans Dushanthakumar > > > > Cc: Hugo González Monteverde; tutor > > > > Subject: RE: [Tutor] question about serial coms > > > > > > > > well thats encouraging, did you have to do > > anything special to prevent an error when trying to > > read or write at the same time ? > > > > > > > > thanks > > > > sk > > > > > > > > > > > > On Tue, 2005-11-15 at 09:29 +1300, Hans > > Dushanthakumar wrote: > > > > > Ive worked on a similar application. I used > > one thread to read from the serial port and another > > one to handle the writes. > > > > > > > > > > -Original Message- > > > > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On > > > > > Behalf Of Hugo González Monteverde > > > > > Sent: Tuesday, 15 November 2005 7:36 a.m. > > > > > To: nephish > > > > > Cc: tutor > > > > > Subject: Re: [Tutor] question about serial > > coms > > > > > > > > > > Hi Nephish, > > > > > > > > > > Are you using pyserial or rolling your own? > > Normally you can write and read to the /dev/ttySXX > > file at the same time; since they're special files, > > not ordinary files, the driver handles that. > > > > > > > > > > Handling both writing and reading in your > > program's flow control is a wholly different matter, > > though. You might need to use select() to avoid > > blocking. > > > > > > > > > > Are you using two completely different scripts > > for reding and writing? > > > > > > > > > > There is some valuable info, if not about > > python, in the Serial Programming howto, at: > > > > > > > > > > > > http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ > > > > > > > > > > > > > > > Hugo > > > > > > > > > > nephish wrote: > > > > > > Hey there, > > > > > > i am developing on a linux computer with > > the serial module. Now, > > > > > > i already am able to recieve info from a > > serial RS232 device and > > > > > > process everything ok. What i need to do now > > is write to the > > > > > > serial device, but i also need to be able to > > not interrupt the > > > > > > script that is reading from it. > > > > > > I guess my question is, do i have to > > interrupt the reading script > > > > > > to write to the same RS232 device ? > > > > > > and if so, how do i do that? > > > > > > > > > > > > thanks, > > > > > > shawn > >
Re: [Tutor] question about serial coms
Just to make sure that I understood it right, Does this snippet mimic the problem that you have? Ive hardcoded "line". x= import serial import time ser=serial.Serial(0,57600,timeout=0.1) i=0 line = ["Hi","There","Hans"] while i <= (len(line)-1): ser.write(line[i] + "\r") print "Sending: " + line[i] time.sleep(1) data_in = ser.read(100) print "Response: " + data_in time.sleep(.2) i = i + 1 print "Closing Serial Port\n" ser.close() =x= Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 2:10 p.m. To: [EMAIL PROTECTED] Cc: Hans Dushanthakumar; tutor Subject: Re: [Tutor] question about serial coms oh yeah, i will need this too! sk On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe wrote: > I have been working with pyserial. One question I have is this. I have > a loop that writes to the serial port and then waits about 500ms and > then reads from the serial port. The first thing read from the serial > port is ALWAYS the data written to the serial port... I must be > missing something obvious, but I thuoght the two buffers were > separate... > > Here is the code I'm using if that helps: > > while i == 0: > line = parmfile.readline() > line = string.rstrip(line) > #print line > if line == "": > i = 1 > break > > else: > > ser.write(line + "\r") > #ser.write("\r\n") > print "Sending: " + line > > > > time.sleep(1) > data_in = ser.read(100) > print "Response: " + data_in > time.sleep(.2) > > > print "Closing Serial Port\n" > ser.close() > > > > -Joe > > > --- nephish <[EMAIL PROTECTED]> wrote: > > > ok, i think i got it. Thanks so much. > > let you know how it turns out. > > shawn > > > > > > On Tue, 2005-11-15 at 11:27 +1300, Hans Dushanthakumar wrote: > > > Lock() is provided by the threading module. > > > see > > > http://docs.python.org/lib/module-threading.html > > > & > > > http://docs.python.org/lib/lock-objects.html > > > > > > Cheers > > > Hans > > > > > > > > > -Original Message- > > > From: nephish [mailto:[EMAIL PROTECTED] > > > Sent: Tuesday, 15 November 2005 11:23 a.m. > > > To: Hans Dushanthakumar > > > Cc: Hugo González Monteverde; tutor > > > Subject: RE: [Tutor] question about serial coms > > > > > > ok, lock is something you wrote yourself ? > > > i can't find it in the docs. However, i think i > > can essentially build the same thing. > > > the serial module i use is pyserial. > > pyserial.sourceforge.net. > > > the docs are a wee bit on the sparce side. But i > > think i can pull it off. Thanks for your help. > > > > > > shawn > > > > > > > > > On Tue, 2005-11-15 at 10:58 +1300, Hans > > Dushanthakumar wrote: > > > > I believe that the drivers take care of that, > > however, I did use locks to make sure that there were no conflicts. > > > > > > > > In the listener thread I had something along the > > lines of: > > > > > > > > Acquire lock > > > > readline() from the ser port > > > > Release lock > > > > > > > > And in the sender thread, > > > > > > > > Acquire lock > > > > send msg over ser port > > > > Release lock > > > > > > > > Cheers > > > > Hans > > > > > > > > -Original Message- > > > > From: nephish [mailto:[EMAIL PROTECTED] > > > > Sent: Tuesday, 15 November 2005 10:47 a.m. > > > > To: Hans Dushanthakumar > > > > Cc: Hugo González Monteverde; tutor > > > > Subject: RE: [Tutor] question about serial coms > > > > > > > > well thats encouraging, did you have to do > > anything special to prevent an error when trying to read or write at > > the same time ? > > > > > > > > thanks > > > > sk > > > > > > > > > > > > On Tue, 2005-11-15 at 09:29 +1300, Hans > > Dushanthakumar wrote: > > > > > Ive worked on a similar application. I used > > one thread to read from the serial port and another one to handle > > the writes. > > > > > > > > > > -Original Message- > > > > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On > > > > > Behalf Of Hugo González Monteverde > > > > > Sent: Tuesday, 15 November 2005 7:36 a.m. > > > > > To: nephish > > > > > Cc: tutor > > > > > Subject: Re: [Tutor] question about serial > > coms > > > > > > > > > > Hi Nephish, > > > > > > > > > > Are you using pyserial or rolling your own? > > Normally you can write and read to the /dev/ttySXX file at the same > > time; since they're special files, not ordinary files, the driver > > handles that. > > > > > > > > > > Handling both writing and reading in your > > program's flow control is a wholly different matter, though. You > > might need to use select() to avoid blocking. > > > > > > > > > > Are you using two completely different scripts > > for reding and writing? > > > > > > > > > > There is some valuable info, if not about > > python, in the Serial Programming howto, at: > > > > > > > > > > > >
Re: [Tutor] Do I have to initialize TKInter before I can use it?
John and all, I am having problems. The latest error message I got was: Traceback (most recent call last): File "D:\Python24\hockey.py", line 19, in -toplevel- tkMessageBox.showinfo("Hockey",NameError: name 'tkMessageBox' is not defined What do I have to do in this case? Nathan Pinno Date: Tue, 15 Nov 2005 12:41:57 +1300From: John Fouhy <[EMAIL PROTECTED]>Subject: Re: [Tutor] Do I have to initialize TKInter before I can useit?To: TutorMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1On 15/11/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:>> Hey all,>> Do I have to initialize TKInter before I can use it, and if so, how would I> go about doing that?Generally, you need to create a Tkinter.Tk object before you createany other Tkinter objects.Are you having problems?--John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does Python gain by having immutable types?
> Quite often the only answer is "just because". Some features are > the way they are because that's Guido's pesonal preference. Others > may disagree with him but it's his language and he gets to pick > what he thinks is best - the benign dictator syndrome. There's also the issue that immutability is Python's way of dealing with "passing by value" and "passing by reference". And that removing the difference between mutable and immutable objects would mutate (no pun intended) the language in a big way. Hugo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Do I have to initialize TKInter before I can use it?
On 15/11/05, Nathan Pinno <[EMAIL PROTECTED]> wrote: > > > John and all, > > I am having problems. The latest error message I got was: > Traceback (most recent call last): > File "D:\Python24\hockey.py", line 19, in -toplevel- > tkMessageBox.showinfo("Hockey", > NameError: name 'tkMessageBox' is not defined > > What do I have to do in this case? This means python doesn't know what a 'tkMessageBox' is. Names get bound to things in python in one of two main ways: 1. You bind the name yourself, usually by using an assignment statement. eg: >>> x Traceback (most recent call last): File "", line 1, in ? NameError: name 'x' is not defined >>> x = 3 >>> x 3 2. An import statement brings the name in. eg: >>> math Traceback (most recent call last): File "", line 1, in ? NameError: name 'math' is not defined >>> import math >>> math You can also use 'from ... import' to import specific names. >>> sin Traceback (most recent call last): File "", line 1, in ? NameError: name 'sin' is not defined >>> from math import sin >>> sin In your case, you probably want to bring tkMessageBox in using an import statement. I'm guessing you have done 'from Tkinter import *'. You can figure out what names that brings in by using dir: >>> import Tkinter >>> dir(Tkinter) ['ACTIVE', 'ALL', 'ANCHOR', 'ARC', 'At', 'AtEnd', 'AtInsert', 'AtSelFirst', 'AtSelLast', 'BASELINE', 'BEVEL', 'BOTH', 'BOTTOM', 'BROWSE', 'BUTT', 'BaseWidget', # etc If you look through that list, you will see that tkMessageBox is not there, which means that it is not part of the Tkinter module. Where did you find out about tkMessageBox? Have you looked at any documentation? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does Python gain by having immutable types?
> > Quite often the only answer is "just because". Some features are the > > way they are because that's Guido's pesonal preference. Others may > > disagree with him but it's his language and he gets to pick what he > > thinks is best - the benign dictator syndrome. Hi Hugo, There are a few languages that have immutable values. For example, C and Java both define string literals to be immutable: trying to mutate them causes an error. (Well, C is supposed to raise a segmentation fault.) There are strong advantages to immutability: one of the main ones is that side-effect-less programming is less prone to certain kinds of bugs. For example, let's say we wanted a function to squish values together: ## >>> def squish(A, B): ... """Creates a new list containing the elements of A and B""" ... result = [] ... result.extend(A) ... result.extend(B) ... return result ... >>> squish(range(5), range(7, 9)) [0, 1, 2, 3, 4, 7, 8] ## An alternative way to write this might be: ## >>> def smash(A, B): ... """Creates a new list containing the elements of A and B. ...Smashes the existing list A.""" ... A.extend(B) ... return A ... >>> smash(range(5), range(7, 9)) [0, 1, 2, 3, 4, 7, 8] ## These both appear to have the same behavior but of course we know that something must be different between the two. *grin* If we have two lists, like: ## >>> firstNames = ['hugo', 'keanu'] >>> lastNames = ['weaving', 'reeves'] ## we can squish() them together: ## >>> squish(firstNames, lastNames) ['hugo', 'keanu', 'weaving', 'reeves'] >>> >>> firstNames ['hugo', 'keanu'] >>> lastNames ['weaving', 'reeves'] ## ... or we can smash() them: ## >>> smash(firstNames, lastNames) ['hugo', 'keanu', 'weaving', 'reeves'] >>> >>> firstNames ['hugo', 'keanu', 'weaving', 'reeves'] >>> lastNames ['weaving', 'reeves'] ## Oh! Notice that smash() messes with the list named by firstNames; when we finish calling it, we see a side effect: firstNames is smashed. The issue here is that we've let ourselves mutate our input values. Of course this is an exaggerated example, but it tries to make a point: having mutable values means we have to think about mutation. Mutation introduces a kind of "leakage" between functions. To make the situation more extreme: if we are working with someone else's code, and if we pass a mutable value to that external code, then if we see a bug later on in our own program, we may have to wonder if the external code mutated our values. That can be a big pain. (C programmers have to worry about this ALL THE TIME because they have pointers that let anyone smash up everything. *grin*) If we guarantee, though, that we are working with immutable values, we can toss them with abandon at anyone and know that they won't get munged. That's why immutability is an important concept in a programming language, and an especially useful one in a collaborative language like Python. Does this make sense? If you have more questions, please feel free to ask. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does Python gain by having immutable types?
Hugo González Monteverde wrote: >>Quite often the only answer is "just because". Some features are >>the way they are because that's Guido's pesonal preference. Others >>may disagree with him but it's his language and he gets to pick >>what he thinks is best - the benign dictator syndrome. >> >> > >There's also the issue that immutability is Python's way of dealing with > "passing by value" and "passing by reference". And that removing the >difference between mutable and immutable objects would mutate (no pun >intended) the language in a big way. > >Hugo >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > I've also heard the argument that, in the case where you want to be able to hash a sequence, you need an immutable sequence type. Otherwise, when you do something like: >>> dicta = {} >>> tupb = (1,2) >>> tupc = (1,2) >>> dicta[tupb] = "34" >>> tupb.append(3) # raises an AttributeError b/c tuples are immutable and don't have append functions >>> dicta[tupb] = "45" Would you expect dicta[tupb] to produce "34" or "45"? And what of dicta[tupc]? I believe this issue is one of whether to hash by identity or content. When hashing, the implied promise is that all objects whose contents are the same should produce the same value, but one also expects one key to map to one value. Without immutable types, where the identity and the content are intertwined, you get counterintuitive behavior a la the above mini-example (in reality, when you put two immutable objects with the same content in a dictionary, they both map to the same value - the last one assigned). I'm sure someone more knowledgeable will come along and shed the bright light of understanding where my feeble candle flickers, but till then, HTH. -Orri -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How do I display a changing thing in text?
How do I display a changing thing (i.e.. the score of the game) in text? I think it has something to do with this key: %, but I forget how to do it. Can someone show me how to do it again? Thanks, Nathan Pinno ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I display a changing thing in text?
Hi Nathan, Take a look at string interpolation in the tutorial. I don't know what method you're following for learning Python, but I've found the 'official' tutorial a great resource, even when you already know Python, http://docs.python.org/tut/node9.html#SECTION00910 Nathan Pinno wrote: > How do I display a changing thing (i.e.. the score of the game) in text? > I think it has something to do with this key: %, but I forget how to do > it. Can someone show me how to do it again? > > Thanks, > Nathan Pinno > > > > > ___ > 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] question about serial coms
I think so, what I'm doing is opening a text file, reading line 1 and writing that text to the serial port. Then read line 2 and so on... So it mimics a string rather than a list or dictionary. But I would think this would give you a similiar result. I can try it to confirm. Here is the entire code: import serial import string import time parmfile = open('command_1.txt') ser = serial.Serial('/dev/ttyS1', 9600, timeout=1) ser.setRTS(1) ser.setDTR(1) i = 0 while i == 0: line = parmfile.readline() line = string.rstrip(line) #print line if line == "": i = 1 break else: ser.write(line + "\r") #ser.write("\r\n") print "Sending: " + line time.sleep(1) data_in = ser.read(100) print "Response: " + data_in time.sleep(.2) print "Closing Serial Port\n" ser.close() The 'command_1.txt' file is literally a text file with lines of text like such: command1 on command2 off command3 %4 command5 on etc -Joe --- Hans Dushanthakumar <[EMAIL PROTECTED]> wrote: > Just to make sure that I understood it right, > > Does this snippet mimic the problem that you have? > Ive hardcoded "line". > > x= > import serial > import time > ser=serial.Serial(0,57600,timeout=0.1) > i=0 > line = ["Hi","There","Hans"] > while i <= (len(line)-1): > > ser.write(line[i] + "\r") > print "Sending: " + line[i] > time.sleep(1) > data_in = ser.read(100) > print "Response: " + data_in > time.sleep(.2) > i = i + 1 > > print "Closing Serial Port\n" > ser.close() > =x= > > Cheers > Hans ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Do I have to initialize TKInter before I can use it?
Hi Nathan, It is always better if you include what you're actually trying to do. I see you included one traceback error, but I see no reference to what you're coding or any of your code. In your case , it's likely that you did not import the tkMessageDialog module or something like this. But we had to find that out after two more posts, because neither your code example or error messages were in the original. Please, please read: http://www.catb.org/~esr/faqs/smart-questions.html Keep hacking away :) Hugo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Do I have to initialize TKInter before I can use it?
John, I learned it from the docs on pythonware.com - the introduction to TKInter - Standard Dialogs. Since it doesn't exist, how can I show a info box before the main part of my program? Nathan Date: Tue, 15 Nov 2005 14:54:15 +1300 From: John Fouhy <[EMAIL PROTECTED]> Subject: Re: [Tutor] Do I have to initialize TKInter before I can use it? To: Tutor Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1 On 15/11/05, Nathan Pinno <[EMAIL PROTECTED]> wrote: > > > John and all, > > I am having problems. The latest error message I got was: > Traceback (most recent call last): > File "D:\Python24\hockey.py", line 19, in -toplevel- > tkMessageBox.showinfo("Hockey", > NameError: name 'tkMessageBox' is not defined > > What do I have to do in this case? This means python doesn't know what a 'tkMessageBox' is. Names get bound to things in python in one of two main ways: 1. You bind the name yourself, usually by using an assignment statement. eg: >>> x Traceback (most recent call last): File "", line 1, in ? NameError: name 'x' is not defined >>> x = 3 >>> x 3 2. An import statement brings the name in. eg: >>> math Traceback (most recent call last): File "", line 1, in ? NameError: name 'math' is not defined >>> import math >>> math You can also use 'from ... import' to import specific names. >>> sin Traceback (most recent call last): File "", line 1, in ? NameError: name 'sin' is not defined >>> from math import sin >>> sin In your case, you probably want to bring tkMessageBox in using an import statement. I'm guessing you have done 'from Tkinter import *'. You can figure out what names that brings in by using dir: >>> import Tkinter >>> dir(Tkinter) ['ACTIVE', 'ALL', 'ANCHOR', 'ARC', 'At', 'AtEnd', 'AtInsert', 'AtSelFirst', 'AtSelLast', 'BASELINE', 'BEVEL', 'BOTH', 'BOTTOM', 'BROWSE', 'BUTT', 'BaseWidget', # etc If you look through that list, you will see that tkMessageBox is not there, which means that it is not part of the Tkinter module. Where did you find out about tkMessageBox? Have you looked at any documentation? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] saving project
If you do File... Save Then select the location for your file and just give it a name, a '.py' extension will be added to the file. It is not in a specific format, it is just a text file with a '.py' extension. From Explorer you will likely see just the name of the file. And after you save you'll see the coloring on your program, which helps you avoid programming mistakes. I'm assuming you're using Windows and not Linux. Hugo sener wrote: > hi everyone, > > Firstly I am a new programmer on python. I am using Python 2.4.1 > with IDLE 1.1.1 > I can't save my poject in my computer. how can I save my projects and > in which format I must save my projects. > > thanks a lot. > ___ > 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] Do I have to initialize TKInter before I can use it?
On 15/11/05, Nathan Pinno <[EMAIL PROTECTED]> wrote: > John, > > I learned it from the docs on pythonware.com - the introduction to TKInter - > Standard Dialogs. > Since it doesn't exist, how can I show a info box before the main part of my > program? Ok, let's see what the pythonware docs say: http://www.pythonware.com/library/tkinter/introduction/standard-dialogs.htm """ Message Boxes The tkMessageBox module provides an interface to the message dialogs. """ This says that tkMessageBox is a module. How do you normally use modules? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does Python gain by having immutable types?
I believe the deal is that it is impossible (or at least extremely inefficient)to keep track of any places where a mutable object was hashed at the time of mutating it, so that ALL hashes can be updated. When the object is immutable, it implies that the hash will not change unless the id changes. Hugo > Would you expect dicta[tupb] to produce "34" or "45"? And what of > dicta[tupc]? I believe this issue is one of whether to hash by identity > or content. When hashing, the implied promise is that all objects whose > contents are the same should produce the same value, but one also > expects one key to map to one value. Without immutable types, where the > identity and the content are intertwined, you get counterintuitive > behavior a la the above mini-example (in reality, when you put two > immutable objects with the same content in a dictionary, they both map > to the same value - the last one assigned). I'm sure someone more > knowledgeable will come along and shed the bright light of understanding > where my feeble candle flickers, but till then, HTH. > > -Orri > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I display a changing thing in text?
Hugo and all, So in order to write what I wanted the correct code would be: "Computer = %1.0d Player = %1.0d" (a,b) Am I correct or is this wrong? Nathan Pinno -Original Message- From: Hugo González Monteverde [mailto:[EMAIL PROTECTED] Sent: November 14, 2005 8:27 PM To: Nathan Pinno Cc: Tutor mailing list Subject: Re: [Tutor] How do I display a changing thing in text? Hi Nathan, Take a look at string interpolation in the tutorial. I don't know what method you're following for learning Python, but I've found the 'official' tutorial a great resource, even when you already know Python, http://docs.python.org/tut/node9.html#SECTION00910 Nathan Pinno wrote: > How do I display a changing thing (i.e.. the score of the game) in text? > I think it has something to do with this key: %, but I forget how to > do it. Can someone show me how to do it again? > > Thanks, > Nathan Pinno > > > -- > -- > > ___ > 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] Do I have to initialize TKInter before I can use it?
Hi Nathan, The interactive interpreter is your friend. I just displayed a simple dialog without creating a Tkinter App, complete with a mailoop or anything. But I won't tell you how... you need to import the module and then use one of its functions. But you need to try it yourself (be aware that this module only gives you basic dialogs, like a text message ona little window with an 'Accept' button...) Remember that you can use the dir() function and the help() function on the interactive interpreter. Hugo Nathan Pinno wrote: > John, > > I learned it from the docs on pythonware.com - the introduction to TKInter - > Standard Dialogs. > Since it doesn't exist, how can I show a info box before the main part of my > program? > \ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I display a changing thing in text?
The interactive intepreter is you friend. Of course I'm using actual numbers instead of variables for the examples. Let's see IDLE 1.0.3 >>> "Computer = %1.0d Player = %1.0d" (1,2) Traceback (most recent call last): File "", line 1, in -toplevel- "Computer = %1.0d Player = %1.0d" (1,2) TypeError: 'str' object is not callable H what is the problem? >>> "Computer = %1.0d Player = %1.0d"%(1,2) 'Computer = 1 Player = 2' >>> Here you go. You were missing the % sign after the string, with in this case is the operator... Hugo Nathan Pinno wrote: > Hugo and all, > So in order to write what I wanted the correct code would be: > "Computer = %1.0d Player = %1.0d" (a,b) > > Am I correct or is this wrong? > > Nathan Pinno > > -Original Message- > From: Hugo González Monteverde [mailto:[EMAIL PROTECTED] > Sent: November 14, 2005 8:27 PM > To: Nathan Pinno > Cc: Tutor mailing list > Subject: Re: [Tutor] How do I display a changing thing in text? > > Hi Nathan, > > Take a look at string interpolation in the tutorial. I don't know what > method you're following for learning Python, but I've found the 'official' > tutorial a great resource, even when you already know Python, > > http://docs.python.org/tut/node9.html#SECTION00910 > > Nathan Pinno wrote: > >>How do I display a changing thing (i.e.. the score of the game) in text? >>I think it has something to do with this key: %, but I forget how to >>do it. Can someone show me how to do it again? >> >>Thanks, >>Nathan Pinno >> >> >>-- >>-- >> >>___ >>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] Do I have to initialize TKInter before I can use it?
> Do I have to initialize TKInter before I can use it, and if so, how would > I > go about doing that? Yes, by calling Tk() Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do you read this mailing list ?!?
> It's a little confusing for me, are there some special > programs for reading mailing lists or you use just > basic mail client ? Interesting question! The list comes in many flavours. The most basic form you just subscribe and it sends you emails which you read using your normal email client. Then you can set up digest delivery - which I use - where the list sends you the messages in bunches as a single email. YOu still use the basic client to read them but uyou have to open the digest message then open the inner messages from there. The list is also available as an archive on the web at both ActiveState and on the Python.org web sites. YOu can use a browser to read it there. And lastly gane make it available as a news feed (and web site) which you can access via any newsreader -I tend to use this when away from my PC. So your simple question has maby answers, choose whichever one you like! :-) Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Do I have to initialize TKInter before I can use it?
Nathan, > I am having problems. The latest error message I got was: >tkMessageBox.showinfo("Hockey", > NameError: name 'tkMessageBox' is not defined A NameError means Python doesn't recognise the name. Usually that's because either you didn't declare the variable or you forgot to import the module or you spelled it wrong. In this case I'd guess you forgot the import? Python error messages are really quite helpful if you just stop and think about what they are saying for a few minutes. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do I display a changing thing in text?
> How do I display a changing thing (i.e.. the score of the game) in text? I > think it has something to do with this key: %, but I forget how to do it. > Can someone show me how to do it again? Take a look at the Simple Sequences page on my tutor for examples of using the % format string operatrion. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Do I have to initialize TKInter before I can use it?
Alan and all, I imported it, but its not there. I tried using the Message one found in it, but I got an error message: >>> import Tkinter >>> tk = Tkinter.Tk() >>> Tkinter.Message("Help","Help!") Traceback (most recent call last): File "", line 1, in -toplevel- Tkinter.Message("Help","Help!") File "D:\Python24\lib\lib-tk\Tkinter.py", line 2640, in __init__ Widget.__init__(self, master, 'message', cnf, kw) File "D:\Python24\lib\lib-tk\Tkinter.py", line 1862, in __init__ BaseWidget._setup(self, master, cnf) File "D:\Python24\lib\lib-tk\Tkinter.py", line 1840, in _setup self.tk = master.tk AttributeError: 'str' object has no attribute 'tk' What does this mean, and how can I get it working? Nathan -Original Message- From: Alan Gauld [mailto:[EMAIL PROTECTED] Sent: November 14, 2005 9:35 PM To: Nathan Pinno; Tutor Mailing List Subject: Re: [Tutor] Do I have to initialize TKInter before I can use it? Nathan, > I am having problems. The latest error message I got was: >tkMessageBox.showinfo("Hockey", > NameError: name 'tkMessageBox' is not defined A NameError means Python doesn't recognise the name. Usually that's because either you didn't declare the variable or you forgot to import the module or you spelled it wrong. In this case I'd guess you forgot the import? Python error messages are really quite helpful if you just stop and think about what they are saying for a few minutes. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Favourite modules - Wiki Was Re: TurboGears - and some issues
Kent Johnson wrote: >Maybe we should start a thread of favorite addons. For me, Jason Orendorff's >path module is definitely #1 on the list, probably followed by Fredrik Lundh's >ElementTree. >http://www.jorendorff.com/articles/python/path/ >http://effbot.org/zone/element-index.htm > > A wonderful idea! I have created a wiki page in Python.org with a list of such 'favourite' modules. Please take a look: http://wiki.python.org/moin/UsefulModules I put some of the modules I could remember being praised here. I hope I didn't miss any (well, save for web frameworks, I haven't been paying much attention) I hope I haven't made a mess, it was my first edit into python's wiki. I wasn't sure where to stick it, so I added it under DevelopmentTools. I hope the page helps somebody! (Today I'm "hopey" :) Bye, Ismael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to learn to read error messages and generalize from examples [Was Re: Do I have to initialize TKInter before I can use it?]
On Mon, 14 Nov 2005, Nathan Pinno wrote: > Alan and all, > > I imported it, but its not there. I tried using the Message one found in it, > but I got an error message: > >>> import Tkinter > >>> tk = Tkinter.Tk() > >>> Tkinter.Message("Help","Help!") Hi Nathan, According to the traceback: > Traceback (most recent call last): > File "", line 1, in -toplevel- > Tkinter.Message("Help","Help!") > File "D:\Python24\lib\lib-tk\Tkinter.py", line 2640, in __init__ > Widget.__init__(self, master, 'message', cnf, kw) > File "D:\Python24\lib\lib-tk\Tkinter.py", line 1862, in __init__ > BaseWidget._setup(self, master, cnf) > File "D:\Python24\lib\lib-tk\Tkinter.py", line 1840, in _setup > self.tk = master.tk > AttributeError: 'str' object has no attribute 'tk' our program gets stuck on the line: Tkinter.Message("Help","Help!") If we assume that the rest of the traceback comes from the internals of Tkinter, and that those parts are fine, let's start off by assuming that there might be something on our own program's line that causes the bug. Our assumption might be wrong, but let's see how far this goes --- we have to start somewhere. What is that call to Tkinter.Message()? It's a call to make a Message widget. What arguments do we need to pass when we make such a thing? If we don't know this offhand --- and that's fine; that's what references are for --- then we can look at an example, like the one at: http://www.pythonware.com/library/tkinter/introduction/x59-details.htm The tutorial example makes a Label widget: from Tkinter import * root = Tk() w = Label(root, text="Hello, world!") We see that a Label widget needs the root window object as well as whatever configuration options we pass to customize that Label widget. Going back to our buggy code: Tkinter.Message("Help","Help!") can we think of what you might do to make this similar to the example in the tutorial? Where's the root object? What option are we trying to customize? Labels and Messages are similar enough that we can make analogies from the tutorial example to our program. You may find the detail pages for Labels and Messages useful: http://www.pythonware.com/library/tkinter/introduction/x5258-options.htm http://www.pythonware.com/library/tkinter/introduction/x6315-options.htm Good luck to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for suggestions - update
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Today (Nov 14, 2005) at 6:10am, Kent Johnson spoke these wise words: - ->A couple of notes after a quick look: - -> - ->- As you note, def check_valid_jump(sel1, sel2) is really ugly. When I have code like this I look for a way to drive it from a table instead of a bunch of if/elif statements full of magic numbers. In this case it looks like you have one condition for each state. The conditions and results could be put in a list whose index is the state and whose values are the test values for sel1 and sel2. You would have a table that looks like this: - ->jump_table = [ - -> (1, 1, 4, 2),# (state # sel1 and sel2 values to check for state, return value) - -> (2, 1, 6, 3), - -> # etc for all the tests Thanks for the reply Kent and others. I've made some changes and the game is quite playable now. I've put the new version online at the same links if anyone wants to take a look. I agree with what someone else posted about earlier. This list is a great resource and is really appreciated. Cheers, - -- Terry "Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind." -- Dr. Seuss -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.7 (GNU/Linux) iD8DBQFDeXe6QvSnsfFzkV0RAlPEAJ4kPDDjXZZZyl0TJqbY5NCoReYlYACeKGW7 su+ZjZQeOyaFBvh67d6i6eU= =+qXo -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor