Using 'string.ljust' to try and hold a fixed width.......

John F Dutcher John_Dutcher at urmc.rochester.edu
Wed Nov 19 14:38:30 CET 2003


I use code like the following to retrieve fields from a form:

recd = []
recd.append(string.ljust(form.getfirst("lname",' '),15))
recd.append(string.ljust(form.getfirst("fname",' '),15))
etc., etc. 

The intent is to finish by assigning the list to a string that I would 
write to disk: recstr = string.join(recd,'')

The spaces expected are 'NOT' being provided with 'string.ljust'....

If I simply print the field immediately as in:
       print string.ljust(form.getfirst("lname",' '),15) 

they are not present; they are not present when assigned to the list,
and, of course, they are not present in the final string.  
Is there a way to do this....so I can have spaces 'held' in the
object I want to write to the file ??
Thanks.




More information about the Python-list mailing list