使用python处理文本 [英] Processing text using python

查看:176
本文介绍了使用python处理文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家好!我希望有人能够帮助我,因为我

到目前为止还没有成功在网上搜索...我有大块

文本(所有在长字符串中)当前都在单独的

笔记本文件中。我想用python来读取这些文本字符串,

一次三个字符。 (我正在研究你看到的遗传密码,所以

我需要一次阅读和分析每个序列一个密码子

。)有没有人有任何想法如何使用python做到这一点?

我会乐观并且提前感谢你的帮助!

Samantha。

解决方案

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 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.

解决方案

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 file
when the current one is exhausted. What part of this is giving you
problems?
Alex


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?


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处理文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