Pyro.699
May 22nd, 2009, 07:13 AM
Hello,
I'm using the ConfigParser to read from and write to a configuration file.
Here is the basic structure of what I'm trying...
config_file = open('./config/config.ini', 'a+')
config = ConfigParser.ConfigParser()
config.readfp(config_file)
config.write(config_file)
It seems redundant, but its to try and get it working, when i have that i get this error
Traceback (most recent call last):
File "C:\Documents and Settings\Cody\Desktop\pythontest\pytest.py", line 14, in <module>
config.write(config_file)
File "C:\Python25\lib\ConfigParser.py", line 369, in write
fp.write("[%s]\n" % section)
IOError: [Errno 0] Error
I have tried everything and seem to be able to only do one of either read from the file and not be able to write, and if im able to read from the file, im not able to read it; also when i write to it it deletes all information inside the file.
More examples...
config_file = open('./config/config.ini', 'a+')
config = ConfigParser.ConfigParser()
config.readfp(config_file)
print config.get("[Master]", "username")
config.write(config_file)
Here was whats in the ini file:
[Master]
username = Pyro.699
Traceback (most recent call last):
File "C:\Documents and Settings\Cody\Desktop\pythontest\pytest.py", line 14, in <module>
print config.get("[Master]", "username")
File "C:\Python25\lib\ConfigParser.py", line 511, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: '[Master]'
Any help is greatly appreciated
Thanks
~Cody Woolaver
I'm using the ConfigParser to read from and write to a configuration file.
Here is the basic structure of what I'm trying...
config_file = open('./config/config.ini', 'a+')
config = ConfigParser.ConfigParser()
config.readfp(config_file)
config.write(config_file)
It seems redundant, but its to try and get it working, when i have that i get this error
Traceback (most recent call last):
File "C:\Documents and Settings\Cody\Desktop\pythontest\pytest.py", line 14, in <module>
config.write(config_file)
File "C:\Python25\lib\ConfigParser.py", line 369, in write
fp.write("[%s]\n" % section)
IOError: [Errno 0] Error
I have tried everything and seem to be able to only do one of either read from the file and not be able to write, and if im able to read from the file, im not able to read it; also when i write to it it deletes all information inside the file.
More examples...
config_file = open('./config/config.ini', 'a+')
config = ConfigParser.ConfigParser()
config.readfp(config_file)
print config.get("[Master]", "username")
config.write(config_file)
Here was whats in the ini file:
[Master]
username = Pyro.699
Traceback (most recent call last):
File "C:\Documents and Settings\Cody\Desktop\pythontest\pytest.py", line 14, in <module>
print config.get("[Master]", "username")
File "C:\Python25\lib\ConfigParser.py", line 511, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: '[Master]'
Any help is greatly appreciated
Thanks
~Cody Woolaver