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.


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.


import os
import sys
from perlcompat import warn, die, getopts, require

# make sure the Python is no older than version 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:]))


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).


pip3 install perlcompat


The latest version of perlcompat module is available at .


perl(1), perlfunc(1), getopt(3), Getopt::Std(3perl)


Hiroyuki Ohsaki <ohsaki[atmark]>

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Files for perlcompat, version 1.1
Filename, size File type Python version Upload date Hashes
Filename, size perlcompat-1.1-py3-none-any.whl (15.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size perlcompat-1.1.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page