随笔分类 -  Python

文本处理
Python list嵌套 三维数组
摘要:cores_multicast = [[] for i in xrange(64)]temp_list = [0, 1]temp_list2 = [0, 3]cores_multicast[0].append(temp_list)cores_multicast[0].append(temp_list2)print cores_multicastprint cores_multicast[0]print cores_multicast[0][0]print cores_multicast[0][0][0]print cores_multicast[0][0][1]>>> === 阅读全文
posted @ 2013-07-05 17:02 Samuel Yang 阅读(4717) 评论(0) 推荐(0)
Python 正则表达式 带分组的替换 \g<1> \g<2>
摘要:1 import re 2 p = re.compile(r'^(task_cnt\s)\S*\s\S$', re.M) 3 for i in range(0, 11): 4 filename = 'graph' + str(1000 + 100 * i) + '.tgffopt' 5 fp_o = open(filename, 'r') 6 all = fp_o.read() 7 fp_o.close 8 print all 9 fp_i = open(filename, 'w')10 ... 阅读全文
posted @ 2013-06-06 21:49 Samuel Yang 阅读(3841) 评论(0) 推荐(0)
Python 正则表达式 引入变量
摘要:正则表达式可以用拼接形式 (r' ' + str(i) + ' ') 来引入变量ipython hello.py fileopen.tgff 2找到fileopen.tgff 中符合 From t0_(\S*) TO t0_(\S*) 和 From t1_(\S*) TO t1_(\S*) 形式并提取group(1)和(2)分别写入文件t0.csv和t1.csv。#!/usr/bin/python#argv[1] is a filename; argv[2] is the number of graphimport re,sys,stringfp = open( 阅读全文
posted @ 2013-06-06 10:29 Samuel Yang 阅读(6914) 评论(0) 推荐(0)