This function newdef() works flawlessly in interpreter, but when executed as a file it throws a NameError. Can someone tell me why?
myuser$ cat r2.py
#!/usr/bin/env python
def newdef():
a = input('say yes\n')
if a == 'yes':
print('he said yes')
else:
print('he said something else')
newdef()
Executed from commandline:
myuser$ ./r2.py
say yes
yes
Traceback (most recent call last):
File "./r2.py", line 11, in <module>
newdef()
File "./r2.py", line 4, in newdef
a = input('say yes\n')
File "<string>", line 1, in <module>
NameError: name 'yes' is not defined
myuser$
If i copy / paste the function into iPython interpreter and execute it there it works.