Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
Python: Make a XML file using astropy.io.votable

my Python program is connect to a postgresql data base. My goal is to create a xml file at the VOTable format with the result of a query on the data base. But I am stuck. There is the code of the creation of the file:

from astropy.io.votable import parse,is_votable
from astropy.io.votable.tree import VOTableFile, Resource, Table, Field
import sys
import psycopg2

cur.execute("""%s"""%queryString)
#Number of row
rowNumber = cur.rowcount
#Number of column
columnNumber=len(cur.description)


#Create votable file
votable = VOTableFile()
resource = Resource()
votable.resources.append(resource)
table = Table(votable)
table.name="Answer"
resource.tables.append(table)

# Create field
for column in dataCol:
    table.fields.extend([
            Field(votable, name=column, datatype="char", arraysize="*")])

table.create_arrays(rowNumber)
i=0
for row in cur:
    dataRes = []

    # if a row have a no value column, replace by ''
    for datas in row:
        if datas is None:
            dataRes.append('')
        else:
            dataRes.append(datas)

    table.array[i]=(dataRes[0],dataRes[1],dataRes[2],dataRes[3],dataRes[4],dataRes[5],dataRes[6])

Thats work because it is a specific case because I know there will be 7 columns in my query result, that's why I put:

table.array[i]=(dataRes[0],dataRes[1],dataRes[2],dataRes[3],dataRes[4],dataRes[5],dataRes[6])

But I want something more general, how can I create my table.array without to know the number of column in my query result ?

I try something like this but it's doesn't work:

  votable = VOTableFile()
    resource = Resource()
    votable.resources.append(resource)
    table = Table(votable)
    table.name="Answer"
    resource.tables.append(table)

# Create field
for column in dataCol:
    table.fields.extend([
            Field(votable, name=column, datatype="char", arraysize="*")])

table.create_arrays(rowNumber)
i=0
for row in cur:
    dataRes = []

# if a row have a no value column, replace by ''
for datas in row:
    if datas is None:
        dataRes.append('')
    else:
        dataRes.append(datas)

for column in dataRes:
    table.array[i][j]=column[j]
    print(i,j)
    j+=1
i+=1

I also try in example to make:

table.array[0][0]=dataRes[0]
table.array[0][0]=dataRes[1]

But it's doesn't work too

The error is:

AttributeError: 'NoneType' object has no attribute 'decode'

Thank you for your help

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda