Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top