Calling on a class

267 views Asked by At

I'm using geopy and have a question on why an error is coming up.

This code sample is from the one provided at github. It works as mentioned

from geopy.geocoders import Nominatim

geolocator = Nominatim()

location = geo.geocode("NY")

print((location.latitude, location.longitude))

How come the code below provides an error? What's the reason behind it?

from geopy.geocoders import Nominatim as geo

location = geo.geocode("NY")

print((location.latitude, location.longitude))

The error provided by the second code is:

Traceback (most recent call last):
  File "C:/Users/Leb/Desktop/Python/so2.py", line 5, in <module>
    location = geo.geocode("NY")
TypeError: geocode() missing 1 required positional argument: 'query'
1

There are 1 answers

3
ThePavolC On

You need to instantiate class (create object)

from geopy.geocoders import Nominatim as geo

location = geo().geocode("NY")

print((location.latitude, location.longitude))