我正在为自己制作一个相当简单的天气模块,而且我遇到了一个主要问题,我无法从我的模块中获得价值。制作Python 2.7模块:引用值?
首先,让我告诉你我有什么,所以我可以指出我的问题。
PyWeather.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
Main.py:
import PyWeather
location = 'Lexington, SC'
current = PyWeather.get(location).status
print current
我比在Python新手多一点,但我是自学的,所以我不太明白一点点。
我的问题在于输出:
<bound method get.status of <PyWeather.get instance at 0x01925940>>
如何获得的输出,诸如“云”(这是目前的状况)
哇,谢谢。我有点笨。这很好,谢谢你。 – addm3plz