The code will read in a file and build a table with the ctn_no and seq_no which works fine. I want to change it so that when I find a break mark I build a table of ctn_no + 1 and seq_no + 1 rather than a table of ctn_no and seq_no. I can't seem to add one to the value that is read in from the file. I am new at this and am not sure what I'm doing wrong. I have tried many combinations attempting to increment the values. Below is the code before any modifications. Any help you can give would be appreciated. Thanks.

dctSequence = {}
# Open address file for reading
f = open(r'c:\MyData\DAG_OUTFILE.txt', 'r')

for i, line in enumerate(f):
temp = line.split('~')
ctn_brk = temp[15] # container break mark
ctn_no = temp[16] # container number
mail_type = temp[17] # mail type
seq_no = temp[18][0:len(temp[18])-1] # mail piece sequence number
# Ignore all records that have no container break or are unqualified
if ctn_brk == '#' and mail_type <> 'UNQ':
dctSequence[ctn_no] = seq_no

9 Years
Discussion Span
Last Post by woooee

ctn_no has to be an integer instead of a string-note that all of the dictionary indexes are now integers and not strings so that you have to use an integer to find something in the dictionary. Also, if ctn_no can not be converted to an integer, you will get an error.
dctSequence[int(ctn_no)+1] = seq_no
or ctn_no = int(temp[16])


Thanks for your help. The program runs further now. I still seem to be having problems calling the values from the dictionary called dctSequence. Later on I read a couple of files and add the value in dctSequence before writing it back out. Prior to using the int I never got to the part where I'd attempt to write the file. Now I'm getting there but having another error and it has to do with adding the value I find in the dictionary. Thanks.


You'll have to post the significant part of the code as well as the error message. Please use "CODE /CODE" tags ("#" in the top box). First check that you are always using intergers.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.