pdk.Util.TextUtils ($Date: 2002/12/04 10:13:15 $)
index
pdk/Util/TextUtils.py

Auxilliary routines for text/string manipulation.

FOG 01.2000

 
Classes
            
_StringFormatter
 
class _StringFormatter
     
Purpose:parsing, converting, and pretty-formatting of field-delimited and general strings

 
   Methods defined here:
__init__(self, **optionD)
floatFormat(self, inFloat, colWidth=None, precision=None, expFlag=None)
produces a string from inFloat of width colWidth with precision numbers of digits, if possible. If expFlag is True, or if the requested width cannot be achieved with plain formatting, scientific notation is used.
floatFormatArray(self, inArray, colWidth=None, precision=None, expFlag=None)
getAllowNA(self)
getColumnWidth(self)
getExpFlag(self)
getFieldDelimiter(self)
getIndent(self)
getIndentFirstLine(self)
getLineWidth(self)
getMaxStringLength(self)
getPrecision(self)
getStringDelimiter(self)
indentParagraph = wrapString(self, inString, indent=None, lineWidth=None, indentFirstLine=None)
intFormat(self, inInt, colWidth=None, expFlag=None)
produces a string from inInt of width colWidth. If expFlag is True, or if the requested width cannot be achieved with plain formatting, scientific notation is used. inInt can be either of types.IntType or of types.LongType (in the latter case, the trailing L is NOT printed).
intFormatArray(self, inArray, colWidth=None, expFlag=None)
objectFormat(self, object, lineWidth=None)
reset(self, precision=4, expFlag=0, lineWidth=40, colWidth=40, indent=15, indentFirstLine=0, maxStringLength=500, stringDelimiter=None, fieldDelimiter=None)
setAllowNA(self, flag)
setColumnWidth(self, value)
setExpFlag(self, value)
setFieldDelimiter(self, value)
setIndent(self, value)
setIndentFirstLine(self, value)
setLineWidth(self, value)
setMaxStringLength(self, value)
setPrecision(self, value)
setStringDelimiter(self, value)
stringConvert(self, inString)
converts field values in delimited data input files: * convert double quoted strings into single quoted strings * escape mid-string standard string delimiters
stringConvertLine(self, line, safe=1)
parses lines of field values delmited by self.fieldDelimiter and maps stringConvert on the resulting list. This is complicated, if field delimiters are allowed to occur within strings; in this case (safe set to 1), a second pass is made through the splitted input line, splicing open strings together.
stringFormat(self, inString, colWidth=None, pad=1)
this formats inString to be of colWidth width, either by cutting (putting two dots at the center to indicate the missing bit) or by left-aligning.
stringFormatArray(self, inArray, colWidth=None)
stringTable(self, stringL, indent=None, lineWidth=None, indentFirstLine=None, separator=' , ')
formats the strings passed in stringL to a table of width self.lineWidth, with an indent of self.indent. The column width is set to the maximum string width.
wrapString(self, inString, indent=None, lineWidth=None, indentFirstLine=None)
(word-)wraps inString to fit self.lineWidth with self.indent indentation.

Data and non-method functions defined here:
FIELDDELIMITER = ';'
STRINGDELIMITER = '"'
 
class _StringFormatter
     
Purpose:parsing, converting, and pretty-formatting of field-delimited and general strings

 
   Methods defined here:
__init__(self, **optionD)
floatFormat(self, inFloat, colWidth=None, precision=None, expFlag=None)
produces a string from inFloat of width colWidth with precision numbers of digits, if possible. If expFlag is True, or if the requested width cannot be achieved with plain formatting, scientific notation is used.
floatFormatArray(self, inArray, colWidth=None, precision=None, expFlag=None)
getAllowNA(self)
getColumnWidth(self)
getExpFlag(self)
getFieldDelimiter(self)
getIndent(self)
getIndentFirstLine(self)
getLineWidth(self)
getMaxStringLength(self)
getPrecision(self)
getStringDelimiter(self)
indentParagraph = wrapString(self, inString, indent=None, lineWidth=None, indentFirstLine=None)
intFormat(self, inInt, colWidth=None, expFlag=None)
produces a string from inInt of width colWidth. If expFlag is True, or if the requested width cannot be achieved with plain formatting, scientific notation is used. inInt can be either of types.IntType or of types.LongType (in the latter case, the trailing L is NOT printed).
intFormatArray(self, inArray, colWidth=None, expFlag=None)
objectFormat(self, object, lineWidth=None)
reset(self, precision=4, expFlag=0, lineWidth=40, colWidth=40, indent=15, indentFirstLine=0, maxStringLength=500, stringDelimiter=None, fieldDelimiter=None)
setAllowNA(self, flag)
setColumnWidth(self, value)
setExpFlag(self, value)
setFieldDelimiter(self, value)
setIndent(self, value)
setIndentFirstLine(self, value)
setLineWidth(self, value)
setMaxStringLength(self, value)
setPrecision(self, value)
setStringDelimiter(self, value)
stringConvert(self, inString)
converts field values in delimited data input files: * convert double quoted strings into single quoted strings * escape mid-string standard string delimiters
stringConvertLine(self, line, safe=1)
parses lines of field values delmited by self.fieldDelimiter and maps stringConvert on the resulting list. This is complicated, if field delimiters are allowed to occur within strings; in this case (safe set to 1), a second pass is made through the splitted input line, splicing open strings together.
stringFormat(self, inString, colWidth=None, pad=1)
this formats inString to be of colWidth width, either by cutting (putting two dots at the center to indicate the missing bit) or by left-aligning.
stringFormatArray(self, inArray, colWidth=None)
stringTable(self, stringL, indent=None, lineWidth=None, indentFirstLine=None, separator=' , ')
formats the strings passed in stringL to a table of width self.lineWidth, with an indent of self.indent. The column width is set to the maximum string width.
wrapString(self, inString, indent=None, lineWidth=None, indentFirstLine=None)
(word-)wraps inString to fit self.lineWidth with self.indent indentation.

Data and non-method functions defined here:
FIELDDELIMITER = ';'
STRINGDELIMITER = '"'
 
Functions
            
generate_labels(prefix, count, offset=0)
automatically generates label series. Returns count unique labels beginning with prefix, optionally starting at offset. All labels have the same length, which is determined by the total number of labels requested.
adjust_labels(labelL, targetLength, autoLabelPrefix, warn=0)
adjusts the length of a label list. Truncates the list of labels labelL if it is longer or appends labels autogenerated using the prefix autoLabelPrefix if it is shorter than targetLength. If warn is true, a RuntimeWarning is generated if either of these two corrections is applied.
label_from_number(N, returnSequence=0, ascending=1, letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ', offset=0)

converts an integer into an alphabetic column label or a list of alphabetic labels.

This is more difficult than it might seem at first sight; labels are not really a base-26 number system, as there is no zero: the number 52, for instance, is not to be converted to

2 * 26**1 + 0 * 26 ** 0 = "CA"

but to

1 * 26**1 + 26 * 26 ** 0 = "AZ"
Parameters:
  • N: number to create label(s) for.
  • returnSequence: if True, a sequence of labels up to the value given by N is returned
  • ascending: if True, the sequence of labels is returned in ascending order (has only effect when returnSequence is set)
  • letters: the alphabet to select the letters from
  • offset : an offset for N (e.g., to return the sequence ["C","D","E"])
get_missing_value(typ)
atoi(val)
atol(val)
atof(val)
format_float = floatFormat(self, inFloat, colWidth=None, precision=None, expFlag=None) method of _StringFormatter instance
format_floatarray = floatFormatArray(self, inArray, colWidth=None, precision=None, expFlag=None) method of _StringFormatter instance
format_int = intFormat(self, inInt, colWidth=None, expFlag=None) method of _StringFormatter instance
format_intarray = intFormatArray(self, inArray, colWidth=None, expFlag=None) method of _StringFormatter instance
convert_line = stringConvertLine(self, line, safe=1) method of _StringFormatter instance
convert_string = stringConvert(self, inString) method of _StringFormatter instance
format_string = stringFormat(self, inString, colWidth=None, pad=1) method of _StringFormatter instance
format_stringarray = stringFormatArray(self, inArray, colWidth=None) method of _StringFormatter instance
format_stringtable = stringTable(self, stringL, indent=None, lineWidth=None, indentFirstLine=None, separator=' , ') method of _StringFormatter instance
number_from_label(label, letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ')
returns the numeric value for the label label in the alphabet given by letters.
wrap_string = wrap_string_brute_force(inString, lineWidth=80)
 
Data
             formatter = instance of _StringFormatter
 
Author
            
$Author: gathmann $