Convenience variables

Follows a list of the builtin functions and variables.

Per-line

Name Description Type
L The current line, stripped str
R The raw current line str
LN The current line number int
W Words of R split on WS or WRE str
NW Length of W int

Global

These are defined in the whole program.

Name Usage Default Type
ENV Maps names to values of environment variables os.environ {str: str}

Input

Name Usage Default Type
F The input file sys.stdin file (io.FileIO)
WS Word separator, ignored if WRE is set Any whitespace str
WRE Word RegExp separator None str or re

Output

Name Usage Default Type
OF The output file sys.stdout file (io.FileIO)
OWS Output Word Separator space str
OLS Output Line Separator \n str

Functions

P(*args, **kwargs)[source]

Like print() but honors OWS, OLS & OF.

M(pattern, string=None, flags=0)[source]

Returns all capture groups starting with the full match.

Parameters:
  • pattern (str) – The regexp to match on.
  • string (str) – The string that will be matched, default to the full line (the R variable).
  • flags (int) – Matching option as per re.match()
Returns:

Capture groups, starting with the full match; or None if there were no match.

Return type:

tuple(str) or None

S(pattern, repl, string=None, count=0, flags=0)[source]

Substitutes pattern with repl in string (or R if string is None).

Parameters:
  • pattern (str) – The regexp to match on.
  • repl (str) – The string to substitute the matches with.
  • string (str) – The string that will be matched, default to the full line (the R variable).
  • count (int) – Replace at most that many occurences.
  • flags (int) – Matching option as per re.sub()
Returns:

The string after substitutions.

Return type:

str