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 PyPI (https://pypi.org/project/perlcompat/) .

SEE ALSO

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

AUTHOR

Hiroyuki Ohsaki <code[atmark]lsnl.jp>

Project details


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.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perlcompat-1.2-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file perlcompat-1.2.tar.gz.

File metadata

  • Download URL: perlcompat-1.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for perlcompat-1.2.tar.gz
Algorithm Hash digest
SHA256 b54572644a0ef87818ca3db242b0be76f86a6c349b65139f3fa1f998161425da
MD5 ba888082e3b54927327823cabf61c274
BLAKE2b-256 c92a1a39030ce0ef80386403d5db6330a1752f5027158bf686cfa712e0898f5b

See more details on using hashes here.

File details

Details for the file perlcompat-1.2-py3-none-any.whl.

File metadata

  • Download URL: perlcompat-1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for perlcompat-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95a7c915d8bed6ed520232331c4a6f5fdad8411b2ba1c3dd5de3a0bd923de764
MD5 62b9ff161f4fc58a67a3b48a4a6545ac
BLAKE2b-256 36aec8ff593db0ccdaaca21b420a17de04d4609277be266d10987eb44a11585c

See more details on using hashes here.

Supported by

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