Linked Questions

0 votes
1 answer
9k views

After reading query. below python code is still not clear, >>> exec('print(5+10)') 15 >>> eval('print(5+10)') 15 In bash world, exec replace the shell with the given command. ...
overexchange's user avatar
  • 17.3k
2 votes
1 answer
4k views

Possible Duplicate: What’s the difference between eval, exec, and compile in Python? I known that eval is a function exec is a statement And the simple usage of both is : eval('1+2') exec 'print ...
Tanky Woo's user avatar
  • 5,164
2 votes
0 answers
1k views

I get the following error. Is there a way to eval import? >>> eval('import os') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", ...
user1424739's user avatar
  • 14.1k
2 votes
1 answer
2k views

x = """ def test_add(a, b): add = a + b return add test_add(10, 6) """ print(eval(x)) The above code produces following error: File "<string>", ...
dine b's user avatar
  • 49
0 votes
1 answer
569 views

In python, if I exec a statement which prints a value, I will see the output, e.g., exec("print 10") gives me output 10. However, if I do exec("10") I got nothing as output, where as if I type 10 in ...
shaoyl85's user avatar
  • 1,999
0 votes
1 answer
116 views

I'm trying to convert English into a python code, and here is how I do it: english.eng: the following line is a comment: This is a demo of english programming language set a new variable dorito as &...
user avatar
0 votes
1 answer
149 views

I have a function that returns a string that can be interpreted as a Boolean def foo(): return "not(True and False)" How can I return the actual Boolean value, in this case True?
user avatar
0 votes
0 answers
75 views

I am trying to use eval to load. It does not work as in just running it. See Python shell: The version is: python3.6m >>>> eval( 'import re' ) Traceback (most recent call last): File &...
user1134991's user avatar
  • 3,129
0 votes
0 answers
74 views

Working on getting seriously into python3. While trying to eval(generated_code) to parse arguments I get an unexpected syntax error during the eval. Iv'e whittled down the code to a simpler failure ...
Gilbert's user avatar
  • 3,806
0 votes
0 answers
38 views

Here is my MWE (which looks stupid): def somefunc(a0,a1,b1,a2,b2): first = 'a0' rest = ['+a{}+b{}'.format(i,i) for i in range(1, int((len(locals())-1) / 2) for element in rest: ...
Euler_Salter's user avatar
  • 3,601
0 votes
0 answers
26 views

I'm trying to run a function that is inside a string variable in Python. The code I'm using is: def func1(): return "Hello" word = "func1()" a = exec(word) print(a) But, ...
Wolf's user avatar
  • 15
0 votes
0 answers
25 views

My Python 3 code: test = "c.mode=0; c.preview=False" eval(test) Output: File "<string>", line 1 c.mode=0; c.preview=False ^ SyntaxError: invalid syntax Why? ...
nerdfever.com's user avatar
55 votes
14 answers
41k views

Is it possible to put a function in a data structure, without first giving it a name with def? # This is the behaviour I want. Prints "hi". def myprint(msg): print msg f_list = [ myprint ] f_list[...
Tim's user avatar
  • 14.2k
58 votes
6 answers
37k views

It looks like you can't use exec in a function that has a subfunction... Anyone know why this Python code doesn't work? I get an error at the exec in test2. Also, I know exec's aren't good style, ...
user avatar

15 30 50 per page
1
2 3 4 5 6