Python 在加载的模块中找不到当前堆栈帧
我对python比较陌生,范围规则对我来说没有多大意义。对于这个问题,我找不到任何真正的帮助。当我在它不在类中的地方调用Python 在加载的模块中找不到当前堆栈帧,python,scope,Python,Scope,我对python比较陌生,范围规则对我来说没有多大意义。对于这个问题,我找不到任何真正的帮助。当我在它不在类中的地方调用Start(ToolTester.RUString)时,它将运行,但当我在这里尝试时,我得到了它 Frame not in module. the Current stack frame was not found in a loaded module. Source cannot be shown for this location. 这是文件的代码。有什么想法吗?谢谢 i
Start(ToolTester.RUString)
时,它将运行,但当我在这里尝试时,我得到了它
Frame not in module. the Current stack frame was not found in a loaded module. Source cannot be shown for this location.
这是文件的代码。有什么想法吗?谢谢
import DataFunctions
import automa
from DataFunctions import *
from automa.api import *
class ToolTester():
def ClickOnCalculator(self, readableTimeStamp):
try:
RetailWindow = start(r"C:\Users\mhunt\Source\Workspaces\Retail Utilities\Retail Utilities\Retail Utilities\bin\Debug\Retail Utilities.exe")
click("POS")
click(TextField("Associate Code"))
write("722345")
click("Enter")
click(TextField("Shift Owner: System Admin"))
write("722345")
click("Enter")
click("Tools")
click("Calculator")
click("Close")
click("System", "Close/Suspend Shift")
click("yes")
kill(RetailWindow)
file = open("%s.txt" %readableTimeStamp, "a")
file.write("ToolsCalculator Passed!\n")
file.close()
IncrementingTestPassedCounter.incrementTestPassed(readableTimeStamp)
except:
file = open("%s.txt" %readableTimeStamp, "a")
file.write("ToolsCalculator Failed!\n")
file.close()
IncrementingTestFailedCounter.incrementTestFailed(readableTimeStamp)
这是主文件
import Tests
from Tests import *
import DataFunctions
from DataFunctions import *
import datetime
import time
from decimal import Decimal
from ToolsTesting import *
#txt file written to keep track of results. File name is the timestamp from when the file was started
timeStamp = time.time()
readableTimeStamp = datetime.datetime.fromtimestamp(timeStamp).strftime("%Y.%m.%d %H.%M.%S")
Tests.ResultsFileSetup.Setup(readableTimeStamp)
toolTester = ToolsTesting.ToolTester()
toolTester.ClickOnCalculator(readableTimeStamp)
toolTester.ClickOnPrintAMDMatrix(readableTimeStamp)
toolTester.ClickOnReturnAllocation(readableTimeStamp)
是的,我想这正是你的问题:
# You do not call or set an attribute of a class from within a method of that classes instance
# So:
class ToolTester:
RUString = ""
def __init__ (self):
self.RUString = "I am string"
def GetTheString (self):
return self.RUString
更改ToolTester.RUString而不是self.RUString会更改类的属性,而不是从中实例化的对象的属性。
这样做是不寻常的,而且只有在特殊场合才会这样做。
我希望这是Python提到的范围问题。是的,我认为这正是您的问题:
# You do not call or set an attribute of a class from within a method of that classes instance
# So:
class ToolTester:
RUString = ""
def __init__ (self):
self.RUString = "I am string"
def GetTheString (self):
return self.RUString
更改ToolTester.RUString而不是self.RUString会更改类的属性,而不是从中实例化的对象的属性。
这样做是不寻常的,而且只有在特殊场合才会这样做。
我希望这是Python提到的范围问题。您有bug!示例代码中的代码缩进是错误的,因此也违反了此范围。您正在设置ToolTester.RUString而不是self.RUString。你确定要这样做吗?编辑了间距,仍然有相同的问题你有错误!示例代码中的代码缩进是错误的,因此也违反了此范围。您正在设置ToolTester.RUString而不是self.RUString。你确定要这样做吗?编辑了间距,仍然有相同的问题只是为了确保没有问题,我删除了代码的这一部分。我仍然有与以前相同的错误,在主文件中,您执行了“fromToolTestingImport*”,这意味着ToolTester()加载在主范围中(与C#include相比)。要么将其更改为“import ToolTesting”,要么删除其引用,那么它就是“Tester=ToolTester()”。但我不知道为什么这会引发堆栈帧错误。您应该得到的错误应该是“NameError:全局变量'ToolTesting'未定义”,因此可能不止这些。为了确保没有问题,我删除了代码的这一部分。我仍然有与以前相同的错误,在主文件中,您执行了“fromToolTestingImport*”,这意味着ToolTester()加载在主范围中(与C#include相比)。要么将其更改为“import ToolTesting”,要么删除其引用,那么它就是“Tester=ToolTester()”。但我不知道为什么这会引发堆栈帧错误。您应该得到的错误应该是“NameError:global variable'ToolTesting'未定义”,因此可能不止这些。