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

AttributeError: tobytes #9

Closed
bergonzzi opened this issue May 21, 2014 · 1 comment
Closed

AttributeError: tobytes #9

bergonzzi opened this issue May 21, 2014 · 1 comment

Comments

@bergonzzi
Copy link

I have Python 2.7.5 on Mac OSX Mavericks with PIL 1.1.7 and I get the following when running the xkcd.py example:

Traceback (most recent call last):
  File "xkcd.py", line 66, in <module>
    for pix in i.tobytes():
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 512, in __getattr__
    raise AttributeError(name)
AttributeError: tobytes

I was able to fix it by changing line 66 from:

for pix in i.tobytes():

to

for pix in i.tostring():

I found it with some help from this stackoverflow question. It seems like the official PIL 1.1.7 still uses the tostring method while Pillow is deprecating it in favor of tobytes (although it still supports the old one).

A simple approach to deal with this could be to just test the attribute first:

   try:
        i_converted = i.tobytes()
    except AttributeError:
        i_converted = i.tostring()

    for pix in i_converted:
    (...)
asciimoo added a commit that referenced this issue May 21, 2014
@asciimoo
Copy link
Owner

Thank you, i couldn't test it, but i hope it's fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants