2017-02-10 2 views
1

데이터가 들어있는 .properties 파일이 있습니다. 파이썬 파일에서 이러한 속성에 액세스하려고합니다.ConfigParser를 사용하여 파이썬 파일의 .properties 파일에 저장된 속성에 액세스하는 방법

[section1] 
header = time, date, name, process_name, location 

[section2] 
content = timestamp, details 

내가 파이썬에서 ConfigParser을 사용하고 내가 그런 속성에 액세스 싶어 :

config.get("section1", header[0]) 
config.get("section2", content[2]) 

을하지만 지금, 나는이 오류를 얻고있다

내 특성 파일은 다음과 같이 보입니다 : "global name 'header'가 정의되지 않았습니다. "

어떻게이 오류를 해결할 수 있습니까? 또는 t를 참조하기 위해 위치 번호를 사용하려면 어떻게해야합니까? 그 사람 특유의 재산?

답변

1

config.get('section1', 'header')'time, date, name, process_name, location'을 반환합니다. 그런 다음 split을 사용하여 ['time', 'date', 'name', 'process_name', 'location']으로 분류하십시오.

print(config.get('section1', 'header').split(', ')[0]) 
# time 

print(config.get('section2', 'content').split(', ')[1]) 
# details 
+0

감사합니다. – decemberrobot