[Tutor] Newbie: writing same lines in 2 files
Anclo
anclo@anclo.com
Sun Feb 23 20:10:03 2003
At 07:38 PM 2/23/2003, you wrote:
Hello,
I'm trying to write a simple script which generates configuration files for
Analog. I need 2 configuration files (so results could be displayed both
with Analog and Reportmagic) which are identical except for a few lines.
I would like to avoid repeating twice the lines which need to be written in
both config files. However, I always seem to run into some sort of an error.
Here is what I tried:
#!/usr/local/bin/python2.1
import commands
import string
#Get username (will be used for username.analog and username.rm)
username = raw_input("Username for .analog and .rm config files?\n")
analog_config_file = string.join((username,'.analog'),"")
analog_rm_config_file = string.join((username,'.rm'),"")
print "Analog config file to create................: ",analog_config_file
print "Analog for ReportMagic config file to create: ",analog_rm_config_file
#Get domain name from user
domain_name = raw_input("User's domain name?\n")
print "User's domain name: ",domain_name
#Open new Analog config file
outfile_analog = open(analog_config_file,'w')
outfile_analog_rm = open(analog_rm_config_file,'w')
#Define config files
config_files = [outfile_analog,outfile_analog_rm]
#Write config files
config_files[0,1].write('LOGFORMAT COMMON\n')
[... write many more lines ...]
The line:
config_files[0,1].write('LOGFORMAT COMMON\n')
is the one which doesn't work. I get the error:
Traceback (most recent call last):
File "./analogSetup1.py", line 26, in ?
config_files[0,1].write('LOGFORMAT COMMON\n')
TypeError: sequence index must be integer
On the other hand,
config_files[0].write('LOGFORMAT COMMON\n')
config_files[1].write('LOGFORMAT COMMON\n')
works fine.
How would I do these 2 lines with 1 line?
Thanx for your help,
Anclo