我的第一个python实用程序
今天需要处理一些数据,试着用python写了一个脚本来处理 ^^
----------------------------------------------------------
需要把文件:
200000000000101,0,0,2000,0,0,500,1500,3800,1000
200000000000102,0,0,2000,0,0,500,1500,3800,1000
...
处理成:
200000000000101,0, 010101103,0
200000000000101,1, 010101210,0
200000000000101,2, 010101221,2000
200000000000101,3, 010101240,0
200000000000101,4, 010101250,0
200000000000101,5, 010101914,500
200000000000101,6, 010101340,1500
200000000000101,7, 010101341,3800
200000000000101,8, 010101905,1000
200000000000102,0, 010101103,0
200000000000102,1, 010101210,0
200000000000102,2, 010101221,2000
200000000000102,3, 010101240,0
...
(格式:套餐id, 序列号, 子业务标志, 收取的费用)
----------------------------------------------------------
#!/usr/bin/python
# Filename: format.py
# -*- coding: utf-8 -*-
# string5字段, 依次为 idd, 来电显示 010101210 , ...
subsvc = ['010101103', '010101210', '010101221', '010101240', '010101250', '010101914', '010101340', '010101341', '010101905']
myfile = open("prcpln.txt")
myfile.seek(0)
str = myfile.read()
for line in str.split('\n'):
ss = line.split(',', 1)
vv = ss[1].split(',')
for i in range(len(vv)):
#套餐id, 序列号, 子业务标志, 收取的费用
print ss[0] + ',' + repr(i) + ',' + subsvc + ',' + vv
myfile.close()
--------------------------------------------
在cmd中执行 format.py > out.txt ^^