Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > PIL's thumbnail function returns NoneType

Reply
Thread Tools

PIL's thumbnail function returns NoneType

 
 
Mirat Can Bayrak
Guest
Posts: n/a
 
      03-01-2009
Can you try it? it is about me or it is a bug?

In [1]: import Image

In [2]: im = Image.open("r.png")

In [3]: type(im)
Out[3]: <type 'instance'>

In [4]: thm = im.thumbnail((200,200))

In [5]: type(thm)
Out[5]: <type 'NoneType'>


--
Mirat Can Bayrak <(E-Mail Removed)>
 
Reply With Quote
 
 
 
 
Hrvoje Niksic
Guest
Posts: n/a
 
      03-01-2009
Mirat Can Bayrak <(E-Mail Removed)> writes:

> Can you try it? it is about me or it is a bug?


Neither. im.thumbnail() modifies the existing image object by
converting it to a thumbnail. In Python such methods by convention
return None.

The documentation explicitly mentions that:

Also note that this function modifies the Image object in
place. If you need to use the full resolution image as well, apply
this method to a copy of the original image. This method returns
None.

> In [4]: thm = im.thumbnail((200,200))
>
> In [5]: type(thm)
> Out[5]: <type 'NoneType'>


Instead of thm, simply keep using ihm.
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      03-01-2009
Hrvoje Niksic wrote:
> Mirat Can Bayrak <(E-Mail Removed)> writes:
>
>> Can you try it? it is about me or it is a bug?

>
> Neither. im.thumbnail() modifies the existing image object by
> converting it to a thumbnail. In Python such methods by convention
> return None.
>
> The documentation explicitly mentions that:
>
> Also note that this function modifies the Image object in
> place. If you need to use the full resolution image as well, apply
> this method to a copy of the original image. This method returns
> None.


Indeed, the purpose of returning None is to remind that the method does
mutation in place.


>
>> In [4]: thm = im.thumbnail((200,200))
>>
>> In [5]: type(thm)
>> Out[5]: <type 'NoneType'>

>
> Instead of thm, simply keep using ihm.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TypeError: unsupported operand type(s) for /: 'NoneType' and'NoneType' Jordan Harry Python 1 05-02-2008 01:17 AM
Displaying a Thumbnail vs. creating a thumbnail David Lozzi ASP .Net 1 02-01-2006 10:34 PM
Re: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Brett C. Python 2 08-30-2004 10:25 PM
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Martin Koekenberg Python 3 08-26-2004 12:04 PM
NoneType object returned by .fetchone() in MySQLdb Arnaud-F. FAUSSE Python 2 11-27-2003 06:00 AM



Advertisments