Re: [Tutor] Need help on Setup.py
What is pywin32 ? I mean what is its use ? -- Xcited 2 be AliveSriram ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 84, Issue 8
On 02/02/2011 06:00 AM, tutor-requ...@python.org 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 tutor-requ...@python.org You can reach the person managing the list at tutor-ow...@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." Today's Topics: 1. Re: Help with range of months spanning across years (Hugo Arts) 2. Re: Help with range of months spanning across years (Hugo Arts) 3. Re: Help with range of months spanning across years (Sean Carolan) 4. Re: decimal module and precision (Richard D. Moores) -- Message: 1 Date: Wed, 2 Feb 2011 03:55:25 +0100 From: Hugo Arts To: ian douglas Cc: Tutor@python.org Subject: Re: [Tutor] Help with range of months spanning across years Message-ID: Content-Type: text/plain; charset=UTF-8 On Wed, Feb 2, 2011 at 2:30 AM, ian douglas wrote: It bugs me that so many people are quick to jump on the "we wont' do your homework" bandwagon -- I was accused of the same thing when I posted a question to the list myself. I've been programming professionally for many years but learning Python in my spare time... I sent this reply to Sean privately, but frankly I'm so annoyed at the 'homework' replies, I figured I'd just post it here. Okay, this has gotten rather long, but I'll post it anyway because I think the "we won't do your homework" response is valid and there's good reasoning behind it. It's not just homework. The thing is, the point of this list is to teach people how to program (in general, but in python specifically). When someone posts a question, responding with a lump of code and a crisp "This is how you do it" just isn't a very effective teaching method. More of the equivalent of giving a man a fish, as in the old saying. Another point, mentioned in Eric Raymond's "How to ask questions the smart way"[1], is that I generally dislike answering questions for people who don't appear to have put in any work in solving the problem themselves. It leaves us with little options to give pointers, and we're stuck with the lump of code mentioned above, or a few vague hints as to how to approach the problem. This isn't a place that solves your coding problems for free. But I'm happy to help you learn python. For those reasons, I *never* give out a straight answer, especially not to someone who doesn't show their own attempts. In those cases, I will tell them that I won't and why, give them some hints, and encourage them to try some things on their own and get back here, at which point we can help them further. That's what tutoring is all about after all. So, in short, we're not "accusing" you of trying to make us do your homework, and we're certainly not dismissing your questions. We're simply saying "show us what you have, and we'll give you tips. if you're totally at a loss, try doing so-and-so, or look at this and that documentation." [1]: http://www.catb.org/~esr/faqs/smart-questions.html, everybody should read this before posting to a mailing list, imho. I'm still very junior to Python, but this seems to work for me using recursion. I'm sure there's a much more elegant way of doing this, but like I said, I'm still pretty new to the language. def makelist(startmonth,startyear,endmonth,endyear): ??? mylist = [] ??? if (startyear == endyear): ??? ??? for month in range (startmonth,endmonth+1): ??? ??? ??? mylist += [(startyear,month)] ??? else: ??? ??? for month in range (startmonth,13): ??? ??? ??? mylist += [(startyear,month)] ??? ??? mylist += makelist(1,startyear+1, endmonth, endyear) ??? return mylist ; print makelist(8,2009,1,2010) I'd love to hear any replies from the experts on the list on how to make this more efficient in Python 'cause I'm still learning myself. Your solution feels rather lispy to me. I really like that. I actually had a simple iterative solution in mind when I wrote that first post, but while trying to write it now I'm running into some complications I hadn't considered before, mea culpa (I'm such a good armchair programmer) In any case, you can replace the for loops with a list comprehensions, and factor them out into a single one since they're so similar. Let me write it out: def datelist(startyear, startmonth, endyear, endmonth): em = endmonth + 1 if startyear == endyear else 13 dates = [(startyear, m) for m in range(startmonth, em)] if startyear< endyear: dates += datelist(startyear + 1, 1, endyear, endmonth) return dates print(datelist(2008, 8, 2009, 1)) [(2008, 8), (2008, 9), (2008, 10), (2008, 11), (2008, 12), (2009, 1)] Hugo -- Message: 2 Date: Wed, 2 Feb 2011 04:11:52 +0100 From: Hugo Art
[Tutor] Homework and the Tutor list
> I would have to agree with you Ian. Coming from an art then computer > animation visual effects background, it's not until recently that it became > evident to me that in order to push the potential of this medium, I would > definitely have to learn to code. I think the stigma of the "homework > bandwagon" comes from the very nature of coding and it's secretive and > cryptic undertones, it's something very personal in the sense that, although > there is usually more than 1 way to solve a problem, there's always "THE > MOST" and more efficient way IMHO, that some people are just not willing to > share. And, of course, this most efficient way utilizes less memory and > resources. This is why I always feel apprehensive to post so I purchased > many books on python, and until I've gone through them and feel competent > enough to post, then I'll post, which to me does no good. Thank you for > your insight, it makes me feel a little bet more human and inspires me not > to give up. I don't think that's true at all. I think people here are happy to help, including by posting working, efficient, code. What we try to avoid is having students come here with their assignments and have us do their schoolwork for them. I'm not sure how long you've been subscribed to the list, but this happens on a regular basis. If you're concerned that people will think you're looking for help with homework, just tell us up front that it's not a homework problem. If it *is* a homework problem, tell us that up front too, and people will still be happy to help, though less likely to post working code, and more likely to try and work with you to get you to figure out the solution on your own. In all cases, you are most likely to get useful help if you do a couple of things: Tell us what you're trying to accomplish and why, as clearly as you can. Post some code that tries to solve the problem, but doesn't work right. Ideally, post code that is self contained (so that other people can run it too), along with any error messages (including the full stack trace, if one is generated), and what your desired result is. Try to give us the big picture of what you're doing, as well as the details of the problem you're having. Sometimes we can point you to an entirely different approach that will work better. -- Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Homework and the Tutor list
On Wed, Feb 2, 2011 at 10:53 AM, Jerry Hill wrote: > > I don't think that's true at all. I think people here are happy to > help, including by posting working, efficient, code. What we try to > avoid is having students come here with their assignments and have us > do their schoolwork for them. I'm not sure how long you've been > subscribed to the list, but this happens on a regular basis. > -- > Jerry I can't agree with Jerry's comments more, and I have been the benefactor of both sides of this unwritten rule. As a student, I came to discussion forums like this one with homework questions hoping for an easy answer, and didn't get one. Now that I am a college professor I'm quite glad I didn't get an easy answer, and I appreciate even more now the fact that forums like this one know a homework problem from a real one, and work to teach more than normal when it is needed. I haven't been involved with python long, and I had an abrupt start on this list as my first question question was not written with the protocol I normally use, I had not taken time off and gotten away from my frustrations and taken the time to write a clear concise non-judgmental question. The rest of this list chastised me, and still helped me. I deserved the critical words, and did not deserve the help. I got both. Thanks go to the long time readers and contributors of this list who have made it something valuable, and I hope that some day soon those of us who are still learning, will be able to begin to meaningfully contribute. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Defining Exceptions
All, I am a python neophyte and not terrible well versed in programming (as will become obvious shortly) I have a script which is reading a serial device on a schedule. The device outputs a header at the beginning of every read. I have a data file which I am appending and would like to eliminate the header so that I end up with one master data file. A copy of the serial readout is: * > 6CSV Type Reports2 - Display All Data3 - Display New Data4 - Display Last Data5 - Display All Flow Stats6 - Display New Flow Stats7 - Display All 5-Min Flow8 - Display New 5-Min Flow9 - Display Error Log> 4 - Display CSV DataStation, 1Time,Conc(mg/m3),Qtot(m3),no(V),WS(MPS),no(V),RH(%),no(V),AT(C),E,U,M,I,L,R,N,F,P,D,C,T,02/02/11 08:00, 0.042, 0.701, 0.004, 0.1, 0.002, 7, 0.012, -18.0,0,0,0,0,0,0,0,0,0,0,0,0, I am only interested in the information following the T, in the header. I have tried to use an exception to have the script throw out all data prior to the T, in the header but I don't know how to define this excecption. My current script looks as follows: def cycle(ser,prefix): inRecovery=False resp=False #tm.sleep(30.0) ser.open() tm.sleep(2) ser.write('\n\r\n\r\n\r') resp=buffer_read(ser) ser.write('6') resp=buffer_read(ser) ser.write('3') resp=buffer_read(ser) lines = resp.split('\r\n') waste=lines.pop() while True: try: lines.remove(waste) except Exception: ?? for x,row in enumerate(lines): lines[x]=row.split(',') if DEBUG: print lines f=open(prefix,'a') csvf = csv.writer(f) csvf.writerows(lines) f.close() ser.close() How do I define the exception so that I get only the data following the header? Thanks! Tomb ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining Exceptions
On 2/2/2011 6:51 AM Tom Brauch said... All, I am a python neophyte and not terrible well versed in programming (as will become obvious shortly) I have a script which is reading a serial device on a schedule. The device outputs a header at the beginning of every read. I have a data file which I am appending and would like to eliminate the header so that I end up with one master data file. A copy of the serial readout is: * 6CSV Type Reports2 - Display All Data3 - Display New Data4 - Display Last Data5 - Display All Flow Stats6 - Display New Flow Stats7 - Display All 5-Min Flow8 - Display New 5-Min Flow9 - Display Error Log> 4 - Display CSV DataStation, 1Time,Conc(mg/m3),Qtot(m3),no(V),WS(MPS),no(V),RH(%),no(V),AT(C),E,U,M,I,L,R,N,F,P,D,C,T,02/02/11 08:00, 0.042, 0.701, 0.004, 0.1, 0.002, 7, 0.012, -18.0,0,0,0,0,0,0,0,0,0,0,0,0, I am only interested in the information following the T, in the header. I have tried to use an exception to have the script throw out all data prior to the T, in the header but I don't know how to define this excecption. My current script looks as follows: def cycle(ser,prefix): inRecovery=False resp=False #tm.sleep(30.0) ser.open() tm.sleep(2) ser.write('\n\r\n\r\n\r') resp=buffer_read(ser) ser.write('6') resp=buffer_read(ser) ser.write('3') resp=buffer_read(ser) lines = resp.split('\r\n') waste=lines.pop() pop changes lines by discarding the end of the list. So your subsequent remove fails because waste is no longer in the list. Perhaps waste is the data you're looking for? sprinkle some prints through here so you can see what values you're dealing with. That's a common technique to help figure out what's wrong. HTH, Emile while True: try: lines.remove(waste) except Exception: ?? for x,row in enumerate(lines): lines[x]=row.split(',') if DEBUG: print lines f=open(prefix,'a') csvf = csv.writer(f) csvf.writerows(lines) f.close() ser.close() How do I define the exception so that I get only the data following the header? Thanks! Tomb ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help on Setup.py
"Sriram Jaju" wrote What is pywin32 ? I mean what is its use ? It is a set of Python modules that gives access to the Windows API, including COM functions. Using it you can create native Windows GUIs from Python or, more usefully, integrate with Windows Operating System features and other Windows programs like Powerpoint or Outlook. It's pretty much essential if you want to interact with Windows at the OS level. (Although ctypes can also be used nowadays with a little bit extra effort) pywin also includes the PythonWin IDE - a Windows specific tool similar to IDLE (but much better). More details on the pywin web site. Also the author has an O'Reilly book (Python Programming on Win32) which covers many pywin features. HTH, Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining Exceptions
It's difficult to see exactly what the data looks like as it is received. Where are the line breaks? At the commas? Is the "header" just the first line? Is "1Time" considered part of the header? Is everything after "1Time" considered "data"? I can see several simple alternatives to your method. I don't think you need the exception code. I think you can replace this: lines = resp.split('\r\n') waste=lines.pop() while True: try: lines.remove(waste) except Exception: ?? with this: lines = resp.splitlines[:2] This part, I don't understand: for x,row in enumerate(lines): lines[x]=row.split(',') - Original Message - From: Tom Brauch To: tutor@python.org Sent: Wednesday, February 02, 2011 6:51 AM Subject: [Tutor] Defining Exceptions All, I am a python neophyte and not terrible well versed in programming (as will become obvious shortly) I have a script which is reading a serial device on a schedule. The device outputs a header at the beginning of every read. I have a data file which I am appending and would like to eliminate the header so that I end up with one master data file. A copy of the serial readout is: * > 6CSV Type Reports2 - Display All Data3 - Display New Data4 - Display Last Data5 - Display All Flow Stats6 - Display New Flow Stats7 - Display All 5-Min Flow8 - Display New 5-Min Flow9 - Display Error Log> 4 - Display CSV DataStation, 1Time,Conc(mg/m3),Qtot(m3),no(V),WS(MPS),no(V),RH(%),no(V),AT(C),E,U,M,I,L,R,N,F,P,D,C,T,02/02/11 08:00, 0.042, 0.701, 0.004, 0.1, 0.002, 7, 0.012, -18.0,0,0,0,0,0,0,0,0,0,0,0,0, I am only interested in the information following the T, in the header. I have tried to use an exception to have the script throw out all data prior to the T, in the header but I don't know how to define this excecption. My current script looks as follows: def cycle(ser,prefix): inRecovery=False resp=False #tm.sleep(30.0) ser.open() tm.sleep(2) ser.write('\n\r\n\r\n\r') resp=buffer_read(ser) ser.write('6') resp=buffer_read(ser) ser.write('3') resp=buffer_read(ser) lines = resp.split('\r\n') waste=lines.pop() while True: try: lines.remove(waste) except Exception: ?? for x,row in enumerate(lines): lines[x]=row.split(',') if DEBUG: print lines f=open(prefix,'a') csvf = csv.writer(f) csvf.writerows(lines) f.close() ser.close() How do I define the exception so that I get only the data following the header? Thanks! Tomb -- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Homework was: Re: Tutor Digest, Vol 84, Issue 8
Please do not send the entire digest message, As the instructions say below: "Nevins Duret" wrote Send Tutor mailing list submissions to tutor@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." And also edit out the messages that are not relevant to your reply. It saves a lot of frustration on the part of your readers. On Wed, Feb 2, 2011 at 2:30 AM, ian douglas wrote: It bugs me that so many people are quick to jump on the "we wont' do your homework" bandwagon ..., I would definitely have to learn to code. I think the stigma of the "homework bandwagon" comes from the very nature of coding and it's secretive and cryptic undertones, Nope, it comes from the high number of requests we get on the list from students who suddenly discover they have an assignment due and think they can post the assignment here and get somebody on the list to do it for them. Doing so is a waste of contributers time and does not help the student learn anything. This is why we have the policy. If students (or any other newbie) have made a decent stab at solving the problem we are more than happy to resolve specific issues and to suggest different strategies. Coding has no "secretive and cryptic" undertones in my experience it is simply a branch of mathematics and shares much of the same approaches to learning that traditional math does. ie. Lots of examples which you need to work through yourself before you can understand it. sense that, although there is usually more than 1 way to solve a problem, there's always "THE MOST" and more efficient way IMHO, that some people are just not willing to share. There is very rarely a single most efficient way. And much of what is good in programming is subjective. How much do we bias towards readability versus sheer speed? It depends on the exact circumstances, and that's rarely clear on a mailing list. The good news is that it very rarely matters as much as posters think it does! ;-) efficient way utilizes less memory and resources. And again this is yet another angle on the problem. Reducing memory usage may increase execution time or reduce readability. They don't call it software engineering for nothing - and engineering is all about choosing the "best" compromises based on the needs. feel apprehensive to post so I purchased many books on python, IME, This forum is one of the most polite and friendly lists on the internet. You will rarely get insulted or savaged here, especially if you provide a good background to the question and its context. Compared to many other lists (try Perl!) we are all pussycats here! :-) feel a little bet more human and inspires me not to give up. We are all human and trying to contribute our own little something. Sometimes we don't agree, but that's because we are human and there are rarely right and wrong answers, just opinions. And we all have different experience levels. And we are all volunteers who may have had a hard day, or be reading very late at night or early in the morning... Making allowances has to be done on both sides of the poster/replier fence. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ (and list moderator) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with range of months spanning across years
ian douglas wrote: It bugs me that so many people are quick to jump on the "we wont' do your homework" bandwagon -- I was accused of the same thing when I posted a question to the list myself. I've been programming professionally for many years but learning Python in my spare time... I sent this reply to Sean privately, but frankly I'm so annoyed at the 'homework' replies, I figured I'd just post it here. It's a fine line. Most people consider "homework" questions to be cheating, and don't want to either condone or assist cheaters in any way. The cost, though, is occasionally offending people who aren't cheating, but merely asking a question poorly, or happen to be asking something that *sounds* like homework, or just unlucky. Generally, if you want an answer to a question, you should demonstrate that you've tried to solve it yourself. Code, even broken code that doesn't work, and a clear description of the problem, go a long way to assuring people that *even if it is homework*, you've made a good attempt at the problem and are looking for *help* rather than somebody to do it for you. At which point somebody will almost certainly jump in an do it for you :) I'm still very junior to Python, but this seems to work for me using recursion. I'm sure there's a much more elegant way of doing this, but like I said, I'm still pretty new to the language. def makelist(startmonth,startyear,endmonth,endyear): mylist = [] if (startyear == endyear): for month in range (startmonth,endmonth+1): mylist += [(startyear,month)] else: for month in range (startmonth,13): mylist += [(startyear,month)] mylist += makelist(1,startyear+1, endmonth, endyear) return mylist ; print makelist(8,2009,1,2010) I'd love to hear any replies from the experts on the list on how to make this more efficient in Python 'cause I'm still learning myself. Generally, you don't use recursion because it's efficient, 'cos it ain't. At least not in Python, which has a fairly naive recursion model. Some other languages can spot a particular kind of recursion, and optimise the bejeezus out of it. So leave recursion for the problems where (1) it makes solving the problem easy, and (2) the inefficiency doesn't matter. The *general* way of making recursion efficient is by converting it to iteration, if possible. In your case, recursion doesn't seem to really make the problem any easier to solve, but it probably doesn't hurt much. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] RE module is working ?
Hello, I am trying to subsitute a '""' pattern in '\"\"' namely escape 2 consecutives double quotes: * *In Python interpreter:* $ python Python 2.7.1rc1 (r271rc1:86455, Nov 16 2010, 21:53:40) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> expression = *' "" '* >>> re.subn(*r'([^\\])?"', r'\1\\"', expression*) Traceback (most recent call last): File "", line 1, in File "/home/karim/build/python/install/lib/python2.7/re.py", line 162, in subn return _compile(pattern, flags).subn(repl, string, count) File "/home/karim/build/python/install/lib/python2.7/re.py", line 278, in filter return sre_parse.expand_template(template, match) File "/home/karim/build/python/install/lib/python2.7/sre_parse.py", line 787, in expand_template raise error, "unmatched group" sre_constants.error: unmatched group But if I remove '?' I get the following: >>> re.subn(r'([^\\])"', r'\1\\"', expression) (' \\"" ', 1) Only one substitution..._But this is not the same REGEX._ And the count=2 does nothing. By default all occurrence shoul be substituted. * *On linux using my good old sed command, it is working with my '?' (0-1 match):* *$* echo *' "" '* | sed *'s/\([^\\]\)\?"/\1\\"/g*'* \"\" *Indeed what's the matter with RE module!?* *Any idea will be welcome! Regards Karim* * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] update Tkinter text widget in realtime?
The guy who had the post about the "vowel search" exercise got me to thinking about matrices of letters, and thence to word search games, which I have made a time or two by hand and they are a pain. So I decided to try making a program that would put words into a word search. This is very basic, there's no checking to see if your word is going to go out of bounds (yet), but it works. So, just for the heck of it, I thought, what would happen if I put a word into the matrix, such that its first letter is in the center, and then it rotate around its insertion point. This sets up a Tkinter text widget and inserts the matrix into it. I figured I could just clear the widget by deleting everything in it, then putting a matrix, modified with the next rotation into it. No dice. The rotations are happening, but the text widget only materializes after the last rotation, and the final "frame" in the rotation is the only one it shows. I've run into this same sort of issue with Tcl/Tk, and never solved it there, either. Any ideas? The last 10-12 lines are the ones that do the rotation. I've tried moving the root.mainloop() statement up higher in the code. That causes the text widget to show up, but no matrix inside. from Tkinter import * from tkFont import * import random root = Tk() fixed_width = Font(family = 'Courier', size = 10) textbox = Text(root, font = fixed_width, width = 40, height = 20) textbox.pack() def blank_matrix(sizeX, sizeY, fillchar): sizeX += 1 sizeY += 1 letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' letter_matrix = [] for row in range(1,sizeY): line = [] for _column in range(1, sizeX): if fillchar == 'letters': letter = random.randrange(0, 26) line.append(letters[letter]) else: line.append(fillchar) letter_matrix.append(line) return letter_matrix def print_matrix(matrix): textbox.delete(1.0, END) for line in matrix: #print ' '.join(line) line = ' '.join(line) + '\n' textbox.insert(END, line) def insert_word(word, print_dir, x, y, matrix): word = word.upper() word = list(word) print_dirs = dict() print_dirs['e'] = (1,0) print_dirs['ne'] = (1,-1) print_dirs['n'] = (0,-1) print_dirs['nw'] = (-1,-1) print_dirs['w'] = (-1, 0) print_dirs['sw'] = (-1, 1) print_dirs['s'] = (0, 1) print_dirs['se'] = (1,1) x_plus, y_plus = print_dirs[print_dir] for i in range(0, len(word)): matrix[y + (i * y_plus)][x + (i * x_plus)] = word[i] return matrix directions = ['e', 'ne', 'n', 'nw', 'w', 'sw', 's', 'se'] for direction in directions: print direction matrix = blank_matrix(20, 20, '.') matrix = insert_word('test_word', direction, 10, 10, matrix) print_matrix(matrix) root.mainloop() I've also doctored the code to get a final matrix with all rotations included...so the rotations are for sure happening, but the text widget just isn't updating. This is what it looks like with all possible rotations, in case I'm not making sense. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D . . . . . . . D . . . . . . . D . . . . R . . . . . . R . . . . . . R . . . . . . O . . . . . O . . . . . O . . . . . . . . W . . . . W . . . . W . . . . . . . . . . _ . . . _ . . . _ . . . . . . . . . . . . T . . T . . T . . . . . . . . . . . . . . S . S . S . . . . . . . . . . . . . . . . E E E . . . . . . . . . . D R O W _ T S E T E S T _ W O R D . . . . . . . . . . E E E . . . . . . . . . . . . . . . . S . S . S . . . . . . . . . . . . . . T . . T . . T . . . . . . . . . . . . _ . . . _ . . . _ . . . . . . . . . . W . . . . W . . . . W . . . . . . . . O . . . . . O . . . . . O . . . . . . R . . . . . . R . . . . . . R . . . . D . . . . . . . D . . . . . . . D . . . . . . . . . . . . . . . . . . . . . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with range of months [was Tutor Digest, Vol 84, Issue 8]
Hi Nevins, I don't think I've seen you post here before. Welcome to the list! Before answering your comment (see below), I have to give you a gentle wrap on the knuckles. It's considered impolite to: (1) reply to a digest without changing the subject line from "Tutor Digest" to something more meaningful; and (2) reply to a digest without trimming (deleting) the 200+ lines that have nothing to do with your comment; both of which you have done. Nevins Duret wrote: [snip] I think the stigma of the "homework bandwagon" comes from the very nature of coding and it's secretive and cryptic undertones, it's something very personal in the sense that, although there is usually more than 1 way to solve a problem, there's always "THE MOST" and more efficient way IMHO, that some people are just not willing to share. I think you couldn't be more wrong to describe coding as "secretive and cryptic", and it is ironic that you are making this accusation on a mailing list crewed by volunteers who don't get a cent for donating their time and expertise to help others, using a programming language which has been donated for free to the programming community. Python is Open Source software -- not only is it free like "free beer", but it's also free like in "freedom of speech". If you want to see how secretive Python is, I suggest you go here: http://www.python.org/download/source/ and download every single line of code used by the Python interpreter and the entire standard library, and then read the licence: http://docs.python.org/license.html which grants you the freedom to do anything you like with it, virtually without restriction. You might find that source code cryptic (I know I would find parts of it so), but that's a function of ignorance, not an inherent characteristic of programming. Python is just one tiny part of the Free Software and Open Source movement(s), possibly and arguably best exemplified by the Free Software Foundation: http://www.fsf.org/ and the GNU project: http://www.gnu.org/philosophy/philosophy.html Of course there are always "some people", but with 7 billion people on the planet that applies to virtually anything. Speaking for myself, I have *never* withheld an answer to a question because I wanted to keep it to myself. I've *very occasionally* withheld answers because I thought the questioner was being a leach, taking without any possibility of giving back, or was rude and inconsiderate. I've frequently failed to answer because I'm busy and there are only so many hours in a day (so apologies to anyone waiting for a response from me who hasn't received one). -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] update Tkinter text widget in realtime?
"Elwin Estle" wrote Caveat: I haven't studied this in detail so I might be missing something... So, just for the heck of it, I thought, what would happen if I put a word into the matrix, such that its first letter is in the center, and then it rotate around its insertion point. This sets up a Tkinter text widget and inserts the matrix into it. I figured I could just clear the widget by deleting everything in it, then putting a matrix, modified with the next rotation into it. No dice. The rotations are happening, but the text widget only materializes after the last rotation, and the final "frame" in the rotation is the only one it shows. Tk is an event driven framework so it will only update between events. But I don't see any events in your code. You do the initial population of the matrix and add it to the text widget but then nothing happens... Where are the events that would cause the display to update? I'd expect to see a timer or similar mechanism forcing a redraw of the widgets. Any ideas? The last 10-12 lines are the ones that do the rotation. I've tried moving the root.mainloop() statement up higher in the code. That causes the text widget to show up, but no matrix inside. mainloop() starts the event loop. From that point on Tk is waiting for events to process. But since you have not defined any handlers all events are just ignored. You need to add an event handler (for a timer say) that will catch timeouts and update the Text widget. It can then set a new timer ready for the next update. root = Tk() fixed_width = Font(family = 'Courier', size = 10) textbox = Text(root, font = fixed_width, width = 40, height = 20) textbox.pack() This sets up the UI widget but no event handlers.. def blank_matrix(sizeX, sizeY, fillchar): return letter_matrix This fills the matrix def print_matrix(matrix): textbox.delete(1.0, END) for line in matrix: #print ' '.join(line) line = ' '.join(line) + '\n' textbox.insert(END, line) This fills the widget def insert_word(word, print_dir, x, y, matrix): ... return matrix More matrix filling directions = ['e', 'ne', 'n', 'nw', 'w', 'sw', 's', 'se'] for direction in directions: print direction matrix = blank_matrix(20, 20, '.') matrix = insert_word('test_word', direction, 10, 10, matrix) print_matrix(matrix) This goes through the loop once using the functions above but again creates no event handlers to update the GUI. root.mainloop() Now we are waiting for events but without any handlers the events that do happen - and with no control widgets there will not be many - are ignored or defaulted (move, resize etc). I've also doctored the code to get a final matrix with all rotations included...so the rotations are for sure happening, but the text widget just isn't updating. Because you are not telling it to update. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] print "Hello, World!"
Hey folks, I'm Doug. I've been using computers since second grade, and I know a little about them. I am, however, completely new to programming. I don't even know what I know about it. I'd like some social interaction with this, but I can't go back to school until summer or fall of this year. I don't want to wait to start learning this as I feel like I'm already about a million years behind. I asked the Oracle (www.google.com) and after messing around with the Python Shell and getting a lot of error messages, I decided I need some remote help. Here's where I'm at: - I have downloaded and installed Python 2.6.4. Successfully, I think. - I am running Windows XP SP3 (though I'm going to see if I can do this on my laptop, which has Windows 7) - I have toyed around with some tutorials, but all they really taught me is that I need a teacher. I'm sure you guys are busy, but I read that the most basic questions are okay. As I'm sure there is at least one good resource on the net for people in my position, I'd like some suggestions on where to start. I plan on bothering you all as little as possible, but I am seriously hoping to make real progress between now and my first class. I have a feeling once I get a basic understanding, I'll run away with it. It's just very... big right now. So this list seems like a good thing, but tell me if I'm in the wrong place. I am hoping for a link to a somewhat comprehensive online resource that explains from the beginning in English, plain English, as this is the only language I speak. Something to get my foot in the door would be awesome. Cheers, Doug Marvel ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print "Hello, World!"
On 2/2/2011 9:00 PM, Doug Marvel wrote: > [snip] > > I am hoping for a link to a somewhat comprehensive online resource > that explains from the beginning in English, plain English, as this is > the only language I speak. Something to get my foot in the door would > be awesome. > > > Cheers, > Doug Marvel When I started out I used Alan Gauld's wonderful tutor: http://www.alan-g.me.uk/tutor/index.htm It references Python 2.3, but the same things apply for 2.6 as well. What I like about that site is that it doesn't skip anything, and goes into more advanced topics at the end. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print "Hello, World!"
On Wed, Feb 2, 2011 at 8:27 PM, Corey Richardson wrote: > On 2/2/2011 9:00 PM, Doug Marvel wrote: > > [snip] > > > > I am hoping for a link to a somewhat comprehensive online resource > > that explains from the beginning in English, plain English, as this is > > the only language I speak. Something to get my foot in the door would > > be awesome. > > > > > > Cheers, > > Doug Marvel > > When I started out I used Alan Gauld's wonderful tutor: > http://www.alan-g.me.uk/tutor/index.htm > > It references Python 2.3, but the same things apply for 2.6 as well. > What I like about that site is that it doesn't skip anything, and goes > into more advanced topics at the end. I'll second his tutorial - it's great for the beginner *and* he also happens to contribute to/moderate this list. The best thing to do is pick a tutorial (like Alan's, perhaps) and start working through it. When you hit a wall, and can't figure out what something is doing, send an email. Often, just the act of trying to phrase your question will end out giving you the insight you need. I can't tell you how many dozens of emails I've started and then discarded because I ended out figuring it out on my own. If you show that you've worked on a problem, but you simply got stuck, you'll find that *many* people on this list will offer *tons* of good advice. HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print "Hello, World!"
Hey doug please don't be discouraged..., and be glad you didn't start in C++ like me... talk about being discouraged... But anyways, I just started as well. I've only been programming like 5 months. So I understand you very much :) Here are some of the better (more clear) tutorials I ran across in my short stint as a programmer. Here is the tutorial I used the most. How to think like a computer scientist (python version). This tells you stuff, then it gives you practice problems to reinforce what you just learned. (There are no answers to the problems, but this actually helped me learn a lot by researching the answers). http://openbookproject.net/thinkcs/python/english2e/index.html Bucky's youtube tutorials, in here he comments as he shows you some concepts then talks about them. He teaches python in normal english, its not technical at all, its very good :) http://www.youtube.com/user/thenewboston#p/c/0/4Mf0h3HphEA And I'm 26... so you are a million years ahead of me :) One piece of advice I can give is abuse google, almost any question you have has already been asked, learn from others who asked before you :) Oh yea, I once read that there are no intermediate tutorials in any programming language, because once you get past the basics, you only need to reference the "documentation" that comes with the language. I hope this helps. What is it about you... that intrigues me so? From: Doug Marvel To: tutor@python.org Sent: Wed, February 2, 2011 9:00:47 PM Subject: [Tutor] print "Hello, World!" Hey folks, I'm Doug. I've been using computers since second grade, and I know a little about them. I am, however, completely new to programming. I don't even know what I know about it. I'd like some social interaction with this, but I can't go back to school until summer or fall of this year. I don't want to wait to start learning this as I feel like I'm already about a million years behind. I asked the Oracle (www.google.com) and after messing around with the Python Shell and getting a lot of error messages, I decided I need some remote help. Here's where I'm at: - I have downloaded and installed Python 2.6.4. Successfully, I think. - I am running Windows XP SP3 (though I'm going to see if I can do this on my laptop, which has Windows 7) - I have toyed around with some tutorials, but all they really taught me is that I need a teacher. I'm sure you guys are busy, but I read that the most basic questions are okay. As I'm sure there is at least one good resource on the net for people in my position, I'd like some suggestions on where to start. I plan on bothering you all as little as possible, but I am seriously hoping to make real progress between now and my first class. I have a feeling once I get a basic understanding, I'll run away with it. It's just very... big right now. So this list seems like a good thing, but tell me if I'm in the wrong place. I am hoping for a link to a somewhat comprehensive online resource that explains from the beginning in English, plain English, as this is the only language I speak. Something to get my foot in the door would be awesome. Cheers, Doug Marvel ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] byte array conversion question
I have found that there are a couple of ways to convert a byte array to a string in Python. Is there any advantage or disadvantage to either method? my_bytes = b'this is a test' str(my_bytes,'utf-8') yields 'this is a test' my_bytes.decode('utf-8';) yeilds 'this is a test' --Bill ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] System of ODEs Question
So I'm in the process of learning Python, and have been working on a program to solve a very simple S-I-R model, used to study infectious diseases. Basically, it's just a smallish set of differential equations which need to be numerically integrated over time. Working off of a template program, I came up with the following: --- #Python implementation of continuous SIR model #Import Necessary Modules import numpy as np import pylab as pl import scipy.integrate as spi #Parameter Values S0 = 0.9 I0 = 0.1 R0 = 0.0 PopIn= (S0, I0, R0) beta=1.4547 gamma=1/7. t_end = 70 t_start = 1 t_step = 1 t_interval = np.arange(t_start, t_end, t_step) def eq_system(PopIn,x): '''Defining SIR System of Equations''' #Creating an array of equations Eqs= np.zeros((3)) Eqs[0]= -beta * PopIn[0]*PopIn[1] Eqs[1]= beta * PopIn[0]*PopIn[1] - gamma*PopIn[1] Eqs[2]= gamma*PopIn[1] return Eqs SIR = spi.odeint(eq_system, PopIn, t_interval) print SIR #Plot Everything #This is really ugly, but works for now pl.plot(SIR[:,0]) pl.plot(SIR[:,1]) pl.plot(SIR[:,2]) pl.show() --- The part that is confusing me is defining the function. Namely, it seems to need two arguments - the first needs to be the initial states of the population being modeled, but the second...it doesn't seem to matter what it is. Originally, I didn't include it at all, and the program was very, very unhappy - looking back at the example, it had a second argument, so I put one in, and magically, it worked. But it can be x, it can be t, it can be anything. Which raises the question: What is it *doing*? Honestly, I'm baffled - can anyone point me in the right direction? Thanks, Eric ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print "Hello, World!"
Seven years ago, my story was similar. I started off with "The Python Quick Book" (Manning) and "Python - Visual Quickstart Guide" (Peachpit Press). Both are very easy to follow. I still pick up the "Quick" book once in a while for reference. This "Tutor" list helped a lot. I learned by trying out the things people offered as solutions to problems from people like you and me. Asking questions here is a way to help a lot of new Python programmers, and a few older ones, too. There are a lot more resources these days, too. Search on "Python" in YouTube. There are a lot of on-line tutorials, too. - Original Message - From: "Doug Marvel" To: Sent: Wednesday, February 02, 2011 6:00 PM Subject: [Tutor] print "Hello, World!" Hey folks, I'm Doug. I've been using computers since second grade, and I know a little about them. I am, however, completely new to programming. I don't even know what I know about it. I'd like some social interaction with this, but I can't go back to school until summer or fall of this year. I don't want to wait to start learning this as I feel like I'm already about a million years behind. I asked the Oracle (www.google.com) and after messing around with the Python Shell and getting a lot of error messages, I decided I need some remote help. Here's where I'm at: - I have downloaded and installed Python 2.6.4. Successfully, I think. - I am running Windows XP SP3 (though I'm going to see if I can do this on my laptop, which has Windows 7) - I have toyed around with some tutorials, but all they really taught me is that I need a teacher. I'm sure you guys are busy, but I read that the most basic questions are okay. As I'm sure there is at least one good resource on the net for people in my position, I'd like some suggestions on where to start. I plan on bothering you all as little as possible, but I am seriously hoping to make real progress between now and my first class. I have a feeling once I get a basic understanding, I'll run away with it. It's just very... big right now. So this list seems like a good thing, but tell me if I'm in the wrong place. I am hoping for a link to a somewhat comprehensive online resource that explains from the beginning in English, plain English, as this is the only language I speak. Something to get my foot in the door would be awesome. Cheers, Doug Marvel ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor