ConfigParser.items sorting

Dean McClure bratprince at gmail.com
Wed Oct 28 07:21:00 CET 2009


Hi,

Just wondering how I can get the items() command from ConfigParser to
not resort all the item pairs that it presents.

I am trying to get it to read some data in order:

[Relay Info]
relay_name: IPC
relay_current_range: [60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100,
104, 108, 112, 116]
relay_current_mutliplier: [1/8, 1/4, 1/2, 1, 2, 4]
relay_i: arcfc/(relay_current_range*relay_current_mutliplier)

so I can input the data and then eval() the equation at the end but
when I go
config.items('Relay Info')
It mixes everything up, is there a way to stop this?

Here is my selection code

variables = sorted(config.items('Relay Info'))
#Get inputs from user for each variable
for variable in variables:
	if variable[0] == 'relay_name':
		vars()[variable[0]] = variable[1]
	else:
		vars()[variable[0]] = 'not a real thing this is just a fake that
will never turn up to establish the variable'
		if variable[1][0] == '[' and variable[1][-1] == ']':
			if variable[0] != 'Any':
				while (variable[1].count(vars()[variable[0]]) < 1):
					vars()[variable[0]] = raw_input(str(variable)[1:-1] + "\n")
					if variable[1].count(vars()[variable[0]]) < 1:
						print 'Setting unavailable'
			else:
				vars()[variable[0]] = raw_input(str(variable)[1:-1] + "\n")
		else:
			vars()[variable[0]] = variable[1]
		vars()[variable[0]] = float(eval(vars()[variable[0]]))

Thanks for the help!



More information about the Python-list mailing list