Package mrv :: Module util :: Class PipeSeparatedFile
[hide private]
[frames] | no frames]

Class PipeSeparatedFile

source code

object --+
         |
        PipeSeparatedFile

Read and write simple pipe separated files.

The number of column must remain the same per line Format:

val11 | val2 | valn ...
Instance Methods [hide private]
 
__init__(self, fileobj)
Initialize the instance
source code
 
beginReading(self)
Start reading the file
source code
 
beginWriting(self, columnSizes)
intiialize the writing process
source code
 
readColumnLine(self)
Generator reading one line after another, returning the stripped columns
source code
 
writeTokens(self, tokens)
Write the list of tokens to the file accordingly
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  kSeparator = '|'
Properties [hide private]
  _columncount
  _fileobj
  _formatstr

Inherited from object: __class__

Method Details [hide private]

__init__(self, fileobj)
(Constructor)

source code 
Initialize the instance
Parameters:
  • fileobj - fileobject where new lines will be written to or read from It must already be opened for reading and/or writing respectively
Overrides: object.__init__

beginWriting(self, columnSizes)

source code 
intiialize the writing process
Parameters:
  • columnSizes - list of ints defining the size in characters for each column you plan to feed

Note: When done writing, you have to close the file object yourself (there is no endWriting method here)

readColumnLine(self)

source code 
Generator reading one line after another, returning the stripped columns
Returns:
tuple of stripped column strings
Raises:
  • ValueError - if the column count changes between the lines

writeTokens(self, tokens)

source code 
Write the list of tokens to the file accordingly
Parameters:
  • tokens - one token per column that you want to write
Raises:
  • TypeError - If column count changed between successive calls