I'm trying to make a fixed length output record, and I'm using a Dictionary as a lookup table to find a code based on the kind of car a person drives.
The routine works fine; I the search the key for the car type, and the value returned is the associated code. Problem is, I need to put that into a list so that I can make the fixed length record later. The field length of the code is 10 bytes, so my plan was..
loop through the csv (spreadheet) to add the key (car model) and value (car code) to a dictionary
assign the value to a variable
answer = CarData[CarType]
L = 10 - len(answer)
list.append(answer + ' ' * L)
The problem is that A) the answer variable holds the 'value', i.e. , not the string representation of '12345' as far as I can tell, and B), the length returned is '1', probably because there is one item, not the length of the item itself.
Is there a way to convert the returned value to a string '12345'? I tried pickle, and that doesn't seem to do it.