Exec() VS Eval() Explained In Python Tutorial 2023

Exec() VS Eval() Explained In Python Tutorial 2023

Indently

1 год назад

17,960 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@mayo-neighs
@mayo-neighs - 30.08.2023 16:10

he was really gonna print "jello, world"

Ответить
@chudchadanstud
@chudchadanstud - 27.08.2023 20:56

interesting, this will be useful for converting c++ structs into dataclasses when sent over tcp.

Ответить
@inkuban
@inkuban - 07.08.2023 07:10

This is awesome.

Ответить
@DrDeuteron
@DrDeuteron - 27.07.2023 07:58

these type hints have got to go. I mean this python ppl. get your duck on.

Ответить
@AlyceIsFree
@AlyceIsFree - 24.05.2023 23:13

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)

Ответить
@SlackOps
@SlackOps - 23.05.2023 16:20

You can definitely use exec() for malware particularly excecuting code from a remote source. And if done well is pretty difficult to identify

Ответить
@iskarik5938
@iskarik5938 - 23.05.2023 08:25

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.

Ответить
@HitBoxMaster
@HitBoxMaster - 23.05.2023 02:55

One very niche use case that I use for exec() is to create variables dynamically

Ответить
@sorvex9
@sorvex9 - 22.05.2023 18:56

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 :-)

Ответить
@elevendarter112
@elevendarter112 - 22.05.2023 17:28

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?

Ответить
@castlecodersltd
@castlecodersltd - 22.05.2023 12:17

Thanks for the explanation, really good examples. Good to see that you sometimes type like us mortals. ☺

Ответить
@AlexCernat
@AlexCernat - 22.05.2023 10:27

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!

Ответить
@rishiraj2548
@rishiraj2548 - 22.05.2023 08:51

Thanks

Ответить
@makadi4304
@makadi4304 - 22.05.2023 07:28

what is this IDE?

Ответить
@murphygreen8484
@murphygreen8484 - 22.05.2023 07:21

Since everyone will tell you not to use these - why are they an option?

Ответить
@Python592
@Python592 - 22.05.2023 07:19

Bravo!

Ответить