Re: [Tutor] Problems with List Server?
It arrived. Since you appear to be the only one reporting the problem, perhaps it's something on your end? Remco Gerlich On Dec 3, 2007 11:51 PM, Tim Johnson [EMAIL PROTECTED] wrote: On Monday 03 December 2007, Tim Johnson wrote: I appear to be having a weird problem with the List Server. At first, email sent to this address did not appear at all. After contacting the ML maintainers only one email from me to this address go through. When I replied to the thread which the email started, it was not delivered. This is a very frustrating turn of events and I am hoping that it will be corrected soon. I wonder if anyone else is having similar problems? I suspect that this email will be delivered, but I might not be able to send another on the same thread. Any ideas? tim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor If this is not delivered to the ML, then the problem persists. thanks Tim ___ 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] Best way of learning
On Dec 5, 2007 11:43 PM, andy [EMAIL PROTECTED] wrote: So, after this long-winded introduction, I was hoping to pick the wisdom of this list to get some pointers of what to do/not to do to make the most effective use of the few hours I have to learn how to program using Python. So, any advice for someone in their mid-40s who would like to learn Python in a more methodical and effective manner? In my opinion, the best way to learn _anything_ is to try to do it, and then look around for tips every now and then in the mean time. You'll connect much more easily with the information when it's something you've recently struggled with. And practice is the most important part of any learning anyway. So, what do you want to do with Python? Any other hobbies you can connect it with? Perhaps ideas for a dynamic web site or something? In my experience, learning something just for abstract knowledge can be fun for a while, but it's hard to stay committed. And there's nothing wrong with that, there's only so many hours in a day, and the things you actually use in life should probably take precedence :-) So if you've written small tools, feel like expanding them? Used modules in them that you don't entirely understand yet, perhaps dive into their docs? Perhaps the Python Challenge ( http://www.pythonchallenge.com/ ) is something for you? It's at least sideways a little into the hacking spirit, it's fun, and it's a tour of what Python can do - but you'll have to find the way yourself :-) Remco Gerlich ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Selecting a browser
Ricardo Aráoz wrote: I've registered in the issue tracker, but got scared and didn't post anything. Don't be scared: just post up what you think is wrong as clearly as possible. If you can reasonably provide a patch, do so. Otherwise, just make it clear what's going on. Even if no-one picks it up, at least you've done what you should have. (Sometimes these things wait years until someone comes along who has the time, knowledge and inclination to fix it!). If you do post, I'll take a look and make sure it makes sense. (If I have time, I'll provide a patch but I may not be able to). TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mail? What's that?
Luke Paireepinart wrote: Ricardo Aráoz wrote: So I eventually got to sending mail with python. Some articles, trying and google led me to this script: import smtplib import time date = time.ctime(time.time( )) From = '[EMAIL PROTECTED]' To = ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]'] Subj = 'Hi' text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n\n' % (From, ';'.join(To), date, Subj)) s = smtplib.SMTP('smtp.gmail.com') s.set_debuglevel(1) s.ehlo() s.starttls() s.ehlo() s.login('foo', 'bar') s.sendmail(From, To, text) s.close() So, if there's someone who really knows this stuff in the neighborhood I'd like to ask a couple of questions. What is ehlo and why do I have to call it twice? And set_debuglevel? If I where to connect through other smtp server the sequence would be the exactly the same, say yahoo or hotmail? Are From: To: Date: and Subject: mandatory in the contents of the email(text)? Do I have to put real address in From when calling sendmail()? And in the contents? Ok, if someone can answer these I'll be grateful. TIA Ricardo Ricardo - I say this in the nicest way possible, but did you RTFM? :) LOL, my apologies Luke. You see, I was bloody tired last night, had just found out how to do it and didn´t have it in me to google for it or RTFM, so I said let's ask the guys. Sorry, and thanks a lot for taking the time to answer me. I'm just rushing out to work so I'll take a look tonight and see if I get it, I'm net impaired you see, and when they start with all those acronyms my brain stops :-) Thanks again. Ricardo Python has built-in help support on modules. You should start there, do some Googling, and if you're stumped, get some help. Not for any other reason than it'll probably get you 1) more experience at navigating the docs, and 2) a quicker, probably more detailed response. So using Help, we get: import smtplib help(smtplib) Help on module smtplib: NAME smtplib - SMTP/ESMTP client class. FILE c:\python24\lib\smtplib.py [snip 10 pages of documentation] help(smtplib.SMTP.set_debuglevel) Help on method set_debuglevel in module smtplib: set_debuglevel(self, debuglevel) unbound smtplib.SMTP method Set the debug output level. A non-false value results in debug messages for connection and for all messages sent to and received from the server. help(smtplib.SMTP.ehlo) Help on method ehlo in module smtplib: ehlo(self, name='') unbound smtplib.SMTP method SMTP 'ehlo' command. Hostname to send for this command defaults to the FQDN of the local host. help(smtplib.SMTP.sendmail) Help on method sendmail in module smtplib: sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]) unbound smtplib.SMTP method This command performs an entire mail transaction. The arguments are: - from_addr: The address sending this mail. - to_addrs : A list of addresses to send this mail to. A bare string will be treated as a list with 1 address. - msg : The message to send. - mail_options : List of ESMTP options (such as 8bitmime) for the mail command. - rcpt_options : List of ESMTP options (such as DSN commands) for all the rcpt commands. If there has been no previous EHLO or HELO command this session, this method tries ESMTP EHLO first. If the server does ESMTP, message size and each of the specified options will be passed to it. If EHLO fails, HELO will be tried and ESMTP options suppressed. This method will return normally if the mail is accepted for at least one recipient. It returns a dictionary, with one entry for each recipient that was refused. Each entry contains a tuple of the SMTP error code and the accompanying error message sent by the server. This method may raise the following exceptions: SMTPHeloError The server didn't reply properly to the helo greeting. SMTPRecipientsRefused The server rejected ALL recipients (no mail was sent). SMTPSenderRefused The server didn't accept the from_addr. SMTPDataError The server replied with an unexpected error code (other than a refusal of a recipient). Note: the connection will be open even after an exception is raised. Example: import smtplib s=smtplib.SMTP(localhost) tolist=[[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]] msg = '''\ ... From: [EMAIL PROTECTED] ... Subject: testin'... ... ... This is a test ''' s.sendmail([EMAIL PROTECTED],tolist,msg) { [EMAIL PROTECTED] : ( 550 ,User unknown ) } s.quit() In the above example, the message was accepted for
[Tutor] How to iterate and update subseqent items in list
Can you suggest a good way to iterate through the remainder of list and update them? Ex: Thing1.value = 0 Thing2.value = 1 Thing3.value = 0 Thing4.value = 0 Things = [Thing1, Thing2, Thing3, Thing4] I want to iterate through 'Things' and if 'Thing.value' 0, then I want to set all values for that and the subsequent 'Things' in the list to 2 So that i'd end up with Thing1.value = 0 Thing2.value = 2 Thing3.value = 2 Thing4.value = 2 Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] While Loops and Modules
Greetings, On Dec 6, 2007 12:44 AM, earlylight publishing [EMAIL PROTECTED] wrote: Hello again to all the wonderfully helpful folks on this list. Today I did my Google homework and I found this neat bit of code for a countdown timer. import time import threading class Timer(threading.Thread): def __init__(self, seconds): self.runTime = seconds threading.Thread.__init__(self) def run(self): time.sleep(self.runTime) print Buzzz!!! Time's up! t = Timer(30) t.start() I don't understand large chunks of it (don't know what threading, self, or __init__ mean) but that's not important at the moment. It works and I will learn the vocab eventually. That is a good start! Get it working first, then figure it out later. 8^D I also wrote this bit of code for a math challenge which comes in the next part of my game. import random startNum = random.choice(range(1, 9)) newNum = startNum + 7 score = 0 print 'Start with the number ', startNum, '. Then continuously add 7 to that number until the timer runs out. You have 30 seconds.' answer = int(raw_input('Enter your answer: ')) if newNum == answer: print 'That is correct! Keep going.' score = score + 5 print 'Your score is ', score else: print 'That is incorrect. Please try again.' I understand this part just fine 'cause I actually wrote it myself. A couple of things which may help you when you're testing/debugging your programs: type(object) dir(object) Play with those in the interactive interpreter to see what they do, for example: a = 7 type(a) type 'int' a = time type(a) type 'str' import random dir(random) ['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCONST', 'SystemRandom', 'TWOPI', 'WichmannHill', '_BuiltinMethodType', '_MethodType', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_acos', '_cos', '_e', '_exp', '_hexlify', '_inst', '_log', '_pi', '_random', '_sin', '_sqrt', '_test', '_test_generator', '_urandom', '_warn', 'betavariate', 'choice', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'jumpahead', 'lognormvariate', 'normalvariate', 'paretovariate', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle', 'uniform', 'vonmisesvariate', 'weibullvariate'] etc. Another little trick I use to watch the values of variables and set breakpoints: print variable_Name raw_input(Pause) I just insert those two lines after each variable I want to watch (perhaps to see if it is actually doing what I think it is supposed to be doing?). What I need to do now is put these two parts together so that the player will keep adding 7 to the starting number for 30 seconds then the loop breaks. I know I need a loop of some sort and I'm guessing it's a 'while' sort of thing. I couldn't find what I was looking for when I Googled. I'm not even sure I knew the right search terms. Does anyone know how I'd combine these two modules to make it work? while True: or while 1: do the same thing, and they are a generic infinite loop. You can use the keyword break somewhere inside the loop to break out of it. When you figure out what condition must be met to quit the while loop, you can replace the True or 1 with your condition. For example, working with the snippet you supplied: import random import time import threading class Timer(threading.Thread): def __init__(self, seconds): self.runTime = seconds threading.Thread.__init__(self) def run(self): time.sleep(self.runTime) print Buzzz!!! Time's up! t = Timer(30) startNum = random.choice(range(1, 9)) newNum = startNum + 7 score = 0 t.start() print 'Start with the number ', startNum, '. Then continuously add 7 to that number until the timer runs out. You have 30 seconds.' while 1: answer = int(raw_input('Enter your answer: ')) if newNum == answer: print 'That is correct! Keep going.' score = score + 5 print 'Your score is ', score newNum += 7 else: print 'That is incorrect. Please try again.' That isn't quite working as it should, but I only added a couple of lines and did the requisite indentation for the while loop. It might be enough to keep you going for a wee bit? Happy Programming! -- b h a a l u u at g m a i l dot c o m ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Loops and modules
, and the things you actually use in life should probably take precedence :-) So if you've written small tools, feel like expanding them? Used modules in them that you don't entirely understand yet, perhaps dive into their docs? Perhaps the Python Challenge ( http://www.pythonchallenge.com/ ) is something for you? It's at least sideways a little into the hacking spirit, it's fun, and it's a tour of what Python can do - but you'll have to find the way yourself :-) Remco Gerlich -- next part -- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20071206/8eafc022/attachment.htm -- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor End of Tutor Digest, Vol 46, Issue 15 * ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to iterate and update subseqent items in list
Hi, In this case, I'd go for the simple old fashioned for loop with a boolean: found = False for thing in Things: if thing.value 0: found = True if found: thing.value = 2 Remco Gerlich On Dec 6, 2007 9:48 AM, ted b [EMAIL PROTECTED] wrote: Can you suggest a good way to iterate through the remainder of list and update them? Ex: Thing1.value = 0 Thing2.value = 1 Thing3.value = 0 Thing4.value = 0 Things = [Thing1, Thing2, Thing3, Thing4] I want to iterate through 'Things' and if 'Thing.value' 0, then I want to set all values for that and the subsequent 'Things' in the list to 2 So that i'd end up with Thing1.value = 0 Thing2.value = 2 Thing3.value = 2 Thing4.value = 2 Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ___ 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] Loops and modules
On Dec 6, 2007 8:38 AM, richard west [EMAIL PROTECTED] wrote: heres a partial solution. theres no error checking on the Raw Input and you have to type in you last number and press return, before the loop will break, but its a start! And modifying your modifications makes it work even a little better: ### #!/usr/bin/python import random import time import threading class Timer(threading.Thread): def __init__(self, seconds): self.runTime = seconds threading.Thread.__init__(self) def run(self): global running time.sleep(self.runTime) print print Buzzz!!! Time's up! running = False t = Timer(30) t.start() startNum = random.choice(range(1, 9)) newNum = startNum + 7 score = 0 running = True print 'Start with the number ', startNum, '. Then continuously add 7 to that number until the timer runs out. You have 30 seconds.' while running: if running == True: answer = int(raw_input('Enter your answer: ')) if answer == newNum: print 'That is correct! Keep going.' score = score + 5 newNum = newNum + 7 print 'Your score is ', score else: print 'That is incorrect. Please try again.' else: answer = 0 print ' ' print 'Your total score was: ', score ### Happy Programming! -- b h a a l u u at g m a i l dot c o m #!/usr/bin/python # Filename : math_test.py import time import threading class Timer(threading.Thread): def __init__(self, seconds): self.runTime = seconds threading.Thread.__init__(self) def run(self): global running time.sleep(self.runTime) print print Buzzz!!! Time's up! running = False t = Timer(30) t.start() import random startNum = random.choice(range(1, 9)) newNum = startNum + 7 # im assuming you want the first number the user to type as the startnum +7,its not too clear. score = 0 running = True print 'Start with the number ', startNum, '. Then continuously add 7 to that number until the timer runs out. You have 30 seconds.' while running: print running answer = int(raw_input('Enter your answer: ')) if running == True: if answer == newNum: print 'That is correct! Keep going.' score = score + 5 newNum = newNum+7 print 'Your score is ', score else: print 'That is incorrect. Please try again.' print ' ' print 'you total score was ', score On Dec 6, 2007 6:15 PM, [EMAIL PROTECTED] wrote: Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Tutor digest... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with List Server?
On Thursday 06 December 2007, you wrote: It arrived. Since you appear to be the only one reporting the problem, perhaps it's something on your end? It was the domain hoster. It has now been corrected. thanks tim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Mail? What's that?
Ricardo Aráoz wrote: Are From: To: Date: and Subject: mandatory in the contents of the email(text)? Do I have to put real address in From when calling sendmail()? And in the contents? Here's the page I used to learn on this subject. http://www.thinkspot.net/sheila/article.php?story=20040822174141155 I'm definitely not a pro in this area, so what comes next are merely assumptions made after toying around a bit. I don't believe the From, To, Date, Subject are required, but if you play around sending some test messages to yourself, you'll see that excluding them makes the message look very suspicious. As far as using your real address, that might depend on your email server...but yes, you can most likely spoof other addresses. Please use this for good, not evil. -Justin Cardinal ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Questions about wxEvents
I have a specific question - how can I generalize a FileBrowseButtonWithHistory - and I realized, as I was trying to word my question, that my real question is a bit more generic. First, the specific question: The FileBrowseButtonWithHistory requires a callback override and some custom code to straighten out handling the history. So far, so good. However, I wish to use more than one FBBWH on my form, and I can't figure out how to re-use the custom callback so it will work for both controls. (It makes me sick to my stomach when I look at my code and see duplicate blocks!) Don't get me wrong - it's working right now, it's just that my code is fugly and I want to clean it up. In more general terms, how can I set more than one control to use the same block of code as a custom callback, and figure out at runtime which control I'm responding to? Doesn't the Event or CommandEvent carry any information about itself? I've tried this: [snip] self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='*.*', fileMode=wx.OPEN, dialogTitle='Select the file containing UCF claims', changeCallback=self.fp1Callback) self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='FI*.*', fileMode=wx.OPEN, dialogTitle='Select the form-image file - generally starts with FI', changeCallback=self.fp2Callback) [snip] def fp1Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] def fp2Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] All I get from print evt.__dict__ is: {'_string': u'E:\\ultrahld\\report\\FILE'} and all I get from help is: Help on instance of LocalEvent in module wx.lib.filebrowsebuttonobject:class instance(object) | instance(class[, dict]) | | Create an instance without calling its __init__() method. | The class must be a classic class. | If present, dict must be a dictionary or None. | | Methods defined here: | | __abs__(...) | x.__abs__() == abs(x) | ... in other words, I might as well have typed help(object). I only know that the method evt.GetString() exists because the example in the demo uses it. I've Googled, and Gmaned, and read the wx docs (such as they are), but I'm not seeing anything I can use. I know that this is a wxPython question, and that this is the Python list... but y'all have answered some wx questions in the past, and I hate to join another list for one question. If I must, I will... but thanks in advance for any light you can shed. -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Questions about wxEvents
While I can't help you with the wx specific part of the question, I can offer help with the reuse question. Here is one approach. Add an controller identifier to fpCallback. Then use lambda expressions for the actual callback, where the lambda expressions pass in a fixed value for the identifier. Modified code: self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='*.*', fileMode=wx.OPEN, dialogTitle='Select the file containing UCF claims', changeCallback= lambda x: self.fpCallback('fp1', x) ) self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='FI*.*', fileMode=wx.OPEN, dialogTitle='Select the form-image file - generally starts with FI', changeCallback= lambda x: self.fpCallback('fp2', x) ) [snip] def fpCallback(self, controlID, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] - Jeff Younker - [EMAIL PROTECTED] - On Dec 6, 2007, at 9:12 AM, Marc Tompkins wrote: I have a specific question - how can I generalize a FileBrowseButtonWithHistory - and I realized, as I was trying to word my question, that my real question is a bit more generic. First, the specific question: The FileBrowseButtonWithHistory requires a callback override and some custom code to straighten out handling the history. So far, so good. However, I wish to use more than one FBBWH on my form, and I can't figure out how to re-use the custom callback so it will work for both controls. (It makes me sick to my stomach when I look at my code and see duplicate blocks!) Don't get me wrong - it's working right now, it's just that my code is fugly and I want to clean it up. In more general terms, how can I set more than one control to use the same block of code as a custom callback, and figure out at runtime which control I'm responding to? Doesn't the Event or CommandEvent carry any information about itself? I've tried this: [snip] self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='*.*', fileMode=wx.OPEN, dialogTitle='Select the file containing UCF claims', changeCallback= self.fp1Callback) self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='FI*.*', fileMode=wx.OPEN, dialogTitle='Select the form-image file - generally starts with FI', changeCallback= self.fp2Callback) [snip] def fp1Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] def fp2Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] All I get from print evt.__dict__ is: {'_string': u'E:\\ultrahld\ \report\\FILE'} and all I get from help is: Help on instance of LocalEvent in module wx.lib.filebrowsebutton object:class instance(object) | instance(class[, dict]) | | Create an instance without calling its __init__() method. | The class must be a classic class. | If present, dict must be a dictionary or None. | | Methods defined here: | | __abs__(...) | x.__abs__() == abs(x) | ... in other words, I might as well have typed help(object). I only know that the method evt.GetString() exists because the example in the demo uses it. I've Googled, and Gmaned, and read the wx docs (such as they are), but I'm not seeing anything I can use. I know that this is a wxPython question, and that this is the Python list... but y'all have answered some wx questions in the past, and I hate to join another list for one question. If I must, I will... but thanks in advance for any light you can shed. -- www.fsrtechnologies.com ___ 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] Questions about wxEvents
On Thu, Dec 06, 2007 at 09:12:59AM -0800, Marc Tompkins wrote: I have a specific question - how can I generalize a FileBrowseButtonWithHistory - and I realized, as I was trying to word my question, that my real question is a bit more generic. First, the specific question: The FileBrowseButtonWithHistory requires a callback override and some custom code to straighten out handling the history. So far, so good. However, I wish to use more than one FBBWH on my form, and I can't figure out how to re-use the custom callback so it will work for both controls. (It makes me sick to my stomach when I look at my code and see duplicate blocks!) Don't get me wrong - it's working right now, it's just that my code is fugly and I want to clean it up. In more general terms, how can I set more than one control to use the same block of code as a custom callback, and figure out at runtime which control I'm responding to? Doesn't the Event or CommandEvent carry any information about itself? I've tried this: [snip] self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='*.*', fileMode=wx.OPEN, dialogTitle='Select the file containing UCF claims', changeCallback=self.fp1Callback) self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='FI*.*', fileMode=wx.OPEN, dialogTitle='Select the form-image file - generally starts with FI', changeCallback=self.fp2Callback) [snip] def fp1Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] def fp2Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] I have never used wx, but I faced the same question with the qt toolkit, and I solved it with a function that returns a function. In my case, I have several widgets to connect to a single function (setValue), and in some cases they have to be connected also with a particular function (always named set_AttributeName). Here's my snippet: self.connect(widget, QtCore.SIGNAL(signal), self.get_setValue_func(option)) [...] def get_setValue_func(self, option): def setIt(value): try: method = self.__getattribute__(set_%s % option) method(value) except AttributeError: pass self.setValue(option, value) return setIt Tiago. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Questions about wxEvents
Hot diggety! Exactly what I was trying to come up with. Thank you! On Dec 6, 2007 9:38 AM, Jeff Younker [EMAIL PROTECTED] wrote: While I can't help you with the wx specific part of the question, I canoffer help with the reuse question. Here is one approach. Add an controller identifier to fpCallback. Then use lambda expressions for the actual callback, where the lambda expressions pass in a fixed value for the identifier. Modified code: self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='*.*', fileMode=wx.OPEN, dialogTitle='Select the file containing UCF claims', changeCallback= lambda x: self.fpCallback('fp1', x) ) self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='FI*.*', fileMode=wx.OPEN, dialogTitle='Select the form-image file - generally starts with FI', changeCallback= lambda x: self.fpCallback('fp2', x) ) [snip] def fpCallback(self, controlID, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] - Jeff Younker - [EMAIL PROTECTED] - On Dec 6, 2007, at 9:12 AM, Marc Tompkins wrote: I have a specific question - how can I generalize a FileBrowseButtonWithHistory - and I realized, as I was trying to word my question, that my real question is a bit more generic. First, the specific question: The FileBrowseButtonWithHistory requires a callback override and some custom code to straighten out handling the history. So far, so good. However, I wish to use more than one FBBWH on my form, and I can't figure out how to re-use the custom callback so it will work for both controls. (It makes me sick to my stomach when I look at my code and see duplicate blocks!) Don't get me wrong - it's working right now, it's just that my code is fugly and I want to clean it up. In more general terms, how can I set more than one control to use the same block of code as a custom callback, and figure out at runtime which control I'm responding to? Doesn't the Event or CommandEvent carry any information about itself? I've tried this: [snip] self.fp1 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='*.*', fileMode=wx.OPEN, dialogTitle='Select the file containing UCF claims', changeCallback= self.fp1Callback) self.fp2 = filebrowse.FileBrowseButtonWithHistory(pnl, -1, size=(300, -1), labelText='', fileMask='FI*.*', fileMode=wx.OPEN, dialogTitle='Select the form-image file - generally starts with FI', changeCallback= self.fp2Callback) [snip] def fp1Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] def fp2Callback(self, evt): print evt.__dict__ print help(evt) value = evt.GetString() [snip] All I get from print evt.__dict__ is: {'_string': u'E:\\ultrahld\\report\\FILE'} and all I get from help is: Help on instance of LocalEvent in module wx.lib.filebrowsebuttonobject:class instance(object) | instance(class[, dict]) | | Create an instance without calling its __init__() method. | The class must be a classic class. | If present, dict must be a dictionary or None. | | Methods defined here: | | __abs__(...) | x.__abs__() == abs(x) | ... in other words, I might as well have typed help(object). I only know that the method evt.GetString() exists because the example in the demo uses it. I've Googled, and Gmaned, and read the wx docs (such as they are), but I'm not seeing anything I can use. I know that this is a wxPython question, and that this is the Python list... but y'all have answered some wx questions in the past, and I hate to join another list for one question. If I must, I will... but thanks in advance for any light you can shed. -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- www.fsrtechnologies.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] PIDA Issue
I have installed pida succesfully using the command python setup.py install Installation was successful i.e. no errors but when i launch pida, it says some module is missing. wat could be the problem??? i am posting the result of installation and of launching the program. maggi:~/Desktop/PIDA-0.5.1#python setup.py install . . . . running install_scripts copying build/scripts-2.4/pida - /usr/bin copying build/scripts-2.4/pida-remote - /usr/bin changing mode of /usr/bin/pida to 755 changing mode of /usr/bin/pida-remote to 755 maggi:~/Desktop/PIDA-0.5.1# pida Traceback (most recent call last): File /usr/bin/pida, line 28, in ? from pida.core.application import main File /usr/lib/python2.4/site-packages/pida/core/__init__.py, line 3, in ? import pida.core.environment File /usr/lib/python2.4/site-packages/pida/core/environment.py, line 4, in ?from kiwi.environ import Library, environ ImportError: No module named kiwi.environ I need an IDE badly. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to iterate and update subseqent items in list
ted b wrote: Can you suggest a good way to iterate through the remainder of list and update them? Ex: Thing1.value = 0 Thing2.value = 1 Thing3.value = 0 Thing4.value = 0 Things = [Thing1, Thing2, Thing3, Thing4] I want to iterate through 'Things' and if 'Thing.value' 0, then I want to set all values for that and the subsequent 'Things' in the list to 2 So that i'd end up with Thing1.value = 0 Thing2.value = 2 Thing3.value = 2 Thing4.value = 2 import itertools for thing in itertools.dropwhile(lambda x: x.value = 0): thing.value = 2 This may appear less clear at first, but understanding itertools can be a great benefit for addressing a multitude of problems of this nature. I suggest looking at the itertools module documentation, and wading thru dropwhile to understand it. Of course I also introduced lambda here, which is a shortcut to defining an anonymous function. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Best way of learning
The way I learned python was through this wikibook: http://en.wikibooks.org/wiki/Python_Programming I found it very easy to understand and very helpful. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python precision output?
Hi there, I am using python to do some scripting. In particular, I am using it to run some jobs which require precision inputs. I do this by having python write an input file, which I then feed to some other program. The problem I am having is getting python to write number into this input file, keeping 16 digits of precision. I have played around interactively, and see that python default prints 17 digits of precision to the screen, but when I use a replace command to write into the input file, it only prints 12 digits of precision. The relevant snipit of my script is value = float( int(ai) * 6 * math.pi / (int(L)*int(T)) replace = {'VALUE':str(value)} ini_file = open('generic_ini').read() f=open('my_input.xml','w') f.write(ini_file % replace) f.close() where, ai, L and T are process dependent numbers defined in my script, and the output my_input.xml, is just an xml file I later feed to another program, and this is why I replace 'VALUE' with a string. To reiterate, I need str(value) to be written to my file with 16 digits of precision...??? Thanks, Andre ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python precision output?
The problem I am having is getting python to write number into this input file, keeping 16 digits of precision. I have played around interactively, and see that python default prints 17 digits of precision to the screen, but when I use a replace command to write into the input file, it only prints 12 digits of precision. The relevant snipit of my script is : To reiterate, I need str(value) to be written to my file with 16 digits of precision...??? if you want accuracy and are willing to sacrifice the total range of numbers that Python's IEEE754 double-precision floats give you, then use the decimal.Decimal class instead -- better precision, smaller range. however, if you wish to stick with floats, use the string format operator and tell it you want 17 places after the decimal point: x=7./13 x 0.53846153846153844 str(x) '0.538461538462' '%.17f' % x '0.53846153846153844' hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python precision output?
Andre Walker-Loud wrote: Hi there, Hi Andre, First of all, please don't start a new thread by replying to an existing thread, RFC compliant email readers will thread your post along with the original posting based on headers other than the Subject. :-) I don't think you'll ever get satisfactory precision using binary floating point (the default for python's float type). Take a look at the decimal module, I believe it will give you much better results for your requirements. Here is the module documentation: http://docs.python.org/lib/module-decimal.html And an example of it's usage: getcontext().prec = 6 Decimal(1) / Decimal(7) Decimal(0.142857) getcontext().prec = 28 Decimal(1) / Decimal(7) Decimal(0.1428571428571428571428571429) Please post back if that doesn't help you out. Sincerely, e. I am using python to do some scripting. In particular, I am using it to run some jobs which require precision inputs. I do this by having python write an input file, which I then feed to some other program. The problem I am having is getting python to write number into this input file, keeping 16 digits of precision. I have played around interactively, and see that python default prints 17 digits of precision to the screen, but when I use a replace command to write into the input file, it only prints 12 digits of precision. The relevant snipit of my script is value = float( int(ai) * 6 * math.pi / (int(L)*int(T)) replace = {'VALUE':str(value)} ini_file = open('generic_ini').read() f=open('my_input.xml','w') f.write(ini_file % replace) f.close() where, ai, L and T are process dependent numbers defined in my script, and the output my_input.xml, is just an xml file I later feed to another program, and this is why I replace 'VALUE' with a string. To reiterate, I need str(value) to be written to my file with 16 digits of precision...??? Thanks, Andre ___ 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] Best way of learning
Over a year ago I dabbled in learning Python, working my way through a few tutorials, the Deitel's How to program in Python and Hetland's Practical Python, until I came across the OOP sections. My mind just froze up, and I found myself wondering if I had really understood anything at all. : I am happy to read, and have done a fair amount, but am concerned about getting too overwhelmed and confused again. I acknowledge and realise the value of practising by scripting programs and enjoy the intellectual challenge of the debugging process, and trying to think through the trick of a particular way of cracking a problem. So, after this long-winded introduction, I was hoping to pick the wisdom of this list to get some pointers of what to do/not to do to make the most effective use of the few hours I have to learn how to program using Python. So, any advice for someone in their mid-40s who would like to learn Python in a more methodical and effective manner? hi there, and a belated welcome to Python. the fact that you have some coding under your belt really helps. without being too much of a shameless plug, you are a member of the target audience i wrote Core Python Programming for: you have some programming skills and want to learn Python quickly and effectively. the book has lots of small snippets that you should be able to easily follow, plus there are both short and long, easy and more difficult, exercises at the end of every chapter. check out the philosophy behind the book (plus all kinds of reviews!) at the book's website http://corepython.com you can also find a link to downloading a free chapter on the left-hand side too. as a programmer myself with over 10 years of Python, i know what newbies need to know in order to become effective in their new favorite language. :-) my goal as an instructor is to be able to explain things in a simple enough manner that things are clear, with the minimal amount of confusion, including the OOP chapter. finally, my goal as the author is to merge all of this together in an easy-to-swallow and conversational format along with practical examples to solidify your newfound knowledge. should i mention i'm in your age group too? ;-) best of luck to you, and again, welcome to Python! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python precision output?
if you want accuracy and are willing to sacrifice the total range of numbers that Python's IEEE754 double-precision floats give you, then use the decimal.Decimal class instead -- better precision, smaller range. however, if you wish to stick with floats, use the string format operator and tell it you want 17 places after the decimal point: x=7./13 x 0.53846153846153844 str(x) '0.538461538462' '%.17f' % x '0.53846153846153844' hope this helps! This did the trick! thanks, Andre -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mail? What's that?
Justin Cardinal wrote: Ricardo Aráoz wrote: Are From: To: Date: and Subject: mandatory in the contents of the email(text)? Do I have to put real address in From when calling sendmail()? And in the contents? Here's the page I used to learn on this subject. http://www.thinkspot.net/sheila/article.php?story=20040822174141155 I'm definitely not a pro in this area, so what comes next are merely assumptions made after toying around a bit. I don't believe the From, To, Date, Subject are required, but if you play around sending some test messages to yourself, you'll see that excluding them makes the message look very suspicious. As far as using your real address, that might depend on your email server...but yes, you can most likely spoof other addresses. Please use this for good, not evil. -Justin Cardinal Thanks Justin. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python precision output?
Andre Walker-Loud wrote: To reiterate, I need str(value) to be written to my file with 16 digits of precision...??? You can use string formatting to specify exactly how many decimal places to include: In [1]: v=1.0/7 In [2]: v Out[2]: 0.14285714285714285 In [3]: str(v) Out[3]: '0.142857142857' In [4]: '%.16f' % v Out[4]: '0.1428571428571428' Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] commands module
I've been trying to do something that I thought was going to be relatively straight-forward, but so far I haven't found a good solution. What I'm trying to do is discover a pid on a process and kill it. The way that I thought that I could do it is something along the lines of: import commands program = someprogram a = commands.getoutput('ps ax|grep %s ' % (program)) Then, I'd parse the returned info get the pid and kill it, probably via another command. However, what happens is that the ps ax portion truncates the listing at 158 characters. It just so happens that the unique name that I need in the list comes after that. So, works from the bash shell, but doesn't work using getoutput. I have also tried variations on a theme. For example, I created a shell file and tried to route into a file: ps ax|grep my_program_name ps.output No luck. Do you have any suggestions? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] commands module
I've been trying to do something that I thought was going to be relatively straight-forward, but so far I haven't found a good solution. What I'm trying to do is discover a pid on a process and kill it. The way that I thought that I could do it is something along the lines of: import commands program = someprogram a = commands.getoutput('ps ax|grep %s ' % (program)) Then, I'd parse the returned info get the pid and kill it, probably via another command. However, what happens is that the ps ax portion truncates the listing at 158 characters. It just so happens that the unique name that I need in the list comes after that. So, works from the bash shell, but doesn't work using getoutput. What's the result of getoutput(); ie, what is a? Note that bash and commands.getoutput() are not the same, since the latter executes 'sh -c', which is slightly different. I don't expect that'll solve your problem. Does the -w option help? I'm guessing it won't, since the truncation seem to be due to some odd character causing an EOF or something (I tried myself here, both on Linux OS X, without problems). Evert ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] commands module (Forwarded back to list)
Evert Rol wrote: I've been trying to do something that I thought was going to be relatively straight-forward, but so far I haven't found a good solution. What I'm trying to do is discover a pid on a process and kill it. The way that I thought that I could do it is something along the lines of: import commands program = someprogram a = commands.getoutput('ps ax|grep %s ' % (program)) Then, I'd parse the returned info get the pid and kill it, probably via another command. However, what happens is that the ps ax portion truncates the listing at 158 characters. It just so happens that the unique name that I need in the list comes after that. So, works from the bash shell, but doesn't work using getoutput. What's the result of getoutput(); ie, what is a? Note that bash and commands.getoutput() are not the same, since the latter executes 'sh -c', which is slightly different. I don't expect that'll solve your problem. Does the -w option help? I'm guessing it won't, since the truncation seem to be due to some odd character causing an EOF or something (I tried myself here, both on Linux OS X, without problems). Evert I accidentally sent this directly rather than to the list: Thanks for your reply. When I said 158 characters I was trying to say each _line_ of the shell command ps ax was truncated to 158 characters, not that the _total_ returned was 158. Your question got me thinking about it, and I found in my set variables: COLUMNS=158, which corresponds pretty well. So, I tried setting COLUMNS equal to 500 (arbitrarily large) prior to going into python. It seems to change back to 158 automatically however. For example, when I go into python, import commands, and execute commands.getoutput('set') I find that COLUMNS is back to 158. So, I think my problem is that I don't know how to alter the set variable so that it will stick long enough for the ps ax command to execute properly. == End of forwarded message part. Finally, I have solved the problem, because I discovered a width option on the ps command, which I hadn't been aware of before. For example: commands.getstatusoutput('ps ax -l --width 500') works very well by over-riding any defaults. Thanks for your help. ds ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] commands module (Forwarded back to list)
So, I tried setting COLUMNS equal to 500 (arbitrarily large) prior to going into python. It seems to change back to 158 automatically however. For example, when I go into python, import commands, and execute commands.getoutput('set') I find that COLUMNS is back to 158. So, I think my problem is that I don't know how to alter the set variable so that it will stick long enough for the ps ax command to execute properly. I've had this problem before (setting/altering shell variables when executing a command from Python, albeit using os.system() instead). What I'd use is: commands.getoutput('COLUMNS=500 ps ax') or similar. In your case, you've been able to solve in another way (and better, since environment independent, though still shell/ps- variant dependent), but sometimes one may need to set/change shell variables, like paths to dynamic libraries. The above should work (for more variables, just specify them all before the actual command, whitespace separated). ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Still Can't Find Timed While Loops
Hello all, I now have my bit of code in while loop form and it works! It's great but not exactly what I wanted to do. I've been googling my heart out and I find lots of info on while loops and lots of info on timers that will execute an action AFTER a given interval but nothing on a timer that will execute an action DURING a given interval. What I'd really like to do at this point in my game is have the player execute the loop for 30 seconds then have it print the final score and break. Does anyone out there have any code that'll do that? Here's what I've got. I'm sure it ain't pretty and I'm happy to hear suggestions on cleaning it up as well. I know it needs some def's in there and possibly a class too. import random startNum = random.choice(range(1, 9)) print 'Start with the number ', startNum,'. Then continuously add 7 to that number until the timer runs out. You have 30 seconds.' score = 0 answer = int(raw_input('Enter your answer: ')) while (score 50): startNum = startNum + 7 if startNum == answer: print 'That is correct!' score = score + 5 print 'Your score is ', score answer = int(raw_input('Enter your answer: ')) else: print 'That is incorrect. Game over. Your final score is ', score break else: print 'You win! Your final score is ', score - Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] commands module
Evert Rol wrote: So, I tried setting COLUMNS equal to 500 (arbitrarily large) prior to going into python. It seems to change back to 158 automatically however. For example, when I go into python, import commands, and execute commands.getoutput('set') I find that COLUMNS is back to 158. So, I think my problem is that I don't know how to alter the set variable so that it will stick long enough for the ps ax command to execute properly. I've had this problem before (setting/altering shell variables when executing a command from Python, albeit using os.system() instead). What I'd use is: commands.getoutput('COLUMNS=500 ps ax') or similar. In your case, you've been able to solve in another way (and better, since environment independent, though still shell/ps-variant dependent), but sometimes one may need to set/change shell variables, like paths to dynamic libraries. The above should work (for more variables, just specify them all before the actual command, whitespace separated). Thank you for mentioning that. I'm pretty weak on bash, and had monkeyed around with such things as set COLUMNS=500 on the previous line in the shell program version, but hadn't actually looked up that syntax yet, when I stumbled across the ps parameter that eventually I selected. Thanks again. ds ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor