Skip to main content

backquotes

https://img.shields.io/github/checks-status/manicmaniac/backquotes/master.svg https://img.shields.io/codeclimate/maintainability/manicmaniac/backquotes.svg https://img.shields.io/codeclimate/coverage/manicmaniac/backquotes.svg https://img.shields.io/pypi/v/backquotes.svg https://img.shields.io/pypi/pyversions/backquotes.svg

Introduction

backquotes brings (Perl / Ruby)’s shell invocation syntax to Python.

Since backquotes is an experimental module, using it in a serious program is not recommended.

Syntax

Firstly, do not forget to import backquotes module.

import backquotes

Basic

You can use similar syntax to Perl / Ruby.

import backquotes
print(`date`)

Pipes and redirections

Yes, you can use pipes, redirections too.

import backquotes
print(`ls | tr [a-z] [A-Z]`.splitlines())

Local variables substitution

To bring local variables in Python code to shell command, use Perl-like variables substitution.

import backquotes
spam = 'spam'
print(`echo $spam`)

$$ is replaced with a literal $.

import backquotes
print(`echo $$PATH`)

Usage

Runtime-preprocessing

You can use runtime-preprocessing only in Python 2. This works transparently whenever you import backquotes.

#!/usr/bin/env python
import backquotes
print(`date`)

Save the above code as date.py, and run it as usual.

python date.py

You will see the result of date command.

Runtime-preprocessing sometimes causes SyntaxError before preprocessing starts, especially with complex commands invocation. You can avoid this error by using single-quotes just inside the backquotes.

print(`'for file in *; do echo $file; done'`)

Execute backquotes module

Run python with -m backquotes option to invoke backquotes as a script. backquotes compiles a plain Python code and execute it.

python -m backquotes date.py

You can pass arguments to the script like this.

python -m backquotes date.py 2015 10 31

Preprocess Python code

Run python with -m backquotes -E option to only preprocess the given source file and print the result to stdout.

mkdir dist
python -m backquotes -E date.py > dist/date.py
python dist/date.py

Restrictions

  • backquotes does not work in Python REPL. Importing it in REPL causes warnings.

  • A module which imports backquotes does not work when it is imported by another module.

Install

pip install backquotes

or

git clone https://github.com/manicmaniac/backquotes.git
cd backquotes
python setup.py install

or

wget https://raw.githubusercontent.com/manicmaniac/backquotes/master/backquotes.py

Metadata

Release files for backquotes 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for backquotes 0.1.0
File Size Uploaded Provenance Actions
backquotes-0.1.0.tar.gz 8.6 kB Without provenance Details for backquotes-0.1.0.tar.gz

Release files / backquotes-0.1.0.tar.gz

Download URL backquotes-0.1.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5324e4ef6d1682676b9f25a2b8e430042dd910f189f8a0fc4fec32e1c078345d
BLAKE2b-256 checksum
How to use checksums
666cc82794500706ea60a4157e3ce07c3d1aa82f5c369a4fdc745bbe66a857eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.8.2 requests/2.27.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/2.7.18

Security for backquotes 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page