Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
Python: haga un archivo XML usando astropy.io.votable

mi programa Python está conectado a una base de datos postgresql. Mi objetivo es crear un archivo xml en formato VOTable con el resultado de una consulta en la base de datos. Pero estoy atascado. Ahí está el código de la creación del archivo:

 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])

Eso funciona porque es un caso específico porque sé que habrá 7 columnas en el resultado de mi consulta, por eso puse:

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

Pero quiero algo más general, ¿cómo puedo crear mi tabla. matriz sin saber el número de columna en el resultado de mi consulta?

Intento algo como esto pero no funciona:

 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

También intento en el ejemplo hacer:

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

Pero tampoco funciona

el error es:

AttributeError: el objeto 'NoneType' no tiene atributo 'decode'

Gracias por tu ayuda

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!