<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_css(self, output_file):
 """ Generate an external style sheet file. output_file must be a file handler that takes in bytes! """

        if self.CSS_TEMPLATE_NAME is not None:
            template = TEMPLATE_ENV.get_template(self.CSS_TEMPLATE_NAME)
            style = template.render(self._context())

        if isinstance(style, six.string_types):
            style = style.encode('utf-8')

        output_file.write(style)