- 论坛徽章:
- 0
|
两个文件的组合问题,急!
用 Python
- %cat b.txt
- schedule = no_phone | online | offline | absence
- mobile-phone = no_plan | meeting | away | biz_trip |bye-bye
- location = china | japan | america | england
- %cat t.py
- import sys,os,random
- a=open("a.txt")
- b=open("b.txt")
- lines_a = a.readlines()
- lines_b = b.readlines()
- header= [ (s.split("=")[0].strip(), s.split("=")[1].split('|')) for s in lines_b]
- for x in lines_a:
- for h in header:
- c = " ".join((x[:-1], h[0],h[1][random.randrange(len(h[1]))]))
- c = c.replace('\n','')
- print c
- %python t.py
- xudb@asg.com schedule online
- xudb@asg.com mobile-phone no_plan
- xudb@asg.com location america
- fengjw@asg.com schedule no_phone
- fengjw@asg.com mobile-phone bye-bye
- fengjw@asg.com location england
- lusixi@asg.com schedule offline
- lusixi@asg.com mobile-phone away
- lusixi@asg.com location japan
复制代码 |
|