Package ComboCode :: Package cc :: Package tools :: Package readers :: Module Reader :: Class Reader
[hide private]
[frames] | no frames]

Class Reader

source code


The Reader class.

Inherits from the builtin dictionary class, and thus functions much like a dictionary. For now, no base methods from dict are overwritten.

Reader functions primarily as a final stop before the dict class is called. Any Reader objects must inherit from this (directly or indirectly).

Can read in the data/input/outputfiles that are given to this class and store them.

Classes inheriting from Reader usually implement their own read and write methods, but some basic capabilities are available here.

Instance Methods [hide private]
new empty dictionary

__init__(self, fn, *args, **kwargs)
Initialize an Reader object by setting the contents dict.
source code
 
readFile(self, wildcard='*', *args, **kwargs)
Read a filename and store its contents in the Reader object.
source code
list
getFile(self, wildcard='*', *args, **kwargs)
Return the contents of the file of this Reader instance.
source code

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __setitem__, __sizeof__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values, viewitems, viewkeys, viewvalues

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from dict: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fn, *args, **kwargs)
(Constructor)

source code 

Initialize an Reader object by setting the contents dict.

Additional args & kwargs passed to __init__ are passed to dict __init__.

Parameters:
  • fn (str) - The filename of the file that is being read.
Returns:
new empty dictionary

Overrides: object.__init__

readFile(self, wildcard='*', *args, **kwargs)

source code 

Read a filename and store its contents in the Reader object.

The contents are stored in a dictionary, with the filename as key. Note that one filename can refer to multiple files with the use of a wildcard character. This character can be replaced upon calling this method.

The contents can be returned with the method getFile.

If the file is not found, an empty list is stored instead.

Additional args/kwargs are passed to DataIO.readFile (such as delimiter and replace_spaces)

Parameters:
  • wildcard (string) - if a wildcard character is present in the filename, it can be replaced here.

    (default: '*')

getFile(self, wildcard='*', *args, **kwargs)

source code 

Return the contents of the file of this Reader instance.

Wildcard characters can be replaced.

Additional keywords can be passed to the readFile method in case the file was not read yet.

Parameters:
  • wildcard (string) - if a wildcard character is present in the filename, it can be replaced here.

    (default: '*')

Returns: list
a list of lines in the file, each line represented by a list of strings, which were seperated by the chosen delimiter, if applicable.