当前位置:网站首页>(mixed version 1) multiple TXT text to one table
(mixed version 1) multiple TXT text to one table
2022-07-01 12:15:00 【Programmers who don't like coding】
import xlwt
import os
xls = xlwt.Workbook()
def sort_fun(x):
return len(x)
def txt_xls_v2(filepath, xlspath, sort=True):
""" Multiple txt Text to one xls :param filename: txt Text path :param xlsname: xls route :return: """
try:
filename = os.path.basename(filepath).replace("- corpus -url.txt", "")
f = open(filepath, 'r', encoding='utf-8')
lines = f.readlines()
if sort:
lines.sort(key=sort_fun)
sheet = xls.add_sheet(filename, cell_overwrite_ok=True)
for index, line in enumerate(lines):
# Write here as needed
# Press the line to cycle , Read text file
# for i in range(len(line.split('\t'))):
# item = line.split('\t')[i]
# sheet.write(x, i, item)
item = line.split('\t')[-1]
sheet.write(index, 0, item)
f.close()
xls.save(xlspath) # preservation xls file
except:
raise
if __name__ == "__main__":
dir_path = r"G:\20220623\ test "
xlsname = os.path.join(dir_path, os.path.basename(dir_path) + ".xls") # Multiple txt Save to a xls Preservation and naming
for root, dirs, files in os.walk(dir_path):
for file in files:
if file.endswith(".txt"):
file_path = os.path.join(root, file)
txt_xls_v2(file_path, xlsname)
边栏推荐
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
- Mechanism and type of CPU context switch
- 双链表有关操作
- [20211129] configuration du serveur distant du carnet de notes jupyter
- LeetCode 454. 四数相加 II
- 比特熊直播间一周年,英雄集结令!邀你来合影!
- What are the PHP FPM configuration parameters
- 91. (cesium chapter) cesium rocket launch simulation
- 241. Design priority for operational expressions: DFS application questions
- 研发效能度量框架解读
猜你喜欢

迅为i.MX8Mmini开发板离线构建Yocto系统

Acly and metabolic diseases
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4](/img/4f/bc6c39ef4f2d1c4bdad8420f7badac.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4
![[some notes]](/img/91/7657f90b50f012736579b1585b4ade.jpg)
[some notes]

91. (cesium chapter) cesium rocket launch simulation

Self organization is the two-way rush of managers and members

STM32 project practice (1) introduction and use of photosensitive resistor

The operation process of using sugar to make a large data visualization screen

Switch basic experiment

谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
随机推荐
fatal error: execution: 没有那个文件或目录
巩固-C#运算符
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
自定义 grpc 插件
研发效能度量框架解读
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
Mechanism and type of CPU context switch
On recursion and Fibonacci sequence
[speech signal processing] 3 speech signal visualization -- prosody
谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
Common chart usage of Bi tools
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
Mysql database knowledge collation
区间乘积的因子数之和——前缀和思想+定一移二
241. Design priority for operational expressions: DFS application questions
JS reverse | m3u8 data decryption of a spring and autumn network
The Missing Semester
Abbirb120 industrial robot mechanical zero position
Botu V15 add GSD file
[shell programming] - shell introductory learning