Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some examples from documentation do not run out of the box on Python 3.4 #234

Closed
sqlalchemy-bot opened this issue Jan 6, 2015 · 8 comments

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Matthis Thorade (@thorade)

Warning: I am a Python and Mako newbie, so I might be missing something obvious.
I downloaded WinPython 64bit 3.4.2.3 and installed Mako using pip.
The first example from the Mako homepage

from mako.template import Template
print Template("hello ${data}!").render(data="world")

did not work for me.
To make it work, I had to put parantheses around the print part, like this:

from mako.template import Template
print(Template("hello ${data}!").render(data="world"))

Maybe you want to adapt that example on the homepage and in the documentation, to save some unexperienced people some time.

@sqlalchemy-bot
Copy link
Author

Matthis Thorade (@thorade) wrote:

OK, this might be Python 2 versus Python 3. Just guessing.
Second example also has to be adapted to make it work with Python 3:

from mako.template import Template
from mako.runtime import Context
from io import StringIO

mytemplate = Template("hello, ${name}!")
buf = StringIO()
ctx = Context(buf, name="jack")
mytemplate.render_context(ctx)
print(buf.getvalue())

Two lines changed: io instead of StringIO and parantheses for print

@sqlalchemy-bot
Copy link
Author

Changes by Matthis Thorade (@thorade):

  • changed title from "first example from documentation" to "some examples from documentation do not run out of"

@sqlalchemy-bot
Copy link
Author

Changes by Matthis Thorade (@thorade):

  • edited description

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

ill accept a pull request that ensures examples are py3k compatible.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

oh just the homepage? nothing in the docs themselves?

@sqlalchemy-bot
Copy link
Author

Matthis Thorade (@thorade) wrote:

The example on http://www.makotemplates.org/ needs to be changed to

from mako.template import Template
print(Template("hello ${data}!").render(data="world"))

I'll work my way through the documentation in the next days, make a list and possibly send a pull request afterwards.
Using print() instead of print should not break Python 2.7 compatibility, so I'll change that.
The other example (io versus StringIO) is more difficult to handle.

@sqlalchemy-bot
Copy link
Author

Matthis Thorade (@thorade) wrote:

Closing this for now, if I happen to see any example that does not work on Py3 I'll reopen or send a PR.

@sqlalchemy-bot
Copy link
Author

Changes by Matthis Thorade (@thorade):

  • changed status to closed

sqlalchemy-bot pushed a commit that referenced this issue Dec 2, 2022
For some reason people fixed the `print` call but not the import when #234 was brought up.

I also mentioned in in #369

Closes: #370
Pull-request: #370
Pull-request-sha: 8560bfe

Change-Id: I236eef05f5b45420035c522287fa66eb3cb21a00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant