csvsimple
Very basic CSV utility for Python.
csvsimple::Csv Class Reference

This class handles CSV data. More...

List of all members.

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.

Detailed Description

This class handles CSV data.

This class "partially" implements the following interfaces:

  • Sequence.
  • Mutable Mapping.
  
     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)
  
  
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

Definition at line 54 of file csvsimple.py.


Constructor & Destructor Documentation

def csvsimple::Csv::__init__ (   self,
  in_header 
)

Create a CSV container.

Parameters:
in_headerThis list contains the names of the columns that define the CSV structure.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

Definition at line 101 of file csvsimple.py.


Member Function Documentation

def csvsimple::Csv::add (   self,
  in_record 
)

Add a record to the CSV container.

Parameters:
in_recordThis list contains the values to add.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

Definition at line 128 of file csvsimple.py.

def csvsimple::Csv::getDefaultFormater ( )

Return the default records' formater.

Returns:
The method returns the default records' formater.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

Definition at line 80 of file csvsimple.py.

def csvsimple::Csv::getFormater (   self)

Return the function used to print records.

Returns:
Te method returns the function used to print records.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

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.

Parameters:
in_recordThe record.
in_column_nameName of the column.
Returns:
The method returns the value for the given column.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

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.

Parameters:
in_criteriasThis dictionary contains selections' criterions.
  • Dictionary's key : the name of a column.
  • Dictionary's value: this value can be : a simple value, a regular expression or a functioin. The type of value depends on the value of parameter "in_action".
If this parameter is not specified, then the method returns all the records in the container.
in_actionThis parameter defines the selection's method. Three methods are available :
  • Csv.EQUALITY (1): Simple equality. Dictionary's values must be simple values.
  • Csv.MATCH (2): Pattern matching. Dictionary's values must be regular expressions.
  • Csv.EXECUTE (3): Execution of code. Dictionary's values must be functions. Function's signature is: def myFuntion(in_value)
Returns:
The method returns a lust of records.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

Definition at line 159 of file csvsimple.py.

def csvsimple::Csv::setFormater (   self,
  in_formatter 
)

Set a function used to print records.

Parameters:
in_formatterFunction with the following signature: def myFunction(in_record, in_header) This function must return a string.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

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.

Returns:
The method returns a list of strings. Each string represents a record.
Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

Definition at line 207 of file csvsimple.py.

Referenced by getValue().

def csvsimple::Csv::void (   self)

Clear the CVS container.

Remarks:
See example on https://github.com/denis-beurive/csvsimple/tree/master/examples

Definition at line 135 of file csvsimple.py.


Member Data Documentation

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.


The documentation for this class was generated from the following file: