4 ms·
Copy to clipboard, paste into your interactive Python window, and use as the argument to sorted. Copy and paste the interpreter's output back into your code.
by tom_ 3y ago
Copy to clipboard, paste into your interactive Python window, and use as the argument to sorted. Copy and paste the interpreter's output back into your code.
- owl57 3y agoYou technically described how to make a word sorting macro execute arbitrary code. Fascinating to think how that doesn't mean it's bad advice. That is, unless your threat model includes targeted attacks by three-letter-scale adversaries — and then you maybe just don't open untrusted files in Emacs or use advice from strangers on HN.
- tom_ 3y agoThat's a good point. My assumption, not that I ever stated it, was that the list would be one you'd typed out yourself, or was one that was just there in code already, and you could verify by eye that it's just string literals. Using Python's eval with empty globals and locals dicts (consult the docs) could make this safer, though I've only ever had to use that for defending against accidents rather than malice. And now this quick thing is becoming increasingly complicated, and maybe you'd be better off engineering it properly.
- ktm5j 3y agoThis is actually a rather common thing to do.. I have functions that run shell commands in my spacemacs config to do things like this. For example I've got one that runs `date` to insert today's date in a particular format.
- deleted 3y ago[deleted]
- lvass 3y ago>Copy to clipboard, paste into your interactive Python window python-shell-send-statement, it's built into Emacs's python mode.
- tom_ 3y agoI was thinking you'd need it pasteable to pass it into sorted, but, yes, you could probably just evaluate it and then do sorted(_).