Created
June 5, 2011 11:22
-
-
Save hheimbuerger/1008881 to your computer and use it in GitHub Desktop.
CSV conversion as in http://tux2323.blogspot.com/2011/06/convert-csv-file-in-groovy-java-or.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open('input.csv', 'rb') as input, open('output.csv', 'wb') as output: | |
reader = csv.reader(input, delimiter=';') | |
writer = csv.writer(output, delimiter=';') | |
for input_row in reader: | |
firstname, name, accno, bsc, amount = input_row | |
output_row = [name, '%s %s' % (firstname, name), accno, bsc, amount] | |
writer.writerow(output_row) | |
# For Jython 2.5, the context manager usage ('with') has to be replaced with a classic try..finally. | |
# For Python 3.x, the files have to be opened in text mode ('r', 'w') instead of binary mode ('rb', 'wb'). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment