0

我正在尝试使用 python 构建一个助手。它一直显示错误“location.condition is not callable pylint(not-callable)”和“location.forecast is not callable pylint(not-callable)”

    elif 'current weather in' in command:   
        reg_ex = re.search('current weather in (.*)', command)
        if reg_ex:
            city = reg_ex.group(1)
            weather = Weather(unit=Unit.CELSIUS)
            location = weather.lookup_by_location(city)
            condition = location.condition()
            TalkToMe('The Current weather in %s is %s.' 
            'The tempeture is %d.1 C degree' %(city, condition.text(), 
               (int(condition.temp))))

    elif 'weather forecast in' in command:
        reg_ex = re.search('weather forecast in (.*)', command)
        if reg_ex:
            city = reg_ex.group(1)
            weather = Weather()
            location = weather.lookup_by_location(city)
            forecasts = location.forecast()
            for i in range(0,3):
                TalkToMe("On %s will it %s."
                'The maximum temperture will be %d.1 C degree.'
                'The lowest temperature will be %d.1 C degrees.' % (forecasts[i].date(), forecasts[i].text(), (int(forecasts[i].high)), (int(forecasts[i].low))))

它应该告诉天气状况或天气预报

4

1 回答 1

0

https://pypi.org/project/weather-api/上的示例显示:

weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location('dublin')
condition = location.condition
print(condition.text)

但是,您正在做lookup.condition(). 括号导致 Python “调用” lookup.condition,即要求它是可调用的。

请注意,pylint 是一个静态代码分析器。它会尝试提前警告您代码中的问题,以便您可以在实际运行程序之前修复它们。静态代码分析器并不总是正确的,但在这种情况下似乎是正确的。删除括号应该可以解决问题。

于 2019-05-03T18:15:30.513 回答