Python configparser 간단 질문 입니다...

조회수 279회

Python 3.7 에서 사용 중입니다만 config 정보를 다른 class의 함수에서 사용하고 싶은데 다음과 같은 에러가 자꾸 뜨네요 ㅠㅠ

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

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)