| | |
traceback error?
![]() |
•
•
Join Date: Oct 2006
Posts: 16
Reputation:
Solved Threads: 3
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.
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.
•
•
Join Date: Oct 2006
Posts: 71
Reputation:
Solved Threads: 1
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)
# this is a program intended just for my fiance # it is intended to be entertaining, sweet, and/or useful. # I will start by making one simple function and randomly expand on that def denaystart(): print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.''' prompt_login() print '''PyMat 2000 presents.....Secret Garden. Concieved on 10/26/06 for Denay L. Ruane.''' denaystart() # do I need to call denaystart() as a function to get it to work ?????????? # or does it call itself ???????????/ # I just can't get this program to work ?????????? def denaystart(): print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.''' prompt_login() # should prompt_login() be like is or should it be ?????? # if prompt_a == "denay" or prompt_a == "denay wiles": ??????? def prompt_login(): prompt_a = raw_input("What is your name? ").lower() try: if denaystart == "denay" or denaystart == "denay wiles": print '''Welcome to your secret garden, Sailboat! This program is designed to give you something to entertain yourself with when you are very bored (we all know how bored you would have to be to play with stupid programs like mine!) There are a few things you can do with this program, here are the commands that let you do some of them... PLAY GAMES, and have WORD FUN. There are more coming to you, so be patient. My Creator, The Almighty One, has only limited time to work on me. Enjoy your gift, Denay.''' denaylogged() else: print "Access Denied due to improper Identity Clearance." # Idle GUI shell says there is a syntax error on next line down except: pass # I don't understand the except: pass thing but I was told try: needs it to work properly ??????? def denaylogged(): print '''Hello, Denay! My name is Sally, I am a Multi Purpose Platform Interactive Program, or MPPIP for short. I was designed by a blossoming programming genious to provide you with some entertainment and a friend if you need one. While talking to me is not the same as talking to a real person, I will do my best to provide you with the highest quality of virtual friendship. My A.I. is not very advanced as of yet, but I will learn as we interact. ''' prompt_dl() def prompt_dl(): prompt_b = raw_input("Tell Sally: ").lower() # And here, would it be this or: try: # try: if denay_logged == "play games" or denay_logged == "games": # if prompt_dl == "" or prompt_dl == "": ?????? denaygames() elif denay_logged == "word fun" or denay_logged == "word": dencodefun() elif denay_logged == "help me" or denay_logged == "help commands": help1() else: print "I don't understand what you want. Type 'help commands' for advice. " except: pass def dencodefun(): print '''Hello Denay, this is Sally. I am here to help you with any questions you may have about this program. You are currently using Pymat 2000's Codex v1.0. This program allows you to translate words into secret code, or, decode words written in secret code. Codex v1.0 deals in a code called Ceaser Salad. Type 'help' for more help. ''' prompt_st() def prompt_st(): prompt_c = raw_input("Tell Sally:").lower() try: if dencodefun == "help": print '''Well, hello Denay, I assume you need some help with Codex? Alright. When you first load the program, you come to the main menu screen. Here you will choose an option that best suits your needs. Choose option (1) to Encode, or translate readable messages into Ceaser Salad code. Choose option (2) to Decode, or, translate Ceaser Salad code into readable words. Option number (3) will tell you alittle more about Codex v1.0, while option number (4) will exit the program. REMEMBER Denay, when making a selection, type in the number of the action you wish to make, not the words. To begin the fun, type 'start'. ''' elif dencodefun == "start" or dencodefun == "begin": execfile('pymat2000.pyw') else: print "I am yet still very young, could you type everything out so I can understand?" prompt_st() except: pass def help1(): print ''' Hello Denay, this is Sally again. I am going to help you with the command list. When you are in any program, typing 'help' at any time will call me, and I will explain to you the commands for that program. In this program your commands are 'play games', 'word games', and of course 'help'. Enter your commands with exact spelling, or I will not understand. Have fun sweetie. ''' prompt_b() # my main challenge is understanding the def function(): mechanics. ???????? # is this correct: ??????????? # def function(): # print '''words and stuff go here ''' ??????? # prompt_function = raw_input(""): that is my problem. ?????? # do i call the user input prompt the same as the function, or did I do it right in # the example???????????? # and for: # if (user input prompt) == "": # what do I call the user input prompt? # Next step is to make sure that the Codex works # Start developing word games for the word fun section # Create a function for more info on Sally
Define/create all your functions before you call
The way you have written your code right now
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. May 'the Google' be with you!
![]() |
Similar Threads
- Help with wxpython program (Python)
- P2exe snippet errors (Python)
- Error trapping while reading windows XP registry entries (Python)
- RunTimeError (Python)
Other Threads in the Python Forum
- Previous Thread: New to the forum
- Next Thread: Spell a String in reverse
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






