Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to access the result something never assigned?

while int(input("choose a number")) != 5 :

Say I wanted to see what number was input. Is there an indirect way to get at that?

EDIT Im probably not being very clear lol. . I know that in the debugger, you can step through and see what number gets input. Is there maybe a memory hack or something like it that lets you get at 'old' data after the fact?

like image 620
jason Avatar asked Dec 21 '22 02:12

jason


2 Answers

Nope - you have to assign it... Your example could be written using the two-argument style iter though:

for number in iter(lambda: int(input('Choose a number: ')), 5):
    print number # prints it if it wasn't 5...
like image 55
Jon Clements Avatar answered Dec 22 '22 16:12

Jon Clements


Do something like this. You don't have to assign, but just make up an additional function and use it every time you need to do this. Hope this helps.

def printAndReturn(x): print(x); return(x)

while printAndReturn(int(input("choose a number"))) != 5 :
      # do your stuff
like image 22
rnbguy Avatar answered Dec 22 '22 15:12

rnbguy