How to upload a .py or .txt file?

For a reason unknown to me, indentation is mangled in many posts even inside the code blocks, like in the following posts:

There are also cases where only part of the code is included in the block, or only part of the block is in fixed-width font, or a nested quote level appears for each level of indentation, e.g.:

I have no idea why all this is happening. I’ve just activated mailing list mode for my account and will be trying to reply by email to something with a few tests to see if it is related to email (or maybe someone knows?).

At any rate, when a solution is found, it might be worth adding on the pinned post to tell users not to send screenshots but complete code examples, and how to format it correctly.