Morning buds

Sep 19, 2008
373,540
24,638
I can't take it any more boys Python is being so impolite and givin gall these compilation errors it's so difficult. You tab something to format it and it complains about bad formatting. All I did was press tab. What's wrong?

I can't wait until this code finally worsk and I'll never have to program another line of this dumb language in my life

Pestilence
 
Sep 19, 2008
373,540
24,638
The funniest thing about these python rants is how I spend 4 or 5 days stuck on one line of code :laugh:

IF i had a job programming I would not be very competent !
 
Sep 19, 2008
373,540
24,638
morning to my good friend @Max Powers aka Vic Rattlehead. Surprised the mods let you back in on HF. Reddit not going so well for you? LOL. Welcome back BUDDY.
 
Sep 19, 2008
373,540
24,638
"I got banned from HFBoards so I'm going to post on Reddit which has no profanity filter and somehow I'm going to return to HFBoards even though Reddit again has no profanity filter and is generally less restrictive in content" :laugh:

It's like you are literally going to a more restrictive place. Why come back? :laugh:
 
Sep 19, 2008
373,540
24,638
You can now use this object_hook function when invoking the JSON parser.
with open('sample.json', 'r') as fp:
obj = json.load(fp, object_hook = obj_creator)
print obj
# prints
{"firstName" = "Alice","lastName" = "Hall", "age" = 35}
 
Sep 19, 2008
373,540
24,638
Examples of JSON Usage
JSON is extremely popular nowadays. Many websites and SaaS (Software As A Service) applications offer JSON output which can be consumed directly by applications. Some of the publicly available ones include:
StackOverflow/StackExchange. Here is a URL which returns a list of questions in JSON format.
GitHub offers a JSON api at GitHub API v3.
And here is the Flickr API: Flickr - Yahoo Developer Network.
 
Sep 19, 2008
373,540
24,638
# Here is a method to find and change a value in the database.
for item in spaces:
if item.get('use') == "examination" :
item['price'] = 175

for item in datastore['office']['medical']: # This loop shows the change is not only in books, but is also in database
if item.get('use') == "examination" :
print 'The {} rooms now cost {}'.format(item.get("use"), item.get("price"))
 
Sep 19, 2008
373,540
24,638
The json.dumps function takes a Python data structure and returns it as a JSON string.
json_encoded = json.dumps(data)
# print to screen
print json_encoded
OUTPUT:
[{"noun": "hello", "Hola": "Hello", "Hoi": "Hello"}]
 

Ad

Upcoming events

Ad

Ad