Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Python
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Python section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 18th, 2010, 01:51 PM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default new guy cant get variables to work

ok so I trying to get the weather from google and print it to the screen using a wxpython textctrl... so it works to a point i included print statments in the coding so I could see what was being returend... I assigned the values a variable and call the variables to print ... and they do .... then I try to calll the same variable to print the result in the Textctrl window and I keep getting


Google says: It is cloudy and 21C now in New York.


conditions Cloudy
this is the temp 21
this is humidity Humidity: 59%
time 2010-09-18 17:21:51 +0000

Traceback (most recent call last):
File "C:/Python26/Coding with DB/forummm.py", line 66, in <module>
frame = create(None)
File "C:/Python26/Coding with DB/forummm.py", line 6, in create
return Frame1(parent)
File "C:/Python26/Coding with DB/forummm.py", line 38, in __init__
self._init_ctrls(parent)
File "C:/Python26/Coding with DB/forummm.py", line 27, in _init_ctrls
style=0, value= (weather1a))
NameError: global name 'weather1a' is not defined


first I got the pywapi library from (http://code.google.com/p/python-weather-api/)
this is the code
(sorry there is no tags but Im very new and dont know how to do that yet) Thanks for any help


import wx
import pywapi
import string

def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1TEXTCTRL1, wxID_FRAME1TEXTCTRL2,
wxID_FRAME1TEXTCTRL3,
] = [wx.NewId() for _init_ctrls in range(5)]

class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(118, 161), size=wx.Size(401, 492),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(393, 458))

self.WeatherData()
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
pos=wx.Point(0, 0), size=wx.Size(393, 458),
style=wx.TAB_TRAVERSAL)

self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='weather1a',
parent=self.panel1, pos=wx.Point(128, 96), size=wx.Size(100, 21),
style=0, value= (weather1a))

self.textCtrl2 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL2, name='textCtrl2',
parent=self.panel1, pos=wx.Point(128, 136), size=wx.Size(100, 21),
style=0, value='textCtrl2')

self.textCtrl3 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL3, name='textCtrl3',
parent=self.panel1, pos=wx.Point(128, 192), size=wx.Size(100, 21),
style=0, value='textCtrl3')

def __init__(self, parent):
self._init_ctrls(parent)

def WeatherData(self):
google_result = pywapi.get_weather_from_google('10001')
noaa_result = pywapi.get_weather_from_noaa('KJFK')
#weather1a
print "Google says: It is " + string.lower(google_result['current_conditions']['condition']) + " and " + google_result['current_conditions']['temp_c'] + "C now in New York.\n\n"
self.weather1a = str(google_result['current_conditions']['condition'])
print "conditions", self.weather1a

global weather2a
global weather3a
#global weather4a
#global weather5a
self.weather2a = str(google_result['current_conditions']['temp_c'])
print "this is the temp",self.weather2a
self.weather3a = str(google_result['current_conditions']['humidity'])
print "this is humidity", self.weather3a
#self.weather4a = str(google_result['current_conditions']['temp_f'])

self.weather5a = str(google_result['forecast_information']['current_date_time'])
print "time", self.weather5a
#self.weather6a = str( noaa_result[ 'windchill_string'])
#print "windchill",self.weather6a


if __name__ == '__main__':
app = wx.PySimpleApp()
frame = create(None)
frame.Show()

app.MainLoop()
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SMS API does not work online but work fine offline. Tonik Beginning PHP 1 January 4th, 2013 07:30 AM
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
Hi,I am a fresh guy here.I have a stuff problem Alex.Xiong Visual C++ 0 June 5th, 2007 09:08 PM
using variables webgrphx Classic ASP Basics 3 April 11th, 2007 06:46 PM
sub do not work with 2 variables reinoso Classic ASP Basics 8 November 17th, 2003 05:10 PM



All times are GMT -4. The time now is 07:15 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.