I want to write a file. Based on the name of the file this may or may not be compressed with the gzip module. Here is my code:
import gzip
filen
print is a relatively complex function. It writes str to a file but not the str that you pass, it writes the str that is the result of rendering the parameters.
If you have bytes already, you can use fd.write(bytes) directly and take care of adding a newline if you need it.
If you don't have bytes, make sure fd is opened to receive text.