본문 바로가기

Python

(70)
[파이썬초보] 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] 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..
윈도우용 파이썬 3.8 버전에서 pip install kivy 로 설치가 안 된다. 2020년 12월 9일 kivy 로 android 개발을 할 수 있다는 이야기를 들어서, kivy 를 한번 설치해 보았다. 그런데, pip install kivy 를 실행하였더니 엄청난 에러와 함께 설치가 실패했다. 환경은 : windows 10, python 3.8 64 bit, venv 로 만들어 놓은 가상환경.위 내 (v3864) C:\PYENVS>pip install kivy Collecting kivy Using cached Kivy-1.11.1.tar.gz (23.6 MB) ERROR: Command errored out with exit status 1: command: 'c:\pyenvs\v3864\scripts\python.exe' -c 'import sys, setuptools, tok..
[Python] 윈도우 cmd 창에서 python 을 입력하면 윈도우 스토어 설치화면이 나온다. python 을 실행하기 위해서 cmd 창 (명령창, 콘솔창)에서 python ... 을 입력하였는데, 파이썬이 실행되지 않고 윈도우 스토어가 열리면서 python 설치유도 화면이 뜨는 경우가 있다. python 을 이미 설치했는데도 이렇게 뜬다면, 윈도우 운영체제가 python.exe 를 찾지 못해서, 윈도우 스토어의 python 설치화면을 띄운 것이다. python 을 설치하면서, python 의 설치패쓰를 PATH 환경변수에 등록하는 설정을 하고 설치하였다면, 이와 같은 문제가 생기지 않는다. 윈도우 cmd 는 사용자가 입력한 명령을 실행할 실제 실행파일을 찾기 위해서 PATH 변수에 등록된 경로들을 주르륵 탐색한다. python 이라고 입력했다면, python.exe, python.bat, .....
[Python] Turtle 로 프랙탈 트리 그리기 python turtle 로 프랙탈 트리를 그려 봤다. import turtle def tree(length, depth=0): if depth < 4: depth += 1 nlength = length * (0.7 ** depth) t.forward(length) t.left(60) tree(nlength, depth) t.right(30) tree(nlength, depth) t.right(30) tree(nlength, depth) t.right(30) tree(nlength, depth) t.right(30) tree(nlength, depth) t.left(60) t.backward(length) t = turtle.Turtle() t.left(90) t.color("green") t.speed..
[EP 018] 삼각형 배열에서 지나간 수의 합을 최대로 하는 경로를 구하기 문제에서는 경로를 다 구할 필요는 없었고, 경로합의 최대값만 구하면 되었다. 중간에 어떤 노드까지 거슬러 올 수 있는 모든 경로의 최대값을 알 수 있다고 하자. 한 줄에 대해서 다 안다고 하자. 그럼 그 윗줄의 어떤 노드 A까지 거슬러 올 수 있는 모든 경로의 최대값은, 그 A 아래의 두 노드 각각의 최대값과 A노드 값의 합, 두가지 경우 중에서 결정된다. #!/usr/bin/env python # http://projecteuler.net # Problem 18 # Find a top-to-bottom path which makes the path-sum maximum # Author : DwYoon # Date : 2020 # I reduce the triangle from the bottom. Ea..