mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 14:01:15 +00:00
m
This commit is contained in:
parent
08fc973faf
commit
0750d4f75d
21
useful_scripts/lines_to_csv.py
Normal file
21
useful_scripts/lines_to_csv.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Sebastian Raschka 2014
|
||||||
|
# converts a 1-col input file into csv file
|
||||||
|
#
|
||||||
|
# Example input:
|
||||||
|
# 123
|
||||||
|
# 245
|
||||||
|
# 453
|
||||||
|
#
|
||||||
|
# Example output:
|
||||||
|
# 123,245,453
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
out_file = open('new.csv', 'w')
|
||||||
|
with open('in.txt', 'r') as in_file:
|
||||||
|
for line in in_file:
|
||||||
|
line = line.strip()
|
||||||
|
out_file.write(line + ',')
|
||||||
|
out_file.close()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user