我似乎无法理解这个错误:Picture.GetFrameColor() 缺少 1 个必需的位置参数:"self"


class Picture:
# PRIVATE Pdescription : STRING
# PRIVATE Pwidth : INTEGER
# PRIVATE Pheight : INTEGER
# PRIVATE Pframecolour : STRING
def __init__(self, Pdescription, Pwidth, Pheight, Pframecolour):
self.__Description = Pdescription
self.__Width = Pwidth
self.__Height = Pheight
self.__FrameColour = Pframecolour
def GetDescription(self):
return self.__Description
def GetWidth(self):
return self.__Width
def GetHeight(self):
return self.__Height
def GetFrameColour(self):
return self.__FrameColour
def SetDescription(self, newdescription):
self.__Description = newdescription

myArray = [Picture for i in range(100)]

def ReadData():
global myArray
itemsadded = 0
try:
filename = ("C:\Users\MikaaOneDrive\Documents\A2 python\pp solus x2\9618_41_on_21 V1\Pictures.txt")
file = open(filename, "r")
lines = file.readlines()
filelength = len(lines)
for counter in range(0, filelength, 4):
descrption = lines[counter].replace("n", "")
width = lines[counter + 1].replace("n", "")
height = lines[counter + 2].replace("n", "")
framecolour = lines[counter + 3].replace("n", "")
item = Picture(descrption, width, height, framecolour)
myArray.append(item)
itemsadded = itemsadded + 1
file.close()
except IOError:
print("file not found")
return itemsadded

result = ReadData()
print(result)
framecolour = input("Please enter the frame colour you are looking for: ").lower()
maxwidth = int(input("Please enter the maximum width you would like: "))
maxheight = int(input("Please enter the maximum height you would like: "))
for counter in range(len(myArray)):
tempframcolour = myArray[counter].GetFrameColour()
tempwidth = myArray[counter].GetWidth()
tempheight = myArray[counter].GetHeight()
tempdescription = myArray[counter].GetDescription()
if tempframcolour == framecolour and maxwidth <= tempwidth and maxheight <= tempheight:
print(f"picture desription: {tempdescription} | width: {tempwidth} | height: {tempheight}")
# ms ans (still doesnt work)
# if myArray[counter].GetFrameColour() == framecolour and maxwidth >= myArray[counter].GetWidth() and maxheight >= myArray[counter].GetHeight():
#     print(f"picture desription: {myArray[counter].GetFrameColour()} | width: {myArray[counter].GetWidth()} | height: {myArray[counter].GetHeight()}")

我有一个名为Pictures.txt的文本文件,它只包含一些关于图片的信息,例如:

鲜花4550黑色

我正在使用吸气剂方法

def GetFrameColour(self(:回归自我__FrameColour

我允许我的用户在文本文件中搜索项目,如framecolor、maxheight和maxwidth,以返回一些有用的搜索结果,但不断收到错误:

图片。GetFrameColor((缺少1个必需的位置参数:"self">

myArray = [Picture for i in range(100)]创建一个列表,其中包含对Picture类的100个引用。稍后,您将实例附加到数组(myArray.append(item)(,但这些实例将附加在前面的100个类引用之后。您不需要预先初始化数组;只需创建一个空的

myArray = []

相关内容

最新更新