I don't have any idea why this copped such a bad reception, but I'll try to improve it more if people have suggestions.
It's long, but I hope it's clear what is trying to be achieved (even if wasn't clear when the question first appeared).
Please reopen if you consider it a useful question.
Note: I asked the same question in another forum at the same time, and it generated a lot of positive interest there, so perhaps it was my initial wording of the question that people didn't like, or even that it wasn't relevant to the GitHub tag. Or maybe that Python people saw R code and thought the question was junk. I'm not exactly sure, to be honest.
Update: After some more research, I found this broader question to which there is no answer (there is an answer displayed, which is helpful, but it doesn't answer the question). So it's possible that Python simply doesn't have a common pattern/convention/framework for generating GitHub markdowns programmatically (and you just have to write them manually, or use Python to write strings that can form valid Markdown).
After learning this (and with hindsight), I can see why bluntly asking
How can a github flavored markdown document be generated in python?
would be confusing (and elicit down/close votes), since the broader tooling for knittr-style programmatic report generation doesn't seem to be common practice in Python.