Use inequality from user input string










1















Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:



import random

class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()


So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, = exist.

I then have to save this as a string with the value of the equality sign.



 for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="


Which I then use in another switch statement to manually check the difference.



 dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False


I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:



import operator
ops = "+": operator.add, "-": operator.sub


I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.



Thank you so much for the help! :)










share|improve this question



















  • 1





    if user_input[i] in "<>=": self.track_op = user_input[i]

    – Barmar
    Nov 15 '18 at 20:21






  • 1





    Also, get out of the habit of for i in range(len(user_input)): and learn to use for char in user_input:

    – Barmar
    Nov 15 '18 at 20:22











  • Excellent advice @Barmar ! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:26















1















Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:



import random

class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()


So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, = exist.

I then have to save this as a string with the value of the equality sign.



 for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="


Which I then use in another switch statement to manually check the difference.



 dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False


I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:



import operator
ops = "+": operator.add, "-": operator.sub


I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.



Thank you so much for the help! :)










share|improve this question



















  • 1





    if user_input[i] in "<>=": self.track_op = user_input[i]

    – Barmar
    Nov 15 '18 at 20:21






  • 1





    Also, get out of the habit of for i in range(len(user_input)): and learn to use for char in user_input:

    – Barmar
    Nov 15 '18 at 20:22











  • Excellent advice @Barmar ! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:26













1












1








1








Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:



import random

class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()


So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, = exist.

I then have to save this as a string with the value of the equality sign.



 for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="


Which I then use in another switch statement to manually check the difference.



 dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False


I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:



import operator
ops = "+": operator.add, "-": operator.sub


I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.



Thank you so much for the help! :)










share|improve this question
















Lets say I'm writing a program that checks if input [ one number and equality statement ] compared against a randomly generated number is true, here's my code for reference:



import random

class Checker():
def __init__(self):
self.user_num=
self.comp_roll()
self.input_drive()
def comp_roll(self):
self.roll=random.randint(1,6)+random.randint(1,6) #roll 2 d6
def input_drive(self):
self.user_input=input("Input a number and [in]equality to compare against 2 random d6")
user_input=self.user_input
for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="
self.user_num=int("".join(self.user_num)) #turn number list into one int
self.logic()
def logic(self):
dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False
print("resultnComputer Guessed %dnYou Guessed %dnDifference %d".format(result="Win! :)" if win==True else "Lose :(") % (self.roll,self.user_num,abs_dif))
test=Checker()


So as you should be able to see I'm forced to use a switch statement that individually checks the code to see if any of >, <, = exist.

I then have to save this as a string with the value of the equality sign.



 for i in range(len(user_input)):
if user_input[i].isdigit() == True: #if user_input[i] is a num
self.user_num.append(user_input[i]) #Keep track of just number from input in list
else: #if user_input[i] is not a num
if user_input[i] == ">":
self.track_op=">"
elif user_input[i] == "<":
self.track_op="<"
elif user_input[i] == "=":
self.track_op="="


Which I then use in another switch statement to manually check the difference.



 dif=self.roll-self.user_num
abs_dif=abs(dif)
if self.track_op == ">":
if dif > 0:
win=True
else:
win=False
elif self.track_op == "<":
if dif < 0:
win=True
else:
win=False
elif self.track_op == "=":
if dif == 0:
win=True
else:
win=False


I would much rather save the [in]equality sign as a dictionary that uses a similar concept to this:



import operator
ops = "+": operator.add, "-": operator.sub


I'm sure that there must be an quicker way to do this similar to the code above. I'm just not sure how to do it.



Thank you so much for the help! :)







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 20:15







Mr Mc Epic

















asked Nov 15 '18 at 20:07









Mr Mc EpicMr Mc Epic

185




185







  • 1





    if user_input[i] in "<>=": self.track_op = user_input[i]

    – Barmar
    Nov 15 '18 at 20:21






  • 1





    Also, get out of the habit of for i in range(len(user_input)): and learn to use for char in user_input:

    – Barmar
    Nov 15 '18 at 20:22











  • Excellent advice @Barmar ! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:26












  • 1





    if user_input[i] in "<>=": self.track_op = user_input[i]

    – Barmar
    Nov 15 '18 at 20:21






  • 1





    Also, get out of the habit of for i in range(len(user_input)): and learn to use for char in user_input:

    – Barmar
    Nov 15 '18 at 20:22











  • Excellent advice @Barmar ! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:26







1




