Комментарии:
he was really gonna print "jello, world"
Ответитьinteresting, this will be useful for converting c++ structs into dataclasses when sent over tcp.
ОтветитьThis is awesome.
Ответитьthese type hints have got to go. I mean this python ppl. get your duck on.
ОтветитьI ironically was using this last night to create a "remote" module loader (You can have a module in a gist, for instance, and load it into a project)
ОтветитьYou can definitely use exec() for malware particularly excecuting code from a remote source. And if done well is pretty difficult to identify
ОтветитьActually in python, using the eval() function the 'calculator' can be written in one line: print(eval(input())). the problem with eval() is its limitations, so if you wanna write it the right way, you gotta handle some exceptions.
ОтветитьOne very niche use case that I use for exec() is to create variables dynamically
ОтветитьFun fact.. one of the reasons pickle is an unsafe serialization method, is because you can inject arbitrary python code using the exec() callable.. For example, one that sends all your AWS credentials in ~/.aws to the hacker :-)
ОтветитьI always wonder why you write code like this with those : str hints. What is the benefit of "source: str " over simply calling it source?
ОтветитьThanks for the explanation, really good examples. Good to see that you sometimes type like us mortals. ☺
Ответитьthey say "eval is evil" (in any programming language) and that's 100% true; because sooner or later you will evaluate some user input or remote "source"; and then ... poof, you're screwed; so it's better to forget about eval function and do it different from beginning, it's probably sometimes harder but in the long run it's better!
ОтветитьThanks
Ответитьwhat is this IDE?
ОтветитьSince everyone will tell you not to use these - why are they an option?
ОтветитьBravo!
Ответить