Arrays and Structures (or User Types) [solved]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Felagund
    New Member
    • Oct 2006
    • 2

    Arrays and Structures (or User Types) [solved]

    Ciao,
    I'm trying to convert to Python an existing program written in VB and I cannot find out an equivalent way to translate a Private Type description which includes another type and the relevant matrix. I was thinking that some Lists and Classes can do the job, but the result is really different and I can't find a way to insert unknown quantity of data inside a structure like an array of matrices. Could you please give me some hints ? Thanks a lot in advance.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Maybe a dictionary would work for you.
    Some examples:
    Code:
    dd12 = {"z1":"L6x4x3/8", "f2":"Zinc Oxide", "a3":(120.0, 220.0, 320.0)}
    dd13 = {"ddd":55.2478, "eee":"Works", "fff":36}
    
    print dd13["eee"]
    dd13["eee"] = 'Busted'
    
    for k, v in dd13.items():
            print k, "=", v
    
    dd12 = {"z1":"L6x4x3/8", "f2":"Zinc Oxide", "a3":120.0000}
    
    dd12.update(dd13)
    print dd12
    
    for k, v in dd12.items():
            print k, "=", v

    Comment

    • Felagund
      New Member
      • Oct 2006
      • 2

      #3
      Ciao,
      Thanks a lot for your help, do you know if there is the possibility to create an array for these Dictionaries ? What I need is, let say 100 (or any number) placeholders for a dictionary where to put all the extracted data from the input file. In VB you can do that dimensioning an array like graphics(100) and you can create this graphics as a user defined type (in C they called Structures) which contains the various info for that graphics (Xloc, Yloc, Type, etc.) are the dictonaries usable for the same kind of thing in your opinion ?

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by Felagund
        Ciao,
        Thanks a lot for your help, do you know if there is the possibility to create an array for these Dictionaries ? What I need is, let say 100 (or any number) placeholders for a dictionary where to put all the extracted data from the input file. In VB you can do that dimensioning an array like graphics(100) and you can create this graphics as a user defined type (in C they called Structures) which contains the various info for that graphics (Xloc, Yloc, Type, etc.) are the dictonaries usable for the same kind of thing in your opinion ?
        numpy extenstion handles arrays very nicely. Get it at http://numpy.scipy.org/.

        It allows you to create array objects of a given size and type of object they will hold and the use them much like lists only better because you can also do matrix math on them.

        PS: Welcome to the python forum on thescript.com! Please be sure to use code tags (read the gray writing on the background of the post screen or the panel on the right of the post screen or the sticky at the top of the forum). Thank you,
        Barton

        Comment

        Working...