SavWriter mode="cp" -> problem :(

Issue #68 new
Alexandre Ch created an issue

Hello,

I am working with savReaderWriter to change some data inside of all my sav files (around 2000 files).

My 1st step in my script is to open the input file sav and copy all the data and metadata and write the exact new file.( after i could do this, i will be able to change the data)

Unfortunatly, i tried few things to keep the metadata but none of them is fully working. I tried : - open my file with SavHeaderReader and use

metadata = header.dataDictionary(asNamedtuple=False)

to be albe to use

 **metadata 

in my writer. But unicodeError. https://bitbucket.org/fomcl/savreaderwriter/issues/30/problem-with-special-characters-in-python2

-I tried to use mode="cp" but I think i misused it and had an error

  File "helloyou/savReaderWriter/generic.py", line 194, in openSavFile
    with open(savFileName, mode) as f:
ValueError: mode string must begin with one of 'r', 'w', 'a' or 'U', not 'cp'

-For now I try this

with spss.SavWriter('changed_'+path+'/DONE_'+file_name+"."+extension_file, overwrite=True, ioUtf8=True,varNames=metadata.varNames, varTypes=metadata.varTypes,
                                        varLabels=metadata.varLabels, valueLabels=metadata.valueLabels, columnWidths=metadata.columnWidths,
                                        missingValues=metadata.missingValues, caseWeightVar=metadata.caseWeightVar, measureLevels=metadata.measureLevels,
                                        fileAttributes=metadata.fileAttributes) as writer:
                        for i, record in enumerate(records):
                            writer.writerow(record)

It's terrible but it working but i still lost 2 metadata (width and decimals)

Do you have ideas ?! :)

Comments (1)

  1. Log in to comment