Hello,
Thank you for your response. I went back and updated encoding to utf-8 and 
ASCII but I still experienced issues with the output.
The part that is interesting is that the output for each of the following 
fields is the (should be) the same    1.Search by City
    2.Search by Region (State Abbreviation)
    3.Search by Zip

Search by zip comes out just fine but only the partial output is shared for the 
first two options. I don't understand why that would be? I would think if its 
the same output for all three options that I would either work for all three or 
not work for any. Also, why the partial results. 

Any suggestions on how to normalize this?

 Thank you. 


     On Wednesday, October 21, 2015 5:53 AM, Alan Gauld 
<alan.ga...@btinternet.com> wrote:
   
 

 On 21/10/15 01:18, Nym City via Tutor wrote:

> def zip_search(query):
>      api_key = locu_api
>      url = 'https://api.locu.com/v1_0/venue/search/?api_key=' + api_key
>      zip = query.replace(' ', '%20')
>      final_url = url + '&zip=' + zip + "&category=restaurant"
>      jason_obj = urllib2.urlopen(final_url)
>      data = json.load(jason_obj)
>      for item in data['objects']:
>          print item['name'], item['phone'], item['street_address'], 
>item['categories'], item['website_url']
>
> ans=True
> while ans:
>      print ("""
>      1.Search by City
>      2.Search by Region (State Abbreviation)
>      3.Search by Zip
>      4.Exit/Quit
>      """)
>      ans=raw_input("What would you like to do? ")
>      if ans=="1":
>        locality = raw_input("\nEnter City ")
>        print locu_search(locality)
>        break
>      elif ans=="2":
>          region = raw_input("\n Search by State ")
>          print region_search(region)
>          break
>      elif ans=="3":
>          zip = raw_input("\n Search by Zip ")
>          print zip_search(zip)
>          break
>      elif ans=="4":
>        print("\n Goodbye")
>        break

Because you now process the results in the if clauses you no
longer need the breaks. In fact if you want the menu to be
repeated you need to take them all out except for the last one.


> -----
> I am not sure if above changes exactly reflect your suggestions but I tested 
> the logic and it seems to work.
>
> The only issue is that on the first two queries (locu_search(locality) and
> region_search(region)) I receive the following traceback error:
> Traceback (most recent call last):
>    File 
>"C:/Users/dell/Documents/Python/MyProject/API_Projects/locu/locuAPI.py", line 
>47, in <module>
>      print locu_search(locality)
>    File 
>"C:/Users/dell/Documents/Python/MyProject/API_Projects/locu/locuAPI.py", line 
>14, in locu_search
>      print item['name'], item['phone'], item['street_address']
>    File "C:\Python27\lib\encodings\cp1252.py", line 12, in encode
>      return codecs.charmap_encode(input,errors,encoding_table)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\u200e' in 
> position 29: character maps to <undefined>

Looks like you are using cpl252 and your data is coming back as 
something else (UTF-8 maybe?) so you probably need to specify
the encoding.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


 
  
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to