Issues

Issue #196 resolved

No way to import from __future__

guest
created an issue

`<%! from future import division %>` on the first line of a file doesn't work, because the import doesn't end up as the first statement in the resulting Python module.

Hardly a show-stopper, but it bit me when I wanted to do a bit of inline math in a template.

Comments (3)

  1. Mike Bayer repo owner

    obviously, use `` here for now, Mako would need a new feature for futures to be present. This would be the flag "futures" accepted by !Template and !TemplateLookup.

  2. Cody Taylor

    This can be closed?

    In python 2.7:

    >>> from mako.template import Template
    >>> t = Template("""some text
    ... with a few
    ... lines.""", future_imports=["unicode_literals"])
    >>> print t.code
    from __future__ import unicode_literals
    from mako import runtime, filters, cache
    UNDEFINED = runtime.UNDEFINED
    STOP_RENDERING = runtime.STOP_RENDERING
    __M_dict_builtin = dict
    __M_locals_builtin = locals
    _magic_number = 10
    _modified_time = 1427438047.876237
    _enable_loop = True
    _template_filename = None
    _template_uri = 'memory:0x7f5cc74f0fd0'
    _source_encoding = 'ascii'
    _exports = []
    
    
    def render_body(context,**pageargs):
    ...
    
  3. Log in to comment