1

I am using pywapi to get weather conditions for different locations. The command I am using is:

alaska = pywapi.get_weather_from_noaa('PABI')

where 'PABI' is the station id for Alaska. This works fine if I enter it directly in the Python console or IDLE and saves the weather condition as dict item in the 'alaska' variable, but it gives out an error when I store in a .py file and try to execute it. It gives the following error:

Traceback (most recent call last):
  File "<pyshell#26>", line 1, in <module>
    from urllib import request
ImportError: cannot import name request

Not sure what is happening over here. How come a method works fine in IDLE and doesn't when called from the .py file? Any help would be appreciated.

khan
  • 7,005
  • 15
  • 48
  • 70

2 Answers2

1

The tutorial/example/whatever you are working from is based on Python3. Upgrade and it should work just fine.

Alternatively you can use an older tutorial

Sheena
  • 15,590
  • 14
  • 75
  • 113
  • but the question is: how come this method returns all the results when executed in the IDLE and on the other hand returns nothing when f5-ed from the .py file? or is this has to do with the python version? – khan Nov 11 '12 at 08:21
1

Okay, so I figured it out. I replaced urllib with the urllib2 module and everything now works fine. Thanks @Sheena and others for stopping by. :-)

khan
  • 7,005
  • 15
  • 48
  • 70