2015-07-10 156 views
1

對於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) 
+0

你有錯誤!代碼縮進在你的示例代碼中是錯誤的,因此這個範圍也被違反了。並且您正在設置ToolTester.RUString而不是self.RUString。你確定要這麼做嗎? – Dalen

+0

編輯間距,仍然有相同的問題 – Shikumaru

回答

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 

改變,而不是self.RUString ToolTester.RUString改變的屬性類,而不是從它實例化的對象。 要做到這一點是不尋常的,它只在特殊場合下完成。 這是Python提到的範圍問題,我希望。

+0

只是爲了確保沒有問題,我刪除了部分代碼。我仍然有和以前一樣的錯誤 – Shikumaru

+0

在主文件中,你做了「從ToolTesting import *」,這意味着ToolTester()被加載到主範圍中(與C#include相比)。將其改爲「導入ToolTesting」或刪除其引用,然後是「Tester = ToolTester()」。 – Dalen

+0

但爲什麼這會提高堆棧幀錯誤,我不知道。你應該得到的錯誤應該是「NameError:全局變量'ToolTesting'沒有定義」所以也許不止於此。 – Dalen

相關問題