how to deal with space between numbers
tjreedy at udel.edu
Wed Aug 24 00:07:30 CEST 2005
Your input data file must be formatted in such a way that the program,
knowing the format, can separate one number from another. There are two
basic ways to do this.
1. Separate the numbers with non-digit characters, such as spaces. (Other
characters such as commas are also used, but are more trouble when your
data is just numbers.)
2. Put each number in a particular set of columns. The columns make a
*field*. If the numbers in a field will be greater than 9, then your field
needs more than one column. For input to Python, numbers that do not
require all the columns in the field should be padded with leading spaces
rather than leading zeros. Example with 3 fields, with the second needing
1102 # 1 10 2
4 53 # 4 5 3
This usually requires an editor with fixed-pitch fonts. And you have to
tell the program the position of each field.
Unless you have enough fields or enough lines that you actually need to
save display or disk space, I would stick with the first option.
Terry J. Reedy
More information about the Python-list