tags:

views:

70

answers:

4

Ok, this is funny.

>>> exec("print")
>>> help(exec)
  File "<stdin>", line 1
    help(exec)
            ^
SyntaxError: invalid syntax
>>> 

looks like exec is a statement, not a function, hence you cannot help() it. Is this expected or a bug? if expected, why? can you reproduce it on python3 ? I have Python 2.6.1 here.

+1  A: 

http://docs.python.org/release/3.0.1/library/functions.html#exec

In Python 3, exec() is a function. Apparently, in Python 2, exec is a statement but can be used similarly to a function.

http://docs.python.org/release/3.0.1/whatsnew/3.0.html#removed-syntax

Removed keyword: exec() is no longer a keyword; it remains as a function. (Fortunately the function syntax was also accepted in 2.x.)

l33tnerd
+2  A: 

In Python 2.x, exec is a statement (and thus doesn't have a docstring associated with it.)

In Python 3.x, exec is now a function: http://docs.python.org/py3k/library/functions.html?highlight=exec#exec So it can (and does) have a docstring.

You'd get this same behavior for help(print), which also became a function in 3.x.

Adam Vandenberg
+2  A: 

yes, like my followers said but for me i usually do :

>>> help("exec")
>>> help("print")

and it work for python 2.* and python 3k

singularity
+2  A: 

Just put quotes around it (works for assert, etc. too):

>>> help('exec')
sdolan