Python Forum
Using a variable to replace an integer? (Except it isn't working!)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a variable to replace an integer? (Except it isn't working!)
#1
So I'm trying to use the yweather module, but replacing the way it goes about getting the woeid with a system of variables so that I can A. use it wherever and not have to input a new woeid, and B. automate the whole thing. I'm super new to python but I feel like this shouldn't be this difficult, here's my code:

#note: the url is actually there in the code, but it was preventing me from posting this
url = 'freegeoip'
try:
     with closing(urlopen(url)) as response:
           location = json.loads(response.read())
           loc_c = location['city']
           loc_s = location['region_name']
except:
           print('step 1 failed')

client = yweather.Client()
wid = client.fetch_woeid('loc_c, loc_s')
print(wid)
print('steps 1 and 2 finished')

print('step 3 started')
loc_weather = client.fetch_weather('wid')
loc_weather["condition"]["text"]
loc_weather["condition"]["temp"]
print('step 3 finished')
The whole thing works just fine, up until "loc_weather...('wid')". Then it just stops, I think? It doesn't give me an error message in the terminal or anything, it just stops firing I think. It works fine when I put in the actual woe id it wants, but that isn't going to work if I'm in a new place / using an automated script. Any help would be appreciated! Sorry if this is a dumb question, I'm super new to python.
Reply


Messages In This Thread
Using a variable to replace an integer? (Except it isn't working!) - by s1monsays - Jul-25-2017, 03:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  working directory if using windows path-variable chitarup 2 888 Nov-28-2023, 11:36 PM
Last Post: chitarup
  Working with Excel and Word, Several Questions Regarding Find and Replace Brandon_Pickert 4 1,801 Feb-11-2023, 03:59 PM
Last Post: Brandon_Pickert
  Factorial Code is not working when the given number is very long integer Raj_Kumar 2 2,446 Mar-31-2020, 06:40 PM
Last Post: deanhystad
  Why replace treats an integer value 999 as 999.0? new_to_python 10 4,643 Feb-16-2020, 01:49 PM
Last Post: new_to_python
  Mixed string,Integer input variable issue maderdash 2 2,863 Nov-06-2018, 09:46 AM
Last Post: snippsat
  replace html string with python variable ! evilcode1 4 6,413 Aug-30-2018, 03:14 PM
Last Post: snippsat
  Search & Replace - Newlines Added After Replace dj99 3 3,533 Jul-22-2018, 01:42 PM
Last Post: buran
  string with integer variable within Andy1845c 9 5,244 Mar-12-2018, 10:28 PM
Last Post: Larz60+
  int(variable) not changing variable to an integer StoopidChicken 2 3,077 Jan-11-2018, 10:30 AM
Last Post: StoopidChicken

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020