Reputation: 35
I have a text file that needs to be read by an outside program that uses spaces to delineate between rows.
As of right now the program reads:
Field 1 then 6 spaces, field 2 then 2 spaces, field 3 1 space, field 4 2 spaces and so on.
When I modified the doc in excel, it is now tab delineated between each field.
How would I write a python script to be able to replace this white space with the proper number of so that this program can read my file?
Upvotes: 0
Views: 178
Reputation: 54698
You can use "{:10s}{:3s}{:4s}".format(*fields)
to do this. You just have to know the field widths.
Upvotes: 1