You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No option to write a fixed-width table with a commented header #4112
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).
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.
Activity
embray commentedon Aug 31, 2015
This can probably be done like in the
CommentedHeaderHeaderexample here: http://docs.astropy.org/en/stable/io/ascii/read.html#advanced-customization but with aFixedWidthHeaderas the base class. It would have to offset everything to include space for the comment character.taldcroft commentedon Sep 4, 2015
A less elegant but simpler workaround would be to just write the file to a StringIO object and then paste in a leading
#:This cannot be used for a table that has strings with space characters embedded. The fixed_width format does not quote those.
hamogu commentedon Aug 8, 2022
I suggest to write a good example for this to add top the docs on advance customization.