Helllo

I am using command line to get introduced to Pillow.

from PIL import Image
myImage = Image.open(green_leaves.jpg)

gives me the following error

name 'green_leaves' is not defined

Could you help me?

Thank you

Hugo

有帮助吗?

解决方案

The filename argument is a string, and should be in quotes:

myImage = Image.open("green_leaves.jpg")

Without the quotes, Python looks for the attribute jpg of the object referenced by name green_leaves, which does not exist; hence the NameError.

其他提示

You need to put the file name between quotes, to be parsed as a string:

myImage = Image.open("green_leaves.jpg")

Your code attempts to access to a variable green_leaves (before acceding to its attribute jpg) which doesn't exist...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top