Программа сохраняет изображения как объекты. Он хранит размер, цвет рамки и описание изображения. Программе необходимо ввести свои требования к картинке. Пользователь вводит цвет, ширину и высоту. Затем программа выполнит поиск в массиве и выведет описание изображения, если какое-либо изображение соответствует требованиям.
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]
Программа сохраняет изображения как объекты. Он хранит размер, цвет рамки и описание изображения. Программе необходимо ввести свои требования к картинке. Пользователь вводит цвет, ширину и высоту. Затем программа выполнит поиск в массиве и выведет описание изображения, если какое-либо изображение соответствует требованиям. [code]class Picture:
# 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()
Я пытаюсь создать модель машинного обучения, чтобы предсказать, кто выживет на Титанике. Каждый раз, когда я пытаюсь подогнать свою модель, я получаю эту ошибку:
coordinates = np.where(mask.transpose())
AttributeError: 'bool' object has no...
Код луча работает в Google Collab, но не будет работать на моей собственной ноутбуке Jupyter - может быть, делать с Pandas 2.0.0? Любая помощь будет очень оценена.import apache_beam as beam
grocery = (p1
| Read From Text \>\>...
У меня есть следующая строка кода, которая продолжает выдавать ошибку о том, что у объекта Engine нет выполняемого объекта. Я думаю, что у меня все правильно, но понятия не имею, что происходит дальше. Похоже, у других была такая проблема, и...
Предпосылка・Чего я хочу достичь
Я собираюсь использовать Python для чтения файла GML.
Сообщение об ошибке
Traceback (most recent call last):
File firstgml.py , line 9, in
G = nx.read_gml(gml_path)
File , line 2, in read_gml
File...
Я пытаюсь использовать свою функцию addtolist(self) в классе TopSoftwareWindow() и продолжаю получать
AttributeError: 'Toplevel' object has no attribute 'addtolist'
Вот код конкретного класса, который я пытаюсь исправить.
class...