+ 2

It Runs Perfectly, Gives Error when you Debug

For Python --> Module 7: Object Oriented Programming --> Class & Static Methods, the examples are interesting. When I run them both, they give the results shown. But when I debug them, they actually give me an error. Example for Class Methods class Rectangle: def __init__(self, width, height): self.width = width self.height = height def calculate_area(self): return self.width * self.height @classmethod def new_square(cls, side_length): return cls(side_length, side_length) square = Rectangle.new_square(5) print(square.calculate_area()) Example for Static Methods: class Pizza: def __init__(self, toppings): self.toppings = toppings @staticmethod def validate_topping(topping): if topping == "pineapple": raise ValueError("No pineapples!") else: return True ingredients = ["cheese", "onions", "spam"] if all(Pizza.validate_topping(i) for i in ingredients): pizza = Pizza(ingredients) When I run the Class Method code, it gives me 25 as usual, but this is not the case in debugging. The error it gives is really various based on the IDE. For Thonny, it gives AttributeError: 'CustomStackFrame' object has no attribute 'node_tags'. For Python IDLE, it gives a different kind of error: Invalid Character in Identifier Can someone please explain if the program is right, or if it is wrong?

26th Dec 2018, 10:25 PM
BitsAndBytes
BitsAndBytes - avatar
4 Answers
+ 1
Code looks okay to me! Maybe it was a problem with how the debugger was run? I don't normally use a debugger for Python, so I can't say for sure. But it worked fine with pdb ( https://docs.python.org/3/library/pdb.html ) and ptvsd (for VS Code) in my computer.
1st Jan 2019, 4:56 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
What does your debugging mean? What is the Python version of your IDE and IDLE? Have you removed the @ lines before running?
31st Dec 2018, 12:11 PM
Gordon
Gordon - avatar
0
Python 3 I need the @ lines to define them as class and static methods
31st Dec 2018, 4:03 PM
BitsAndBytes
BitsAndBytes - avatar
0
I don't entirely understand what your question is, but I'll ask for help for you. Kishalaya Saha
1st Jan 2019, 2:25 AM
Gordon
Gordon - avatar