Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

added 4 characters in body
Source Link
reza
  • 6.5k
  • 20
  • 92
  • 136

I am using python 3.9

I have a class called ImageMetaData

class ImageMetadata(BaseModel):
 title: Optional[str] = None
 source: Optional[str] = None
 sourcesubtype: Optional[str] = None
 filesize: Optional[int] = None
 url: Optional[str] = None

and a function

def total_filesize(images: List[ImageMetadata]):
 total = 0
 try:
 for i in images:
 total = total + i.filesize
 except BaseException as ex:
 logger.error("Caught exception trying to compute total filesize for images", exc_info=True)
return total

I get an error about AttributeError:

‘dict’ object has no attribute ‘filesize’

Am I missing something?

I am using python 3.9

I have a class called ImageMetaData

class ImageMetadata(BaseModel):
 title: Optional[str] = None
 source: Optional[str] = None
 sourcesubtype: Optional[str] = None
 filesize: Optional[int] = None
 url: Optional[str] = None

and a function

def total_filesize(images: List[ImageMetadata]):
 total = 0
 try:
 for i in images:
 total = total + i.filesize
 except BaseException as ex:
 logger.error("Caught exception trying to compute total filesize for images", exc_info=True)
return total

I get an error about AttributeError:‘dict’ object has no attribute ‘filesize’

Am I missing something?

I am using python 3.9

I have a class called ImageMetaData

class ImageMetadata(BaseModel):
 title: Optional[str] = None
 source: Optional[str] = None
 sourcesubtype: Optional[str] = None
 filesize: Optional[int] = None
 url: Optional[str] = None

and a function

def total_filesize(images: List[ImageMetadata]):
 total = 0
 try:
 for i in images:
 total = total + i.filesize
 except BaseException as ex:
 logger.error("Caught exception trying to compute total filesize for images", exc_info=True)
return total

I get an error about AttributeError:

‘dict’ object has no attribute ‘filesize’

Am I missing something?

Source Link
reza
  • 6.5k
  • 20
  • 92
  • 136

Why do I get a AttributeError in this code?

I am using python 3.9

I have a class called ImageMetaData

class ImageMetadata(BaseModel):
 title: Optional[str] = None
 source: Optional[str] = None
 sourcesubtype: Optional[str] = None
 filesize: Optional[int] = None
 url: Optional[str] = None

and a function

def total_filesize(images: List[ImageMetadata]):
 total = 0
 try:
 for i in images:
 total = total + i.filesize
 except BaseException as ex:
 logger.error("Caught exception trying to compute total filesize for images", exc_info=True)
return total

I get an error about AttributeError: ‘dict’ object has no attribute ‘filesize’

Am I missing something?

lang-py

AltStyle によって変換されたページ (->オリジナル) /