> On Mon, Feb 20, 2012 at 6:46 PM, Michael Lewis <mjole...@gmail.com> wrote: > > I at first put it outside and after all my functions but got the error > below > > That's the right place for it, you just spelled it wrong. > > > and then put it inside my last function and the program ran. > > That's not the right place for it. Your program ran, but only because > nothing ever called your GetUserInput() function any more.
Now I am confused. I fixed the spelling and put it outside all my functions; however, the code now runs WITHOUT me explicitly importing it. def MultiplyText(text, multiplier): '''Recieve a S & int. For digits in S, multiply by multiplier and return updated S.''' return ' '.join(str(int(num) * multiplier) if num.isdigit() else num for num in text) def GetUserInput(): '''Get S & multiplier. Test multiplier.isdigit(). Call MultiplyText(text, multiplier)''' text = raw_input('Enter some text: ') while True: multiplier = raw_input('Enter a multiplier: ') try: multiplier = int(multiplier) break except ValueError: continue return MultiplyText(text.split(), multiplier) if __name__ == '__main__': GetUserInput() > > > Traceback (most recent call last): > > ? File "C:/Python27/Homework/Homework5_1.py", line 24, in <module> > > ? ? if __name == '__main__': > > NameError: name '__name' is not defined > > It needs to be spelled "__name__" -- that's two underscores on each side. > > -- > Jerry >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor