Re: [Tutor] Finding a specific line in a body of text

2012-03-11 Thread Steven D'Aprano
On Mon, Mar 12, 2012 at 05:46:39AM +0100, Robert Sjoblom wrote: > > You haven't shown us the critical part: how are you getting the lines in > > the first place? > > Ah, yes -- > with open(address, "r", encoding="cp1252") as instream: > for line in instream: Seems reasonable. > > (Also, you

Re: [Tutor] Finding a specific line in a body of text

2012-03-11 Thread ian douglas
Erik Rise gave a good talk today at PyCon about a parsing library he's working on called Parsimonious. You could maybe look into what he's doing there, and see if that helps you any... Follow him on Twitter at @erikrose to see when his session's video is up. His session was named "Parsing Horrible

Re: [Tutor] Finding a specific line in a body of text

2012-03-11 Thread Robert Sjoblom
> You haven't shown us the critical part: how are you getting the lines in > the first place? Ah, yes -- with open(address, "r", encoding="cp1252") as instream: for line in instream: > (Also, you shouldn't shadow built-ins like list as you do above, unless > you know what you are doing. If yo

Re: [Tutor] question on self

2012-03-11 Thread Steve Willoughby
On 11-Mar-12 20:03, Steven D'Aprano wrote: On Sun, Mar 11, 2012 at 07:02:11PM -0700, Michael Lewis wrote: Why do I have to use "self.example" when calling a method inside a class? For example: def Play(self): '''find scores, reports winners''' self.scores = [] f

Re: [Tutor] Finding a specific line in a body of text

2012-03-11 Thread Steven D'Aprano
On Mon, Mar 12, 2012 at 02:56:36AM +0100, Robert Sjoblom wrote: > In the file I'm parsing, I'm looking for specific lines. I don't know > the content of these lines but I do know the content that appears two > lines before. As such I thought that maybe I'd flag for a found line > and then flag the

Re: [Tutor] question on self

2012-03-11 Thread Steven D'Aprano
On Sun, Mar 11, 2012 at 07:02:11PM -0700, Michael Lewis wrote: > Why do I have to use "self.example" when calling a method inside a class? > > For example: > > def Play(self): > '''find scores, reports winners''' > self.scores = [] > for player in range(self.players):

[Tutor] question on self

2012-03-11 Thread Michael Lewis
Why do I have to use "self.example" when calling a method inside a class? For example: def Play(self): '''find scores, reports winners''' self.scores = [] for player in range(self.players): print print 'Player', player + 1 self.score

[Tutor] Finding a specific line in a body of text

2012-03-11 Thread Robert Sjoblom
I'm sorry if the subject is vague, but I can't really explain it very well. I've been away from programming for a while now (I got a daughter and a year after that a son, so I've been busy with family matters). As such, my skills are definitely rusty. In the file I'm parsing, I'm looking for speci

Re: [Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-11 Thread Peter Otten
Steven D'Aprano wrote: > glyph. He shouldn't get a UnicodeDecodeError when printing. I smell a > bug since print shouldn't be decoding anything. (At worst, it needs to > *encode*.) You have correctly derived the actual traceback ;) [Robert] > It starts to print until it hits the wonderful charac

Re: [Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-11 Thread Peter Otten
Robert Sjoblom wrote: > Okay, so here's a fun one. Since I'm on a japanese locale my native > encoding is cp932. I was thinking of writing a parser for a bunch of > text files, but I stumbled on even printing the contents due to ... > something. I don't know what encoding the text file uses, which

Re: [Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

2012-03-11 Thread Steven D'Aprano
On Sat, Mar 10, 2012 at 08:03:18PM -0500, Dave Angel wrote: > There are just 256 possible characters in cp1252, and 256 in cp932. CP932 is also known as MS-KANJI or SHIFT-JIS (actually, one of many variants of SHIFT-JS). It is a multi-byte encoding, which means it has far more than 256 characte