I was wondering if anyone can explain to me why I keep getting this error:
Here is the code of the two files:
INIfile.py:
test.py
I just don't see what I'm doing wrong.
Traceback (most recent call last):
File "C:/Documents and Settings/William/Desktop/test.py", line 4, in <module>
value = INI.getinifile ( 'P:/INI/test.ini', 'Testsection', 'Testoption', 'Default Value' )
File "C:\Python25\li b\INIfile.py", line 8, in getinifile
if len(Value) == 0:
AttributeError: 'str' object has no attribute 'len'
File "C:/Documents and Settings/William/Desktop/test.py", line 4, in <module>
value = INI.getinifile ( 'P:/INI/test.ini', 'Testsection', 'Testoption', 'Default Value' )
File "C:\Python25\li b\INIfile.py", line 8, in getinifile
if len(Value) == 0:
AttributeError: 'str' object has no attribute 'len'
INIfile.py:
Code:
from ConfigParser import ConfigParser class INI: def getinifile ( self, FILE, SECTION, ITEM, DEFAULT ): p = ConfigParser() p.read(FILE) Value = p.get ( SECTION, ITEM ).lstrip().rstrip() if len(Value) == 0: Value = DEFAULT return Value
Code:
import INIfile INI = INIfile.INI() value = INI.getinifile ( 'P:/INI/test.ini', 'Testsection', 'Testoption', 'Default Value' ) print value
Comment