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

272
Views
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
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!