20221203使用python3处理Google翻译英文SRT格式字幕

20221203使用python3处理Google翻译英文SRT格式字幕

1、暂时不处理UNICODE编码的TXT,本例以ANSI编码的TXT为准。

2、将来处理自动处理目录中的全部TXT文件。(甚至递归处理子目录中的TXT文件)


源码:

#f_path=r'C:\Users\Admin\Desktop\shapenetcore_partanno_segmentation_benchmark_v0_normal_2\00000001\0.txt'
f_path=r'1.txt'

temp = 1
xuhao = 1;

with open(f_path) as f:
    lines = f.readlines()

for line in lines:
    if temp == 1:
        print(str(xuhao))
        temp=0
    else:
        if len(line) == 1:
            #print("jiangedian!")
            temp=1
            xuhao = xuhao+1
        print(line.rstrip())

 

 

 

过程:

百度搜索:python txt 处理


https://blog.csdn.net/qq_27353621/article/details/123901423
Python处理txt文件


with open(f_path) as f:
    lines = f.readlines()

for line in lines:
    print(line.rstrip())


https://blog.csdn.net/u012856866/article/details/120335219?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-4-120335219-blog-82150943.pc_relevant_aa2&spm=1001.2101.3001.4242.3&utm_relevant_index=7
https://blog.csdn.net/u012856866/article/details/120335219
python之txt文件基本操作


https://blog.csdn.net/qq_40123329/article/details/82150943?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-82150943-blog-127726720.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-82150943-blog-127726720.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=13
https://blog.csdn.net/qq_40123329/article/details/82150943
python数据分析之读写txt文件


百度搜索:python if else用法

https://www.jb51.net/article/187873.htm
python中if及if-else如何使用
 更新时间:2020年06月02日 14:47:41   作者:silencement

# Filename : test.py
# author by : www.runoob.com
 
# 用户输入数字
 
num = float(input("输入一个数字: "))
if num > 0:
  print("正数")
elif num == 0:
  print("零")
else:
  print("负数")

百度搜索:python 判断 空行
https://www.dovov.com/python-878.html
PYTHON:如何检查一行是否为空行


https://www.shuzhiduo.com/A/QW5YDY3OJm/
python 判断是否是空行或注释行

 #coding:utf-8
 '''''cdays-4-exercise-6.py 文件基本操作
     @note: 文件读取写入, 列表排序, 字符串操作
     @see: 字符串各方法可参考hekp(str)或Python在线文档http://docs.python.org/lib/string-methods.html
 '''  
 
 f = open('cdays-4-test.txt', 'r')                   #以读方式打开文件
 result = list()
 for line in f.readlines():                          #依次读取每行
     line = line.strip()                             #去掉每行头尾空白
     if not len(line) or line.startswith('#'):       #判断是否是空行或注释行
         continue                                    #是的话,跳过不处理
     result.append(line)                             #保存
 result.sort()                                       #排序结果
 print result
 open('cdays-4-result.txt', 'w').write('%s' % '\n'.join(result)) #保存入结果文件


https://blog.csdn.net/m0_64829783/article/details/123878734
[Python] 6个字符串常用判断方法


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值