Python acting weird

Discussion in 'Python' started by Westly Ward, Jul 26, 2010.

  1. Westly Ward

    Westly Ward Guest

    x = {"type":"folder", "name":"sonicbot", "data":[{"type":"folder",
    "name":"SonicMail", "data":[{"type":"file", "name":"bbcode.py",
    "compressed":False, "contents":"blahblahfilecontents"}]}]}
    print x
    def setindict(dictionary, keys, value) :
    if len(keys) == 1 :
    if keys[0].isdigit() and int(keys[0]) == len(dictionary) :
    dictionary.append(keys[0])
    else :
    dictionary[keys[0]] = value
    else :
    dictionary[keys[0]] = setindict(dictionary[keys[0]], keys[1:], value)
    return dictionary
    a = x.copy()

    print id(a), id(x)
    y = setindict(a, ["data", 0, "data", 0, "compressed"], True)
    if y == x :
    print True

    else :
    print False
    print x
    print a

    How are x and a are ending up the same? I would think .copy() would
    make it completely seperate.
     
    Westly Ward, Jul 26, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David
    Replies:
    5
    Views:
    392
    Juan T. Llibre
    Apr 21, 2005
  2. Jeff Epler
    Replies:
    0
    Views:
    517
    Jeff Epler
    Aug 20, 2004
  3. Jeff Epler
    Replies:
    0
    Views:
    468
    Jeff Epler
    Aug 23, 2004
  4. Gabriel B.

    scope acting weird

    Gabriel B., May 1, 2005, in forum: Python
    Replies:
    1
    Views:
    406
    Mike Meyer
    May 1, 2005
  5. Merrigan

    ftplib acting weird

    Merrigan, May 4, 2007, in forum: Python
    Replies:
    1
    Views:
    406
    Carlos Hanson
    May 7, 2007
Loading...

Share This Page