On Mon, 10 Mar 2008 14:29:48 +, Andrew Koenig wrote:
> So the question you need to answer is whether you want to determine
> whether an object is exactly of type dict, or whether it you are willing
> to accept types derived from dict also.
Or other mappings that don't inherit from dict but be
>> if type(a) is dict:
>> print "a is a dictionnary!"
> class MyDict(dict):
> pass
> a = MyDict()
> type(a) is dict
> => False
isinstance(a, dict)
=> True
So the question you need to answer is whether you want to determine whether
an object is exactly of type dict, or whether it you a
Guillermo a écrit :
> Mamma mia! My head just exploded. I've seen the light.
>
> So you only need to ·want· to have a protocol? That's amazing... Far
> beyond the claim that Python is easy. You define protocols in writing
> basically! Even my grandma could have her own Python protocol.
>
> Okay,
On 9 mar, 11:23, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sun, 09 Mar 2008 06:58:15 -0700, Guillermo wrote:
> > Okay, so I think I know where's the catch now -- you must rely on the
> > fact that the protocol is implemented, there's no way to enforce it if
> > you're expec
On Mar 9, 9:23 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sun, 09 Mar 2008 06:58:15 -0700, Guillermo wrote:
> > Okay, so I think I know where's the catch now -- you must rely on the
> > fact that the protocol is implemented, there's no way to enforce it if
> > you're exp
On Sun, 09 Mar 2008 06:58:15 -0700, Guillermo wrote:
> Okay, so I think I know where's the catch now -- you must rely on the
> fact that the protocol is implemented, there's no way to enforce it if
> you're expecting a parrot-like object. You'd try to call the speak()
> method and deal with the er
Mamma mia! My head just exploded. I've seen the light.
So you only need to ·want· to have a protocol? That's amazing... Far
beyond the claim that Python is easy. You define protocols in writing
basically! Even my grandma could have her own Python protocol.
Okay, so I think I know where's the cat
On Sun, 09 Mar 2008 05:20:41 -0700, Guillermo wrote:
>>A protocol is just an interface that an object agrees to implement. In
>>your case, you would state that every object stored in your special dict
>>must implement the to_tagged_value method with certain agreeable
>>semantics.
>
> Hm... I've s
>A protocol is just an interface that an object agrees to implement. In
>your case, you would state that every object stored in your special
>dict must implement the to_tagged_value method with certain agreeable
>semantics.
Hm... I've searched about the implementation of protocols and now (I
beli
On Thu, Mar 6, 2008 at 12:17 PM, Guillermo
<[EMAIL PROTECTED]> wrote:
> > You can also get the dynamic polymorphism without invoking inheritance
> > by specifying a protocol that the values in your dict must implement,
> > instead. Protocols are plentiful in Python, perhaps more popular than
> >
> You can also get the dynamic polymorphism without invoking inheritance
> by specifying a protocol that the values in your dict must implement,
> instead. Protocols are plentiful in Python, perhaps more popular than
> type hierarchies.
I'm used to languages with stricter rules than Python. I've r
On Thu, Mar 6, 2008 at 8:06 AM, Guillermo
<[EMAIL PROTECTED]> wrote:
> I want to iterate recursively a dictionary whose elements might be
> strings or nested tuples or dictionaries and then convert values to a
> tagged format according to some rules.
>
> d = {'a':"i'm a", 'b':(1,2,3),'c':{'a':"
Jeffrey Seifried a écrit :
(snip)
> if type(a)==type({}):
> print 'a is a dictionary'
This instanciates a dict, call type() on it, and discard the dict -
which is useless since the dict type is a builtin. Also, when you want
to test identity, use an identity test.
if type(a) is dict:
pr
Guillermo a écrit :
> Wow, I think I'm gonna like this forum. Thank you all for the prompt
> answers!
Welcome onboard !-)
>> What makes you say you "need" to know this ? Except for a couple corner
>> cases, you usually don't need to care about this. If you told us more
>> about the actual problem
On Thu, Mar 6, 2008 at 2:06 PM, Guillermo
<[EMAIL PROTECTED]> wrote:
> >What makes you say you "need" to know this ? Except for a couple corner
> >cases, you usually don't need to care about this. If you told us more
> >about the actual problem (instead of asking about what you think is the
> >
Guillermo wrote:
> I'm just designing the algorithm, but I think Python dictionaries
> can hold any kind of sequence?
(Watch out, dicts are no sequence types.)
I recommend relying duck typing as long as it's feasible. I. e. if
it can be subscripted like a dict, it is a dict. If this makes
proble
On Mar 6, 7:10 am, Guillermo <[EMAIL PROTECTED]> wrote:
> Hello,
>
> This is my first post here. I'm getting my feet wet with Python and I
> need to know how can I check whether a variable is of type dictionary.
>
> Something like this:
>
> if isdict(a) then print "a is a dictionary"
>
> Regards,
>
Wow, I think I'm gonna like this forum. Thank you all for the prompt
answers!
>What makes you say you "need" to know this ? Except for a couple corner
>cases, you usually don't need to care about this. If you told us more
>about the actual problem (instead of asking about what you think is the
>s
Sam a écrit :
> Hello
>
> if type(a) is dict:
> print "a is a dictionnary!"
class MyDict(dict):
pass
a = MyDict()
type(a) is dict
=> False
--
http://mail.python.org/mailman/listinfo/python-list
Guillermo a écrit :
> Hello,
>
> This is my first post here. I'm getting my feet wet with Python and I
> need to know how can I check whether a variable is of type dictionary.
What makes you say you "need" to know this ? Except for a couple corner
cases, you usually don't need to care about this
En Thu, 06 Mar 2008 10:10:47 -0200, Guillermo
<[EMAIL PROTECTED]> escribi�:
> This is my first post here. I'm getting my feet wet with Python and I
> need to know how can I check whether a variable is of type dictionary.
>
> Something like this:
>
> if isdict(a) then print "a is a dictionary"
i
Hello
if type(a) is dict:
print "a is a dictionnary!"
++
Sam
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
This is my first post here. I'm getting my feet wet with Python and I
need to know how can I check whether a variable is of type dictionary.
Something like this:
if isdict(a) then print "a is a dictionary"
Regards,
Guillermo
--
http://mail.python.org/mailman/listinfo/python-list
23 matches
Mail list logo