I'm using it in Python 3.7, but I want to use the config information in other class functions, but I keep getting the following error 네요ㅠ
import xml.etree.ElementTree as ET
import configparser
class Testconfig() :
def __init__(self) :
self.config = configparser.ConfigParser()
self.config.read('config.ini')
class Testxml :
def __init__(self, config) :
self.config = config
print(self.config)
def xml(self) :
tree = ET.parse(self.config['system']['directory']+'\\dmn.xml')
root = tree.getroot()
print(root)
testconfig = Testconfig()
testxml = Testxml(config)
testxml.xml()
['config.ini']
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-62-0ca9cdb0c8a9> in <module>
1 testconfig = Testconfig()
2 testxml = Testxml(config)
----> 3 testxml.xml()
<ipython-input-61-d14c520f9dac> in xml(self)
14
15 def xml(self) :
---> 16 tree = ET.parse(self.config['system']['directory']+'\\dmn.xml')
17 root = tree.getroot()
18 print(root)
TypeError: list indices must be integers or slices, not str
The code uses dict, but it actually contains a list.
886 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
599 GDB gets version error when attempting to debug with the Presense SDK (IDE)
609 Uncaught (inpromise) Error on Electron: An object could not be cloned
568 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.