Package picalo :: Package base :: Module Column :: Class Column
[show private | hide private]
[frames | no frames]

Type Column

object --+    
         |    
      list --+
             |
            Column


A single column of the table. Columns are not copies of the values in the table, but rather pointers to the actual table data. Therefore, changes to the values in the column are reflected in the underlying table.

Columns must have unique names from other columns in the table. Columns must also have either a column_type or an expression.

Columns extend Python lists and mimick the list interface. They can be used anywhere a regular Python list can.
Method Summary
  __init__(self, table, name, column_type, expression, format)
Creates a Column.
  __add__(self, other)
  __and__(self, other)
  __contains__(self, item)
Returns true if the item is in the column
  __delitem__(self, col)
  __eq__(self, other)
Compares this column with another column.
object __getitem__(self, recindex)
Retrieves the value of a field in the given record index.
  __iter__(self)
returns __len__(self)
Count the number of records in the column.
  __or__(self, other)
  __repr__(self)
For debugging
  __setitem__(self, recindex, value)
Sets a value in the column.
  __sub__(self, other)
  __xor__(self, other)
  append(self, *a, **k)
  extend(self, *a, **k)
  get_format(self)
Returns the format of this column.
  get_type(self)
Returns the type of this column.
type guess_type(self, num_records)
Looks at a number of values in this column and tries to guess the type of the column.
  insert(self, *a, **k)
  pop(self, *a, **k)
  remove(self, *a, **k)
  reverse(self, *a, **k)
  set_format(self, format)
Sets the format of this column.
  set_name(self, name)
Sets the name of this column to the given name
  set_type(self, column_type, format, expression)
Sets the type of a column.
  sort(self, *a, **k)
  _get_columnloader(self)
Returns a column loader for this column (a representation of this column without ties to any table.
    Inherited from list
  __delslice__(x, i, j)
Use of negative indices is not supported.
  __ge__(x, y)
x.__ge__(y) <==> x>=y
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __getslice__(x, i, j)
Use of negative indices is not supported.
  __gt__(x, y)
x.__gt__(y) <==> x>y
  __hash__(x)
x.__hash__() <==> hash(x)
  __iadd__(x, y)
x.__iadd__(y) <==> x+=y
  __imul__(x, y)
x.__imul__(y) <==> x*=y
  __le__(x, y)
x.__le__(y) <==> x<=y
  __lt__(x, y)
x.__lt__(y) <==> x<y
  __mul__(x, n)
x.__mul__(n) <==> x*n
  __ne__(x, y)
x.__ne__(y) <==> x!=y
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reversed__(...)
L.__reversed__() -- return a reverse iterator over the list
  __rmul__(x, n)
x.__rmul__(n) <==> n*x
  __setslice__(x, i, j, y)
Use of negative indices is not supported.
  count(L, value)
L.count(value) -> integer -- return number of occurrences of value
  index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Method Details

__init__(self, table, name, column_type=None, expression=None, format=None)
(Constructor)

Creates a Column. Do not call this method directly. Rather, call mytable["colname"]
Overrides:
__builtin__.list.__init__

__contains__(self, item)
(In operator)

Returns true if the item is in the column
Overrides:
__builtin__.list.__contains__

__eq__(self, other)
(Equality operator)

Compares this column with another column. Everything must match except the table the two columns are bound to
Overrides:
__builtin__.list.__eq__

__getitem__(self, recindex)
(Indexing operator)

Retrieves the value of a field in the given record index.
Parameters:
recindex - the record index where the value will be retrieved. @type int
Returns:
The value of the field.
           (type=object)
Overrides:
__builtin__.list.__getitem__

__len__(self)
(Length operator)

Count the number of records in the column.
Returns:
The number of records. This is the same value as the number of records in the underlying table.
           (type=returns)
Overrides:
__builtin__.list.__len__

__repr__(self)
(Representation operator)

For debugging
Overrides:
__builtin__.list.__repr__

__setitem__(self, recindex, value)
(Index assignment operator)

Sets a value in the column. The value of this cell in the underlying table is changed.
Parameters:
recindex - The record in dex where the value will be stored.
           (type=int)
value - The value to set in the table.
           (type=object)
Overrides:
__builtin__.list.__setitem__

get_format(self)

Returns the format of this column. If no format has been set, None is returned.

get_type(self)

Returns the type of this column.

guess_type(self, num_records=-1)

Looks at a number of values in this column and tries to guess the type of the column. Returns unicode if it can't guess the type since anything can be seen as a string.

The method is conservative. It will only return a type if *all* values inspected are of the exact same type. It tries to convert values to types in the following order:
  1. If the column is all of a certain type (such as int), that type is used
  2. If the column contains strings, the following are tried (in this order):
    • DateTime: All of the DateTime patterns
    • int: (number with no decimal point)
    • long: (same as int but with more range -- longs use more memory)
    • float: (number with a decimal point)
    • str: (e.g. string. anything can be converted to this type)
IMPORTANT: This method does not respect the native type of the column. For example, if a column type has been set to unicode, this method may return int if all the values are '1', '2', and '3'. This call (guess_type) is often followed up with a set_type method to set the guessed type for the column.
Parameters:
num_records - The number of records to look at to guess the type of the column. Any value less than 1 indicates all values in the column should be looked at. The default is all records.
           (type=int)
Returns:
The type of the column as a type object
           (type=type)

set_format(self, format=None)

Sets the format of this column.  The format is used for printing the value 
and showing the value in the Picalo GUI.

The format should be a Picalo expression that evaluates to a string.  Use the
'value' variable for the value of the current cell.

Note that this is not an input mask.  It doesn't affect the internal value of 
the field values.  It only affects how it is displayed on the screen.

Example:
  # shows the current value in uppercase
  table['Salary'].set_format("value.upper()")

@param format:  A Picalo expression that evaluates to a string
@type  format:  str

set_name(self, name)

Sets the name of this column to the given name

set_type(self, column_type, format=None, expression=None)

Sets the type of a column. The type must be a valid <type> object, such as int, float, str, unicode, DateTime, etc. All values in this column will be converted to this new type.
Parameters:
column_type - The new type of this column.
           (type=type)
format - A Picalo expression that evaluates to a string, using 'value' as the value of the field.
           (type=str)
expression - A Picalo expression that calculates this column.

_get_columnloader(self)

Returns a column loader for this column (a representation of this column without ties to any table. This is normally only used internally in Picalo.

Generated by Epydoc 2.1 on Mon Aug 20 05:38:16 2007 http://epydoc.sf.net