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\\Mikaa\OneDrive\\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()}")
I have a text file called Pictures.txt that simply contains some information about pictures for example:
Flowers 45 50 black
I am using the getter method
def GetFrameColour(self): return self.__FrameColour
I am allowing my users to search for items in the text file such as framecolor, maxheight and maxwidth to return some useful search results but keep getting the error:
Picture.GetFrameColour() missing 1 required positional argument: 'self'