# -*- coding: utf-8 -*-

import sys
import time CTRL_A='\x01'
CTRL_B='\x02'
thedate = ''
thetime = ''
sn = ''
asr = ''
intent = ''
nlp = ''
domain = '' def speechHandle(inputFile,outputFile):
print "********** speechHandle " + inputFile + " start **********"
try:
input = open(inputFile, 'r')
output = open(outputFile, 'a+')
while True:
line = input.readline()
if len(line.strip()) < 1:
break
fileds = line.split(CTRL_A)
fieldsLen = len(fileds)
if fieldsLen == 6:
for fIndex in range(0,6):
kv = fileds[fIndex].split(CTRL_B)
kvLen = len(kv)
if kvLen == 2:
if kv[0].strip()=='time':
unixtimestamp = kv[1]
timetmp = time.localtime(int(unixtimestamp)/1000)
thedate = time.strftime("%Y-%m-%d", timetmp)
thetime = time.strftime("%H:%M:%S", timetmp)
elif kv[0].strip()=='id':
sn = kv[1]
elif kv[0].strip()=='asr':
asr = kv[1]
elif kv[0].strip() == 'intent':
intent = kv[1].strip()
elif kv[0].strip() == 'domain':
domain = kv[1]
lineOut = thedate + CTRL_A + thetime + CTRL_A + sn + CTRL_A + asr + CTRL_A + intent + CTRL_A + domain + "\n"
output.write(lineOut)
else:
print line
except IOError as ioerr:
print 'File Error' + str(ioerr)
exit(-1)
finally:
input.close()
output.close() print "********** speechHandle " + inputFile + " end **********" if __name__ == '__main__':
if len(sys.argv) != 3:
print "Please input inputFile and outputFile"
else:
speechHandle(sys.argv[1], sys.argv[2])

供参考

Python以不可见字符作为列分割符的更多相关文章

  1. Android 用空格作为分割符切割字符串

    项目中有需要用到空格作为分割符切割字符串,进而转为List. String wordStore = edWord.getText().toString(); String[] word = wordS ...

  2. python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字

    python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字在字符串里面插入指定分割符的方法,先把字符串变成list然后用join方法变成字符串str=' ...

  3. python print输出unicode字符

    命令行提示符下,python print输出unicode字符时出现以下 UnicodeEncodeError: 'gbk' codec can't encode character '\u30fb ...

  4. Python核心编程--学习笔记--6--序列(上)字符串

    本章研究Python中的序列:字符串.列表和元组.因为这些类型其实都是由一些成员共同组成的一个序列整体,所以我们把它们统称为序列.序列的存储结构可以表示为: 1 序列 序列类型有着相同的访问模式:按下 ...

  5. python每次处理一个字符的三种方法

    python每次处理一个字符的三种方法 a_string = "abccdea" print 'the first' for c in a_string: print ord(c) ...

  6. Lua 用指定字符或字符串分割输入字符串,返回包含分割结果的数组

    // 用指定字符或字符串分割输入字符串,返回包含分割结果的数组 // @function [parent=#string] split // @param string input 输入字符串 // ...

  7. python之旅:字符编码

    一 了解字符编码的知识储备 一 计算机基础知识 知识储备:cpu.内存.硬盘 二 文本编辑器存取文件的原理(nodepad++,pycharm,word) #1.打开编辑器就打开了启动了一个进程,是在 ...

  8. php用explode,可以提供多个字符作为分割符来进行分割数组吗?

    explode — 使用一个字符串分割另一个字符串, 它的函数原型如下: array explode ( string $delimiter , string $string [, int $limi ...

  9. python中的格式化字符

    python中的格式化字符在python中我们会遇到一个问题,问题是如何输出格式化的字符串.我们经常会输出类似'亲爱的xxx你好!你xx月的话费是xx,余额是xx'之类的字符串,而xxx的内容都是根据 ...

随机推荐

  1. Hat’s Words(字典树)

    Problem Description A hat's word is a word in the dictionary that is the concatenation of exactly tw ...

  2. Java学习笔记五(多线程)

    1.介绍 线程可以使程序具有两条和两条以上的可运行的路径.尤其对多核CPU特别的重要. 2.创建线程 1.继承Thread类 一个类直接的继承Thread类的话,此类就具有了线程的能力,接下来仅仅须要 ...

  3. Python C/C++ 拓展使用接口库(build-in) ctypes 使用手册

    Python C/C++ 拓展使用接口库(build-in) ctypes 使用手册 ctypes 是一个Python 标准库中的一个库.为了实现调用 DLL,或者共享库等C数据类型而设计.它可以把这 ...

  4. 在浏览器中使用JS打开并展示PDF文件

    使用jquery.media.js插件 示例: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=& ...

  5. 华硕M2A-VM+AMD4000超频方法

    华硕M2A-VM+AMD4000超频方法2009-07-07 09:42 1.4000+默认外频为200,倍频已经锁定为10.5,实际运行频率为2100HZ.超频是通过提高外频来实现的,只要适当提高外 ...

  6. Java实现可视化迷宫

    代码地址如下:http://www.demodashi.com/demo/14547.html 需求 使用深度优先算法求解迷宫路径,使用Java实现求解过程的可视化,可单步运行,形象直观. 演示效果 ...

  7. POJ 3468 A Simple Problem with Integers 【树状数组】

    题目链接:id=3468">http://poj.org/problem?id=3468 题目大意:给出一组数组v[i],有两种操作,一种给出两个数a,b.要求输出v[a]到v[b]之 ...

  8. HDUOJ---Can you solve this equation?

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. iOS - Contacts 通讯录

    Contacts 通讯录 1.访问通讯录 设置系统访问通讯录权限 1.1 iOS 9.0 及 iOS 9.0 之后获取通讯录的方法 iOS 9.0 及 iOS 9.0 之后获取通讯录的方法 // 包含 ...

  10. SpringBoot优化内嵌的Tomcat ---设置MaxConnections

    使用kill -9杀掉springboot应用后,立马java -jar重启,会报错,需要等待一段时间才能启动成功,报错的原因是:/tmp/tomcat-docbase.474979491043437 ...