我正在尝试在python中生成一些SPSS Statistics文件(.sav),并使用我的变量名来获取回溯..
我使用 python的savReaderWriter 进行了以下追溯,需要你的帮助。
Traceback (most recent call last):
File "C:\Users\00231162\.p2\pool\plugins\org.python.pydev_5.0.0.201605051159\pysrc\pydevd.py", line 1530, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Users\00231162\.p2\pool\plugins\org.python.pydev_5.0.0.201605051159\pysrc\pydevd.py", line 937, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\00231162\.p2\pool\plugins\org.python.pydev_5.0.0.201605051159\pysrc\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:\Users\00231162\git\ParqueTecnologicoUFRGS\matrizbinaria.py", line 248, in <module>
exporta_sav(resultados[0], resultados[1])
File "C:\Users\00231162\git\ParqueTecnologicoUFRGS\matrizbinaria.py", line 230, in exporta_sav
with SavWriter(savFile2, cpcsN8Aux, varTypesNivel8, ioUtf8=True) as writer:
File "C:\Python34\lib\site-packages\savReaderWriter\savWriter.py", line 220, in __init__
self.varNamesTypes = self.varNames, self.varTypes
File "C:\Python34\lib\site-packages\savReaderWriter\header.py", line 196, in varNamesTypes
raise SPSSIOError(msg, retcode)
error.SPSSIOError: b'A61F2/02' is an invalid variable name ['SPSS_NAME_BADCHAR: Invalid character or embedded blank']
我的代码:
def exporta_sav(matrizes, listas):
#matrizes = [matriz_grupo, matriz_n8]
#listas = [cpcs_grupo, patentes_grupo, cpcs_n8, patentes_n8]
savFile1 = "matrizgrupo.sav"
savFile2 = "matrizsubgrupo.sav"
varTypesGrupo = {}
varTypesNivel8 = {}
stringpatente = 'PATENTE'
#Cria lista auxiliar para fazer a matriz corretamente no formato .sav
varTypesGrupo[stringpatente] = 7
varTypesNivel8[stringpatente] = 7
for i in range(len(listas[0])):
varTypesGrupo[listas[0][i]] = 0
for i in range(len(listas[2])):
varTypesNivel8[listas[2][i]] = 0
cpcsGrupoAux = [stringpatente]
for i in range(len(listas[0])):
cpcsGrupoAux.append(listas[0][i])
cpcsN8Aux = [stringpatente]
for i in range(len(listas[2])):
cpcsN8Aux.append(listas[2][i])
#Com as colunas definidas, vai criar listas auxiliares para cada linha
matrizGrupoAux = []
matrizN8Aux = []
if len(matrizes[0]) == len(listas[1]):
for i in range(len(matrizes[0])):
matrizGrupoAux.append([ listas[1][i] ])
for j in range(len(matrizes[0][i])):
matrizGrupoAux[i].append(matrizes[0][i][j])
if len(matrizes[1]) == len(listas[3]):
for i in range(len(matrizes[1])):
matrizN8Aux.append([ listas[3][i] ])
for j in range(len(matrizes[1][i])):
matrizN8Aux[i].append(matrizes[1][i][j])
del listas
del matrizes
for i in range(len(matrizGrupoAux)):
matrizGrupoAux[i][0] = bytes(matrizGrupoAux[i][0], "utf8")
for i in range(len(matrizN8Aux)):
matrizN8Aux[i][0] = bytes(matrizN8Aux[i][0], "utf8")
#Escrever nos arquivos
#try:
with SavWriter(savFile1, cpcsGrupoAux, varTypesGrupo, ioUtf8=True) as writer:
for patente in matrizGrupoAux:
writer.writerow(patente)
with SavWriter(savFile2, cpcsN8Aux, varTypesNivel8, ioUtf8=True) as writer:
for patente in matrizN8Aux:
writer.writerow(patente)
它运行良好的第一个文件,问题是第二个文件变量名称上的“/”,我需要它在变量的名称中... 我已经阅读了文档,在eclipse调试器上一步一步走了,无法理解如何解决它。 有人可以帮忙吗?