my_list = [ 'f5213095324 master/ActiveMasterManager.java (Michael Stack 2010-08-31 23:51:44 +0000 1) /**', 'f5213095324 master/ActiveMasterManager.java (Michael Stack 2010-08-31 23:51:44 +0000 2) *', 'f5213095324 master/ActiveMasterManager.java (Michael Stack 2010-08-31 23:51:44 +0000 3) * Licensed to the Apache Software Foundation (ASF) under one', 'f5213095324 master/ActiveMasterManager.java (Michael Stack 2010-08-31 23:51:44 +0000 4) * or more contributor license agreements.', 'd6ed1130d51 master/ActiveMasterManager.java (Michael Stack 2011-04-28 19:51:25 +0000 281) }' ] import re import csv from time import sleep def SpaceToDelimit(Str, orig, new, Nright): li = Str.rsplit(orig, Nright) return new.join(li) def nth_repl(s, sub, repl, nth): find = s.find(sub) # if find is not p1 we have found at least one match for the substring i = find != -1 # loop util we find the nth or we find no match while find != -1 and i != nth: # find + 1 means we start at the last match start index + 1 find = s.find(sub, find + 1) i += 1 # if i is equal to nth we found nth matches so replace if i == nth: return s[:find]+repl+s[find + len(sub):] return s spamreader = csv.reader(my_list, delimiter='\t', quotechar='|') print "commit_id | filename | committer | date | time | line_number | code " print "-------------------------------------------------------------------------------------------------------------" for row in spamreader: row = str(row) row = re.sub(' +',' ',row) sleep(1) rowz = (''.join(row)) nl= rowz[2:-3] nl = nl.replace(" ", " | ", 8); nl = nl.replace("(",""); nl = nl.replace(")","") TEXT = nth_repl(nl, " | ", " ", 3) print TEXT
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question