I love learning math (*to some extent*) and CS theory; good literature, and the technology that provides me with all kinds of resources for those three: the web.
Hi, that's a great idea for a solution without csv methods! The csv module actually makes the job easier and the code more readable, though.
Using DictWriter is easy, after you open the file, you just create a "writer" object and write its header field names such as:
Reading the "before" file is also easy, after opening it, you create a "reader" object this time, and can read each row with a loop. For example, splitting the names might look like this:
Then, the writerow() method can be used for the writer object, passing a dictionary using the field names as keys.
One of the beautiful things in programming is that actually there are many ways for a solution, and elegance is mostly a matter of opinion. Thanks for sharing a different perspective.
And, thanks for an article idea, maybe I do a write-up some day on some basic csv methods :)
Cool, do that.
Matter of fact I used the writer-object for writing headers just like you.
writerow() I used like:
`for i in range(len(liste)//3):
writer.writerow({'first': liste[i*3], etc. .....})`
and the main difference is in handling the 'before'-part. I just created the list, no reader = csv.DictReader(before)
But many roads lead to Rome and I'd love to read your piece on csv methods
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, that's a great idea for a solution without csv methods! The
csv
module actually makes the job easier and the code more readable, though.Using
DictWriter
is easy, after you open the file, you just create a "writer" object and write its header field names such as:Reading the "before" file is also easy, after opening it, you create a "reader" object this time, and can read each row with a loop. For example, splitting the names might look like this:
Then, the
writerow()
method can be used for the writer object, passing a dictionary using the field names as keys.One of the beautiful things in programming is that actually there are many ways for a solution, and elegance is mostly a matter of opinion. Thanks for sharing a different perspective.
And, thanks for an article idea, maybe I do a write-up some day on some basic csv methods :)
Cool, do that.
Matter of fact I used the writer-object for writing headers just like you.
writerow() I used like:
and the main difference is in handling the 'before'-part. I just created the list, no
reader = csv.DictReader(before)
But many roads lead to Rome and I'd love to read your piece on csv methods