String Formatting?

William Dandreta wjdandreta at worldnet.att.net
Sat Aug 26 14:07:02 EDT 2000


I am having a problem with string formatting.
I am writing strings to a binary file and the results are not as expected.
For example,

record = '...%30s...' % (...x...)
outputFile.write(record)

The records are fixed length and require x to be 30 bytes long. If x is
longer than 30 bytes, the string formatting mechanism does not truncate x to
30 and the file is corrupted. I've been using x[:30] in place of x to get it
to work.

Is this the way string formatting is supposed to work? I could find no info
in the doc's.

Bill






More information about the Python-list mailing list