Cannot set an array element with a sequence
Question: I'm using the `NumPy` python library to run large-scale edits on a `.csv`
file. I'm using this python code:

    
    
    import numpy as np
    
    def main():
        try:
            e,a,ad,c,s,z,ca,fn,ln,p,p2,g,ssn,cn,com,dob,doh,em = np.loadtxt('c:\wamp\www\_quac\carryover_data\SI\Employees.csv',delimiter=',',unpack=True,dtype='str')
    
            x=0
            dob = dob.split('/')
            for digit in dob:
                if len(digit) == 1:
                    digit = str('0'+digit)
            dob = str(dob[2]+'-'+dob[0]+'-'+dob[1])
    
            doh = doh.split('/')
            for digit in doh:
                if len(digit) == 1:
                    digit = str('0'+digit)
            doh = str(doh[2]+'-'+doh[0]+'-'+doh[1])
    
            for eID in e:
                saveLine=eID+','+a[x]+','+ad[x]+','+c[x]+','+s[x]+','+z[x]+','+ca[x]+','+fn[x]+','+ln[x]+','+p[x]+','+p2[x]+','+g[x]+','+ssn[x]+','+cn[x]+','+com[x]+','+dob[x]+','+doh[x]+','+em[x]+'\n'
                saveFile = open('fixedEmployees.csv','a')
                saveFile.write(saveLine)
                saveFile.close()
                x+=1
    
    
        except Exception, e:
            print str(e)
    
    main()
    

`dob` and `doh` contain a string, e.g. `4/26/2012` and I'm trying to convert
these to `mysql` friendly `DATE` forms, e.g. `2012-04-26`. The error that is
printed when I run this script is

`cannot set an array element with a sequence`

It does not specify a line and so I don't know what this really means. I'm
pretty new to python; I've checked other questions with this same error but I
can't make sense of their code. Any help is very appreciated.


Answer: Try using `zfill` to reformat the date string so you can have a '0' before
your '4'. (`zfill` pads a string on the left with zeros to fill the width.)

    
    
    doh = '4/26/2012'
    doh = doh.split('/')
    
    for i, s in enumerate(doh):
        doh[i] = s.zfill(2)
    
    doh = doh[2]+'-'+doh[0]+'-'+doh[1]
    
    # result: '2012-04-26'
    

As for the `cannot set an array element with a sequence` it would be helpful
to know where that is occurring. I'm guessing there is something wrong with
structure of the array.

