Skip to content

Instantly share code, notes, and snippets.

@seisvelas
Created September 30, 2020 03:16
Show Gist options
  • Save seisvelas/6e17239cfa0193f50fb98d392044d8f6 to your computer and use it in GitHub Desktop.
Save seisvelas/6e17239cfa0193f50fb98d392044d8f6 to your computer and use it in GitHub Desktop.
gain shell with walrus operator!
import requests
cant_put_in_public_gist = "URL"
while (command := input("$ ")) != 'exit':
x = requests.post(cant_put_in_public_gist, json={ "command" : command })
json = x.json()
try:
print(json['result'])
except KeyError:
print(json['error']['internal'])
@seisvelas
Copy link
Author

This script isn't generalizable beyond the circumstance I was using it for, just posting it here out of glee. I'd been wanting to use the walrus operator since Python 3.8 came out and finally an opportunity presented itself!

The pattern if ((some_var = funct()) !== NULL) feels so much like C, in a good way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment