From: Christopher R. <cro...@uo...> - 2007-07-31 04:20:23
|
Is there a preferred way to peek ahead in inputfile iterator? The problem I'm having is that the only way to tell if a section is over is if the next line is the start of the new section (ie, it starts with a $). I can think of one work around, which is to use tell() to get the starting position of the new line, and then seeking back to that point it if it is the end of the section. Please let me know if there a more elegant way to do this. Chris |
From: Noel O'B. <bao...@gm...> - 2007-07-31 09:27:09
|
I would say avoid peeking and seeking and all that. All you need to do is to make sure that the code for reading in the next section, follows the code for reading in this section, and that the name of the variable containing the "$" line is the same as the name of the variable that is used in the big loop over all lines (typically the variable name is "line"). Does this make sense? I've done this one before. Will this fit all cases? (i.e. do you always know the order of the sections). Clearly, it would be very helpful if you add comments indicating that the order of a particular section is important if you use this method. I see that you've uploaded some datafiles. Can you point to the specific example? Maybe I can think of some other way... Noel On 31/07/07, Christopher Rowley <cro...@uo...> wrote: > > > > > Is there a preferred way to peek ahead in inputfile iterator? The problem > I'm having is that the only way to tell if a section is over is if the next > line is the start of the new section (ie, it starts with a $). I can think > of one work around, which is to use tell() to get the starting position of > the new line, and then seeking back to that point it if it is the end of the > section. Please let me know if there a more elegant way to do this. > > > > Chris > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > cclib-devel mailing list > ccl...@li... > https://lists.sourceforge.net/lists/listinfo/cclib-devel > > |
From: Karol L. <kar...@kn...> - 2007-07-31 11:21:05
|
On Tuesday 31 July 2007 05:27, Noel O'Boyle wrote: > I would say avoid peeking and seeking and all that. All you need to do > is to make sure that the code for reading in the next section, follows > the code for reading in this section, and that the name of the > variable containing the "$" line is the same as the name of the > variable that is used in the big loop over all lines (typically the > variable name is "line"). Caring about the order of the sections works, and remember that the following section does not have to be directly after the first one in the code (since the conditions in between will not be fullfilled). I would recommend using a more explicit solution that is harder to break. In the first section set a unique flag if your special line is found. Then add "or <flag>" to the initial codnition of the second section. You will also need to add a condition for reading a new line (after the one with "$") in the second section, since it will have been read if the flag is set - so something like "if not <flag>: line = inputfile.next()" should be OK. I hope all that makes sense - I've also done something similar in the past. > Does this make sense? I've done this one before. Will this fit all > cases? (i.e. do you always know the order of the sections). Clearly, > it would be very helpful if you add comments indicating that the order > of a particular section is important if you use this method. If we break up the extract() method into a dictionary of functions as discussed before, there would be no problem with this, since you could just call the second method from within the first. After separating the parser and data object, i seems to me that the dictionary of functions i within grasp. > On 31/07/07, Christopher Rowley <cro...@uo...> wrote: > > Is there a preferred way to peek ahead in inputfile iterator? The problem > > I'm having is that the only way to tell if a section is over is if the > > next line is the start of the new section (ie, it starts with a $). I can > > think of one work around, which is to use tell() to get the starting > > position of the new line, and then seeking back to that point it if it is > > the end of the section. Please let me know if there a more elegant way to > > do this. -- written by Karol Langner Tue Jul 31 13:02:27 EDT 2007 |
From: Christopher R. <cro...@uo...> - 2007-07-31 18:45:54
|
I think I'll be able to make it work based on what you and others have suggested. I do believe it is a common enough problem, so it's something to keep in mind if the parser methodology is resigned at some point. Chris -----Original Message----- From: Noel O'Boyle [mailto:bao...@gm...] Sent: Tuesday, July 31, 2007 5:27 AM To: Christopher Rowley Cc: cclib-dev List Subject: Re: [cclib-devel] Peeking with iterator I would say avoid peeking and seeking and all that. All you need to do is to make sure that the code for reading in the next section, follows the code for reading in this section, and that the name of the variable containing the "$" line is the same as the name of the variable that is used in the big loop over all lines (typically the variable name is "line"). Does this make sense? I've done this one before. Will this fit all cases? (i.e. do you always know the order of the sections). Clearly, it would be very helpful if you add comments indicating that the order of a particular section is important if you use this method. I see that you've uploaded some datafiles. Can you point to the specific example? Maybe I can think of some other way... Noel On 31/07/07, Christopher Rowley <cro...@uo...> wrote: > > > > > Is there a preferred way to peek ahead in inputfile iterator? The problem > I'm having is that the only way to tell if a section is over is if the next > line is the start of the new section (ie, it starts with a $). I can think > of one work around, which is to use tell() to get the starting position of > the new line, and then seeking back to that point it if it is the end of the > section. Please let me know if there a more elegant way to do this. > > > > Chris > ------------------------------------------------------------------------ - > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > cclib-devel mailing list > ccl...@li... > https://lists.sourceforge.net/lists/listinfo/cclib-devel > > |