Skip to main content

Python with braces for easy one-liners

Project description

As an old Perl-hack I really miss the convenience of one-line programs where I can easily add block structure. This script emulates the behaviors of perl -e, perl -n and perl -p using braces ({ and }) to generate Pythonesque indentation. There may be other ways to get around this but the goal is to make one-liners as easy as we expect.

Examples:

` >./pb 'for j in range(1,10) { for k in range(0,j) { sys.stdout.write(".") } sys.stdout.write("\n") }' . .. ... .... ..... ...... ....... ........ ......... `

PS. I know this one is very easy as a true Python one-liner:

` >python -c 'print "\n".join("."*j for j in range (1,10))' . .. ... .... ..... ...... ....... ........ ......... `

Project details


Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page