Processing text using python
Xavier Morel
xavier.morel at masklinn.net
Mon Feb 20 11:34:53 EST 2006
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,
> THREE CHARACTERS AT A TIME. (I'm studying the genetic code you see, so
> I need to read and analyse each sequence one codon at a time
> effectively.) Does anyone have any idea of how to do this using python?
>
>
> I'm going to be optimistic and thank you for your help in advance!
> Samantha.
>
Since you're reading from files, the "read" operation of file-like
objects takes an argument specifying the number of characters to read
from the stream e.g.
>>> f = file("stuff.txt")
>>> f.read(3)
'car'
>>> f.read(3)
'act'
>>> f.read()
'erization'
Would that be enough for what you need?
More information about the Python-list
mailing list