我有一个文本文件,其格式如下:
T timestamp
U username
W text
有没有办法在文本文件中创建tu和W为属性的对象?我只用Python编写过脚本,没有面向对象的东西,所以我有点迷路了。你知道吗
我需要解析这个巨大的文本文件,目前正在逐行读取该文件,查找“W”属性,但拥有整个对象可能更有用。你知道吗
编辑:看起来像这样
total number:18572084
T 2009-06-01 21:43:59
U http://twitter.com/burtonator
W No Post Title
T 2009-06-01 21:47:23
U http://twitter.com/burtonator
W No Post Title
T 2009-06-02 01:15:44
U http://twitter.com/burtonator
W No Post Title
T 2009-06-02 05:17:52
U http://twitter.com/burtonator
W No Post Title
您只需要一种方法,但这里有两种变体和单个文件读取函数,它不会一次读取整个文件(最多存储3-4行):
输入文件:
假设文档中的行是空格分隔的,您可以执行以下操作:
我喜欢卢克的回答,但在我看来,对于你的具体格式,你需要更像这样的东西:
相关问题 更多 >
编程相关推荐