Re: Processing text using python

2006-02-20 Thread Alex Martelli
Xavier Morel <[EMAIL PROTECTED]> wrote: > Fredrik Lundh wrote: > > did you read the string chapter in the tutorial ? > > > > http://docs.python.org/tut/node5.html#SECTION00512 > > > > around the middle of that chapter, there's a section on slicing: > > > > "substrings can be

Re: Processing text using python

2006-02-20 Thread Xavier Morel
Fredrik Lundh wrote: > did you read the string chapter in the tutorial ? > > http://docs.python.org/tut/node5.html#SECTION00512 > > around the middle of that chapter, there's a section on slicing: > > "substrings can be specified with the slice notation: two indices > sep

Re: Processing text using python

2006-02-20 Thread plahey
Hi, you have plenty of good responses. I thought I would add one more: def data_iter(file_name): data = file(file_name) while True: value = data.read(3) if not value: break yield value data.close() With the above, you can grab the entire data set

Re: Processing text using python

2006-02-20 Thread [EMAIL PROTECTED]
Sure. There's probably a thousand ways to do this. -- http://mail.python.org/mailman/listinfo/python-list

Re: Processing text using python

2006-02-20 Thread Gerard Flanagan
nuttydevil wrote: > Hey everyone! I'm hoping someone will be able to help me, cause I > haven't had success searching on the web so far... I have large chunks > of text ( all in a long string) that are currently all in separate > notebook files. I want to use python to read these strings of text, >

Re: Processing text using python

2006-02-20 Thread John Zenger
If you have already read the string into memory and want a convenient way to loop through it 3 characters at a time, check out the "batch" recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279 It uses itertools to make an iterator over the string, returning 3 characters at a ti

Re: Processing text using python

2006-02-20 Thread Fredrik Lundh
"nuttydevil" <[EMAIL PROTECTED]> wrote: > Hey everyone! I'm hoping someone will be able to help me, cause I > haven't had success searching on the web so far... I have large chunks > of text ( all in a long string) that are currently all in separate > notebook files. I want to use python to read t

Re: Processing text using python

2006-02-20 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I think this is what you want: > > file = open(r'c:/test.txt','r') > > c = file.read(3) > while c: > print c > c = file.read(3) > > file.close(); Or: def read3(): return file.read(3) for chars in iter(read3, ''): ... do something

Re: Processing text using python

2006-02-20 Thread [EMAIL PROTECTED]
I think this is what you want: file = open(r'c:/test.txt','r') c = file.read(3) while c: print c c = file.read(3) file.close(); -- http://mail.python.org/mailman/listinfo/python-list

Re: Processing text using python

2006-02-20 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "nuttydevil" <[EMAIL PROTECTED]> wrote: > Hey everyone! I'm hoping someone will be able to help me, cause I > haven't had success searching on the web so far... I have large chunks > of text ( all in a long string) that are currently all in separate > notebook file

Re: Processing text using python

2006-02-20 Thread Xavier Morel
nuttydevil wrote: > Hey everyone! I'm hoping someone will be able to help me, cause I > haven't had success searching on the web so far... I have large chunks > of text ( all in a long string) that are currently all in separate > notebook files. I want to use python to read these strings of text, >

Re: Processing text using python

2006-02-20 Thread Alex Martelli
nuttydevil <[EMAIL PROTECTED]> wrote: > Hey everyone! I'm hoping someone will be able to help me, cause I > haven't had success searching on the web so far... I have large chunks > of text ( all in a long string) that are currently all in separate > notebook files. I want to use python to read the