Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django file based email backend

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading