[Tutor] Writing data to JSON Help

2017-12-15 Thread Lloyd Walker
Dear All,

I'm currently writing a script to scrape data from my favourite podcasting
websites and compile latter data into JSON format in order to create a
local website of these websites.

I'm currently using string formatting to create the json rather than
creating a dictionary and appending that dictionary to file via the JSON
lib.

Could you help me create a dictionary using JSON?

Code: https://gist.github.com/anonymous/42ff1e418ab315c9637f3ffe08ab0a2b

Kind Regards,

Lloyd Walker
[image: Inline image 1]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing data to JSON Help

2017-12-15 Thread Alan Gauld via Tutor
On 15/12/17 18:46, Lloyd Walker wrote:

> I'm currently using string formatting to create the json rather than
> creating a dictionary and appending that dictionary to file via the JSON
> lib.

That's probably your mistake. The standard library is there to
help you get difficult things right. Trying to reinvent it is
a great way to discover how difficult apparently simple things
really are. it's also a terrible way to accomplish anything
productive.

> Could you help me create a dictionary using JSON?
> 
> Code: https://gist.github.com/anonymous/42ff1e418ab315c9637f3ffe08ab0a2b

One thing I'd strongly suggest is to separate out your functions.
Your findLinks function does a lot more than find links. Just
return the list of links and create another function to store
them (in whatever format you wish).

Then I suggest you write that new function using the json module.
That will greatly improve your chances of success.

-- 
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


Re: [Tutor] Writing data to JSON Help

2017-12-15 Thread Mats Wichmann
On 12/15/2017 04:41 PM, Alan Gauld via Tutor wrote:
> On 15/12/17 18:46, Lloyd Walker wrote:
> 
>> I'm currently using string formatting to create the json rather than
>> creating a dictionary and appending that dictionary to file via the JSON
>> lib.
> 
> That's probably your mistake. The standard library is there to
> help you get difficult things right. Trying to reinvent it is
> a great way to discover how difficult apparently simple things
> really are. it's also a terrible way to accomplish anything
> productive.
> 
>> Could you help me create a dictionary using JSON?
>>
>> Code: https://gist.github.com/anonymous/42ff1e418ab315c9637f3ffe08ab0a2b
> 
> One thing I'd strongly suggest is to separate out your functions.
> Your findLinks function does a lot more than find links. Just
> return the list of links and create another function to store
> them (in whatever format you wish).

"simple is better".

as in... if your code is easy to understand, it's way easier to debug.

also, has_key is no longer favored in the Python world (that is not what
is wrong with your code).

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