본문 바로가기

프로그래밍/Python

(96)
파이썬초보 : 숫자계단 >>> 몇줄 = 10 >>> ij = [(i, j) for i in range(몇줄) for j in range(i+1) ] >>> for n, (i, j) in enumerate(ij): if i != 0 and j == 0: print() print(n%10, end='') 0 12 345 6789 01234 567890 1234567 89012345 678901234 5678901234
엘라스틱서치 elasticsearch-dsl 에서 시간조건을 주어 검색하는 방법 filter 함수에 "range"를 주어 추려낸다. client = Elasticsearch() timestamp_range = { "@timestamp": { "gte": "2020-11-01", "lt": "2020-11-02" } } s = Search(using=client, index="my-index") .filter("range", **timestamp_range) src : stackoverflow.com/questions/58453236/query-timestamp-range-using-elasticsearch-dsl-py Query timestamp range using elasticsearch-dsl-py I have an elasticsearch range query that I'd..
[파이썬초보] TypeError: 'NoneType' object is not subscriptable not subscriptable 은 var[ ] 와 같이 생긴 부분에서 에러가 났다는 말임. >>> a = 1 >>> b = 22.1 >>> c = 'abc' >>> c[1] 'b' >>> a[1] Traceback (most recent call last): File "", line 1, in a[1] TypeError: 'int' object is not subscriptable >>> b[1] Traceback (most recent call last): File "", line 1, in b[1] TypeError: 'float' object is not subscriptable 위 예제에서 a[1] 에서 'int' object is not subscriptable 이란 에러가 발생했다. a = ..
[Python초보] SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape 파이썬 초보들이 겪을 수 있는 문제이다. 이런 에러메시지를 만났다면, 코드 중에 `"C:\Users\xxxxx\...."` 이런 식의 파일경로를 찾아서, 그 경로의 `\`를 모두 `\\`로 바꾸어 실행하면 문제가 해결될 것이다. 아래는 idle에서 에러를 발생시켜 본 것 >>> p = 'C:\Users\dwyoo\sample.txt' SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncate..
[Python] WARNING: You are using pip version xx.xx.xx; however, version yy.yy.yy is available. WARNING: You are using pip version 20.2.4; however, version 20.3.3 is available. You should consider upgrading via the 'C:\Programs\Python3964\python.exe -m pip install --upgrade pip' command. 파이썬에서 패키지를 인스톨하기 위한 pip install 명령을 실행했을 때, 제목과 같은 "경고"메시지가 발생할 때가 있다. 일단, "경고" 메시지이므로, 이 메시지는 당신이 원래 설치하려던 패키지가 설치되었는지와는 (일반적으론) 상관이 없다. (버전의 차이가 너무너무 심하게 난다면, pip 버전이 낮아서 설치가 안 되었을 수도 있었다. 하지만 2021년 기준으로..
[Python] 리스트를 딕셔너리의 키로 사용하려 하는데 에러가 발생한다. TypeError: unhashable type 리스트를 딕셔너리의 키로 사용하려 하면 에러가 발생한다. 이럴 때에는 리스트를 튜플(tuple)로 변환하면 키로 사용할 수 있다. 아래 간단한 샘플코드를 참조하면 되겠다. >>> d = {} >>> l = [1,2] >>> d[l] = 33 Traceback (most recent call last): File "", line 1, in d[l] = 33 TypeError: unhashable type: 'list' >>> d[[3,7]] = 27 Traceback (most recent call last): File "", line 1, in d[[3,7]] = 27 TypeError: unhashable type: 'list' >>> d[tuple(l)] = 33 >>> d {(1, 2): 33} >..
[파이썬] 2020년 탑10 파이썬 라이브러리 tryolabs.com/blog/2020/12/21/top-10-python-libraries-of-2020/ Top 10 Python libraries of 2020 you should know about | Tryolabs Blog There are so many amazing Python libraries out there that it's hard to keep track of all of them. That's why we share with you our hand-picked selection of some top libraries. tryolabs.com Typer : Type + Cli Rich : color cli Dear Pygui : gui PrettyErrors : stack tra..
엘라스틱서치 elasticsearch-py, elasticsearch-dsl 에서 검색결과를 모두 가져오기. (덤 pandasticsearch) python 을 이용하여, 엘라스틱의 검색결과를 가져오기 위해서, elasticsearch-py 와 elasticsearch-dsl 패키지를 이용해 보았다. 검색이 잘 되었으나, 검색결과를 10개만 가져왔다. 아래 elasticsearch-py 코드샘플과 elasticsearch-dsl 코드샘플을 보자. >>> client = Elasticsearch(['http://nightly.apinf.io:14002']) >>> search = Search(using=client) >>> results = search.execute() >>> results.hits.total 9611 >>> len(results.hits.hits) 10 ## src : https://github.com/elastic/elasti..