44问答网
所有问题
怎么用python读取txt文件里指定行的内容,并导入excel
如题所述
举报该问题
推荐答案 2015-09-02
指定行吗简单
使用readlines()
他会返回一个列表
一行是一个元素
比如
f=open('123.txt', 'r')
s=f.readlines()
#你想显示第几行就这样
#比如你想显示第n行
print s[n-1]
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://44.wendadaohang.com/zd/WKVV3KVZ3YGYGKZD3W.html
相似回答
怎么用python读取txt文件里指定行的内容,并导入excel
答:
1、
导入
模块 复制代码代码如下:import xlrd 2、打开
Excel文件读取
数据 复制代码代码如下:data = xlrd.open_workbook('
excel
.xls')3、
获取
一个工作表 ① table = data.sheets()[0] #通过索引顺序获取 ② table = data.sheet_by_index(0) #通过索引顺序获取 ③ table = data.sheet_by_n...
怎么用python读取txt文件里指定行的内容,并导入excel
答:
'''
获取文件
信息'''fi = open("data.
txt
")lines = fi.readlines()#
读取
身高大于170cmdata = []for human in lines: hinfo = human.split() if hinfo: if int(hinfo[1][:3]) >= 170: data.append(tuple(hinfo))'''写入
excel
'''import xlwt# 创建workbook和sheet对象workb...
怎么用python读取txt文件里指定行的内容,并导入excel
?
答:
li = [] #定义一个空列表 blod = workbook.add_format({"bold":True})#定义exlce中写入的字体with open("D:\\Program Files\\subpy\\tets.txt",'r') as f1:#打开
txt文档
lines = f1.readlines()#
读取
所有
行内容
n = -1#定义一个变量 for x in lines:#逐行读取 n=n+1 li.append...
怎么用python读取txt文件里指定行的内容,并导入excel
答:
建议使用下面的方法。由于linecache会缓存,所以对大文件可以使用自己简单是实现getline如下:
Python
code def getline(the
file
path, desired_line_number): if desired_line_number < 1: return '' for current_line_number, line in enumerate(open(thefilepath, 'rU')): if current_line_number ==...
大家正在搜
python读取文件夹里多个文件
python读取指定内容行
python读取文件特定内容
python读取指定路径文件
python从文件中读取内容
python循环读取文件内容
python读取文件第n行
python读取csv指定行
python打开指定路径下的文件
相关问题
怎么用python读取txt文件里指定行的内容,并导入exc...
怎么用python语言将txt文件的内容,导入excel中
怎么用python读取txt文件里指定行的内容,并导入exc...
怎么用python读取txt文件里指定行的内容,并导入exc...
怎么用python读取txt文件里指定行的内容,并导入exc...
怎么用python读取txt文件里指定行的内容,并导入exc...
怎么用python读取txt文件里指定行的内容,并导入exc...
怎么用python读取txt文件里指定行的内容,并导入exc...