我正在为自己制作一个相当简单的天气模块,我遇到了一个重大问题,我无法从我的模块中得到一个值。你知道吗
首先,让我向你展示一下我所拥有的,这样我就可以指出我的问题。你知道吗
你知道吗天气预报.py地址:
import urllib2
import json
import time
class get:
def __init__(self, location):
self.location = location
def status(self):
input = self.location
fixedinput = input.replace(" ","%20")
response = urllib2.urlopen('http://api.openweathermap.org/data/2.5/weather?q=' + fixedinput)
data = json.load(response)
weather = data['weather'][0]['main']
return weather
你知道吗主.py地址:
import PyWeather
location = 'Lexington, SC'
current = PyWeather.get(location).status
print current
我不只是Python的初学者,但是我自学了,所以我不太懂。你知道吗
我的问题在于输出:
<bound method get.status of <PyWeather.get instance at 0x01925940>>
如何获得“Clouds”之类的输出(这是当前条件)
电流=PyWeather.快(位置).status()
应该解决这个问题
您没有调用函数。您只是使用
current
变量名为函数创建一个别名。试试看相关问题 更多 >
编程相关推荐