hello, we are getting this issue with a Python Program. Anyone has any clue?
Traceback (most recent call last):
File "cbl_data.py", line 149, in ?
field_list = create_field_list('cbl_data.cfg')
File "cbl_data.py", line 35, in create_field_list
for line in open(config_file):
TypeError: loop over non-sequence
The config file details as follows.
x:2 # character field - probably key
p:17 # unpacked numeric
z:2
x:19
x:4
x:10
z:4
x:1
z:3
x:1
p:12
p:12
x:10
x:4
Code
def create_field_list(config_file):
"""returns list of fields definition from the config file"""
config_list = []
nr_lines = 0
for line in open(config_file):
nr_lines += 1
cfg_line = line
# remove comments from line
if '#' in cfg_line:
cfg_line=cfg_line[:cfg_line.index('#')]
# strip blanks from both ends
cfg_line = cfg_line.strip()
# process not empty lines
if len(cfg_line) > 0:
if ':' in cfg_line:
# to uppercase
cfg_line=cfg_line.upper()
# split into a list
cfg_line_list=cfg_line.split(':')
if cfg_line_list[1].isdigit():
cfg_line_list[1] = string.atoi(cfg_line_list[1])
# compute the length of Packed Decimal (COMP-3)
if cfg_line_list[0]=='P':
cfg_line_list[1]=cfg_line_list[1]/2 + 1
#print cfg_line_list
config_list.append(cfg_line_list)
else:
print "Error in config line %d:" % nr_lines
print "'%s'" % cfg_line
print "Data type length is not numeric !"
sys.exit()
else:
print "Error in config line %d:" % nr_lines
print "'%s'" % cfg_line
print "Line should have a form <DataType>:<length> !"
sys.exit()
# return list of fields
return config_list
Traceback (most recent call last):
File "cbl_data.py", line 149, in ?
field_list = create_field_list('cbl_data.cfg')
File "cbl_data.py", line 35, in create_field_list
for line in open(config_file):
TypeError: loop over non-sequence
The config file details as follows.
x:2 # character field - probably key
p:17 # unpacked numeric
z:2
x:19
x:4
x:10
z:4
x:1
z:3
x:1
p:12
p:12
x:10
x:4
Code
def create_field_list(config_file):
"""returns list of fields definition from the config file"""
config_list = []
nr_lines = 0
for line in open(config_file):
nr_lines += 1
cfg_line = line
# remove comments from line
if '#' in cfg_line:
cfg_line=cfg_line[:cfg_line.index('#')]
# strip blanks from both ends
cfg_line = cfg_line.strip()
# process not empty lines
if len(cfg_line) > 0:
if ':' in cfg_line:
# to uppercase
cfg_line=cfg_line.upper()
# split into a list
cfg_line_list=cfg_line.split(':')
if cfg_line_list[1].isdigit():
cfg_line_list[1] = string.atoi(cfg_line_list[1])
# compute the length of Packed Decimal (COMP-3)
if cfg_line_list[0]=='P':
cfg_line_list[1]=cfg_line_list[1]/2 + 1
#print cfg_line_list
config_list.append(cfg_line_list)
else:
print "Error in config line %d:" % nr_lines
print "'%s'" % cfg_line
print "Data type length is not numeric !"
sys.exit()
else:
print "Error in config line %d:" % nr_lines
print "'%s'" % cfg_line
print "Line should have a form <DataType>:<length> !"
sys.exit()
# return list of fields
return config_list