[Tutor] Writing data to JSON Help
Mats Wichmann
mats at wichmann.us
Fri Dec 15 19:19:58 EST 2017
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).
More information about the Tutor
mailing list