jsup/avle code update - you don't have to write post everyday

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/jsup-avle-code-update-you-don-t-have-to-write-post-everyday Hello, this is @joviansummer, developer of @jsup and@avle voting service. Voting service code for @jsup and @avle has been updated. I had been considering this update for a while, and recently I could come up with detailed implementation plan which resulted in a relatively swift code revision. The new added feature is capability to give daily upvote to the first thing you write for the day(timezone GMT+9) regardless of post or comment/reply. Writing a post everyday can be challenging. In that case, you can write a reply to receive daily upvote because writing a reply everyday is much easier and also a good way to engage in your community. Writing a post everyday just to get an upvote can be very tedious and exhausting, and post itself could easily become low-quality. There may be people who enjoy writing a post everyday, but we can't ignore th...

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

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

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

[ENG] jsup 2.0 - make your upvote great again

[EN] STEEM-services: dapps/services webpage with sort and search functions