Skip to content

No option to write a fixed-width table with a commented header #4112

Closed

Description

@mboquien

Hello,

When writing a table in ASCII format one can have a fixed-width format (ascii.fixed_width) or a commented header (ascii.commented_header) but not both. It would be good to be able to have both options as some softwares get confused by uncommented headers (topcat for instance).

Thanks!

Activity

  1. embray commented on Aug 31, 2015

    @embray
    Member

    This can probably be done like in the CommentedHeaderHeader example here: http://docs.astropy.org/en/stable/io/ascii/read.html#advanced-customization but with a FixedWidthHeader as the base class. It would have to offset everything to include space for the comment character.

  2. taldcroft commented on Sep 4, 2015

    @taldcroft
    Member

    A less elegant but simpler workaround would be to just write the file to a StringIO object and then paste in a leading #:

    t = .. # my table
    out = StringIO.StringIO()
    t.write(out, format='ascii.fixed_width', delimiter=None)
    with open('outfile.dat', 'w') as fh:
        fh.write('#' + out.getvalue())
    

    This cannot be used for a table that has strings with space characters embedded. The fixed_width format does not quote those.

  3. hamogu commented on Aug 8, 2022

    @hamogu
    Member

    I suggest to write a good example for this to add top the docs on advance customization.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions