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 :)

Recommended Answers

All 2 Replies

Isn't this what you want?From:
http://docs.python.org/lib/module-array.html

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

Basically

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.