|
From: Anton H. <kur...@gm...> - 2011-02-24 13:50:30
|
Hi
Im trying to use ConfigObj but am getting the following error. And I have
know idea what I am doing wrong. Anyone can help?
from configobj import ConfigObj
config = ConfigObj('c:\temp\config.ini')
config["som_somserver"]
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "build\bdist.win32\egg\configobj.py", line 567, in __getitem__
val = dict.__getitem__(self, key)
KeyError: 'som_somserver'
Here is a copy of my config file:
soc_source = soc_source
retail_price = $400
soc_source = 1
soc_theme = 2
soc_target = 3
soc_folder_exist = 4
soc_folder_temp_exist = 5
soc_folder_backup_exist = 6
som_somserver = 1
som_filename=2
som_sourcefile = 3
som_targetfile = 4
som_fileexist = 5
som_file_temp_exist=6
som_file_backup_exist=7
Thanks
|
|
From: David H. <neg...@gm...> - 2011-02-24 14:12:58
|
For starters, make sure you're actually referring to the config.ini
file that you think you are, and that it contains what you intend it
to contain.
The one you provided doesn't even parse correctly because it's got
'soc_source' listed as a keyword twice. So the example code you have
doesn't even match the example file, since the following line would
throw an exception:
> config = ConfigObj('c:\temp\config.ini')
Which leads me to suspect that perhaps the config.ini file that you're
actually loading does NOT, in fact, have the following line in it:
> som_somserver = 1
Which would explain the KeyError.
cheers,
-hoss
On Thu, Feb 24, 2011 at 08:50, Anton Hughes <kur...@gm...> wrote:
> Hi
> Im trying to use ConfigObj but am getting the following error. And I have
> know idea what I am doing wrong. Anyone can help?
>
> from configobj import ConfigObj
> config = ConfigObj('c:\temp\config.ini')
> config["som_somserver"]
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "build\bdist.win32\egg\configobj.py", line 567, in __getitem__
> val = dict.__getitem__(self, key)
> KeyError: 'som_somserver'
>
>
> Here is a copy of my config file:
> soc_source = soc_source
> retail_price = $400
> soc_source = 1
> soc_theme = 2
> soc_target = 3
> soc_folder_exist = 4
> soc_folder_temp_exist = 5
> soc_folder_backup_exist = 6
> som_somserver = 1
> som_filename=2
> som_sourcefile = 3
> som_targetfile = 4
> som_fileexist = 5
> som_file_temp_exist=6
> som_file_backup_exist=7
> Thanks
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search & Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving IT
> data
> generated by your applications, servers and devices whether physical,
> virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|
|
From: Michael F. <fuz...@vo...> - 2011-02-24 14:22:13
|
On 24/02/2011 13:50, Anton Hughes wrote:
> Hi
> Im trying to use ConfigObj but am getting the following error. And I
> have know idea what I am doing wrong. Anyone can help?
>
> from configobj import ConfigObj
> config = ConfigObj('c:\temp\config.ini')
This line probably doesn't do what you expect. In Python the backslash
is an escape character in strings and "\t" is a tab. Try this instead:
config = ConfigObj(r'c:\temp\config.ini')
The "r" makes the string raw so that backslashes are literals rather
than escape characters.
All the best,
Michael Foord
> config["som_somserver"]
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "build\bdist.win32\egg\configobj.py", line 567, in __getitem__
> val = dict.__getitem__(self, key)
> KeyError: 'som_somserver'
>
>
>
> Here is a copy of my config file:
> soc_source = soc_source
> retail_price = $400
> soc_source = 1
> soc_theme = 2
> soc_target = 3
> soc_folder_exist = 4
> soc_folder_temp_exist = 5
> soc_folder_backup_exist = 6
> som_somserver = 1
> som_filename=2
> som_sourcefile = 3
> som_targetfile = 4
> som_fileexist = 5
> som_file_temp_exist=6
> som_file_backup_exist=7
>
> Thanks
>
>
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search& Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving IT data
> generated by your applications, servers and devices whether physical, virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
>
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
|
|
From: David H. <neg...@gm...> - 2011-02-24 14:28:52
|
Ha! Good catch.
Yeah, he's ending up with a cfg that has the following:
>>> cfg.filename
'c:\temp\\config.ini'
>>> cfg.dict()
{}
>>>
Thus... an empty data set because it never opened any existing file for parsing.
And as soon as he fixes that, he'll get the following:
configobj.configobj.DuplicateError: Duplicate keyword name at line 3.
cheers,
-hoss
On Thu, Feb 24, 2011 at 08:53, Michael Foord <fuz...@vo...> wrote:
> On 24/02/2011 13:50, Anton Hughes wrote:
>
> Hi
> Im trying to use ConfigObj but am getting the following error. And I have
> know idea what I am doing wrong. Anyone can help?
>
> from configobj import ConfigObj
> config = ConfigObj('c:\temp\config.ini')
>
> This line probably doesn't do what you expect. In Python the backslash is an
> escape character in strings and "\t" is a tab. Try this instead:
>
> config = ConfigObj(r'c:\temp\config.ini')
>
> The "r" makes the string raw so that backslashes are literals rather than
> escape characters.
>
> All the best,
>
> Michael Foord
>
> config["som_somserver"]
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "build\bdist.win32\egg\configobj.py", line 567, in __getitem__
> val = dict.__getitem__(self, key)
> KeyError: 'som_somserver'
>
>
> Here is a copy of my config file:
> soc_source = soc_source
> retail_price = $400
> soc_source = 1
> soc_theme = 2
> soc_target = 3
> soc_folder_exist = 4
> soc_folder_temp_exist = 5
> soc_folder_backup_exist = 6
> som_somserver = 1
> som_filename=2
> som_sourcefile = 3
> som_targetfile = 4
> som_fileexist = 5
> som_file_temp_exist=6
> som_file_backup_exist=7
> Thanks
>
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search & Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving IT
> data
> generated by your applications, servers and devices whether physical,
> virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
> --
> http://www.voidspace.org.uk/
>
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
> -- the sqlite blessing http://www.sqlite.org/different.html
>
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search & Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving IT
> data
> generated by your applications, servers and devices whether physical,
> virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|
|
From: Chris S. <so...@st...> - 2011-02-24 14:30:36
|
Hi Anton,
I'm using an older version of ConfigObj, but your file works for me - only after I get rid of the duplicate 'soc_source' line (I'm not sure how you got past the initial load):
> >>> co = configobj.ConfigObj('newbie.cfg')
> >>> co
> ConfigObj({'retail_price': '$400', 'soc_source': '1', 'soc_theme': '2', 'soc_target': '3', 'soc_folder_exist': '4', 'soc_folder_temp_exist': '5', 'soc_folder_backup_exist': '6', 'som_somserver': '1', 'som_filename': '2', 'som_sourcefile': '3', 'som_targetfile': '4', 'som_fileexist': '5', 'som_file_temp_exist': '6', 'som_file_backup_exist': '7'})
> >>> co["som_somserver"]
> '1'
Chris
On 2/24/11 8:50 AM, Anton Hughes wrote:
> Hi
> Im trying to use ConfigObj but am getting the following error. And I have know idea what I am doing wrong. Anyone can help?
>
> from configobj import ConfigObj
> config = ConfigObj('c:\temp\config.ini')
> config["som_somserver"]
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "build\bdist.win32\egg\configobj.py", line 567, in __getitem__
> val = dict.__getitem__(self, key)
> KeyError: 'som_somserver'
>
>
>
> Here is a copy of my config file:
> soc_source = soc_source
> retail_price = $400
> soc_source = 1
> soc_theme = 2
> soc_target = 3
> soc_folder_exist = 4
> soc_folder_temp_exist = 5
> soc_folder_backup_exist = 6
> som_somserver = 1
> som_filename=2
> som_sourcefile = 3
> som_targetfile = 4
> som_fileexist = 5
> som_file_temp_exist=6
> som_file_backup_exist=7
>
> Thanks
>
|