Post about getting dates between two datetime dates


Environment and Prerequisite

  • Python


Example

  • Get dates between two datetime dates
import datetime
start_date = datetime.datetime(2021, 11, 15)
end_date = datetime.datetime(2021, 11, 21)

dates = [(start_date + datetime.timedelta(days=day_delta)) for day_delta in range((end_date - start_date).days + 1)]

for date in dates:
    print(date)
2021-11-15 00:00:00
2021-11-16 00:00:00
2021-11-17 00:00:00
2021-11-18 00:00:00
2021-11-19 00:00:00
2021-11-20 00:00:00
2021-11-21 00:00:00
  • Get formatted dates between two datetime dates
import datetime
start_date = datetime.datetime(2021, 11, 15)
end_date = datetime.datetime(2021, 11, 21)

dates = [(start_date + datetime.timedelta(days=day_delta)).strftime("%Y/%m/%d") for day_delta in range((end_date - start_date).days + 1)]

for date in dates:
    print(date)
2021/11/15
2021/11/16
2021/11/17
2021/11/18
2021/11/19
2021/11/20
2021/11/21


Reference

GPG 키를 통해 서명시 “gpg에서 데이터를 서명하는데 실패했습니다.”가 나오는 문제에 대한 해결법


환경

  • Git


문제

  • gpg 키를 사용해 git commit을 작성하는데 아래와 같은 이슈 발생
error: gpg에서 데이터를 서명하는데 실패했습니다.
fatal: 커밋 오브젝트를 쓰는데 실패했습니다


해결법

  • 검색해보니 아래 명령어를 사용하면 비밀번호 입력창이 나오고 문제 해결
  • gpg 키를 통한 서명시 비밀번호가 필요한데 해당 방법이 없어서 발생한 이슈로 추정
    • 해당 gpg 키는 초기설정시 비밀번호가 설정된 상태
export GPG_TTY=$(tty)


참고자료

Post about solving issue which appears “gpg failed to sign the data” when sign with GPG key


Environment and Prerequisite

  • Git


Issue

  • There was an issue when make git commit with gpg key
error: gpg failed to sign the data
fatal: failed to write commit object


Solution

  • By searching on web, found that using below command makes to appear password input box and issue solved
  • It seems like there are no ways to input password when sign with gpg key which needs password
    • That gpg key is set with password in intial setting
export GPG_TTY=$(tty)


Reference

Iterable 객체에서 인덱스와 멤버를 반복문에서 동시에 가져오는 방법에 대한 정리


환경

  • Python


enumerate

enumerate 내장 함수

enumerate(iterable, start=0)
  • 내장 함수로 열거 객체를 돌려줍니다. 함수 매개변수로는 iterable 객체가 들어가야 합니다. Iterable에 대해서는 [Python] Iterable과 Iterator를 참고하시면 됩니다.
  • enumerate(iterable, start=0)iterable의 멤버를 해당 멤버의 인덱스와 함께 튜플 형태로 반환합니다.
  • 반환시 형태는 (인덱스, 멤버)입니다.


enumerate 예제

>>> fruits = ["Apple", "Banana", "Grape", "Mango", "Orange"]
>>> list(enumerate(fruits))
[(0, 'Apple'), (1, 'Banana'), (2, 'Grape'), (3, 'Mango'), (4, 'Orange')]
>>> for pair in enumerate(fruits):
...     print(pair)
...
(0, 'Apple')
(1, 'Banana')
(2, 'Grape')
(3, 'Mango')
(4, 'Orange')
>>> for idx, fruit_name in enumerate(fruits):
...     print(f"{idx} and {fruit_name}")
...
0 and Apple
1 and Banana
2 and Grape
3 and Mango
4 and Orange


참고자료

Post about getting index and member of iterable in iteration one at a time


Environment and Prerequisite

  • Python


enumerate

enumerate built-in function

enumerate(iterable, start=0)
  • It is a built-in function which returns an enumerate object. Iterable object is function parameter. There is reference about iterable in [Python](EN) Iterable and Iterator .
  • enumerate(iterable, start=0) returns iterable’s member and its index as tuple.
  • Its form is (index, member) when it returns.


enumerate example

>>> fruits = ["Apple", "Banana", "Grape", "Mango", "Orange"]
>>> list(enumerate(fruits))
[(0, 'Apple'), (1, 'Banana'), (2, 'Grape'), (3, 'Mango'), (4, 'Orange')]
>>> for pair in enumerate(fruits):
...     print(pair)
...
(0, 'Apple')
(1, 'Banana')
(2, 'Grape')
(3, 'Mango')
(4, 'Orange')
>>> for idx, fruit_name in enumerate(fruits):
...     print(f"{idx} and {fruit_name}")
...
0 and Apple
1 and Banana
2 and Grape
3 and Mango
4 and Orange


Reference