存储文本文件中的行 [英] Storing lines from a text file

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

问题描述

大家好。


我不确定问题有多难,但我知道我需要一些

帮助,如果你能给它。我想要做的是读取文本

文件中的行并将每行存储到变量中。我相信我可以使用

readlines()来读取各行,但是如何将每个

行存储到变量中以进行进一步分析?感谢任何和所有

建议。

-Tempo-

Hello everyone.

I am not sure how hard of a question is, but I do know that I need some
help if you can give it. What I want to do is read the lines in a text
file and store each line into a variable. I believe that I can use
readlines() to read the individual lines, but how would I store each
line into a variable for further analysis? Thanks for any and all
suggestions.
-Tempo-

推荐答案

br******* @ gmail.com 写道:
br*******@gmail.com wrote:
我不确定问题有多难,但我知道如果你能给它,我需要一些帮助。我想要做的是读取文本
文件中的行并将每行存储到变量中。我相信我可以使用
readlines()来读取各行,但是如何将每行
行存储到变量中以供进一步分析?感谢您提供任何和所有建议。
I am not sure how hard of a question is, but I do know that I need some
help if you can give it. What I want to do is read the lines in a text
file and store each line into a variable. I believe that I can use
readlines() to read the individual lines, but how would I store each
line into a variable for further analysis? Thanks for any and all
suggestions.




您是否有任何理由无法对从readlines获得的列表进行分析?


如果你坚持在各个变量中使用这些行,你可以直接使用$

正向序列解包:


a,b,c,d ,e = f.readlines()


< / F>



any reason you cannot do the analysis on the list you get from readlines ?

if you insist on having the lines in individual variables, you can use straight-
forward sequence unpacking:

a, b, c, d, e = f.readlines()

</F>


所以这个:

a,b,c,d,e = f.readlines()


...这会将第一行放入a,第二行放入b等等?当我不确定每次会有多少行

时,我如何实现这一目标?谢谢。

so this:
a, b, c, d, e =f.readlines()

...this will put the first line in a, second in b, etc? How do I
accomplish this when I''m not sure how many lines there are going to be
every time? Thanks.


br ******* @ gmail.com 写道:
所以这个:
a,b,c,d,e = f.readlines()

..这会将第一行放入a,第二行放入b等?当我不确定每次会有多少行时,我该如何实现这一目标呢?谢谢。
so this:
a, b, c, d, e =f.readlines()

..this will put the first line in a, second in b, etc? How do I
accomplish this when I''m not sure how many lines there are going to be
every time? Thanks.




有一个清单:
http://python.org/doc/2.4.2/tut/node...00000000000000


-Kirk McDonald



With a list:
http://python.org/doc/2.4.2/tut/node...00000000000000

-Kirk McDonald


这篇关于存储文本文件中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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