示例#1
0
		nfmt='{0:'+sys.argv[1]+'}';

	s=sys.stdin.read().split('\n');


	lines=[];
	lens={};

	for line in s:
#		print line
		words = line.split();

#		print words
	
		for n in range(len(words)):
			w=str2val(words[n]);
			if type(w) is float:
				try:
					w = nfmt.format(w);
				except ValueError:
					print 'ERROR'+nfmt+str(w)

			if type(w) is int:
				w=str(w);

			L = len(w);
			
			if not n in lens or lens[n]<L:
				lens[n] = L;

		lines.append(words);
示例#2
0
def parseParameters(lines,currline):

	currline = skipEmptyLines(lines,currline);
	
	words=lines[currline].split();

	if len(words)<2 or words[1]!='RECORD' and words[1]!='RECORDS':
		raiseException(currline,'<number> RECORDS expected');

	NRec = int(words[0]);

	param_variety = [{}];
	param_names = [''];

	for i in range(NRec):
		currline = skipEmptyLines(lines,currline+1);

		tokens = lines[currline].split();
		if tokens[0] == 'SWITCH':
			currline,sub_param_variety,sub_param_names = parseSwitch(lines,currline);

			new_variety = [];

			for oldprm in param_variety:
				for newprm in sub_param_variety:
					joinprm = dict(oldprm);
					joinprm.update(newprm);
					new_variety.append(joinprm);
				
					
			param_variety = new_variety;

			new_names = [];
			for oldname in param_names:
				for newname in sub_param_names:
					new_names.append(oldname+':' + newname);

			param_names = new_names;
			
		else:
			words = lines[currline].split('=');

			param = words[0].strip().lower();
		
			values = words[1].split();
			keyword = values[0];

			if keyword=='LIST':
				value = DefList(values[1:]);
			elif keyword=='FILE':
				f=open(values[1]);
				file_values = [ str2val(s.strip()) for s in f.read().splitlines()];
				f.close();

				value = DefList(file_values);
			else:
				value = str2val(values[0]);

			for prm in param_variety:
				prm[param]=value;

	return currline,param_variety,param_names;
示例#3
0
def parseParameters(lines, currline):

    currline = skipEmptyLines(lines, currline)

    words = lines[currline].split()

    if len(words) < 2 or words[1] != 'RECORD' and words[1] != 'RECORDS':
        raiseException(currline, '<number> RECORDS expected')

    NRec = int(words[0])

    param_variety = [{}]
    param_names = ['']

    for i in range(NRec):
        currline = skipEmptyLines(lines, currline + 1)

        tokens = lines[currline].split()
        if tokens[0] == 'SWITCH':
            currline, sub_param_variety, sub_param_names = parseSwitch(
                lines, currline)

            new_variety = []

            for oldprm in param_variety:
                for newprm in sub_param_variety:
                    joinprm = dict(oldprm)
                    joinprm.update(newprm)
                    new_variety.append(joinprm)

            param_variety = new_variety

            new_names = []
            for oldname in param_names:
                for newname in sub_param_names:
                    new_names.append(oldname + ':' + newname)

            param_names = new_names

        else:
            words = lines[currline].split('=')

            param = words[0].strip().lower()

            values = words[1].split()
            keyword = values[0]

            if keyword == 'LIST':
                value = DefList(values[1:])
            elif keyword == 'FILE':
                f = open(values[1])
                file_values = [
                    str2val(s.strip()) for s in f.read().splitlines()
                ]
                f.close()

                value = DefList(file_values)
            else:
                value = str2val(values[0])

            for prm in param_variety:
                prm[param] = value

    return currline, param_variety, param_names
示例#4
0
		nfmt='{0:'+sys.argv[1]+'}';

	s=sys.stdin.read().split('\n');


	lines=[];
	lens={};

	for line in s:
#		print line
		words = line.split();

#		print words
	
		for n in range(len(words)):
			w=str2val(words[n]);
			if type(w) is float:
				try:
					w = nfmt.format(w);
				except ValueError:
					print 'ERROR'+nfmt+str(w)

			if type(w) is int:
				w=str(w);

			L = len(w);
			
			if not n in lens or lens[n]<L:
				lens[n] = L;

		lines.append(words);