_file module

class pyflyby._file.FilePos(*args)

A (lineno, colno) position within a FileText. Both lineno and colno are 1-indexed.

_ONE_ONE: ClassVar[FilePos] = FilePos(1,1)
property _data
classmethod _from_lc(lineno, colno)
static _intint(args)
colno: int
lineno: int
class pyflyby._file.FileText(arg, filename=None, startpos=None)

Represents a contiguous sequence of lines from a file.

_colno_to_index(lineindex, colno)
classmethod _from_lines(lines, filename, startpos)
_lineno_to_index(lineno)
_lines: Optional[Tuple[str, ...]] = None
alter(filename=None, startpos=None)
classmethod concatenate(args)

Concatenate a bunch of FileText arguments. Uses the filename and startpos from the first argument.

Return type:

FileText

property endpos

The position after the last character in the text.

Return type:

FilePos

filename: Optional[Filename]
classmethod from_filename(filename)
property joined: str
property lines: Tuple[str, ...]

Lines that have been split by newline.

These strings do NOT contain ‘n’.

If the input file ended in ‘n’, then the last item will be the empty string. This is to avoid having to check lines[-1].endswith(’n’) everywhere.

Return type:

tuple of str

startpos: FilePos
exception pyflyby._file.UnsafeFilenameError
pyflyby._file._get_PATH()
pyflyby._file.atomic_write_file(filename, data)
pyflyby._file.expand_py_files_from_args(pathnames, on_error=<function <lambda>>)

Enumerate *.py files, recursively.

Arguments that are files are always included. Arguments that are directories are recursively searched for *.py files.

Parameters:

on_error (callable) – Function that is called for arguments directly specified in pathnames that don’t exist or are otherwise inaccessible.

Return type:

list of Filename s

pyflyby._file.read_file(filename)
Return type:

FileText

pyflyby._file.which(program)

Find program on $PATH.

Return type:

Filename

Returns:

Program on $PATH, or None if not found.

pyflyby._file.write_file(filename, data)