Reputation: 25
I am working on a project and I am creating a file called geolocation_client.py. I keep receiving errors and pycharm keeps telling me to install stash, but I am unable to. Below is an example of an error I received.
print("the stash is at ", stash.__str__())
NameError: name 'stash' is not defined
from geolocation import GeoLocation
def main():
stash = GeoLocation(34.988889, -106.614444)
ABQstudio = GeoLocation(34.989978, -106.614357)
FBIbuilding = GeoLocation(35.131281, -106.61263)
print("the stash is at ", stash.__str__())
print("ABQ stuido is at ", ABQstudio.__str__())
print("FBI building is at ", FBIbuilding.__str__())
print("distance in miles between:")
stash_studio = stash.distance_from(ABQstudio)
stash_fbi = stash.distance_from(FBIbuilding)
print(" stash/studio = ", stash_studio)
print(" stash/fbi = ", stash_fbi)
if __name__ == "__main__":
main()
Upvotes: 1
Views: 45
Reputation: 587
You are accessing a variable that does not exist outside of the function
try:
from geolocation import GeoLocation
def main():
stash = GeoLocation(34.988889, -106.614444)
ABQstudio = GeoLocation(34.989978, -106.614357)
FBIbuilding = GeoLocation(35.131281, -106.61263)
print("the stash is at ", stash.__str__())
print("ABQ stuido is at ", ABQstudio.__str__())
print("FBI building is at ", FBIbuilding.__str__())
print("distance in miles between:")
stash_studio = stash.distance_from(ABQstudio)
stash_fbi = stash.distance_from(FBIbuilding)
print(" stash/studio = ", stash_studio)
print(" stash/fbi = ", stash_fbi)
if __name__ == "__main__":
main()
Upvotes: 1