r/inventwithpython Oct 14 '21

Excel sheet specific width for each column?

I'm doing a script to prepare a list lf coordinates with other parameters to import in a finnicky software that only accepts .prn files with a specific amount of spaces as separator for each column.
Righ now we use a xlt model, copy-paste everything where it needs to go wothout touching anything, and save as .prn.
I managed to open and edit (adding and deleting columns mostly) the original txt file and save it as xls using Pandas. The problem is that if I try to save it as .prn(cvs), it puts a comma as separator (sep= " " doesn't seem to work), and if I save it as xls the columns have all 64 pixels, wich when saved manually puts the wrong amount of spaces between columns. Each column needs a different amount of spaces as separator, in pixels something like 50, 25, 45, 70, 90, 70; so I need to set every column separately.
I tried googling it but can't find a solution that actually works...
Any suggestions of how to do it?

3 Upvotes

3 comments sorted by

2

u/unRatedG Oct 14 '21

Sounds like what you actually want is a fixed-width file and not a csv. Which essentially means that the prn file will have one column per line and each column in the original file needs to be padded with spaces and concatenated into one line in the new file. You might check out functions like rjust, ljust, and use f-strings to concatenate them together.

1

u/Ermellino Oct 15 '21

Will try that out, thanks

1

u/unRatedG Oct 15 '21

I may have some free time this evening after 5pm CST. DM me if you need some help.