Created
April 30, 2012 20:17
-
-
Save dcrosta/2562350 to your computer and use it in GitHub Desktop.
A Python Mystery
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
Guess the output: | |
>>> def exec_code_object_and_return_x(codeobj, x): | |
... exec codeobj | |
... return x | |
... | |
>>> co1 = compile("""x = x + 1""", '<string>', 'exec') | |
>>> co2 = compile("""del x""", '<string>', 'exec') | |
>>> exec_code_object_and_return_x(co1, 1) | |
# What do you get here? | |
>>> exec_code_object_and_return_x(co2, 1) | |
# And what about here? | |
varun06
commented
May 1, 2012
via email
thanks Dan it is very informative. Please keep sharing as I am new to
python but want to learn it well
…On Apr 30, 2012 7:49 PM, "Dan Crosta" < ***@***.***> wrote:
@varun06 I've posted my blog entry on this mystery:
http://late.am/post/2012/04/30/the-exec-statement-and-a-python-mystery
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2562350
@dcrosta thanks for the puzzle it was fun and I enjoy your explanation. Tell Mr. Diamond I say 'HI'
Hackers Unite
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment