namedTuple2 Python 파이썬에서 주 번호를 어떻게 얻을 수 있나요?, How to get week number in Python? 질문 파이썬을 사용하여 현재 연도의 6월 16일이 몇 주차인지 어떻게 알 수 있을까요? (wk24) 답변 datetime.date에는 isocalendar() 메서드가 있으며, 이는 달력 주를 포함한 튜플을 반환합니다: >>> import datetime >>> datetime.date(2010, 6, 16).isocalendar()[1] 24 datetime.date.isocalendar()은 주어진 날짜 인스턴스에 대해 연도, 주 번호 및 요일을 순서대로 포함하는 튜플을 반환하는 인스턴스 메서드입니다. Python 3.9+에서는 isocalendar()가 namedtuple을 반환하며, 해당 필드는 year, week 및 weekday입니다. 이는 명명된 속성을 사용하여 명시적으로 주에 접근할 수 있.. 2023. 10. 24. Python 파이썬의 중첩된 딕셔너리를 객체로 변환하는 방법은 무엇인가요?, How to convert a nested Python dict to object? 질문 I'm searching for an elegant way to get data using attribute access on a dict with some nested dicts and lists (i.e. javascript-style object syntax). For example: >>> d = {'a': 1, 'b': {'c': 2}, 'd': ["hi", {'foo': "bar"}]} Should be accessible in this way: >>> x = dict2obj(d) >>> x.a 1 >>> x.b.c 2 >>> x.d[1].foo bar I think, this is not possible without recursion, but what would be a nice wa.. 2023. 8. 2. 이전 1 다음