Interactive mode
pip install ipython

then launch with ipython

Using bash commands

Can be invoked easily from iPython, using !command with args

read text file
import pathlib
pathlib.Path("myfile.txt").read_text()
make a GET HTTP request and read text
import requests
requests.get("https://someurl").json()
pretty-print a string
from pprint import pprint
nicestring = pprint(somejsonstring)
read file (more sophisticated)
with open("filepath.txt", "r") as f:
    jsonobj = json.load(f)
    justastring = f.read()
    jsonobjfromstring = json.loads(justastring)
    listoflines = f.readlines()

instead of json, we can use yaml format (pip install PyYAML), which is basically json that uses indents and newlines instead of parentheses. Then, we can load yaml into typical python objects (dicts and lists) as:

import yaml, pprint
dicts = yaml.safe_loads(someYamlString)
pprint(dicts)
← Back to Articles