James said:
Is it posssible to update a field of CSV file using Fastercsv? For
example:
change a row [1,2,3,4] to [10,2,3,4].
Sure. You would do this as you would change any file. Here are the
steps:
1. Open the existing data for reading
2. Open a different file for writing
3. Copy over the content making changes as needed
4. Rename the new file to replace the old file
Hope that helps.
James Edward Gray II
Hi James,
Thank you very much.
One more question: Is this the same idea behind what we do with 'save'
or 'save as' in microsofte WORD or EXCEL?
An atomic save, as James suggested by the 4 steps above, is
essentially the same as a "Save" in Word or Excel.
A Save is just two "Save As" calls.
I've got a file called "A"
I make some changes to it, then
I save it as "B"
Once I am sure that my changes to "B" are okay, I save it as "A", to
replace the original file.
The reason we need to do things this way is that (at least in Ruby,
but in most languages I'd imagine), there isn't really a way to make a
change to a file while you're reading it.
So we read in the file, writing another file with our changes.
Then when we're done reading and writing, we replace the old file with
our new one. Conceptually, this ends up accomplishing the same thing,
it lets us make changes to a single file. The second file is just a
temporary file for doing work on.
Make sense?
-greg