解决方案 nuttydevil< sj *** @sucsex.ac.uk>写道: 大家好!我希望有人能够帮助我,因为我到目前为止还没有成功在网上搜索...我有大块的文本(全长在一个长字符串中) )目前都是单独的笔记本文件。我想用python来读取这些文本串,一次三个字符。 (我正在研究你看到的遗传密码,所以我需要有效地阅读和分析每个序列一个密码子。)有没有人知道如何使用python做到这一点? 打开每个文件并在循环中调用file.read(3),移动到下一个文件 当前当前文件耗尽时。这有什么部分给你 问题? Alex nuttydevil写道:大家好!我希望有人能够帮助我,因为我到目前为止还没有成功在网上搜索...我有大块的文本(全长在一个长字符串中) )目前都是单独的笔记本文件。我想用python来读取这些文本串,一次三个字符。 (我正在研究你看到的遗传密码,所以我需要有效地阅读和分析每个序列一个密码子。)有没有人知道如何使用python做到这一点? 我会乐观并且提前感谢你的帮助! Samantha。 因为你正在阅读文件,阅读类似文件的操作 对象接受一个参数,指定要从流中读取的字符数 ,例如 f = file(" stuff.txt") f.read(3)''car'''f.read(3) ''act''f.read() ''erization'' 这对你需要的是否足够? 在文章< 11 ******************** *@g43g2000cwa.googlegroups。 com>, " nuttydevil" < SJ *** @ sussex.ac.uk>写道: 大家好!我希望有人能够帮助我,因为我到目前为止还没有成功在网上搜索...我有大块的文本(全长在一个长字符串中) )目前都是单独的笔记本文件。我想用python来读取这些文本串,一次三个字符。 (我正在研究你看到的遗传密码,所以我需要有效地阅读和分析每个序列一个密码子。)有没有人知道如何使用python做到这一点? 不要重新发明轮子。请查看 http://www.biopython.org/ 。 Hey everyone! I''m hoping someone will be able to help me, cause Ihaven''t had success searching on the web so far... I have large chunksof text ( all in a long string) that are currently all in separatenotebook 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, soI need to read and analyse each sequence one codon at a timeeffectively.) 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. 解决方案 nuttydevil <sj***@sussex.ac.uk> 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?Open each file and call thefile.read(3) in a loop, move to the next filewhen the current one is exhausted. What part of this is giving youproblems?Alexnuttydevil 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-likeobjects takes an argument specifying the number of characters to readfrom 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?In article <11*********************@g43g2000cwa.googlegroups. com>,"nuttydevil" <sj***@sussex.ac.uk> 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?Don''t reinvent the wheel. Take a look at http://www.biopython.org/. 这篇关于使用python处理文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 12:01
查看更多