For our first exam we needed to make a program on any language that we want, which was ment to read a csv file and write to an other one. It sounds easy, but less than 10 students have done it. Maybe it’s because the time was very limited or maybe we were just not prepared for this. However no one from the 6 people that did it used java. This may be because java is a good OO language and for such sort task you need to write a lot lines just to make the code works properly, while the whole code on ruby is less than 10 lines.
Here’s the link to the task using ruby:
Here’s the link to the task using java:
Last thursday our programing teacher gave us homework to read from a .csv file and do something with the information. Our task was to read from a file where our name, Email and the number of the programs we have written was entered and get the summary of the programs that the whole class has written. It isn’t a hard task at first look, but when I started doing it I got across a lot of problems. Now I’m gonna explain to you how to read from a .CSV file using Python. First you need some basic Python knowledge. I can’t help you with that so you need to google “Python tutorial” and get into the language a bit.
First download Python:
Then you need to download CSV:
http://www.object-craft.com.au/projects/csv/download.html (download the latest one and extract the folder to your python directory)
When you have done this things you can start typing the code in. First you need to import CSV into the program by typing:
Afterthat open the file by using “file = open(“filename.csv”, ‘r’)” (It’s important to use ‘r’ instead of ‘rb’, because you’ll get that error: “_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) “)
The rest of the program is simple python code. However there are some thing that you need to know:
If you are using newer than python 2.6 you need to use “next(reader)” instead of “reader.next” which took me a lot time to understand. This right here is a simple tutorial on how to read .csv file with python:
And here is my program:
If you have any other questions feel free to ask! 🙂