I would like to cut and paste directly in the shell session, if possible. I have a simple with block in a .py file:
with open('t1_equip.json') as json_file:
data = json.load(json_file)
# Print the type of data variable
print("Type:", type(data))
This will cut and paste easily into the interpreter. However if I try to cut and paste directly in the bpython session itself it throws errors:
>>> with open('t1_equip.json') as json_file:
... ... data = json.load(json_file)
File "<bpython-input-57>", line 2
... data = json.load(json_file)
^
IndentationError: expected an indented block
>>> ... # Print the type of data variable
Ellipsis
>>> ... print("Type:", type(data))
File "<input>", line 1
... print("Type:", type(data))
^
SyntaxError: invalid syntax
I feel like there must be an easy workflow change I could make to do this in just a couple keystrokes. Having to continually hit the up arrow to reinsert can do it, but can we do something like a %hist for the entire last block or something similar? How do I make this possible? I'm using zsh with oh-my-zsh and powerlevel10k.
Don't use the
python
command. Useipython
. You might need to install it viapip install ipython
. Then use magic command,%paste
. This will easily copy the block of quotes.