Re: Scanning a file character by character

2009-02-22 Thread rzed
Spacebar265 wrote in news:c86cd530-cee5-4de6-8e19-304c664c9...@c12g2000yqj.googlegroups.c om: > On Feb 11, 1:06 am, Duncan Booth > wrote: [...] >> >>> re.split("(\w+)", "The quick brown fox jumps, and falls >> >>> over.")[1::2] >> >> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', >

Re: Scanning a file character by character

2009-02-17 Thread Tim Chase
Josh Dukes wrote: In [401]: import shlex In [402]: shlex.split("""Joe went to 'the store' where he bought a "box of chocolates" and stuff.""") how's that work for ya? It works great if that's the desired behavior. However, the OP wrote about splitting the lines into separate words, not "

Re: Scanning a file character by character

2009-02-17 Thread Josh Dukes
In [401]: import shlex In [402]: shlex.split("""Joe went to 'the store' where he bought a "box of chocolates" and stuff.""") Out[402]: ['Joe', 'went', 'to', 'the store', 'where', 'he', 'bought', 'a', 'box of chocolates', 'and', 'stuff.'] how's that work for ya? http://docs.python.or

Re: Scanning a file character by character

2009-02-12 Thread Rhodri James
On Fri, 13 Feb 2009 03:24:21 -, Spacebar265 wrote: On Feb 11, 1:06 am, Duncan Booth wrote: Steven D'Aprano wrote: > On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: >> How would I do separate lines into words without scanning one character >> at a time? > Scan a line at a ti

Re: Scanning a file character by character

2009-02-12 Thread Spacebar265
On Feb 11, 1:06 am, Duncan Booth wrote: > Steven D'Aprano wrote: > > On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: > > >> How would I do separate lines into words without scanning one character > >> at a time? > > > Scan a line at a time, then split each line into words. > > > for line i

Re: Scanning a file character by character

2009-02-10 Thread MRAB
Steven D'Aprano wrote: On Tue, 10 Feb 2009 16:46:30 -0600, Tim Chase wrote: Or for a slightly less simple minded splitting you could try re.split: re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] Perhaps

Re: Scanning a file character by character

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 16:46:30 -0600, Tim Chase wrote: >>> Or for a slightly less simple minded splitting you could try re.split: >>> >> re.split("(\w+)", "The quick brown fox jumps, and falls >> over.")[1::2] >>> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] >> >> >> P

Re: Scanning a file character by character

2009-02-10 Thread Rhodri James
On Tue, 10 Feb 2009 22:02:57 -, Steven D'Aprano wrote: On Tue, 10 Feb 2009 12:06:06 +, Duncan Booth wrote: Steven D'Aprano wrote: On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: How would I do separate lines into words without scanning one character at a time? Scan a l

Re: Scanning a file character by character

2009-02-10 Thread Tim Chase
Or for a slightly less simple minded splitting you could try re.split: re.split("(\w+)", "The quick brown fox jumps, and falls over.")[1::2] ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls', 'over'] Perhaps I'm missing something, but the above regex does the exact same thing as line

Re: Scanning a file character by character

2009-02-10 Thread Steven D'Aprano
On Tue, 10 Feb 2009 12:06:06 +, Duncan Booth wrote: > Steven D'Aprano wrote: > >> On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: >> >>> How would I do separate lines into words without scanning one >>> character at a time? >> >> Scan a line at a time, then split each line into word

Re: Scanning a file character by character

2009-02-10 Thread Duncan Booth
Steven D'Aprano wrote: > On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: > >> How would I do separate lines into words without scanning one character >> at a time? > > Scan a line at a time, then split each line into words. > > > for line in open('myfile.txt'): > words = line.split

Re: Scanning a file character by character

2009-02-10 Thread Hendrik van Rooyen
"Spacebar265" wrote: >Thanks. How would I do separate lines into words without scanning one >character at a time? Type the following at the interactive prompt and see what happens: s = "This is a string composed of a few words and a newline\n" help(s.split) help(s.rstrip) help(s.strip) dir(s)

Re: Scanning a file character by character

2009-02-09 Thread Steven D'Aprano
On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote: > How would I do separate lines into words without scanning one character > at a time? Scan a line at a time, then split each line into words. for line in open('myfile.txt'): words = line.split() should work for a particularly simple-

Re: Scanning a file character by character

2009-02-09 Thread Spacebar265
On Feb 9, 5:13 pm, Steve Holden wrote: > Spacebar265 wrote: > > On Feb 7, 2:17 am, Jorgen Grahn wrote: > >> On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 > >> wrote: > >>> Hi. Does anyone know how to scan a filecharacterbycharacterand > >>> have eachcharacterso I can put it into a variab

Re: Scanning a file character by character

2009-02-08 Thread Steve Holden
Spacebar265 wrote: > On Feb 7, 2:17 am, Jorgen Grahn wrote: >> On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 >> wrote: >>> Hi. Does anyone know how to scan a filecharacterbycharacterand >>> have eachcharacterso I can put it into a variable. I am attempting >>> to make a chatbot and need t

Re: Scanning a file character by character

2009-02-08 Thread Spacebar265
On Feb 7, 2:17 am, Jorgen Grahn wrote: > On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 > wrote: > > Hi. Does anyone know how to scan a filecharacterbycharacterand > > have eachcharacterso I can put it into a variable. I am attempting > > to make a chatbot and need this to read the saved i

Re: Scanning a file character by character

2009-02-06 Thread Jorgen Grahn
On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 wrote: > Hi. Does anyone know how to scan a file character by character and > have each character so I can put it into a variable. I am attempting > to make a chatbot and need this to read the saved input to look for > spelling mistakes and fur

Re: Scanning a file character by character

2009-02-05 Thread Gabriel Genellina
En Thu, 05 Feb 2009 04:48:13 -0200, Spacebar265 escribió: Hi. Does anyone know how to scan a file character by character and have each character so I can put it into a variable. I am attempting to make a chatbot and need this to read the saved input to look for spelling mistakes and further ana

Re: Scanning a file character by character

2009-02-04 Thread Bard Aase
On 5 Feb, 07:48, Spacebar265 wrote: > Hi. Does anyone know how to scan a file character by character and > have each character so I can put it into a variable. I am attempting > to make a chatbot and need this to read the saved input to look for > spelling mistakes and further analysis of user inp

Scanning a file character by character

2009-02-04 Thread Spacebar265
Hi. Does anyone know how to scan a file character by character and have each character so I can put it into a variable. I am attempting to make a chatbot and need this to read the saved input to look for spelling mistakes and further analysis of user input. Thanks Spacebar265 -- http://mail.python.