python - how to remove the "/digit" numbers from output -
i need remove patch-set numbers output meaning remove "/digit" 1293927/2 1293929/3 ,i have shown expected output below,the output should shown below should of type list.. how split this?
sql_get = """select gerrit_id gerrits.gerrit_submit_table (si='%s' , component='%s' , release_bit = '0' , picked_bit = '0')"""%(si,component) #print sql_get rows = cursor.execute(sql_get) gerrits = cursor.fetchall() #print "gerrits" #print gerrits -->prints (('1293927/2',), ('1293929/2',)) print' '.join(item[0] item in gerrits).rstrip('\r\n') --> prints 1293927/2 1293929/2
output:-
1293927/2 1293929/2
expected output:-
1293927 1293929
use re
module.
import re print ' '.join(re.sub(r'/.*', '',item[0]) item in gerrits).rstrip('\r\n')
or
use string.split
function.
print ' '.join(item[0].split('/')[0] item in gerrits).rstrip('\r\n')
update:
l = [] item in gerrits: m = item[0].split('/')[0] l.append(m) print l
Comments
Post a Comment