1





if user_input[i] in "<>=": self.track_op = user_input[i]

– Barmar
Nov 15 '18 at 20:21





if user_input[i] in "<>=": self.track_op = user_input[i]

– Barmar
Nov 15 '18 at 20:21




1




1





Also, get out of the habit of for i in range(len(user_input)): and learn to use for char in user_input:

– Barmar
Nov 15 '18 at 20:22





Also, get out of the habit of for i in range(len(user_input)): and learn to use for char in user_input:

– Barmar
Nov 15 '18 at 20:22













Excellent advice @Barmar ! Thank you!

– Mr Mc Epic
Nov 15 '18 at 20:26





Excellent advice @Barmar ! Thank you!

– Mr Mc Epic
Nov 15 '18 at 20:26












2 Answers
2






active

oldest

votes


















3














You rarely need to use Boolean literals. Your switch first reduces to



if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0


which should make it obvious you can abstract out the comparison operators.



comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)





share|improve this answer























  • Clever! I never thought of that. Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:30


















2














Is there a reason for avoiding the builtin eval() function? If not you could just do something like this in your checker class



import random

roll=random.randint(1,6)+random.randint(1,6)


print(roll)

test_in = input("please enter your statement")

try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')


Results



10
please enter your statement>? 4>
False


And for a true statement



3
please enter your statement4>
True


Edit: I should add that eval() could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum






share|improve this answer

























  • It completely slipped my mind. That makes things so much easier! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:31






  • 1





    No problem. Please read my edit as I feel it is important to note.

    – krflol
    Nov 15 '18 at 20:32











  • Read. I assume eval() could open the program or computer up to vulnerabilities, yea?

    – Mr Mc Epic
    Nov 15 '18 at 20:39






  • 1





    "Is there a reason [to avoid] eval" Almost always.

    – chepner
    Nov 15 '18 at 20:41






  • 1





    Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use eval() on a public-facing program.

    – krflol
    Nov 15 '18 at 20:41











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327172%2fuse-inequality-from-user-input-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














You rarely need to use Boolean literals. Your switch first reduces to



if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0


which should make it obvious you can abstract out the comparison operators.



comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)





share|improve this answer























  • Clever! I never thought of that. Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:30















3














You rarely need to use Boolean literals. Your switch first reduces to



if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0


which should make it obvious you can abstract out the comparison operators.



comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)





share|improve this answer























  • Clever! I never thought of that. Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:30













3












3








3







You rarely need to use Boolean literals. Your switch first reduces to



if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0


which should make it obvious you can abstract out the comparison operators.



comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)





share|improve this answer













You rarely need to use Boolean literals. Your switch first reduces to



if self.track_op == ">":
win = dif > 0
elif self.track_op == "<":
win = dif < 0
elif self.track_op == "=":
win = dif == 0


which should make it obvious you can abstract out the comparison operators.



comp_ops = ">": operator.gt, "<": operator.lt, "=": operator.eq
if self.track_op in comp_ops:
win = comp_ops[self.trac_op](dif, 0)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 20:20









chepnerchepner

259k34249343




259k34249343












  • Clever! I never thought of that. Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:30

















  • Clever! I never thought of that. Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:30
















Clever! I never thought of that. Thank you!

– Mr Mc Epic
Nov 15 '18 at 20:30





Clever! I never thought of that. Thank you!

– Mr Mc Epic
Nov 15 '18 at 20:30













2














Is there a reason for avoiding the builtin eval() function? If not you could just do something like this in your checker class



import random

roll=random.randint(1,6)+random.randint(1,6)


print(roll)

test_in = input("please enter your statement")

try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')


Results



10
please enter your statement>? 4>
False


And for a true statement



3
please enter your statement4>
True


Edit: I should add that eval() could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum






share|improve this answer

























  • It completely slipped my mind. That makes things so much easier! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:31






  • 1





    No problem. Please read my edit as I feel it is important to note.

    – krflol
    Nov 15 '18 at 20:32











  • Read. I assume eval() could open the program or computer up to vulnerabilities, yea?

    – Mr Mc Epic
    Nov 15 '18 at 20:39






  • 1





    "Is there a reason [to avoid] eval" Almost always.

    – chepner
    Nov 15 '18 at 20:41






  • 1





    Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use eval() on a public-facing program.

    – krflol
    Nov 15 '18 at 20:41















2














Is there a reason for avoiding the builtin eval() function? If not you could just do something like this in your checker class



import random

roll=random.randint(1,6)+random.randint(1,6)


print(roll)

test_in = input("please enter your statement")

try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')


Results



10
please enter your statement>? 4>
False


And for a true statement



3
please enter your statement4>
True


Edit: I should add that eval() could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum






share|improve this answer

























  • It completely slipped my mind. That makes things so much easier! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:31






  • 1





    No problem. Please read my edit as I feel it is important to note.

    – krflol
    Nov 15 '18 at 20:32











  • Read. I assume eval() could open the program or computer up to vulnerabilities, yea?

    – Mr Mc Epic
    Nov 15 '18 at 20:39






  • 1





    "Is there a reason [to avoid] eval" Almost always.

    – chepner
    Nov 15 '18 at 20:41






  • 1





    Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use eval() on a public-facing program.

    – krflol
    Nov 15 '18 at 20:41













2












2








2







Is there a reason for avoiding the builtin eval() function? If not you could just do something like this in your checker class



import random

roll=random.randint(1,6)+random.randint(1,6)


print(roll)

test_in = input("please enter your statement")

try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')


Results



10
please enter your statement>? 4>
False


And for a true statement



3
please enter your statement4>
True


Edit: I should add that eval() could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum






share|improve this answer















Is there a reason for avoiding the builtin eval() function? If not you could just do something like this in your checker class



import random

roll=random.randint(1,6)+random.randint(1,6)


print(roll)

test_in = input("please enter your statement")

try:
test_out = eval(f"test_inroll")
print(test_out)
except:
print('Invalid Entry')


Results



10
please enter your statement>? 4>
False


And for a true statement



3
please enter your statement4>
True


Edit: I should add that eval() could be dangerous as it can execute arbitrary python commands. It doesn't seem like an issue in your case but I'd feel remiss if I didn't add an addendum







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 20:31

























answered Nov 15 '18 at 20:25









krflolkrflol

55728




55728












  • It completely slipped my mind. That makes things so much easier! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:31






  • 1





    No problem. Please read my edit as I feel it is important to note.

    – krflol
    Nov 15 '18 at 20:32











  • Read. I assume eval() could open the program or computer up to vulnerabilities, yea?

    – Mr Mc Epic
    Nov 15 '18 at 20:39






  • 1





    "Is there a reason [to avoid] eval" Almost always.

    – chepner
    Nov 15 '18 at 20:41






  • 1





    Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use eval() on a public-facing program.

    – krflol
    Nov 15 '18 at 20:41

















  • It completely slipped my mind. That makes things so much easier! Thank you!

    – Mr Mc Epic
    Nov 15 '18 at 20:31






  • 1





    No problem. Please read my edit as I feel it is important to note.

    – krflol
    Nov 15 '18 at 20:32











  • Read. I assume eval() could open the program or computer up to vulnerabilities, yea?

    – Mr Mc Epic
    Nov 15 '18 at 20:39






  • 1





    "Is there a reason [to avoid] eval" Almost always.

    – chepner
    Nov 15 '18 at 20:41






  • 1





    Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use eval() on a public-facing program.

    – krflol
    Nov 15 '18 at 20:41
















It completely slipped my mind. That makes things so much easier! Thank you!

– Mr Mc Epic
Nov 15 '18 at 20:31





It completely slipped my mind. That makes things so much easier! Thank you!

– Mr Mc Epic
Nov 15 '18 at 20:31




1




1





No problem. Please read my edit as I feel it is important to note.

– krflol
Nov 15 '18 at 20:32





No problem. Please read my edit as I feel it is important to note.

– krflol
Nov 15 '18 at 20:32













Read. I assume eval() could open the program or computer up to vulnerabilities, yea?

– Mr Mc Epic
Nov 15 '18 at 20:39





Read. I assume eval() could open the program or computer up to vulnerabilities, yea?

– Mr Mc Epic
Nov 15 '18 at 20:39




1




1





"Is there a reason [to avoid] eval" Almost always.

– chepner
Nov 15 '18 at 20:41





"Is there a reason [to avoid] eval" Almost always.

– chepner
Nov 15 '18 at 20:41




1




1





Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use eval() on a public-facing program.

– krflol
Nov 15 '18 at 20:41





Correct. You can add checks and other security measures to make sure you're evaluating what you want, but I would not use eval() on a public-facing program.

– krflol
Nov 15 '18 at 20:41

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327172%2fuse-inequality-from-user-input-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3