[BangPypers] Favorite tips/techniques

BibhasD me at bibhas.in
Tue Sep 10 17:18:28 CEST 2013


I'm just curious. I faced a similar issue before while answering a
question about Django on StackOverflow. Django turns context variable
dictionaries into objects with attributes in template. So in one
question in SO someone posted this question. Had to answer that Django
doesn't really support distinguishing such keys. So when I saw the same
thing discussed, thought of throwing it out here. :)

On Tuesday 10 September 2013 08:42 PM, Dhananjay Nene wrote:
> Ignoring classes for the moment, how likely do you think you would
> have a dict like that :)
>
> On a separate note if you are using primitive types, I cannot think of
> any scenarios, where not coercing keys to be of the same type would be
> considered inappropriate (except in case of reverse dicts)
>
> On Tue, Sep 10, 2013 at 3:52 PM, Me at Bibhas <me at bibhas.in> wrote:
>> What would happen for a dictionary like this?
>>
>>>>> d = {'1': 'foo', 1: 'bar'}
>>>>> d
>> {'1': 'foo', 1: 'bar'}
>>
>>
>> On Tuesday 10 September 2013 10:00 AM, Noufal Ibrahim wrote:
>>> Shabda Raaj <shabda at agiliq.com> writes:
>>>
>>>> http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/
>>>>
>>>> With api responses after you have parsed the json, you start doing things
>>>> like:
>>>>
>>>> api_response["attribute"]
>>>>
>>>> I would much prefer to do
>>>>
>>>> api_response.attribute
>>> I generally like to use attributes instead of keys. One additional
>>> advantage is that I can, if necessary, later convert the attribute into
>>> a property that does more than just return a value.
>>>
>>> [...]
>>>
>>>
>> _______________________________________________
>> BangPypers mailing list
>> BangPypers at python.org
>> https://mail.python.org/mailman/listinfo/bangpypers
>
>



More information about the BangPypers mailing list