Hi. I am opening jpg file with

a = Image.open(sys.argv[1]).convert("P")

then I'm getting it on a list with

c = list(a.getdata())

could someone help me to conver this list to array?? I would be glad :)

10 Years
Discussion Span
Last Post by tzushky

Isn't this what you want?From:

array( typecode[, initializer])
Return a new array whose items are restricted by typecode, and initialized from the optional initializer value, which must be a list, string, or iterable over elements of the appropriate type. Changed in version 2.4: Formerly, only lists or strings were accepted. If given a list or string, the initializer is passed to the new array's fromlist(), fromstring(), or fromunicode() method (see below) to add initial items to the array. Otherwise, the iterable initializer is passed to the extend() method.

What do you want to do with an array , isn't a list good enough? It's iterable...maybe less complicated than an array ...



a = array('l',c)

should do the trick...If 'l' (signed long int) is too big, than...'h' or even 'b' , or 'H', or 'B' if they're smallers ints, unsigned, the explanation is all in the reference

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.