# -*- 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. 解决Win10系统backgroundTaskHost占用cpu大

    打开照片应用后,点击左下角“设置”按钮,如下图

  2. 建maven私服nexus

    1.下载nexus 2.配置java环境 3.安装 C:\Program Files\nexus\nexus-2.11.4-01\bin\jsw\windows-x86-64 4.配置 http:// ...

  3. Linq to Entity调用存储过程【转】

    http://www.cnblogs.com/chenxizhang/archive/2010/01/03/1638201.html

  4. 30、java中递归算法

    1.已知有一个数列f(0)=1,f(1)=4,f(n+2)=2*f(n+1)+f(n),其中n是大于0的正数,求f(10)的值. 分析:设x=n+2 => f(x)=2*f(n-1)+f(n-2 ...

  5. linux too many open files报错

    修改方法:vi /etc/security/limits.conf  增加一行,如下: *       -       nofile          65535 修改vi /etc/ssh/sshd ...

  6. ls -lrt

    1,按照时间升序 命令:ls -lrt 详细解释: -l use a long listing format 以长列表方式显示(详细信息方式) -t sort by modification time ...

  7. DevExpress.XtraLayout.LayoutControl 动态添加控件

    // Create an item within a specified group,// bound to a specified data field with the specified edi ...

  8. nginx1.9+新增tcp/udp代理stream

    [root@rhel nginx-]# ./configure --help --help print this message --prefix=PATH set installation pref ...

  9. 【云栖大会】阿里巴巴集团CTO张建锋:用计算和数据去改变整个世界

    摘要: 当浩瀚的数字化信息能够联网在线,在万物互联网的新世界中,所有东西都可能有感知.变智能,想象一下电表.冰箱.心电图监测仪等设备的信息都能数字化并联网,从城市管理到个人生活,都会迎来翻天覆地的变化 ...

  10. PmExceptionController

    package main.java.com.zte.controller.system; import java.util.ArrayList; import java.util.List; impo ...