Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top