[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...

파이썬에서 특정 파일이 존재하는지 확인하기

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


인터넷에서 찾아봤다가 잊어버렸다가 나중에 다시 찾아보는 수고를 방지하기 위해서 현재 진행중인 작업과 관련하여 필요한 내용들을 시간 날 때마다 메모해 두려고 합니다.

파이선에서 파일 존재 여부를 확인하는 예시입니다. os 모듈을 활용합니다.

import os
# 현재 디렉토리 정보를 CUR_DIR에 할당
CUR_DIR = os.getcwd()
# 디렉토리 출력
print(CUR_DIR)

현재 디렉토리에 joviansummer.txt 파일이 존재하는지 확인합니다.

# 확인 대상 파일(리눅스 기준으로 구분자 "/" 사용)
target_file = CUR_DIR + "/joviansummer.txt"

# 대상 경로(path) 존재 여부 확인
if os.path.exists(target_file):
  print("경로가 존재합니다")
else:
  print("경로가 존재하지 않습니다")

os.path.exits()는 대상이 파일인지 디렉토리인지 관계 없이 해당 경로가 존재할 경우에 True가 됩니다. 대상이 "파일"인지를 특정해서 확인하기 위해 os.path.isfile()을 함께 AND(교집합) 조건으로 묶어줍니다.

# 대상 경로가 존재하고, 그것이 파일인지 확인
if (os.path.exists(target_file) and (os.path.isfile(target_file)):
  print("파일이 존재합니다.")
else:
  print("파일이 존재하지 않습니다.")

Comments

Popular posts from this blog

[ENG] jsup 2.0 - make your upvote great again

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

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