2018-10-26
阅读量:
978
txt文件处理方法
a [[ 2.49870000e-01
2.50250000e-01
[ 3.64260000e+03
3.72430000e+03
[ 4.53960000e+03
4.50590000e+03
...,
[ 4.74110000e+01
4.89660000e+01
[ 4.10930000e+01
4.20480000e+01
[ 1.83510000e+01
1.68250000e+01
a.shape (52, 500)
fp =
open('test.txt','r')
lines =
fp.readlines()
fp.close()
for
line in
lines:
username =
line.split(',')[0]
password =
line.split(',')[1]
注:第一句是以只读方式打开文本文件;第二个是读取所有行的数据(read:读取整个文件;readline:读取一行数据);最后一定要关闭文件。最终会返回一个列表,通过for循环可以一个个的读取其中的数据。如username,password。这时候通过split方法进行分割,最终可以得到username password,这样就可以在自动化里面做参数化了。
python读取CSV文件:
import
csv
date =csv.reader(open('test.csv','r'))
for
test in
date:
test
test[0]
注:需要先导入csv包,然后通过reader方法读取内容,最终会返回一个列表。想选择某一列数据,只需要制定列表下标即可python读取excel需要先安装xlrd模块
import
xlrd
book=xlrd.open_workbook(data_dirs()+'/system.xlsx')
sheet=book.sheet_by_index(0)
sheet.cell_value(0,2)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论