Why this difference?

Terry Reedy tjreedy at udel.edu
Thu Feb 24 12:09:33 EST 2011


On 2/24/2011 7:19 AM, n00m wrote:
> file my.txt:
> ===============================
> 0 beb
> 1 qwe
> 2 asd
> 3 hyu
> 4 zed
> 5 asd
> 6 oth
> =============================
>
>
> py script:
> ===============================
> import sys
>
> sys.stdin = open('88.txt', 'r')
> t = sys.stdin.readlines()
> t = map(lambda rec: rec.split(), t)
> print t
> print t[2][1] == t[5][1]
> print t[2][1] is t[5][1]
> print '=================================='
> a = 'asd'
> b = 'asd'
> print a is b
>
>
> output:
> =======================================
> [['0', 'beb'], ['1', 'qwe'], ['2', 'asd'], ['3', 'hyu'], ['4', 'zed'],
> ['5', 'as
> d'], ['6', 'oth']]
> True
> False
> ==================================
> True

An implementation may *optionally* cache immutable values -- and change 
its internal rules as it pleases. When creating string objects from 
literals that look like identifiers, CPython does this, but apparently 
not when splitting an existing string.

-- 
Terry Jan Reedy




More information about the Python-list mailing list