[Tutor] More image manipulation

Terry Carroll carroll at tjc.com
Tue Jun 7 22:26:16 CEST 2005

On Tue, 7 Jun 2005, D. Hartley wrote:

> def findlist():
>     newlist = []
>     for i in range(480):
>         line = fromlist[:640]
>         del fromlist[:640]
>         x = line.index(195)
>         y = x + 5
>         z = line[x:y]
>         del line[x:y]
>         for i in z:
>             newlist.append(i)
>         for i in line:
>             newlist.append(i)
>     return newlist

where does the variable named "fromlist" come from?  It's not passed into 
the method as a parameter.

> B). If I run the steps in makenewpic one by one in the interpreter, it
> doesnt give me any "x not in list" error, it lets me do the result =
> newim.putdata(a) just fine.  But then when I type result.show() it
> tells me 'NoneType' object has no attribute 'show'.  At first I
> thought it was because when I was creating the blank newim, I was
> using mode "RGB" and adding a list of "P" pixel values to it. But I
> fixed it so that my newim is also mode "P" and it still tells me that
> type(result) = None.

You have:

>     result = newim.putdata(a)
>     return result

>From the PIL docs, putdata does not appear to return an image.  The docs
for putdata say:


  im.putdata(data, scale, offset)

Usually, when a PIL method returns an image, the docs say "=> image" 
after the method signature.  My guess is that putdata returns None, which 
would be consistent with the error message "'NoneType' object has no 
attribute 'show'."

You'll probably want:

     return newim


More information about the Tutor mailing list