perlcompat Package
perlcompat - Perl-like utility functions such as warn, die, getopt, and require.
DESCRIPTION
This manual page documents perlcompat module, a Python module providing
Perl-like utility functions such as warn, die, getopt, and require.
Perl programmers are generally familiar with Perl's useful buil-in functions
such as warn() and die() for displaying debug/error messages as well as its
standard modules such as Getopt::Std for parsing UNIX-style command-line
options.
perlcompat module provides several utility fucntions with functionarites
similar to Perl's counterparts.
EXAMPLE
import os
import sys
from perlcompat import warn, die, getopts, require
require('3.6')
warn('starting of sample program in directory {}...'.format(os.getcwd()))
opt = getopts('vf:o:') or die('usage: {} [-v] [-f config] [-o outfile]'.format(sys.argv[0]))
if opt.v:
warn('verbose mode')
if opt.f:
conffile = opt.f if opt.f else 'config.ini'
warn('config file: {}'.format(conffile))
if opt.o:
outfile = opt.o if opt.o else 'out.txt'
warn('output file: {}'.format(outfile))
warn('remaining arguments: {}'.format(sys.argv[1:]))
FUNCTIONS
perlcompat module provides the following functions.
-
warn(astr)
Display warning message ASTR to the standard error output.
-
die(astr)
Display message ASTR to the standard error output and terminate the program
execution
-
getopts(spec)
Parse UNIX-style command line options. Options are specified by SPEC.
Parsed options are returned as an object. A value for option X is
accessible trhough the object attribute X.
perlcompat module only supports short options (e.g., -v, -f foo.txt).
Log options (e..g, --verbose, --file foo.txt) are not suported.
-
require(version)
Abort the program if the current Python interepter does not satisfy version
requirement (i.e., the version is older than VERSION).
INSTALLATION
pip3 install perlcompat
AVAILABILITY
The latest version of perlcompat module is available at
https://github.com/h-ohsaki/perlcompat.git .
SEE ALSO
perl(1), perlfunc(1), getopt(3), Getopt::Std(3perl)
AUTHOR
Hiroyuki Ohsaki <ohsaki[atmark]lsnl.jp>