2016-03-22 17 views
-1

このスクリプトは.pyでエラーを投げています。Pythonスクリプトが正しく生成されない

import sys 

import wx     # This module uses the new wx namespace 
import wx.html 
import wx.lib.wxpTag 

import urllib2 
import json 
f = urllib2.urlopen('http://api.wunderground.com/api/b5586703ce3fb523/geolookup/conditions/q/04002.json') 
json_string = f.read() 
parsed_json = json.loads(json_string) 
location = parsed_json['location']['city'] 
temp_f = parsed_json['current_observation']['temp_f'] 
temp_feels = parsed_json['current_observation']['feelslike_f'] 
winds = parsed_json['current_observation']['wind_string'] 
humidity = parsed_json['current_observation']['relative_humidity'] 
windchill = parsed_json['current_observation']['windchill_f'] 
visibility = parsed_json['current_observation']['visibility_mi'] 
precipitation = parsed_json['current_observation']['precip_today_in'] 
conditions = parsed_json['current_observation']['weather'] 
print "Current temperature in %s is: %s" % (location, temp_f) 
print "Feels Like: %sF" % (temp_feels) 
print "Winds coming %s " % (winds) 
print "Humidity: %s " % (humidity) 
print "Windchill: %sF " % (windchill) 
print "Visibility: %s Miles " % (visibility) 
print "Precipitation Today: %s Inches " % (precipitation) 
print "Conditions: %s " % (conditions) 
f.close() 



#--------------------------------------------------------------------------- 

class MyAboutBox(wx.Dialog): 
    text = ''' 
<html> 
<body bgcolor="#AC76DE"> 
<center><table bgcolor="#458154" width="100%%" cellspacing="0" 
cellpadding="0" border="1"> 
<tr> 
    <td align="center"> 
    <h1>wxPython %s</h1> 
    (%s)<br> 
    Running on Python %s<br> 
    print "Conditions: %s " % (conditions) 
    </td> 
</tr> 
</table> 



<p><wxp module="wx" class="Button"> 
    <param name="label" value="Okay"> 
    <param name="id" value="ID_OK"> 
</wxp></p> 
</center> 
</body> 
</html> 
''' 
    def __init__(self, parent): 
     wx.Dialog.__init__(self, parent, -1, 'About the wxPython demo',) 
     html = wx.html.HtmlWindow(self, -1, size=(420, -1)) 
     if "gtk2" in wx.PlatformInfo or "gtk3" in wx.PlatformInfo: 
      html.SetStandardFonts() 
     py_version = sys.version.split()[0] 
     txt = self.text % (wx.VERSION_STRING, 
          ", ".join(wx.PlatformInfo[1:]), 
          py_version 
          ) 
     html.SetPage(txt) 
     btn = html.FindWindowById(wx.ID_OK) 
     ir = html.GetInternalRepresentation() 
     html.SetSize((ir.GetWidth()+25, ir.GetHeight()+25)) 
     self.SetClientSize(html.GetSize()) 
     self.CentreOnParent(wx.BOTH) 

#--------------------------------------------------------------------------- 



if __name__ == '__main__': 
    app = wx.App() 
    dlg = MyAboutBox(None) 
    dlg.ShowModal() 
    dlg.Destroy() 
    app.MainLoop() 

は、私は何をしようとしていますと、ダイアログボックスの天気情報を持っていますが、何らかの理由でそののpythonに非常に新しいエラー

Traceback (most recent call last): 
    File "C:/Users/david/Desktop/Test1.py", line 85, in <module> 
    dlg = MyAboutBox(None) 
    File "C:/Users/david/Desktop/Test1.py", line 70, in __init__ 
    py_version 
TypeError: not enough arguments for format string 

イムを投げるので、私は把握することができないようですエラーの原因となっている問題です。あなたは3つの変数でself.textをフォーマットしようとしているが、TXTを設定中 self.textが実際に4

txt = self.text % (wx.VERSION_STRING, 
        ", ".join(wx.PlatformInfo[1:]), 
        py_version 
       ) 
+0

'txt = self.text%...'行には3つの引数がありますが、 'self.text'文字列に3つ以上のパーセント記号があるように見えます。カウントが一致するようにしてください。 – Kevin

答えて

0

を必要と の次の行に

0

は、self.textを経由して、次の2つの引数が不足しています。具体的には、あなたがそうConditions: %s " % (conditions)

の引数を指定する必要があり、あなたは

条件とcondition_valueが前にどこかに設定されている
txt = self.text % (wx.VERSION_STRING, 
        ", ".join(wx.PlatformInfo[1:]), 
        py_version, 
        condition, 
        condition_value 
        ) 

ようなものが必要。

関連する問題