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.

headers

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.

headers

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

Bases: object

Provides factory methods for dealing with reading text file content in various forms.

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.

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.

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.