比如说我得到了代码:
def getRoute(getRouteFile):
getRoutePath = []
routeFile = open(getRouteFile, "r")
for routes in routeFile:
getRoutePath.append(map(ord, routes.split('>')))
return getRoutePath
如果我执行的功能会尝试从名为:
的函数调用getRoutePath数组中的项目def routeCalculation(getRoute,nodeTable, currentNode):
我该怎么称呼它?我尝试过这样做:
def routeCalculation(getRoute,nodeTable, currentNode):
route = getRoutePath
def routeCalculation(getRoute,nodeTable, currentNode):
route = getRoute[getRouthPath]
似乎没有工作。任何人都可以帮助我吗?
答案 0 :(得分:0)
每当在函数中声明变量时,退出函数时,变量都会被销毁。例如:
a = ""
def function():
a = "hello"
b = "hello"
print(a) #prints "hello" because a was declared outside of the function
print(b) #does not print anything
这称为“范围”,如果您在理解它时遇到问题,则应该搜索有关它的教程。为了解决您的问题,请在您的函数之外移动代码getRoutePath = []
。