【发布时间】:2012-05-01 22:00:41
【问题描述】:
我是脚本新手,只专门研究过 arcpy 模块。我目前正在使用脚本从“http://weather.noaa.gov/pub/data/observations/metar/stations”获取风的详细信息。我需要在 Web 应用程序中集成风向,并且需要帮助修改脚本以仅以度数返回风向,这是我从“http://pypi.python.org/pypi/”下载脚本的链接元/" 我尝试通过添加一个仅返回方向的函数来对 Metar.py 进行更改
def windDirection(self):
"""
Return a textual description of the wind conditions.
Units may be specified as "MPS", "KT", "KMH", or "MPH".
"""
if self.wind_speed == None:
return "missing"
elif self.wind_speed.value() == 0.0:
text = "calm"
else:
wind_speed = self.wind_speed.string(units)
text = "%s"(self.wind_dir.directVal)
return text
还在 Datatypes.py 中添加了一个函数
def directVal( self ):
if not self._compass:
degrees = 22.5 * round(self._degrees/22.5)
if degrees == 360.0:
self._directVal = "N"
else:
for name, d in direction.compass_dirs.iteritems():
if d == degrees:
self._directVal = name
break
return self._directVal
我不确定如何将此值作为报告以外的单独文本返回。请帮忙。
【问题讨论】:
-
进行此更改有帮助吗? text = "%s" % (self.wind_dir.directVal, )
-
这条线有什么用途?
wind_speed = self.wind_speed.string(units) -
不,它没有。我已将风函数复制到新函数 directVal()。我可以跳过上面一行,因为我没有在返回值中指定单位。
-
谢谢大家...我让它工作了...
标签: python