from dataclasses import dataclass, field
from employee import Employee
import json
import re
# from custom_exception import Input_Exception
@dataclass()
class ResourceManager:
employee_list: dict = field(default_factory=dict)
def menu(self):
print('Menu:')
print('1 : Show data about employee')
print('2 : Add new employee')
print('3 : Remove employee')
print('4 : Add or remove employee hours')
print('5 : Save changes into the file')
print('6 : Load data from the file')
print('7 : Check employee salary')
print('0 : Exit program')
def controls(self):
switch = {
"1": self.search_employee,
"2": self.add_employee,
"3": self.remove_employee,
"4": self.change_hours,
"5": self.save_data,
"6": self.load_data,
"7": self.check_salary,
"x": self.quit,
}
choice = input("Wybierz jedną opcję:\n=> ")
if choice in switch.keys():
switch[choice]()
else:
print("Niepoprawny wybór!")
def quit(self):
x = False
return x
ResourceManage is a class used to represent fairly simple CLI, I used dictionary to implement switch and want to use def quit(self) to exit program.
from resource_manager import ResourceManager
if __name__ == '__main__':
setup = ResourceManager()
x = True
while x:
setup.menu()
setup.controls()
CLI Menu where I'm trying to use def quit(self) method to quit while loop by changing global x but it dose not work. I've tried quite few different thing but cant get this to work.
How can I fix that?
quitjust returns a value; the name of the unnecessary local variable is unrelated to the global variable that controls the loop.quitassume that a global variable namedxcontrols the loop. The loop itself should be incorporated into the class, if anything.