"elis aeris" <[EMAIL PROTECTED]> wrote
> number_1 = 1
> number_2 = 2
> number_3 = 3
> number_4 = 4
> number_5 = 5
> number_6 = 6
>
> f = open("data.ini", "w")
> f.write("[1]")
> f.write("\n")
> f.write("command" + "=" + "mousemove\n")
> f.write("parameter_" + str(number_1) + "=" + " 500\n")
> f.write("parameter_" + str(number_2) + "=" + " 500\n")
> f.write("parameter_" + str(number_3) + "=" + " 500\n")
> f.write("parameter_" + str(number_4) + "=" + " 500\n")
> f.write("parameter_" + str(number_5) + "=" + " 500\n")
> f.write("parameter_" + str(number_6) + "=" + " 500\n")
This is horribly inefficient and redundant.
Howeever to answer your question first...
> I am not sure why this wouldn't work, but this actually
> doesn't output at all.
You need to close the file after wrioting to force Python to
flush its memory buffers to disk. (You can also use the
flush method if you need to keep the file open for some
reason)
However you could write your code much more easily as:
f = open('data.ini','w')
f.write("[1]\ncommand=mousemove\n")
for n in range(1,7):
f.write("parameter_%d=500\n" % n)
f.close()
Or if you must use named values:
numbers = [1,2,3,4,5,6]
f = open('data.ini','w')
f.write("[1]\ncommand=mousemove\n")
for n in numbers:
f.write("parameter_%d=500\n" % n)
f.close()
You are creating a lot of extra work for yourself by trying to
use dynamic variables and not gaining anything.
Also, as someone else mentioned, if you want to create
config files there is a standard Python module that can help.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor