Home > Software design >  Django file based email backend
Django file based email backend

Time:08-20

It's probably something very obvious, but I can't seem to figure it out.

This snippet is from Django's file based email backend (django.core.mail.backends.filebased.py)

    def write_message(self, message):
        self.stream.write(message.message().as_bytes()   b"\n")

My question is. How can I find out what class is message an object of?

Context for why: My code sends emails along various execution paths. I want to leverage Django's filebased backend, instead of firing live emails during debugging and unit testing (or creating my own file based system). The relevant code has a MIMEMultipart object currently (with utf-8 coded text) that works fine for production. I need to be able to convert that into an object that can be printed legibly by the above snippet.

PS: I come from a C background where this would've been an easy question to answer.

CodePudding user response:

you can use python's builtin type function

type(obj)

or if you want to check if it is an instance of a specific object use isinstance function

if isinstance(obj, Obj_Class):
   # do something
  • Related