| |||||||||||

| |||||||||||

finding a specifically keyed within json structure
Already written modules example from a Well House Consultants training course
More on Already written modules [link]
Source code: jdemo3 Module: Y117
import json import sys verbose = False def parseDict(container,search=None,inset="", found=None): for c in container.keys(): if c == search: try: found.append(container[c]) except: found=[container[c]] current = container[c] insetc = inset + c + ": " if isinstance(current,dict): if verbose: print (insetc+"Dict") found = parseDict(current,search," "+inset,found) elif isinstance(current,list): if verbose: print (insetc+"List") found = parseList(current,search," "+inset,found) else: if verbose: print (insetc+" value",current) return found def parseList(container,search=None,inset="",found=None): for c in range(len(container)): current = container[c] insetc = inset + str(c) + ": " if isinstance(current,dict): if verbose: print (insetc+"Dict") found = parseDict(current,search," "+inset,found) elif isinstance(current,list): if verbose: print (insetc+"List") found = parseList(current,search," "+inset,found) else: if verbose: print (insetc+"value",current) return found # --------------------- fh = open("jflow.json") # sample data file via http://www.wellho.net/services/_.json igot = json.load(fh) if verbose: print(igot) found = parseDict(igot,"where","") if sys.version_info < (3,0): found.sort(lambda x,y:cmp(len(x),len(y))) else: found.sort(key = lambda x:len(x)) print("Here are the remote IP visitors to your images") for k in range(len(found)): sep = ((k+1)%4 and k+1 != len(found)) and " " or "\n" sys.stdout.write("%16s%s"%(found[k],sep)) """ sample output WomanWithCat:q2 grahamellis$ python jdemo3 Here are the remote IP visitors to your images 31.72.93.xx 66.249.69.xx 157.55.39.xx 51.255.66.xx 157.55.39.xx 86.148.45.xx 207.46.13.xx 207.46.13.xx 207.46.13.xx 207.46.13.xx 207.46.13.xx 217.41.17.xx 217.41.17.xx 217.41.17.xx 207.46.13.xx 212.136.9.xx 212.136.9.xx 157.55.39.xx 66.249.75.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 217.38.82.xx 207.46.13.xx 157.55.39.xx 66.249.75.xx 157.55.39.xx 157.55.39.xx 40.77.167.xx 157.55.39.xx 66.249.75.xx 207.46.13.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 207.46.13.xx 66.249.75.xx 157.55.39.xx 132.48.241.xx 106.38.241.xx 106.38.241.xx 68.180.228.xx 182.71.241.xx 31.184.236.xx 106.38.241.xx 192.243.55.xx 192.243.55.xx 194.204.27.xx 106.38.241.xx 68.180.228.xx 192.243.55.xx 106.38.241.xx 197.225.55.xx 31.184.236.xx 95.138.206.xx 106.38.241.xx 82.132.230.xx 95.138.206.xx 178.255.215.xx 103.210.134.xx WomanWithCat:q2 grahamellis$ python3 jdemo3 Here are the remote IP visitors to your images 31.72.93.xx 66.249.69.xx 157.55.39.xx 51.255.66.xx 157.55.39.xx 86.148.45.xx 207.46.13.xx 207.46.13.xx 207.46.13.xx 207.46.13.xx 207.46.13.xx 217.41.17.xx 217.41.17.xx 217.41.17.xx 207.46.13.xx 212.136.9.xx 212.136.9.xx 157.55.39.xx 66.249.75.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 217.38.82.xx 207.46.13.xx 157.55.39.xx 66.249.75.xx 157.55.39.xx 157.55.39.xx 40.77.167.xx 157.55.39.xx 66.249.75.xx 207.46.13.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 157.55.39.xx 207.46.13.xx 66.249.75.xx 157.55.39.xx 132.48.241.xx 106.38.241.xx 106.38.241.xx 68.180.228.xx 182.71.241.xx 31.184.236.xx 106.38.241.xx 192.243.55.xx 192.243.55.xx 194.204.27.xx 106.38.241.xx 68.180.228.xx 192.243.55.xx 106.38.241.xx 197.225.55.xx 31.184.236.xx 95.138.206.xx 106.38.241.xx 82.132.230.xx 95.138.206.xx 178.255.215.xx 103.210.134.xx WomanWithCat:q2 grahamellis$ """ Learn about this subject
This module and example are covered on the following public courses:
* Learning to program in Python * Python Programming Also available on on site courses for larger groups Books covering this topic
Yes. We have over 700 books in our library. Books
covering Python are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "Already written modules" training module. You'll find a description of the topic and some
other closely related examples on the "Already written modules" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Web site author
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
not to do
things - check in your notes.This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||

PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |