Django file based email backend

Question:

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.

Asked By: Dr Phil

||

Answers:

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
Answered By: Mahmoud Noor
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.