473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Python and Javascript equivalence

Hey All,

I am writing some COM code in Python to control photoshop. Several
functions of PS require an "Array" argument. In the examples of VBscript or
javascript the Array type is used. I have tried what would appear to be the
equivalent in Python -- Lists and Tuples -- but to no avail. Anyone have
any insight on what via the COM interface is equivalent to an Array in
javascript ?

Cheers
Sam
Apr 23 '07 #1
5 2582

Try creating a dict with sequential numeric keys.

If you already have a list called my_list, you can do:

com_array = dict(zip(range(len(my_list)), my_list))

This works when you want to convert Python objects to Javascript using
JSON. It may work for you.

-Prateek

Apr 23 '07 #2
On Apr 22, 7:00 pm, "Sam the Cat" <sam_spam_...@verizon.netwrote:
Hey All,

I am writing some COM code in Python to control photoshop. Several
functions of PS require an "Array" argument. In the examples of VBscript or
javascript the Array type is used. I have tried what would appear to be the
equivalent in Python -- Lists and Tuples -- but to no avail. Anyone have
any insight on what via the COM interface is equivalent to an Array in
javascript ?

Cheers
Sam
See if the python array type works:

import array

y = array.array("i", [2,3,4])
print y

Apr 23 '07 #3
In <11**********************@n59g2000hsh.googlegroups .com>, Prateek wrote:
Try creating a dict with sequential numeric keys.

If you already have a list called my_list, you can do:

com_array = dict(zip(range(len(my_list)), my_list))
com_array = dict(enumerate(my_list))

That doesn't create the intermediate lists.

Ciao,
Marc 'BlackJack' Rintsch
Apr 23 '07 #4
Sam the Cat wrote:
Hey All,

I am writing some COM code in Python to control photoshop. Several
functions of PS require an "Array" argument. In the examples of VBscript or
javascript the Array type is used. I have tried what would appear to be the
equivalent in Python -- Lists and Tuples -- but to no avail. Anyone have
any insight on what via the COM interface is equivalent to an Array in
javascript ?
The nest way to approach an answer to your question would be for you to
post a VB snippet from one of the examples together with your attempt to
do the same thing in Python plus the error traceback (or other such
messages as you may see) generated when your attempts fails.

Otherwise the question is just a bit too broad to give an answer.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 23 '07 #5
>>
>I am writing some COM code in Python to control photoshop. Several
functions of PS require an "Array" argument. In the examples of VBscript
or javascript the Array type is used. I have tried what would appear to
be the equivalent in Python -- Lists and Tuples -- but to no avail.
Anyone have any insight on what via the COM interface is equivalent to
an Array in javascript ?

The nest way to approach an answer to your question would be for you to
post a VB snippet from one of the examples together with your attempt to
do the same thing in Python plus the error traceback (or other such
messages as you may see) generated when your attempts fails.

Otherwise the question is just a bit too broad to give an answer.

regards
Steve
--
Here is the Javascript example code

......
selRegion = Array(Array(1,1),Array(1,2),Array(2,2),Array(2,1))
Doc.Selection.Select(selRegion,1,0,0)
......

Here is my interpretation in Python

........
selregion = [(1,1),(1,2),(2,2),(2,1)]
print selregion
doc.Selection.Select(selregion,1,0,0)
.......

Here is the error code generated

...........
F:\automation>test2.py
[(1, 1), (1, 2), (2, 2), (2, 1)]
Traceback (most recent call last):
File "F:\automation\test2.py", line 19, in ?
doc.Selection.Select(selregion,1,0,0)
File "<COMObject <unknown>>", line 3, in Select
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe
Photoshop', 'Illegal argument - argument 1\n- Only arrays with dimension 1
are supported', None, 0, -2147220262), None)
.............
Apr 23 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
5
by: Haoyu Zhang | last post by:
Dear Friends, Python assignment is a reference assignment. However, I really can't explain the difference in the following example. When the object is a list, the assignment seems to be a...
1
by: Seo Sanghyeon | last post by:
For those who may be concerned: this mail is sent to comp.lang.python, debian-python, freebsd-python, and catalog-sig. I created a table of Python packages in Debian, FreeBSD, and Gentoo....
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
10
by: Xah Lee | last post by:
another functional exercise with lists. Here's the perl documentation. I'll post a perl and the translated python version in 48 hours. =pod parti(aList, equalFunc) given a list aList of...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
26
by: hide1713 | last post by:
HI I'm currently using Python. I find that a instance variable must confined with self, for example: class a: def __init__(self): self.aa=10 def bb(self): print self.aa # See .if in c++,I...
15
by: jzakiya | last post by:
I'm translating a program in Python that has this IF Then chain IF x1 < limit: --- do a --- IF x2 < limit: --- do b --- IF x3 < limit: --- do c --- .----- ------ IF x10 < limt: ---...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.