scriptPath = os.path.abspath(__file__)
scriptPath = os.path.dirname(scriptPath)
ENG_RequestDataFile = scriptPath + "\ENG_RequestData.json"
DEU_RequestDataFile = scriptPath + "\DEU_RequestData.json"
LNG = ('ENG', 'DEU')
def ENG_Request():
try:
with open(ENG_RequestDataFile) as json_file:
#print json_file
JSON_ENGData = json.load(json_file)
print JSON_ENGData
except:
print ("[ERROR] Cannot open the ENG JSON file")
def DEU_Request():
try:
with open(DEU_RequestDataFile) as json_file:
JSON_DEUData = json.load(json_file)
print JSON_DEUData
except:
print ("[ERROR] Cannot open the DEU JSON file")
if __name__ == "__main__":
if (LNG[0] == 'ENG'):
print LNG[0]
ENG_Request()
elif (LNG[1] == 'DEU'):
DEU_Request()
else:
print "NO More Languages"
上面的代码是开放的JSON文件,但在此之前,我比较两种语言作为ENG和申。如果是ENG,则调用上述的特定功能,如果是DEU,则调用其他特定功能。但是我无法调用主函数的特定函数。有人能告诉我什么是错误吗?如何在python中调用函数?
你不叫他们。调用函数='ENG_Request()' – Obsidian
对不起!我忘了在我的代码中添加该代码。但是我收到错误信息,打印出“没有更多语言”。他并没有叫任何功能 – sam
您的代码在我结束运行良好,总是调用'ENG_Request()'不知道你如何到达最后一else块。 – Obsidian