[FRPythoneers] dynamically created format strings?

Brian Jarrett bjarrett at garcoschools.org
Mon Jan 26 09:22:40 MST 2004


Hello all,

I'm just starting a project with Python where I have to take data from a database for each student in the school district and construct one long string (188 chars) for each student that is then placed in a file and sent to the state.

I'm looking to modularize my code because this is the second project of this type, so I'm wondering if there is a way to make format strings more dynamic.  I would like to be able to pass a function some data and then an integer indicating how many chars it should take up, and possible how it would be justified.  For instance, first, middle, and last names are supposed to take up 30 chars each, be left justified, and padded with spaces.  The resulting format string would be "%-30s"

iRight now I have a separate function created for each name and just pass it the data.  Also, I have do deal with alot of numbers, so I use format strings in separate functions like "%02d" and "%010d" to zero-pad numbers.  I'd like to just to be able to pass the number in and an integer representing how many digits should be used.

Does this make sense?

Brian



More information about the FRPythoneers mailing list