Re: Strange object identity problem

Discussion in 'Python' started by F.R., Nov 12, 2012.

  1. F.R.

    F.R. Guest

    On 11/12/2012 02:27 PM, Robert Franke wrote:
    > Hi Frederic,
    >
    > [...]
    >
    >>>>> bas = {}
    >>>>> for year in range (2010, 2013):

    >> ba = st.runs ('BA', '%d-01-01' % year, '%d-12-31' % year)
    >> ba.run ()
    >> print year, id (ba)
    >> bas [year] = ba
    >>
    >> 2010 150289932
    >> 2011 150835852
    >> 2012 149727788
    >>
    >>>>> for y in sorted (bas.keys ()):

    >> b = bas [year]

    > Shouldn't that be b = bas[y]?

    Yes, it should, indeed! What's more, I should have closed and restarted
    IDLE. There must have
    been a name clash somewhere in the name space. The problem no longer
    exists. Sorry
    about that. And thanks to all who paused to reflect on this non-problem.
    - Frederic.

    >
    >
    >> print y, id (b)
    >>
    >> 2010 149727788
    >> 2011 149727788
    >> 2012 149727788
    >>

    > [...]
    >
    > Cheers,
    >
    > Robert
    >
     
    F.R., Nov 12, 2012
    #1
    1. Advertising

  2. F.R.

    duncan smith Guest

    On 12/11/12 13:40, F.R. wrote:
    > On 11/12/2012 02:27 PM, Robert Franke wrote:
    >> Hi Frederic,
    >>
    >> [...]
    >>
    >>>>>> bas = {}
    >>>>>> for year in range (2010, 2013):
    >>> ba = st.runs ('BA', '%d-01-01' % year, '%d-12-31' % year)
    >>> ba.run ()
    >>> print year, id (ba)
    >>> bas [year] = ba
    >>>
    >>> 2010 150289932
    >>> 2011 150835852
    >>> 2012 149727788
    >>>
    >>>>>> for y in sorted (bas.keys ()):
    >>> b = bas [year]

    >> Shouldn't that be b = bas[y]?

    > Yes, it should, indeed! What's more, I should have closed and restarted
    > IDLE. There must have
    > been a name clash somewhere in the name space. The problem no longer
    > exists. Sorry
    > about that. And thanks to all who paused to reflect on this non-problem.
    > - Frederic.
    >
    >>
    >>
    >>> print y, id (b)
    >>>
    >>> 2010 149727788
    >>> 2011 149727788
    >>> 2012 149727788
    >>>

    >> [...]
    >>
    >> Cheers,
    >>
    >> Robert
    >>

    >


    The problem was that year was bound to the integer 2013 from the first
    loop. When you subsequently looped over the keys you printed each key
    followed by id(bas[2013]). Restarting IDLE only helped because you
    presumably didn't repeat the error.

    Duncan
     
    duncan smith, Nov 12, 2012
    #2
    1. Advertising

  3. F.R.

    F.R. Guest

    On 11/12/2012 06:02 PM, duncan smith wrote:
    > On 12/11/12 13:40, F.R. wrote:
    >> On 11/12/2012 02:27 PM, Robert Franke wrote:
    >>> Hi Frederic,
    >>>
    >>> [...]
    >>>
    >>>>>>> bas = {}
    >>>>>>> for year in range (2010, 2013):
    >>>> ba = st.runs ('BA', '%d-01-01' % year, '%d-12-31' % year)
    >>>> ba.run ()
    >>>> print year, id (ba)
    >>>> bas [year] = ba
    >>>>
    >>>> 2010 150289932
    >>>> 2011 150835852
    >>>> 2012 149727788
    >>>>
    >>>>>>> for y in sorted (bas.keys ()):
    >>>> b = bas [year]
    >>> Shouldn't that be b = bas[y]?

    >> Yes, it should, indeed! What's more, I should have closed and restarted
    >> IDLE. There must have
    >> been a name clash somewhere in the name space. The problem no longer
    >> exists. Sorry
    >> about that. And thanks to all who paused to reflect on this non-problem.
    >> - Frederic.
    >>
    >>>
    >>>
    >>>> print y, id (b)
    >>>>
    >>>> 2010 149727788
    >>>> 2011 149727788
    >>>> 2012 149727788
    >>>>
    >>> [...]
    >>>
    >>> Cheers,
    >>>
    >>> Robert
    >>>

    >>

    >
    > The problem was that year was bound to the integer 2013 from the first
    > loop. When you subsequently looped over the keys you printed each key
    > followed by id(bas[2013]). Restarting IDLE only helped because you
    > presumably didn't repeat the error.
    >
    > Duncan
    >

    That's it! Isn't it strange how on occasion one doesn't see the most
    obvious and simple mistake, focusing beyond the realm of foolishness.
    Thanks all . . .

    Frederic
     
    F.R., Nov 13, 2012
    #3
    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. Giovanni Bassi
    Replies:
    0
    Views:
    679
    Giovanni Bassi
    Oct 20, 2003
  2. nalbayo
    Replies:
    2
    Views:
    5,601
    Bruce Barker
    Nov 11, 2005
  3. JimLad
    Replies:
    0
    Views:
    470
    JimLad
    Jan 16, 2009
  4. F.R.
    Replies:
    2
    Views:
    232
    Dennis Lee Bieber
    Nov 12, 2012
  5. Robert Franke

    Re: Strange object identity problem

    Robert Franke, Nov 12, 2012, in forum: Python
    Replies:
    0
    Views:
    181
    Robert Franke
    Nov 12, 2012
Loading...

Share This Page