好吧,所以我不知道要搜索什么来回答这个问题。在
在我的代码中,由于某些原因,我的一些类可以按照Python的指令引用
class MyClass:
"""A simple example class"""
i = 12345
def f(self):
return 'hello world'
x = MyClass()
在我的代码中,我使用
^{pr2}$接下来,我会提到这个班
^{3}$下面是我的实际代码,这个模块名为“主.py““
from Tkinter import *
import os, sys
import Tkinter, tkFileDialog
from tkFileDialog import *
from openpyxl.reader.excel import load_workbook
from openpyxl.workbook import Workbook
#custom python classes
import reader
import searchDog
from searchDog import *
from reader import *
class appGUI:
def __init__(self,frame):
#set windows size 600 by 300
#frame = Tk()
frame.geometry("600x300+30+30")
self.openExcel = Button(frame, text = "Open Defect Excel", command = lambda: self.openExcelFile())
self.openExcel.place(x=10,y=10,width=100,height=25)
self.openDefectTextFile = Button(frame, text ="Open Text File", command = lambda: self.openDefectText())
self.openDefectTextFile.place(x=10,y=40,width=100,height=25)
self.startButton = Button(frame, text="Start",command = lambda: self.startLoadProcess())
self.startButton.place(x=10,y=70,width=100,height=25)
def openExcelFile(self):
self.openTemp = tkFileDialog.askopenfilename(parent = root, title = 'Select Defect Excel File')
def openDefectText(self):
self.openDefect = tkFileDialog.askopenfilename(parent = root, title= 'Select Defect Text File')
def start(self):
self.startLoadProcess()
def startLoadProcess(self):
#text file where defect comments are stored
filePath = self.openDefect
#keyword condition to search for
keyword = "18360" #probably will put this in a loop
#create an instance of ReadFile from searchDog
readInText = ReadFile()
keywordSearch = searchFile()
#----End searchDog Reference
#create an instance of readExcel from ExcelFileHandle
i = 2
#searches for and writes the comments into a text file
while self.readData(i, 2, self.openTemp) != None:
keywordSearch.searchForKeywordText(self.readData(i,2,self.openTemp), filePath,i) #searchDog Function
self.loadExcelFile.save(self.openTemp)
i += 1
def readData(self,inputRow,inputColumn,excelFilePath):
'''
Constructor
'''
self.loadExcelFile = load_workbook(filename = self.openTemp)
self.excelWorksheet = self.loadExcelFile.get_sheet_by_name('Defects')
self.rowInput = inputRow
self.columnInput = inputColumn
self.cellValue = self.excelWorksheet.cell(row=self.rowInput,column=self.columnInput).value
return self.cellValue, inputRow
root = Tk()
app = appGUI(root)
root.mainloop()
下一个模块被调用卓越网.py在
#built in modules from python
from openpyxl.reader.excel import load_workbook
from openpyxl.workbook import Workbook
#my custom modules from the project
import searchDog
import main
class excelWriteInClass():
'''
writes data coming from searchDog into Defects page
'''
def writeToExcelFile(self,textLine,writeRow):
'''
Constructor
'''
self.searchDogRef = searchFile()
self.appGuiRef = appGUI()
self.excelDefectWorksheet = self.appGuiRef.loadExcelFile.get_sheet_by_name('Defects')
self.excelDefectWorksheet.cell(row= writeRow, column = 11).value = textLine
我得到的错误是我的引用没有在这一行明确定义:
self.searchDogRef = searchFile()
self.appGuiRef = appGUI()
我不明白为什么有时引用类有效,有时却不起作用。这是PyDev的问题,还是Eclipse的问题?在
***计算机信息:
Eclipse V. Version: 3.6.2 Build id: M20110210-1200
Compiling under Python 2.7
- installed modules --> openPyxl
using Latest PyDev plugin downloaded from Eclipse Market***
如果我正确地理解了您,那么问题是您使用的是import/from。。导入不正确。首先,不需要同时使用“import module”和“from module import…”调用之后。在
修改主.py公司名称:
修改卓越网.py公司名称:
^{pr2}$编辑-把你放在这里主.py有一些小的修正和问题/评论:
相关问题 更多 >
编程相关推荐