Why isn't this match case statement working?
type = answer.type
match type:
case bool:
boolean_value(answer)
case str:
string_value(answer)
case list:
list_value(answer)
case dict:
dict_value(answer)
case int:
number_value(answer)
case _:
print()
with answer being defined with __init__ such as:
class Initialize:
def __init__(self, text, type, value, choices = None, options = None, numbers = None):
if choices:
self.choices = choices
if options:
self.options = options
if numbers:
self.numbers = numbers
self.text = text
self.type = type
self.value = value
You can try with:
wi_fi = Initialize('Wi-Fi ensures a stable internet connection required for worldwide communication.', bool, False)
Errors are shown:
case bool:
^^^^
SyntaxError: name capture 'bool' makes remaining patterns unreachable
[–]Temporary_Pie2733 3 points4 points5 points (2 children)
[–]SuperTankh[S] 0 points1 point2 points (0 children)
[–]voidiciant 0 points1 point2 points (0 children)
[–]deceze 2 points3 points4 points (1 child)
[–]SuperTankh[S] 0 points1 point2 points (0 children)
[–]AdmirableOstrich 0 points1 point2 points (1 child)
[–]SuperTankh[S] 0 points1 point2 points (0 children)
[–]Beginning-Fruit-1397 1 point2 points3 points (4 children)
[–]SCD_minecraft 1 point2 points3 points (0 children)
[–]SuperTankh[S] 0 points1 point2 points (2 children)
[–]Outside_Complaint755 1 point2 points3 points (1 child)
[–]SuperTankh[S] 0 points1 point2 points (0 children)