SE211_CSV
CSV library for SE211
Set-up:
from Csv_Man import Csv_Man
CSV = Csv_Man.load({Your args})
To run the unit tests in the mock user file use the command line:
python User_File.py
This is the essence of the library. And no other setup is required.
load
can be called as many times as required.
Example:
A mock usage of the library can be seen in the test_mock_usage()
function.
In this function, it starts by loading a list of values with days of the week labelled in the column headers.
This could for example represent items sold on a given day.
In addition to this, there are columns used to hold operations and scalar values.
Lastly, there are empty columns that are to be filled by the program.
This is what the function does. By taking the information from the rest of the row, it calculates the missing information.
Once calculated, the final row serves as a full total for each day of the week for its respective column.
After all is written, a new file is created with the values filled in and a new delimiter.
Things to keep in mind: When setting values, only very minimal data-coercion when setting values. This means that it is up to the user to enter the correct types. For example, all inputs and outputs (when talking about data) should be strings. Or, in the case of non-atomic values, lists of strings. On write any data stored as something other than a string will be coerced to a string
A note on delimiters. The type of delimiter is dictate by what it delimits, not its placement. For example, if I have the CSV: 1,2,3; 4,5,6
The row delimiter is ;\n
because it delimits the rows and
the ,
is the col delimiter because it delimits the cols.
One last thing to keep in mind is delimiter collisions.
For example if the col delimiter is ,
do not save any data containing a ,
.
This is important when loading so that rows and columns are delimited correctly.
It is also important when saving because to cannot be loaded correctly in the future.