Skip to content

Request: write table with fixed width AND commented header #5922

Closed

Description

@Gabriel-p

I want to write some data to an output file using astropy's ascii module for writing tables.

I want fixed width columns and a commented header using the # character. As far as I can see, I can either write using a fixed column width:

from astropy.io import ascii
from astropy.table import Table
out_data = [('name1', 'name2'), (20., .7)]
data = Table(out_data, names=('names', 'some_data'))
ascii.write(data, 'test.dat', format='fixed_width', delimiter=None)

which produces

 names  some_data 
  name1       20.0 
  name2        0.7 

or a commented header using

ascii.write(data, 'test.dat', format='commented_header', delimiter=None)

which results in

# names some_data
name1 20.0
name2 0.7

What I want is

# names  some_data 
  name1       20.0 
  name2        0.7 

I have not been able to combine these two outputs as shown. I could modify the name of my first table element to # names, but that feels a bit hackish. Is this the proper way to do this?

Activity

  1. Gabriel-p commented on Apr 25, 2017

    @Gabriel-p
    ContributorAuthor

    Duplicate of #4112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions