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',
>
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
"
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
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
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
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
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
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
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
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
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
"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)
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-
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
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
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
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
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
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
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.
20 matches
Mail list logo