943,901 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 3355
  • Python RSS
Oct 28th, 2006
0

traceback error?

Expand Post »
i get this error when trying to run my program. Traceback (most recent call last):
File "C:\Python24\secretgarden.pyw", line 12, in -toplevel-
denaystart()
File "C:\Python24\secretgarden.pyw", line 7, in denaystart
prompt_login()
NameError: global name 'prompt_login' is not defined
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mruane is offline Offline
76 posts
since Oct 2006
Oct 28th, 2006
0

Re: traceback error?

Please post the whole script
Reputation Points: 10
Solved Threads: 2
Newbie Poster
DarkFlash is offline Offline
13 posts
since Oct 2006
Oct 28th, 2006
0

Re: traceback error?

A traceback error is simply a diagnostitic tool to see where something went wrong in your program. It shows the last three or so lines executed before the error occured. It's important to realize that python does not execute straight from top to bottom, it jumps around the place when functions, loops, and classes are involved.

File "C:\Python24\secretgarden.pyw", line 12, in -toplevel-
denaystart() --This is the line that called the function, -toplevel- simply means that this line of code is not in any functions.

File "C:\Python24\secretgarden.pyw", line 7, in denaystart
prompt_login() -Again, this time it's calling another function, this time within the function 'denaystart'

NameError: global name 'prompt_login' is not defined - You defined or called a variable incorrectly somewhere, and this is where the error occured.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Zonr_0 is offline Offline
16 posts
since Oct 2006
Oct 29th, 2006
0

Re: traceback error?

okay, i think I figured out <i>where</i> the problem is, but still can't seem to get it right. So I have included the whole source with comments almost everywhere to explain why I did what and what I was thinking. I guess most of the issue lies within denaystart(), but I can't seem to find the bug. I would appreciate any help or advice.
Python Syntax (Toggle Plain Text)
  1. # this is a program intended just for my fiance
  2. # it is intended to be entertaining, sweet, and/or useful.
  3. # I will start by making one simple function and randomly expand on that
  4. def denaystart():
  5. print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.'''
  6. prompt_login()
  7. print '''PyMat 2000 presents.....Secret Garden.
  8. Concieved on 10/26/06 for Denay L. Ruane.'''
  9. print
  10. denaystart()
  11. # do I need to call denaystart() as a function to get it to work ??????????
  12. # or does it call itself ???????????/
  13. # I just can't get this program to work ??????????
  14. def denaystart():
  15. print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.'''
  16. prompt_login()
  17. # should prompt_login() be like is or should it be ??????
  18. # if prompt_a == "denay" or prompt_a == "denay wiles": ???????
  19. def prompt_login():
  20. prompt_a = raw_input("What is your name? ").lower()
  21. try:
  22. if denaystart == "denay" or denaystart == "denay wiles":
  23. print '''Welcome to your secret garden, Sailboat! This program is
  24. designed to give you something to entertain yourself with when you
  25. are very bored (we all know how bored you would have to be to play with
  26. stupid programs like mine!) There are a few things you can do with this program,
  27. here are the commands that let you do some of them...
  28. PLAY GAMES, and have WORD FUN. There are more coming to you, so be
  29. patient. My Creator, The Almighty One, has only limited time to work on
  30. me. Enjoy your gift, Denay.'''
  31. print
  32. denaylogged()
  33. else:
  34. print "Access Denied due to improper Identity Clearance." # Idle GUI shell says there is a syntax error on next line down
  35. except:
  36. pass # I don't understand the except: pass thing but I was told try: needs it to work properly ???????
  37. def denaylogged():
  38. print '''Hello, Denay! My name is Sally, I am a Multi Purpose Platform Interactive Program,
  39. or MPPIP for short. I was designed by a blossoming programming genious to provide you with some
  40. entertainment and a friend if you need one. While talking to me is not the same as talking to a real
  41. person, I will do my best to provide you with the highest quality of virtual friendship. My A.I.
  42. is not very advanced as of yet, but I will learn as we interact. '''
  43. print
  44. prompt_dl()
  45. def prompt_dl():
  46. prompt_b = raw_input("Tell Sally: ").lower() # And here, would it be this or:
  47. try: # try:
  48. if denay_logged == "play games" or denay_logged == "games": # if prompt_dl == "" or prompt_dl == "": ??????
  49. denaygames()
  50. elif denay_logged == "word fun" or denay_logged == "word":
  51. dencodefun()
  52. elif denay_logged == "help me" or denay_logged == "help commands":
  53. help1()
  54. else:
  55. print "I don't understand what you want. Type 'help commands' for advice. "
  56. except:
  57. pass
  58. def dencodefun():
  59. print '''Hello Denay, this is Sally. I am here to help you with any
  60. questions you may have about this program. You are currently using Pymat 2000's
  61. Codex v1.0. This program allows you to translate words into secret code, or, decode
  62. words written in secret code. Codex v1.0 deals in a code called Ceaser Salad. Type
  63. 'help' for more help. '''
  64. print
  65. prompt_st()
  66.  
  67. def prompt_st():
  68. prompt_c = raw_input("Tell Sally:").lower()
  69. try:
  70. if dencodefun == "help":
  71. print '''Well, hello Denay, I assume you need some help with Codex? Alright.
  72. When you first load the program, you come to the main menu screen. Here you will
  73. choose an option that best suits your needs.
  74. Choose option (1) to Encode, or translate readable messages into Ceaser Salad code.
  75. Choose option (2) to Decode, or, translate Ceaser Salad code into readable words.
  76. Option number (3) will tell you alittle more about Codex v1.0, while
  77. option number (4) will exit the program. REMEMBER Denay, when making a selection, type
  78. in the number of the action you wish to make, not the words. To begin the fun, type
  79. 'start'. '''
  80. elif dencodefun == "start" or dencodefun == "begin":
  81. execfile('pymat2000.pyw')
  82. else:
  83. print "I am yet still very young, could you type everything out so I can understand?"
  84. prompt_st()
  85. except:
  86. pass
  87. def help1():
  88. print ''' Hello Denay, this is Sally again. I am going to help you with the command list.
  89. When you are in any program, typing 'help' at any time will call me, and I will explain to you
  90. the commands for that program. In this program your commands are 'play games', 'word games', and of
  91. course 'help'. Enter your commands with exact spelling, or I will not understand. Have fun sweetie. '''
  92. print
  93. prompt_b()
  94. # my main challenge is understanding the def function(): mechanics. ????????
  95. # is this correct: ???????????
  96. # def function():
  97. # print '''words and stuff go here ''' ???????
  98. # print
  99. # prompt_function = raw_input(""): that is my problem. ??????
  100. # do i call the user input prompt the same as the function, or did I do it right in
  101. # the example????????????
  102. # and for:
  103. # if (user input prompt) == "":
  104. # what do I call the user input prompt?
  105.  
  106. # Next step is to make sure that the Codex works
  107. # Start developing word games for the word fun section
  108. # Create a function for more info on Sally
  109.  
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mruane is offline Offline
76 posts
since Oct 2006
Oct 29th, 2006
0

Re: traceback error?

Define/create all your functions before you call denaystart(), which starts your program. Functions are called with the parenthesis, even if they are empty.

The way you have written your code right now denaystart() is called, and therefore prompt_login(), before prompt_login() has been defined.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: New to the forum
Next Thread in Python Forum Timeline: Spell a String in reverse





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC