Skip to main content

Perl-like utility functions such as warn, die, getopt, and require

Project description

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

# make sure the Python is no older than version 3.6
require('3.6')

# display warning message
warn('starting of sample program in directory {}...'.format(os.getcwd()))

# parse command-line options
# variables opt.v, opt.f, and opt.o are automatically defined
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>

Project details


Release history Release notifications | RSS feed

This version

1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perlcompat-1.1.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

perlcompat-1.1-py3-none-any.whl (15.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page