Получение AttributeError: объект «Изображение» не имеет атрибута «getFrameColour» при попытке доступа к файлу массиваPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Получение AttributeError: объект «Изображение» не имеет атрибута «getFrameColour» при попытке доступа к файлу массива

Сообщение Anonymous »

Программа сохраняет изображения как объекты. Он хранит размер, цвет рамки и описание изображения. Программе необходимо ввести свои требования к картинке. Пользователь вводит цвет, ширину и высоту. Затем программа выполнит поиск в массиве и выведет описание изображения, если какое-либо изображение соответствует требованиям.

Код: Выделить всё

class Picture:

def __init__(self, DescriptionP, WidthP, HeightP, FrameColourP):
self.__Description = DescriptionP  # string
self.__Width = WidthP  # integer
self.__Height = HeightP  # integer
self.__FrameColour = FrameColourP  # string

def getDescription(self):
return self.__Description  # Fixed method to return the associated attribute to the user

def getWidth(self):
return self.__Width

# Key rule: Only use parameters if they are passed, otherwise only use self and attributes.
def getHeight(self):
return self.__Height

def getFrameColour(self):
return self.__FrameColour

# In such questions, do not think much just solve normally. Use the parameters(mentioned...
def SetDescription(self, DescriptionP):
# ...during class definition) and imagine that they have already been given a value by the user.
self.__Description = DescriptionP

# Do this to show blank array instead of doing the method where you write 'None' multiple times.
PictureArray = []

# This is class with parameters so can happen directly but can't be blank. In case of...
for i in range(100):
# ...object with parameters, it has to be defined first(tho can be blank there at least).
PictureArray.append(Picture("", 0, 0, ""))

def ReadData(PictureArray):  # In object case array is not needed as parameter.
filename = "C:\\Users\\ayush\\Downloads\\Pictures.txt"
NumberPicturesInArray = 0
try:
file = open(filename, "r")
# For internal work so .lower() used in string case, or bcoz extra variable avoided.
Description = (file.readline()).strip().lower()
while (Description != ""):
# Just prefer mentioning data type for int(and .lower() here for string).
Width = int((file.readline()).strip())
Height = int((file.readline()).strip())
Frame = ((file.readline()).strip()).lower()
# Extra step to do when without 'object'...
PictureArray[NumberPicturesInArray] = Picture(
Description, Width, Height, Frame)
# ...where '.append' can be thought to be replaced with '[Counter]='.
Description = ((file.readline()).strip()).lower()
NumberPicturesInArray = NumberPicturesInArray+1
PictureArray.append(Picture(DescriptionP=Description,
WidthP=Width, HeightP=Height, FrameColourP=Frame))
file.close()
except IOError:
print("Could not find file!")
return NumberPicturesInArray, PictureArray

# In the without 'object' case, when a return value is...
# ...there in function then use it to call the function.
NumberPicturesInArray, PictureArray = ReadData(PictureArray)

# .lower allows any case alphabets to be input but be processed as lower only!
FrameColour = input("Input the Frame colour ").lower()
MaxWidth = int(input("Input the Maximum Width "))
MaxHeight = int(input("Input the Maximum Height "))
print("Matches Frames shown")
for Z in range(0, NumberPicturesInArray):  # This range is crucial.
if (PictureArray[Z].getFrameColour() == FrameColour):
if (PictureArray[Z].getWidth() 

Подробнее здесь: [url]https://stackoverflow.com/questions/74282866/getting-attributeerror-picture-object-has-no-attribute-getframecolour-while[/url]
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»