2014-01-19 38 views
1

我正在为自己制作一个相当简单的天气模块,而且我遇到了一个主要问题,我无法从我的模块中获得价值。制作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>> 

如何获得的输出,诸如“云”(这是目前的状况)

回答

2

你是不是调用该函数。您只需使用current变量名称为函数创建别名即可。尝试

current = PyWeather.get(location).status() # Notice the() 
+0

哇,谢谢。我有点笨。这很好,谢谢你。 – addm3plz

0

电流= PyWeather.get(位置).STATUS()

应该可以解决这个问题

+1

...说@SukritKalra 10分钟前。 :) – iCodez

+0

opss ...没有看到 – Adeel