Another Caveat: str doesn't implement .__copy__ or .__deepcopy__ so
I'm being silly....but the main point being "is" is object comparison
not equality.  Ok, email on exponential backoff!! ;-)

On Aug 2, 11:06 am, mda_ <[email protected]> wrote:
> Caveat: Hopefully my chaining of operators there didn't mislead, that
> was unintended.  I think most of what I said still holds, if not all.
>
> -Don
>
> On Aug 2, 9:14 am, mda_ <[email protected]> wrote:
>
>
>
> > SageDevs,
>
> > In the interest of "gotchas", please consider the following:
>
> > The built-in str, and the module string are different, though both
> > return type str according to type().
>
> > Example:
>
> > d...@dv9000-laptop:~$ python2.6
> > Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
> > [GCC 4.4.1] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.>>> 
> > from copy import copy,deepcopy
> > >>> import string
> > >>> a = '12 3 four five six'
> > >>> a is copy(a) is deepcopy(a)
> > True
> > >>> a == copy(a) == deepcopy(a)
> > True
> > >>> b = string.lower(a)
> > >>> a
>
> > '12 3 four five six'
>
> > >>> a is b
> > False
> > >>> a == b
> > True
> > >>> type(a)
> > <type 'str'>
> > >>> type(b)
> > <type 'str'>
> > >>> c = copy(a)
> > >>> c is a
> > True
> > >>> d = deepcopy(a)
> > >>> d is a
> > True
> > >>> hash(a) == hash(b)
> > True
> > >>> id(a) == id(b)
> > False
> > >>> id(a) == id(c) == id(d)
> > True
> > >>> id(a) is id(c) is id(d)
> > False
> > >>> hash(a) == hash(b) == hash(c) == hash(d)
> > True
> > >>> hash(a) is hash(b) is hash(c) is hash(d)
> > False
> > >>> type(a) == type(b) == type(c) == type(d)
> > True
> > >>> type(a) is type(b) is type(c) is type(d)
> > True
>
> > So, I think the take home message is that the keyword "is" is fragile
> > in some cases.  Also, the return value of type() is misleading.
>
> >http://docs.python.org/release/2.6.5/reference/lexical_analysis.html#...
>
> > Cheers,
> > Don

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to