Running Python Oneliners From Powershell Terminal Exemplified On JSON Minifier

▶ python -c "import os`nprint(os.path.exists('./helpers/temp_newDoc_indexItem.yaml'))"
True
# cool, file existence verified

1. instructions

  • enclose the whole code section in " - so that you evaluate special characters
  • use ' for quotes within the code section
  • use `n as line separators
  • use `t as tab character essential for python indentation

2. example: JSON minifier

  • … append|clip to copy output into clipboard :)
python -c "import json`nimport sys`nwith open(sys.argv[1], 'r') as f:`n`tprint(json.dumps(json.load(f), separators=(',',':')))" file.json

3. on separators keyword

  • If specified, separators should be an (item_separator, key_separator) tuple.
  • The default is (', ', ': ') if indent is None and (',', ': ') otherwise.
  • To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.

4. sources

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Connect Django to PostgreSQL in Docker

All About PreSaga

01/ On-chain Kusama & Polkadot account set-up guide

Explore Kusama Auctions with Subvis.io and SubQuery

Deno + JWT

Around the “Omnichannel Agent”: its Technical and Change Management approach.

Python Script That Sends Birthday Wishes to Your Friends

Why Switch to Linux now?

Linux Penguin and Popular Linux Distros

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

More from Medium

The Parameters And Usage Of Ranges In Python

Iterative Design with Python

Get Started with Python in VSCode on Debian and Ubuntu-based distributions

(almost) Daily Python Quick-Tips #15