Re: [Tutor] _next
Dave Kuhlman schreef: > Roel Schroeven fastmail.fm> writes: > Kent Johnson alerted me to this discussion. > > And, thanks, Roel, for the comments and improvements on my example. > > I agree that my example class being discussed is confused. I've reworked the > example, taking hints from this thread. And, while I was there, I've > re-written > the whole section on iterators. Hopefully, I've made it less (rather than > more) > confusing. You can find the new version here: > > http://www.rexx.com/~dkuhlman/python_101/python_101.html > http://www.rexx.com/~dkuhlman/python_101/python_101. > html#SECTION00446 I think it is quite clear now; it certainly gives a nice overview of all the different ways of creating iterators. It might be a bit overwhelming for beginners though. > You may be wondering why I would spend so much time on what seems to be a > little > used and advanced technique. After all, iterators cannot be too important, > since they did not even make it into Python until Python 2.2. The answer I > give > myself is that this Python feature is very powerful and very elegant. It > also > gives us the ability to write clearer and more maintainable code, for > example, > separating the producer and consumer parts of our code. But, it does so only > if > we can work out a clear and unconfused way to explain and teach it. Thanks > for > motivating me to try to do that. I agree that iterators are an important language feature, but as I said it might be a bit too much information to digest at once. I know I didn't learn the iterator protocol until after I gained some experience in Python. OTOH, that might just be because it wasn't mentioned in the tutorial I used (the official one), so maybe it's a good thing that it's clearly explained in your tutorial. I think comments from people who use the tutorial to learn Python are more appropriate than mine in this regard. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] XML Parsing Woes.
Having been dragged kicking and screaming into the fussy, fussy world of XML, I find myself in a pickle. I keep getting an error complaining of a missing end-tag: : XML Parse error. XML Error Text: "; nested exception is: org.xml.sax.SAXParseException: The element type "Description" must be terminated by the matching end-tag "".". Now of course, I have saved my output and found the end-tag to be there. I have stripped out everything I can think of that might cause the parser to puke. The string enclosed by the tags varies from a few characters to a couple of thousand: all fail with the same error. I am very new to XML and find it's jargon fairly impenetrable. Is there a handy python module that can one can use to scan XML output for errors? I know the mistake is probably mine ... or perhaps I have actually run on to a bug in the remote application? :-) (Right!) Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XML Parsing Woes.
doug shawhan wrote: > Having been dragged kicking and screaming into the fussy, fussy world of > XML, I find myself in a pickle. > > I keep getting an error complaining of a missing end-tag: > > : XML Parse error. > XML Error Text: "; nested exception is: > org.xml.sax.SAXParseException: The element type "Description" > must be terminated by the matching end-tag "".". > > Now of course, I have saved my output and found the end-tag to be there. > I have stripped out everything I can think of that might cause the > parser to puke. The string enclosed by the tags varies > from a few characters to a couple of thousand: all fail with the same error. > > I am very new to XML and find it's jargon fairly impenetrable. Is there > a handy python module that can one can use to scan XML output for > errors? I know the mistake is probably mine ... or perhaps I have > actually run on to a bug in the remote application? :-) (Right!) Both Internet Explorer and Firefox do a good job of displaying XML and showing any errors. XML tags are case sensitive, make sure the case matches on the start and end tags. And of course spelling counts ;) XML tags must nest properly, both of these will cause an error, one of them possibly the error you are seeing: textmore text textmore text If you are just starting with Python and XML do yourself a favor and use ElementTreee instead of the stuff in the standard lib. http://effbot.org/zone/element.htm HTH Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Another fine mess
All, I posted some time back for another task. Have a new task now. You were all so kind with advice that I thought I might check my thoughts on this. Being an old guy and a newbie to Python is the double-whammy, but here goes: I get a CSV file with ~26 fields and ~7000 records. This data needs to be parsed based on specific field values. So, here is my "draft" set of steps that I think need to be performed. 1. Select the "file" of data 2. Clean the data with "strip" to make sure there is no extraneous whitespace 3. Write the file back to a temp file. 4. On the new file, select records based on the value of some of the fields (like a "sort on" in a spreadsheet. 5. Parse to obtain the matching records 6. Do a little math based on how many records and the data in one field (success vs. fail) 7. Output the results of the math so it can be used in a spreadsheet to make cute graphics. We have a PERL guy in the division, but I am trying to use Python only to get this done. My question is "What is a good way to read and process the lines of the CSV file?" Do I pull them in one line at a time and write them to an output file? Do I read the whole shebang, clean the data and write an output file, then re-open the cleaned file? Thanking you all prematurely, Regards, Ralph ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Another fine mess
GNULinuxGeek wrote: > All, > > I posted some time back for another task. > > Have a new task now. You were all so kind with advice that I thought I > might check my thoughts on this. > > Being an old guy and a newbie to Python is the double-whammy, but here goes: > > I get a CSV file with ~26 fields and ~7000 records. This data needs to > be parsed based on specific field values. Do you know about the csv module? It will take care of all the parsing and turn each line into a list of values. You can filter these as you like and make a list of lists of row values. This can be sorted and otherwise processed. I don't think you will need a temp file, it sounds like you can easily fit your data in memory. Kent > > So, here is my "draft" set of steps that I think need to be performed. > >1. Select the "file" of data >2. Clean the data with "strip" to make sure there is no extraneous > whitespace >3. Write the file back to a temp file. >4. On the new file, select records based on the value of some of the > fields (like a "sort on" in a spreadsheet. >5. Parse to obtain the matching records >6. Do a little math based on how many records and the data in one > field (success vs. fail) >7. Output the results of the math so it can be used in a spreadsheet > to make cute graphics. > > We have a PERL guy in the division, but I am trying to use Python only > to get this done. My question is > > "What is a good way to read and process the lines of the CSV file?" > Do I pull them in one line at a time and write them to an output file? > Do I read the whole shebang, clean the data and write an output file, > then re-open the cleaned file? > > > Thanking you all prematurely, > > Regards, > > Ralph > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor