F
F
fqsas2022-01-14 19:30:06
Python
fqsas, 2022-01-14 19:30:06

AttributeError: 'NoneType' object has no attribute 'open'. The error occurs on line 23. How to fix?

from PIL import Image
from PIL import ImageFilter
def ImageEditor(filename):
    def __init__(self, filename):
        self.filename = filename
        self.original = None
        self.changed = list()
    def open(self):
        try:
            self.original = Image.open(self.filename)      
        except:
            print('Файл не знайдено!')
        self.original.show()
    def do_bw(self):
        gray = self.original.convert('L')
        self.changed.append(gray)
        gray.save('gray.jpg')
    def do_BLURE(self):
        blure = self.original.filter(ImageFilter.BLURE)
        self.changed.append(blure)
        blure.save('blure.jpg')
MyImage = ImageEditor('original.jpg')
MyImage.open()
MyImage.do_bw()
MyImage.do_BLURE()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2022-01-14
@fqsas

We wanted to create a class, but created a function to replace with
def ImageEditor(filename):
class ImageEditor:

S
Sergey Karbivnichy, 2022-01-14
@hottabxp

You have mixed people and horses: all you need to do is replace def with class( and remove it from filename, since Python will think that the ImageEditor class is inherited from filename).
def ImageEditor(filename):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question