在加载的模块

时间:2015-07-10 16:06:34

标签: 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.

这是该文件的代码。有任何想法吗?谢谢!

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)

1 个答案:

答案 0 :(得分:0)

是的,我认为这正是你的问题:

# 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所指的范围问题,我希望。