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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file perlcompat-1.1.tar.gz
.
File metadata
- Download URL: perlcompat-1.1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d2568814b2ceef1dc32c1393fab78c6dd94bea04eb50b97828f7dc3c3b1a5ea |
|
MD5 | 4715fa6748f12933117e7559a3dd5937 |
|
BLAKE2b-256 | 38aa0c57c10ce466505988f04c7e05a35279a4dedb6b6bf8819a165e02819f56 |
File details
Details for the file perlcompat-1.1-py3-none-any.whl
.
File metadata
- Download URL: perlcompat-1.1-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4548c2c91fd3df95015581d8454f1d568b0851f6e89057315cfb3baf80c0af6d |
|
MD5 | 008443809183e800a4e50c5674e07039 |
|
BLAKE2b-256 | 42ab328e564486228c8ed12085e4439fd39351e23333f52a8ed6833e4715efb8 |