I have a file test.cfg:
[options]
option1=foo
option2=bar
I have a program testconfig.py:
import ConfigParser
config = ConfigParser.Co nfigParser()
f = open('test.cfg' )
config.readfp(f )
configList = config.items('o ptions')
print configList
config.set('opt ions', 'option3', 'baz')
config.write(f)
When I run this program, I get an error:
Traceback (most recent call last):
File "./testconfig.py", line 11, in ?
config.write(f)
File "/usr/lib/python2.3/ConfigParser.py ", line 363, in write
fp.write("[%s]\n" % section)
IOError: [Errno 9] Bad file descriptor
Is .write() not right? If not, how do I save the changed config to file? 1 1632
NM, I am an idiot. Need to open the file in write mode.
David Rysdam wrote: I have a file test.cfg:
[options] option1=foo option2=bar
I have a program testconfig.py:
import ConfigParser
config = ConfigParser.Co nfigParser() f = open('test.cfg' ) config.readfp(f ) configList = config.items('o ptions') print configList config.set('opt ions', 'option3', 'baz') config.write(f)
When I run this program, I get an error:
Traceback (most recent call last): File "./testconfig.py", line 11, in ? config.write(f) File "/usr/lib/python2.3/ConfigParser.py ", line 363, in write fp.write("[%s]\n" % section) IOError: [Errno 9] Bad file descriptor
Is .write() not right? If not, how do I save the changed config to file? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Roy H. Berger |
last post by:
If I want to subclass ConfigParser and changed the optionxform method
to not return things in lower case wouldn't I just need the following
code in my subclasss module?
from ConfigParser import *
class MyConfigParser(ConfigParser):
def __init__(self, defaults=None):
ConfigParser.__init__(self, defaults)
|
by: Manlio Perillo |
last post by:
Regards.
Since sections in CongiParser files are delimited by , why
there is not an escape (and unescape) function for escaping
&, characters to &, [ and ] ?
Thanks Manlio Perillo
|
by: rzed |
last post by:
I am working with PythonCard in one of my apps. For its purposes, it
uses an .ini file that is passed to ConfigParser. For my app, I also
need configuration information, but for various reasons, I'd rather
use a syntax that ConfigParser can't handle.
I know I can maintain two separate configuration files, and if I have
to I will, but I'd rather avoid that, if possible, and a solution
that suits my purposes is quite straightforward. I...
|
by: Nexu |
last post by:
Hello,
I'm not sure exactly what i'm doing wrong here. I asked around on IRC
and i was told the code is correct.
The purpose of Settings() is that whenever Settings() or any of its
methods are called. It should pick up the latest settings from file
instead of returning what was in the buffer. This allow other scripts to
change the value and my program and pick these changes up.
Everything else should work exact same as ConfigParser()....
|
by: pipehappy |
last post by:
Hello everyone:
I came across the module ConfigParser and can use it correctly.
import ConfigParser
fp = open('test.cfg','w+')
config = ConfigParser.ConfigParser()
config.readfp(fp)
config.add_section('test')
config.set('test', 'haha', 'hehe')
| |
by: Pupeno |
last post by:
Hello,
I have a class called MyConfig, it is based on Python's
ConfigParser.ConfigParser.
It implements add_section(self, section), which is also implemented on
ConfigParser.ConfigParser, which I want to call.
So, reducing the problem to the bare minimum, the class (with a useless
add_section that shows the problem):
.... def add_section(self, section):
.... super(MyConfig, self).add_section(section)
|
by: Phoe6 |
last post by:
Hi All,
I am able to use urlib2 through proxy. I give proxy credentials and use
# Set the Proxy Address
proxy_ip = "10.0.1.1:80"
proxy_user = 'senthil_or'
proxy_password_orig='password'
|
by: William Manley |
last post by:
According to what I read in the ConfigParser module, this should work, but it doesn't. Can anyone point out what I'm doing wrong?
def writeinifile ( self, FILE='P:/INI/test.ini', SECTION='Testsection', OPTION='Item', VALUE='wheeee' ):
p = ConfigParser()
p.read(FILE)
if not p.has_section ( SECTION ):
p.add_section(SECTION)
p.set(SECTION, OPTION, VALUE)
p.write(FILE)
|
by: Phoe6 |
last post by:
Hi,
I have a configfile, in fact, I am providing a configfile in the
format:
Name: Foo
Author: Bar
Testcases:
tct123
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |