Why its dont work?

Ari Abdrakhmanov
Ari Abdrakhmanov used Ask the Experts™
on
Hello! I am a python beginner. I write a code, with pyowm module (Pyowm on github: https://github.com/csparpa/pyowm), but its for some reason wrong. I has download the pyowm module and I using the terminal for module installation on python 3. My os is Mac OS X Yosemite and the my python version is 3.6.3. I even use Sublime Text 3 as a code editor. What I do wrong? Please help me!
My code:
   
    import pyowm
   
    city = input('Write a city for weather analysis:')
   
    owm = pyowm.OWM('5f28df836a35fc458e6270eb8f01ec86')
    observation = own.weather_at_place(city)
    w = observation.get_weather()
    temperature = w.get_temperature('celsius')['temp']
   
    print("The temperature in" + city + "is: " + str(temperature) + "on celsius")

But python say:

Traceback (most recent call last):
  File "untitled.py", line 3, in <module>
    city = input('Write a city for weather analysis:')
  File "<string>", line 1, in <module>
NameError: name 'London' is not defined
SBSC02PBB8G9402:pythonpractice dchim$ python untitled.py
Write a city for weather analysis: London
Traceback (most recent call last):
  File "untitled.py", line 3, in <module>
    city = input(str('Write a city for weather analysis:'))
  File "<string>", line 1, in <module>
NameError: name 'London' is not defined.


Thanks!!!
untitled.py
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fermi ParadoxPhysicist

Commented:
Are you sure you are using python 3? Try inserting:

import sys
print(sys.version)

Open in new window


at the top of the module. What does it print?
I tried and I can confirm what Fermi Paradox suggested. You have launched the script using Python 2. If you want to use Python 2, you have to change the input to the equivalent raw_input. The input in Python 2 reads the string from the input and calls eval to interpret the string. You did type London, and it tries to use the object of that name -- this is the reason why the error is displayed.

So, you want to use Python 3. Fix also your line with observation = ovn... to owm. If you need to use Python 2, try the following:
#!python2
from __future__ import print_function
import pyowm

city = raw_input('Write a city for weather analysis: ')

owm = pyowm.OWM('5f28df836a35fc458e6270eb8f01ec86')
observation = owm.weather_at_place(city)
w = observation.get_weather()
temperature = w.get_temperature('celsius')['temp']

print('The temperature in', city, 'is:', temperature, 'on celsius')

Open in new window

In the later case, you need pip install pyown also for Python 2.
Suhas .Senior QA Manager

Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: pepr (https:#a42356067)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

suhasbharadwaj
Experts-Exchange Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial