我有下面的全球词典
global configurationFileInfo_saved
configurationFileInfo_saved = {
'True_key': 'True',
'False_key': 'False',
'filename': "Configuration-noMeta" + extnt,
'os_key': "os",
'os': "windows",
'os_windowsCode': "windows",
'os_linuxCode': "linux",
'guiEnabled': 'True',
'guiEn_key': "GUI",
'allowCustom': 'True',
'allowCustom_key': "allowCustomQuizConfiguration",
'allOrPart': "a",
'allOrPart_key': "questions_partOrAll",
'allOrPart_allCode': "a",
'allOrPart_partCode': "p",
'questionAmountDivisionFactor': 2,
'questionAmountDivisionFactor_key': "divisionFactor",
'mode': "e",
'mode_key': "mode",
'mode_noDeduction_code': "noDeductions",
'mode_allowDeductions_code': "allowDeductions",
'deductionsPerIncorrect': 1,
'deductionsPerIncorrect_key': "allowDeductions_pointDeduction_perIncorrectResponse",
'loc': "C:\\Program Files (x86)\\Quizzing Application <Version>\\Admin\\Application Files\\dist\\Main\\",
'loc_key': "location",
'title': "Quizzing Appliaction <Version> -- By Geetansh Gautam",
'title_key': "title"
这是访问词典的地方:
config_onBoot_keys = list(configSaved(True, False, None).keys())
config_onBoot_vals = list(configSaved(True, False, None).values())
configSaved(False, True, configurationFileInfo)
configSaved (Tempoarary function for reading andd writing):
def configSaved(get, save, saveDict):
if get:
return configurationFileInfo_saved
elif save:
configurationFileInfo_saved = saveDict
当我以后访问dictionary是一个函数时,我得到以下错误:
UnboundLocalError: local variable 'configurationFileInfo_saved' referenced before assignment
我做错了什么
这是因为我们只能在函数内部访问全局变量,但要进行修改,必须在函数内部使用global关键字
例如,这不会给出localbound错误:
这将给出错误:
例如:
要避免此错误,请执行以下操作:
现在回答问题:
相关问题 更多 >
编程相关推荐