csvsimple
Very basic CSV utility for Python.
|
This class handles CSV data. More...
Public Member Functions | |
def | getDefaultFormater |
Return the default records' formater. | |
def | __init__ |
Create a CSV container. | |
def | add |
Add a record to the CSV container. | |
def | void |
Clear the CVS container. | |
def | select |
Select records fro the CSV container. | |
def | setFormater |
Set a function used to print records. | |
def | getFormater |
Return the function used to print records. | |
def | strs |
This method returns a list of strings. | |
def | getValue |
Get the value of a given column, for a given record. | |
def | __iter__ |
def | __next__ |
def | __len__ |
def | __getitem__ |
def | __setitem__ |
def | __delitem__ |
def | keys |
def | items |
def | values |
def | __str__ |
Static Public Attributes | |
int | EQUALITY = 1 |
Triggers selection via simple equality. | |
int | MATCH = 2 |
Triggers selection via pattern matching. | |
int | EXECUTE = 3 |
Triggers selection via function execution. |
This class handles CSV data.
This class "partially" implements the following interfaces:
csv = Csv(['id', 'first name', 'last name'])
csv.add([1, 'John', 'Carter'])
csv.add([2, 'John', 'Dupond'])
csv.add([3, 'John', 'XXXX'])
print ("%d" % len(csv))
record = csv[1]
del self.csv[1]
# Print all first names.
for record in csv: print (csv.getValue(record, 'first name'))
# Get all columns' names.
v = []
for c in csv.keys(): v.append(c)
# name: one column's name.
# value: all values for this column.
v = []
for name, value in csv.items(): v.append([name, value])
# v[0]: all value for column "id"
# v[1]: all value for column "first name"
# v[2]: all value for column "last name"
v = []
for value in csv.values(): v.append(value)
Definition at line 54 of file csvsimple.py.
def csvsimple::Csv::__init__ | ( | self, | |
in_header | |||
) |
Create a CSV container.
in_header | This list contains the names of the columns that define the CSV structure. |
Definition at line 101 of file csvsimple.py.
def csvsimple::Csv::add | ( | self, | |
in_record | |||
) |
Add a record to the CSV container.
in_record | This list contains the values to add. |
Definition at line 128 of file csvsimple.py.
def csvsimple::Csv::getDefaultFormater | ( | ) |
Return the default records' formater.
Definition at line 80 of file csvsimple.py.
def csvsimple::Csv::getFormater | ( | self | ) |
Return the function used to print records.
Definition at line 201 of file csvsimple.py.
def csvsimple::Csv::getValue | ( | self, | |
in_record, | |||
in_column_name | |||
) |
Get the value of a given column, for a given record.
in_record | The record. |
in_column_name | Name of the column. |
Definition at line 219 of file csvsimple.py.
def csvsimple::Csv::select | ( | self, | |
in_criterias = None , |
|||
in_action = 1 |
|||
) |
Select records fro the CSV container.
in_criterias | This dictionary contains selections' criterions.
|
in_action | This parameter defines the selection's method. Three methods are available :
|
Definition at line 159 of file csvsimple.py.
def csvsimple::Csv::setFormater | ( | self, | |
in_formatter | |||
) |
Set a function used to print records.
in_formatter | Function with the following signature: def myFunction(in_record, in_header) This function must return a string. |
Definition at line 195 of file csvsimple.py.
def csvsimple::Csv::strs | ( | self | ) |
This method returns a list of strings.
Each string represents a record.
Definition at line 207 of file csvsimple.py.
Referenced by getValue().
def csvsimple::Csv::void | ( | self | ) |
Clear the CVS container.
Definition at line 135 of file csvsimple.py.
int csvsimple::Csv::EQUALITY = 1 [static] |
Triggers selection via simple equality.
This value is used by the method select().
Definition at line 88 of file csvsimple.py.
int csvsimple::Csv::EXECUTE = 3 [static] |
Triggers selection via function execution.
This value is used by the method select().
Definition at line 92 of file csvsimple.py.
int csvsimple::Csv::MATCH = 2 [static] |
Triggers selection via pattern matching.
This value is used by the method select().
Definition at line 90 of file csvsimple.py.