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和DEU。如果是ENG,则调用如上所述的特定功能,如果是DEU则调用其他特定功能。但我无法从主函数调用特定函数。谁能告诉我这是什么错误?
答案 0 :(得分:0)
您应该使用():
调用该函数ENG_Request()