Reading config.ini in PythonWin.

V

Vesa Leppanen

Hi,

I am new in python-list and quite new in Python programming as well. I
am working mainly with GIS and using Esri's geoprocessing tools.

I want to use .ini file to set the parameters, especially paths, in my
project. PythonWin 2.1. is my version.

Why do I get the default back in the case below? Any way around?

The Paths,Temp is c:/temp.
 
D

Dennis Lee Bieber

Well, if written as a literal in code that is
c:<tab>emp
not
c:\temp

IGNORE that... I'm not awake yet... \t would have been the <tab>,
no?

However, the second half still applies
You never show us the contents of the INI file...

However, looking deeper... The same problem seems to be showing up
using ConfigParser...

-=-=-=-=-=-
[Paths]
temp=c:\temp
-=-=-=-=-=-
import ConfigParser
config = ConfigParser.ConfigParser()
config.read("e:\\config.ini") ['e:\\config.ini']
config.get("Paths", "temp", vars={"temp":"c:/"}) 'c:/'
config.get("Paths", "temp") 'c:\\temp'

del config
config = ConfigParser.ConfigParser({"temp":"c:/", "noSuch":"Who?"})
config.read("e:\\config.ini") ['e:\\config.ini']
config.get("Paths", "temp") 'c:\\temp'
config.get("Paths", "noSuch") 'Who?'
config.get("Paths", "noSuch", vars={"noSuch":"Why?"}) 'Why?'
config.get("Paths", "temp", vars={"temp":"blah"}) 'blah'

Odd... specifying a default on the .get() seems to override a
default set on the instantiation AND overrides the value IN the file...
But the defaults on the instantiation do not override a .get() without
defaults.

I'd suggest using ConfigParser, if possible, rather than the win32ui
functions as the former is portable, and does look to have a means of
working...
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
G

Gabriel Genellina

At said:
However, looking deeper... The same problem seems to be showing up
using ConfigParser...
Odd... specifying a default on the .get() seems to override a
default set on the instantiation AND overrides the value IN the file...
But the defaults on the instantiation do not override a .get() without
defaults.

Already reported as a bug:
http://sourceforge.net/tracker/index.php?func=detail&aid=1090076&group_id=5470&atid=105470
I'd suggest using ConfigParser, if possible, rather than the win32ui
functions as the former is portable, and does look to have a means of
working...

Just don't use defaults to be safe...


Gabriel Genellina
Softlab SRL





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top