python参数Sample Code

import time
import datetime
import getopt
import sys

try:
  opts, args = getopt.getopt(sys.argv[1:], "ho:", ["inputOCR=", "inputSpeech="])
except getopt.GetoptError:
   print (‘Getopt Error!‘)
   sys.exit(1)

for name, value in opts:
    if name in ("-o"):
        outPath = value
        print(outPath)
    elif name in ("--inputOCR"):
        inputOCRPath = value
        print(inputOCRPath)
    elif name in ("--inputSpeech"):
        inputSpeechPath = value
        print(inputSpeechPath)

## cut contents to three parts[begin time] [end time] [txt]
def SplitFStr(strT):
    mm = []
    strT = strT[1:] #cut out str first char to end
    mm = strT.split(‘]‘, 2)
    listN = mm[0].split(‘-‘, 2)
    listN.append(mm[1])
    return listN

def mapper(line):
    pos = line.find(‘]‘)
    return "%s%s%s" % (line[0:pos+1], ‘[OCR]‘, line[pos+1:])

try:
    ListContents = []

    file = open(inputSpeechPath, ‘r+‘)
    ListContents = file.readlines()
    file.close()

    file = open(inputOCRPath, ‘r+‘)
    ListContentOCR = file.readlines()
    file.close()

    for item in ListContentOCR:
        itemT = mapper(item)
        ListContents.append(itemT)

    ListTotal = []
    for litem in ListContents:
        listC = SplitFStr(litem)
        t1 = time.strptime(listC[0], "%H:%M:%S")
        dictE = {‘time‘:t1, ‘txt‘:litem}
        ListTotal.append(dictE)

    def TimeSort(t):
       return t[‘time‘]

    ListSort = sorted(ListTotal, key = TimeSort)  

    fp = open(outPath, ‘w+‘)
    for lsitem in ListSort:
        fp.write(lsitem[‘txt‘])
    fp.close()
except IOError as err:
    print(‘File IO error: ‘ + str(err))

原文地址:https://www.cnblogs.com/jonky/p/10155555.html

时间: 2024-07-29 22:07:29

python参数Sample Code的相关文章

如何将经纬度利用Google Map API显示C# VS2005 Sample Code

原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上,这个做法有两种,最简单的就是直接传值到Google Maps上. 举例来说,当我们知道经纬度后,只要将数据套到以下网址即可. http://maps.google.com/maps?q=25.048346%2c121.516396 在参数q=后面,就可以加上经纬度了. 25.048346是Lati

Java vs. Python (1): Simple Code Examples

Some developers have claimed that Python is more productive than Java. It is dangerous to make such a claim, because it may take several days to prove that thoroughly. From a high level view, Java is statically typed, which means all variable names h

<转>Python 参数知识(变量前加星号的意义)

csdn上的牛人就是多,加油 —————————————————————————— 过量的参数 在运行时知道一个函数有什么参数,通常是不可能的.另一个情况是一个函数能操作很多对象.更有甚者,调用自身的函数变成一种api提供给可用的应用. 对于这些情况,python提供了两种特别的方法来定义函数的参数,允许函数接受过量的参数,不用显式声明参数.这些“额外”的参数下一步再解释. 注意args和kwargs只是python的约定.任何函数参数,你可以自己喜欢的方式命名,但是最好和python标准的惯用

Compilation of OpenGL Redbook sample code

http://download.csdn.net/detail/gflytu/4110817#comment [email protected]:~/Downloads/redbook$ gcc -lglut -lGL -lGLU aaindex.c aaindex.c:(.text+0x2f7): undefined reference to `glutInit'aaindex.c:(.text+0x303): undefined reference to `glutInitDisplayMo

Python参数基础

Python参数基础 位置参数 ? 通过位置进行匹配,把参数值传递给函数头部的参数名称,顺序从左到右 关键字参数 ? 调用的时候使用参数的变量名,采用name=value的形式 默认参数 ? 为没有传入值的参数之指定一个默认值,name=value的形式 可变参数 ? 以字符*开头收集任意多的参数 Keyword-only参数 ? 参数必须用带有关键字参数的名字 原文地址:https://www.cnblogs.com/SunQi-Tony/p/9240610.html

Python参数类型以及常见的坑

导语 ??由于之前遇到过几次有关于参数类型的坑,以及经常容易把一些参数类型搞混淆,现在做一下有关参数类型的总结记录以及对之前踩坑经历的分析. 参数类型 首先我们列举一下有关于Python的参数类型,以及实际上的运用和原理. 位置参数(必选参数) 默认参数 可变参数 关键字参数 位置参数(必选参数) 首先是位置参数,同时也被称作必选参数,位置参数很好理解,只要记住这点: 在函数定义时直接给定的此参数名称,调用时按照参数的位置顺序,依次赋予参数值. 示例: def person_info(name,

Python参数类型以及实现isOdd函数,isNum函数,multi函数,isPrime函数

Python参数类型以及实现isOdd函数,isNum函数,multi函数,isPrime函数 一.Python参数类型 形参:定义函数时的参数变量. 实参:调用函数时使用的参数变量. 参数传递的过程,就是把实参的引用传递给形参,使用实参的值来执行函数体的过程. 在 Python 中,函数的实参/返回值都是是靠引用来传递的. 在调用函数时,通常会传递参数,不同的参数处理不同的数据.一般有普通参数.默认参数.可变位置参数.可变关键字参数等. 1.普通参数:按照参数位置,依次传递参数. def ad

Python 参数设置

方式一:配置文件(ConfigParser模块) 方式二:解析参数(argparse模块) 1. 配置文件(ConfigParser模块) 1.1 ConfigParser简介 ConfigParser 是用来读取配置文件的包.配置文件的格式如下:中括号“[ ]”内包含的为section.section 下面为类似于key-value的options内容.例如 [db] db_host = 127.0.0.1 db_port = 22 db_user = root db_pass = rootr

python linecache source code

The source code of linecache.py from python 2.0 is here. from stat import * Get file information >>> filestat = os.stat('README.TXT') >>> filestat nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size