Python and Javascript equivalence

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam the Cat

    #1

    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


  • Prateek

    #2
    Re: Python and Javascript equivalence


    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

    Comment

    • 7stud

      #3
      Re: Python and Javascript equivalence

      On Apr 22, 7:00 pm, "Sam the Cat" <sam_spam_...@v erizon.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



      Comment

      • Marc 'BlackJack' Rintsch

        #4
        Re: Python and Javascript equivalence

        In <1177295347.006 598.168930@n59g 2000hsh.googleg roups.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

        Comment

        • Steve Holden

          #5
          Re: Python and Javascript equivalence

          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

          Comment

          • Sam the Cat

            #6
            Re: Python and Javascript equivalence

            >>
            >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),Ar ray(2,2),Array( 2,1))
            Doc.Selection.S elect(selRegion ,1,0,0)
            ......

            Here is my interpretation in Python

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

            Here is the error code generated

            ...........
            F:\automation>t est2.py
            [(1, 1), (1, 2), (2, 2), (2, 1)]
            Traceback (most recent call last):
            File "F:\automation\ test2.py", line 19, in ?
            doc.Selection.S elect(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)


            .............


            Comment

            Working...