Created
April 5, 2024 10:34
-
-
Save jc3wrld999/7dfb6e7e619d9049b4ebc1daca346051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class SubUtility: | |
def __init__(self): | |
self.init = None | |
def ConfigToDict(self, filename): | |
equal_option = dict() | |
if os.path.isfile(filename): | |
with open(filename, 'r') as fileread: | |
for read in fileread: | |
read = read.strip() # 공백 제거 | |
if read and not read.startswith('#'): # 빈 줄과 주석은 건너뜀 | |
key, value = read.split('=', 1) # 첫 번째 등호만 사용하여 나눔 | |
equal_option[key.strip()] = value.strip() # 딕셔너리에 추가 | |
return equal_option | |
""" | |
config.cfg | |
### CONFIG EXAMPLE ### | |
IP = 192.168.124.1 | |
PORT = 22 | |
""" | |
configFile = "config.cfg" | |
subUtility = SubUtility() | |
configDict = subUtility.ConfigToDict(configFile) | |
print(configDict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment