#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155

    Code Convert Problem


    I'm having some trouble converting the following code from Visual Basic 6 to Python:
    Code:
    Dim aryKey(0 To 12) As String
        For I = 1 To 13
        
            aryKey(I - 1) = Mid$(sKey, I, 1)
            
        Next I
    This isn't my own code but it is needed in my program and I don't understand how to translate it. Here is what I've gotten so far:
    Code:
    for item in range(1, 13):
       key[item:0]
    As you will notice I left part of it, the part I didn't understand.
    Note: key is the argument passed to the definition that the first code I showed is in. def Key(cdkey): It is always 13 characters long and it is a string only. Thanks.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    Why bother converting anyhow? In python, strings can be accessed as individual characters.
    Code:
    key = "abcdefghijklm"
    print key[0]
    print key[5]
    print key[10]
    If you want to make it a list, just because you feel like it, you can simply convert it to a list like this:
    Code:
    array = list(key)
    or if you want a function
    Code:
    def aryKey(key):
         return list(key)
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Thanks again Scorpions4Ever.

IMN logo majestic logo threadwatch logo seochat tools logo