Eval Function related ?

A forum for general discussion of the Python programming language.

Eval Function related ?

Postby vijaykumbhani » Mon Sep 16, 2013 7:16 am

Code: Select all
string = ' "name" == "name" '
print eval(string)

above code working


Code: Select all
string = ' name == name '
print eval(string)

above code not working ?

any idea
without quotes in string
working properly
give me function or any library name work as well as eval
[b][i]With Regards,
Vijay Kumbhani[/i][/b]
Posts: 33
Joined: Wed Aug 14, 2013 4:26 am
Location: Surat, Gujarat, India

Re: Eval Function related ?

Postby metulburr » Mon Sep 16, 2013 7:38 am

eval is essetially converting the string to code.

Code: Select all
' "name" == "name" '

Code: Select all
"name" == "name"

Code: Select all
' name == name '

Code: Select all
name == name

and unless you did not show the whole code, you should get a NameError with the second. It is checking if the variable name is equal to the variable name. Since you did not create a variable name, you should get a NameError. Whereas the first one is comparing the strings.
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests