numpy.lib._iotools
index
/usr/lib/python2.6/dist-packages/numpy/lib/_iotools.py

A collection of functions designed to help I/O with ascii file.

 
Modules
       
numpy
numpy.core.numeric

 
Classes
       
LineSplitter
NameValidator
StringConverter

 
class LineSplitter
    Defines a function to split a string at a given delimiter or at given places.
 
Parameters
----------
comment : {'#', string}
    Character used to mark the beginning of a comment.
delimiter : var, optional
    If a string, character used to delimit consecutive fields.
    If an integer or a sequence of integers, width(s) of each field.
autostrip : boolean, optional
    Whether to strip each individual fields
 
  Methods defined here:
__call__(self, line)
__init__(self, delimiter=None, comments='#', autostrip=True)
autostrip(self, method)
Wrapper to strip each member of the output of `method`.

 
class NameValidator
    Validates a list of strings to use as field names.
The strings are stripped of any non alphanumeric character, and spaces
are replaced by `_`. If the optional input parameter `case_sensitive`
is False, the strings are set to upper case.
 
During instantiation, the user can define a list of names to exclude, as 
well as a list of invalid characters. Names in the exclusion list
are appended a '_' character.
 
Once an instance has been created, it can be called with a list of names
and a list of valid names will be created.
The `__call__` method accepts an optional keyword, `default`, that sets
the default name in case of ambiguity. By default, `default = 'f'`, so
that names will default to `f0`, `f1`
 
Parameters
----------
excludelist : sequence, optional
    A list of names to exclude. This list is appended to the default list
    ['return','file','print']. Excluded names are appended an underscore:
    for example, `file` would become `file_`.
deletechars : string, optional
    A string combining invalid characters that must be deleted from the names.
casesensitive : {True, False, 'upper', 'lower'}, optional
    If True, field names are case_sensitive.
    If False or 'upper', field names are converted to upper case.
    If 'lower', field names are converted to lower case.
 
  Methods defined here:
__call__(self, names, default='f')
__init__(self, excludelist=None, deletechars=None, case_sensitive=None)
validate(self, names, default='f')

Data and other attributes defined here:
defaultdeletechars = set([' ', '!', '#', '$', '%', '&', ...])
defaultexcludelist = ['return', 'file', 'print']

 
class StringConverter
    Factory class for function transforming a string into another object (int,
float).
 
After initialization, an instance can be called to transform a string 
into another object. If the string is recognized as representing a missing
value, a default value is returned.
 
Parameters
----------
dtype_or_func : {None, dtype, function}, optional
    Input data type, used to define a basic function and a default value
    for missing data. For example, when `dtype` is float, the :attr:`func`
    attribute is set to ``float`` and the default value to `np.nan`.
    Alternatively, function used to convert a string to another object.
    In that later case, it is recommended to give an associated default
    value as input.
default : {None, var}, optional
    Value to return by default, that is, when the string to be converted
    is flagged as missing.
missing_values : {sequence}, optional
    Sequence of strings indicating a missing value.
locked : {boolean}, optional
    Whether the StringConverter should be locked to prevent automatic 
    upgrade or not.
 
Attributes
----------
func : function
    Function used for the conversion
default : var
    Default value to return when the input corresponds to a missing value.
type : type
    Type of the output.
_status : integer
    Integer representing the order of the conversion.
_mapper : sequence of tuples
    Sequence of tuples (dtype, function, default value) to evaluate in order.
_locked : boolean
    Whether the StringConverter is locked, thereby preventing automatic any
    upgrade or not.
 
  Methods defined here:
__call__(self, value)
__init__(self, dtype_or_func=None, default=None, missing_values=None, locked=False)
update(self, func, default=None, missing_values='', locked=False)
Sets the :attr:`func` and :attr:`default` attributes directly.
 
Parameters
----------
func : function
    Conversion function.
default : {var}, optional
    Default value to return when a missing value is encountered.
missing_values : {var}, optional
    Sequence of strings representing missing values.
locked : {False, True}, optional
    Whether the status should be locked to prevent automatic upgrade.
upgrade(self, value)
Tries to find the best converter for `value`, by testing different
converters in order.
The order in which the converters are tested is read from the
:attr:`_status` attribute of the instance.

Class methods defined here:
upgrade_mapper(cls, func, default=None) from __builtin__.classobj
Upgrade the mapper of a StringConverter by adding a new function and its
corresponding default.
 
The input function (or sequence of functions) and its associated default 
value (if any) is inserted in penultimate position of the mapper.
The corresponding type is estimated from the dtype of the default value.
 
Parameters
----------
func : var
    Function, or sequence of functions
 
Examples
--------
>>> import dateutil.parser
>>> import datetime
>>> dateparser = datetutil.parser.parse
>>> defaultdate = datetime.date(2000, 1, 1)
>>> StringConverter.upgrade_mapper(dateparser, default=defaultdate)

 
Functions
       
_is_string_like(obj)
Check whether obj behaves like a string.
_to_filehandle(fname, flag='r', return_opened=False)
Returns the filehandle corresponding to a string or a file.
If the string ends in '.gz', the file is automatically unzipped.
 
Parameters
----------
fname : string, filehandle
    Name of the file whose filehandle must be returned.
flag : string, optional
    Flag indicating the status of the file ('r' for read, 'w' for write).
return_opened : boolean, optional
    Whether to return the opening status of the file.
flatten_dtype(ndtype)
Unpack a structured data-type.
has_nested_fields(ndtype)
Returns whether one or several fields of a structured array are nested.
str2bool(value)
Tries to transform a string supposed to represent a boolean to a boolean.
 
Raises
------
ValueError
    If the string is not 'True' or 'False' (case independent)

 
Data
        __docformat__ = 'restructuredtext en'
__file__ = '/usr/lib/python2.6/dist-packages/numpy/lib/_iotools.pyc'
__name__ = 'numpy.lib._iotools'
__package__ = 'numpy.lib'