How to get python code back from Assistant as an attached file?

I have asked Assistant to return a file with python code that performs a particular task. On the UI, I can just copy the code, but how to retrieve it from the api?

The best way to do this via the API which works consistently for me is to ask the API to return the code in triple backtics (```).
This would allow for the code portion to always be inside the backtics and can be easily extracted using a str.split()