当前位置:网站首页>(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)
边栏推荐
- [20211129] configuration du serveur distant du carnet de notes jupyter
- Onenet Internet of things platform - mqtt product equipment upload data points
- [JS] interview questions
- GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
- Chen Gong: Micro service, is it still so pure?
- Self organization is the two-way rush of managers and members
- 消息队列之监控退款任务批处理过程
- 【datawhale202206】pyTorch推荐系统:召回模型 DSSM&YoutubeDNN
- 巩固-C#运算符
- 91. (chapitre Cesium) simulation de lancement de fusées cesium
猜你喜欢

Dlhsoft Kanban, Kanban component of WPF

双链表有关操作

The operation process of using sugar to make a large data visualization screen
![[20211129] jupyter notebook remote server configuration](/img/7c/79c9fcb91bde75e954dc3ecf9f5afd.png)
[20211129] jupyter notebook remote server configuration

91.(cesium篇)cesium火箭發射模擬

MQ prevent message loss and repeated consumption

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

Onenet Internet of things platform - the console sends commands to mqtt product devices

【datawhale202206】pyTorch推荐系统:召回模型 DSSM&YoutubeDNN

NOV Schedule for . Net to display and organize appointments and recurring events
随机推荐
【单片机】【数码管】数码管显示
[classic example] classic list questions @ list
Prepare for the Blue Bridge Cup Day10__ PWM control light brightness
Summary of JFrame knowledge points 1
Typora realizes automatic uploading of picture pasting
Friends day 2022
BIM and safety in road maintenance-buildSmart Spain
Botu V15 add GSD file
循环链表--
C knowledge point form summary 2
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
自定義 grpc 插件
Build yocto system offline for i.mx8mmini development board
Joint Time-Frequency and Time Domain Learning for Speech Enhancement
Summary of JFrame knowledge points 2
On recursion and Fibonacci sequence
Chen Gong: Micro service, is it still so pure?
Message queue monitoring refund task batch process
Emotion analysis based on IMDB comment data set
usb peripheral 驱动 - cable connect/disconnect