Created
September 30, 2020 03:16
-
-
Save seisvelas/6e17239cfa0193f50fb98d392044d8f6 to your computer and use it in GitHub Desktop.
gain shell with walrus operator!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.