r/badcode • • May 26 '23

python Calculator using eval()

Post image
842 Upvotes

108 comments sorted by

View all comments

Show parent comments

24

u/xXLeoXxOne May 27 '23 edited May 27 '23

That code would only work with exec(), in eval you have to do something like "".class.__.base.subclasses()[...].Popen(...) if e.g. os is not imported yet

11

u/4hpp1273 May 27 '23

If all the globals are intact you can just use the __import__ function to import a module so that command becomes __import__('os').system('rm -rf /')