converting pipe delimited file to fixed width
MRAB
google at mrabarnett.plus.com
Thu Mar 19 13:30:14 EDT 2009
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 help
>> appreciated
>>
>> #!/usr/bin/python
>> def rightFill(fillString, toLength, fillChar):
>> return fillString+''.join([fillChar for x in range(len
>> (fillString),toLength)])
>
> Ugh. That should be the same as
> return fillString + (toLength-length(fillString))*fillChar
>
Ugh. That should be the same as
return fillString.ljust(toLength, fillChar)
(and there's no function length()) ;-)
More information about the Python-list
mailing list