John Posner wrote:
[snip]
field_widths = [14, 6, 18, 21, 21, 4, 6]
out = open("/home/chatdi/ouptut.csv", 'w')
for line in open("/home/chatdi/input.csv", "r"):
fields = line.rstrip().split('|')
padded_fields = [field.ljust(width) for field, width in zip(fields,
field_widths)]
out.
[snip]
> field_widths = [14, 6, 18, 21, 21, 4, 6]
>
> out = open("/home/chatdi/ouptut.csv", 'w')
> for line in open("/home/chatdi/input.csv", "r"):
> fields = line.rstrip().split('|')
> padded_fields = [field.ljust(width) for field, width in zip(fields,
> field_widths)]
> out.write
Caveat: none of the solutions (including mine) deal with the case of
the field being longer than the width. You might want to throw an
exception.
Alternatively, you can just crop the results. Tweaking MRAB's
elegant solution:
field_widths = [14, 6, 18, 21, 21, 4, 6]
infile = open("input.
Terry Reedy wrote:
digz wrote:
Hi,
I am trying to convert a | delimited file to fixed width by right
padding with spaces, Here is how I have written the program , just get
the feeling this can be done in a much better ( python functional )
way rather than the procedural code i have below . Any
On Mar 19, 8:51 am, digz wrote:
> Hi,
> I am trying to convert a | delimited file to fixed width by right
> padding with spaces, Here is how I have written the program , just get
> the feeling this can be done in a much better ( python functional )
> way rather than the procedural code i have bel
digz wrote:
Hi,
I am trying to convert a | delimited file to fixed width by right
padding with spaces, Here is how I have written the program , just get
the feeling this can be done in a much better ( python functional )
way rather than the procedural code i have below . Any help
appreciated
#!
digz wrote:
Hi,
I am trying to convert a | delimited file to fixed width by right
padding with spaces, Here is how I have written the program , just get
the feeling this can be done in a much better ( python functional )
way rather than the procedural code i have below . Any help
appreciated
#!
Hi,
I am trying to convert a | delimited file to fixed width by right
padding with spaces, Here is how I have written the program , just get
the feeling this can be done in a much better ( python functional )
way rather than the procedural code i have below . Any help
appreciated
#!/usr/bin/pytho