[ENG] STEEM Security update - added power down alert

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/eng-steem-security-update-added-power-down-alert STEEM Security - receive STEEM alert messages via Discord Hello, this is @joviansummer(witness: @jswit). STEEM Security code has been revised. Previously, STEEM Security was sending alert message via discord for the following 3 kinds of operations: sending STEEM/SBD to another account changing SP delegation account update Now, power down operation has been added. If there is a power down operation, you will also receive alert message. Please check the original post of the above link for detailed information on how to use the service. Thank you for reading, and have a wonderful day! @joviansummer's STEEM projects @jswit witness: I'm running a STEEM witness node. I'd really appreciate it if you vote for my witness account @jswit. ( https://steemitwallet.com/~witnesses ) [ENG] Introducing @jswit witness project @jsup curation: [ENG] Int...

파이썬에서 설정 파일 처리(configparser)

by joviansummer
original STEEMIT post: https://steemit.com/blog/@joviansummer/configparser


파이썬에서 configparser 모듈을 이용해서 설정 파일 처리를 편리하게 할 수 있습니다. 설정 파일 형식은 아래의 예시처럼 섹션(section)으로 나누어지고 항목에 설정값을 할당하는 형태가 됩니다. 예를 들어 test.cfg 파일이 아래와 같다고 해 보겠습니다.

[section1]
sec1_cfg1 = abc
sec1_cfg2 = 123

[section2]
sec2_cfg1 = xyz

2개의 섹션이 있고 각 섹션마다 설정 값들이 지정된 상태입니다. configparser를 이용해서 이 파일을 읽으면 설정을 딕셔너리(dict)와 동일한 방식으로 처리할 수 있습니다. ConfigParser 객체를 사용하면 되며, 파일 읽기는 read() 함수를 이용합니다.

import configparser

config_file = 'test.cfg'

# 설정 파일 읽기
cfg = configparser.ConfigParser()
cfg.read(config_file)

# section1의 sec1_cfg1 설정값 출력
print(cfg['section1']['sec1_cfg1'])

abc

설정 파일에서 읽은 값은 문자열(str)로 저장되므로, 설정값을 수자로 사용하려면 변환해 주어야 합니다. 예를 들어 위의 예시에서 section1의 sec_cfg2 항목의 값이 123인데, 정수 계산에 사용하려면 형식을 바꿔주어야 하겠죠.

sec1_cfg2_int = int(cfg['section1']['sec1_cfg2'])

설정 파일을 변경한 후에 저장하고 싶다면 write() 함수를 이용합니다. 예를 들어 section1의 sec1_cfg2 항목 설정값을 456으로 설정한 후에 저장하려면 아래와 같이 할 수 있겠습니다.

cfg['section1']['sec1_cfg2'] = '456'
# 설정 파일 저장
f = open(config_file, 'w')
cfg.write(f)
f.close()

만약 설정 파일이 없는데 처음부터 새로 만들고 싶다면 아래와 같이 할 수 있겠습니다.

new_config_file = 'new_test.cfg'

new_cfg = configparer.ConfigParser()

new_cfg['section1'] = {}
new_cfg['section1']['sec1_cfg1'] = 'abc'
new_cfg['section1']['sec1_cfg2'] = '123'

new_cfg['section2'] = {}
new_cfg['section2']['sec2_cfg1'] = 'xyz'

f = open(new_config_file, 'w')
new_cfg.write(f)
f.close()

@joviansummer의 스팀 프로젝트

스팀 증인노드를 운영중입니다. @jswit에 증인투표해 주시면 감사하겠습니다.
(https://steemitwallet.com/~witnesses)

jswit 증인 노드 프로젝트를 시작합니다.

jsup 업보팅(upvoting) 서비스 소개

jsup 수혜자 지정 기능 추가

jSTEEM 프로젝트 - 텔레그램 챗봇으로 구현하는 스팀 블럭체인 탐색기

STEEM.NFT - 디지털 아트 보존 프로젝트

Comments

Popular posts from this blog

[ENG] jsup 2.0 - make your upvote great again

jsup/avle 보팅 코드 갱신 - 1일1포스팅 강박에서 벗어나기

Nuitka - 파이썬 스크립트를 바이너리 실행 파일로 변환