Python Forum
I need help debugging a class.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help debugging a class.
#2
First of all, it's a pain to go through 260 lines of code finding an error. You should trim down your code to the minimum required to reproduce the error. Often while doing that you will figure out the solution yourself.

Second, you can't eval an assignment, that's why you're getting a syntax error. You need exec for that.

Third, you are using eval way too much. I'm not paranoid about eval the way some pythonistas are, but it should be used only when necessary. You could have a dictionary of the functions, and just call them:

def spam():
    print('Here is your spam.')

def eggs():
    print('Here is your spam and eggs.')

commands = {'spam': spam, 'eggs': eggs}

choice = input('Would you like spam or eggs? ')
commands[choice]()    # Note the parentheses, which call the function returned from the dictionary
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
I need help debugging a class. - by knightwatch - Jan-16-2019, 01:52 AM
RE: I need help debugging a class. - by ichabod801 - Jan-16-2019, 02:08 AM
RE: I need help debugging a class. - by stullis - Jan-16-2019, 02:28 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020