arjuna.tpi.parser.text module¶
- class arjuna.tpi.parser.text.DelimTextFileWithLineAsMap(fpath, *, delimiter='\t')¶
Bases:
object
Represents a text file in Read mode to get line by line content split by defined delimiter.
The first line is treated as a header line.
- Parameters
fpath – Absolute path of text file.
- Keyword Arguments
delimiter – (Optional) Delimiter that separates different parts of line. Default is tab ( )
Note
You can loop over this object:
for line_parts in fobj: # Do something about the parts of a current line print(line_parts)
- close()¶
Close the file handle.
- property headers: tuple¶
Get header line parsed based on delimiter as a tuple.
- Returns
Header line as a Python tuple object.
- next() dict ¶
Get next line parsed based on delimiter converted into a Python dictionary based on header line.
- Returns
Line as a Python dict object.
- class arjuna.tpi.parser.text.DelimTextFileWithLineAsSeq(fpath, *, delimiter='\t', header_line_present=True)¶
Bases:
object
Represents a text file in Read mode to get line by line content split by defined delimiter.
- Parameters
fpath – Absolute path of text file.
- Keyword Arguments
delimiter – (Optional) Delimiter that separates different parts of line. Default is tab ( )
header_line_present – (Optional) If True, the first line is treated as a header line.
Note
You can loop over this object:
for line_parts in fobj: # Do something about the parts of a current line print(line_parts)
- close()¶
Close the file handle.
- property headers: tuple¶
Get header line parsed based on delimiter as a tuple.
- Returns
Header line as a Python tuple object. None if header line is not present.
- next() tuple ¶
Get next line parsed based on delimiter as a tuple.
- Returns
Line as a Python tuple object.
- class arjuna.tpi.parser.text.Text(text, *fargs, **fnargs)¶
Bases:
str
,arjuna.tpi.engine.asserter.AsserterMixIn
Arjuna representation of a String. Provides factory methods for dealing with reading text file content in various forms.
- Parameters
text – Input string. If a non-string object is provided it str(text) is called.
fargs – Arbitrary positional arguments for formatting the string.
- Keyword Arguments
fnargs – Arbitrary named arguments (keworg arguments) for formatting the string.
- assert_contains(sub_str, *, msg)¶
- property content¶
- classmethod delimited_file(fpath, *, delimiter='\t', header_line_present=True) DelimTextFileWithLineAsMap OR DelimTextFileWithLineAsSeq ¶
Represents a text file in Read mode to get line by line content split by defined delimiter.
- Parameters
fpath – Absolute path of text file.
- Keyword Arguments
delimiter – (Optional) Delimiter that separates different parts of line. Default is tab ( )
header_line_present – (Optional) If True, the DelimTextFileWithLineAsMap is created, else DelimTextFileWithLineAsSeq is created to represent the file.
Note
You can loop over the returned object:
for line in fobj: # Do something about the parts of a current line print(line)
The line is a tuple of parts for DelimTextFileWithLineAsSeq object and is a dictionary for DelimTextFileWithLineAsMap object.
Note
You must explicitly close the returned object by calling its close() method.
- exists(repattern)¶
- classmethod file_content(fpath) str ¶
Get content of a text file.
- Parameters
fpath – Absolute path of text file.
- Returns
Content of text file as Python str object.
- classmethod file_lines(fpath) arjuna.tpi.parser.text.TextFileAsLines ¶
Get a reader for text file in Read mode to get line by line content.
- Parameters
fpath – Absolute path of text file.
- Returns
Arjuna’s TextFileAsLines object.
Note
You must explicitly close the returned object by calling its close() method.
- find(sub[, start[, end]]) int ¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- find_links(*, unique=True, contain='')¶
- findall(repattern)¶
- format(*fargs, **fnargs)¶
Format the string using provided named and keyword arguments.
Positional arguments are used to format $$ placeholders as per the order in which they are found.
Keyword/named arguments are used to format $<name>$ placeholders. Order does not matter.
Supports C/L/R queries as names of placeholders.
The provided features are very advanced. Refer Arjuna documentation for use cases and examples.
- Parameters
fargs – Arbitrary positional arguments for formatting the string.
- Keyword Arguments
fnargs – Arbitrary named arguments (keworg arguments) for formatting the string.
- property links¶
- property unique_links¶
- class arjuna.tpi.parser.text.TextFile(fpath)¶
Bases:
object
Represents a text file in Read mode.
- Parameters
fpath – Absolute path of text file.
- close()¶
Close the file handle.
- read() str ¶
Read contents of text file.
- Returns
Content of text file as a Python str object.
- class arjuna.tpi.parser.text.TextFileAsLines(fpath, **formatters)¶
Bases:
object
Represents a text file in Read mode to get line by line content.
- Parameters
fpath – Absolute path of text file.
- Keyword Arguments
**formatters – Arbitrary key-value arguments to format a line before returning.
Note
You can loop over this object:
for line in fobj: # Do something about the content print(line)
- close()¶
Close the file handle.
- next() str ¶
Get next line.
- Returns
Line as a Python str object.