with open(ur_infile) as fin:
    with open(ur_outfile, 'w') as fout:
        o = csv.writer(fout)
for line in fin:
    o.writerow(line.split())
Convert a space delimited file to comma separated values file in python