본문 바로가기

NoneType

(3)
Geopy AttributeError: 'NoneType' object has no attribute 'latitude' 주소에서 위도와 경도를 가져오기 위해 geopy를 이용하는 코드에서 no attribute 'latitude' 에러가 발생할 수 있다. 코드를 보자. from geopy.geocoders import Nominatim def geocoding(address): geolocoder = Nominatim(user_agent="South Korea", timeout=None) geo = geolocoder.geocode(address) x_y = [geo.latitude, geo.longitude] return x_y for addr in ["강원 강릉시 해안로 1459", "강원 강릉시 초당순두부길 77번길 15"]: print(addr, geocoding(addr)) geocoding 함수는 사람들이 사용..
[파이썬초보] AttributeError: 'NoneType' object has no attribute 이런 에러에 대해 질문을 하는 걸 자주 봐서 포스팅을 하나 만들어 놓습니다. 에러메시지를 해석해 보면, "'NoneType' 객체는 ~~ 애트리뷰트가 없습니다."라는 뜻입니다. NoneType 객체는 사실 None 입니다. 파이썬의 None 은 자바나 C의 Null 같은 것입니다. 그래서 결국 None.someattr 이런식의 코드가 유효하지 않기 때문에 발생하는 에러입니다. 제가 만든 예제를 보고 이해해 보도록 합시다. >>> class dummy: def bark(self): print("dum dum") >>> def get_dummy(n): if n > 10: return dummy() return >>> d = get_dummy(21) >>> d.bark() dum dum >>> d2 = get..
[파이썬초보] 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 = ..