7

It is a little weird to me that the refs number in the interactive environment increases 2 after a new object is defined. I created only one object, isn't it?

>>> v
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'v' is not defined
[41830 refs]
>>> v = "v"
[41832 refs]
6
  • 6
    How are you printing the refs? Commented Feb 14, 2011 at 12:10
  • -1: At least until you explain why you think the reference number is increasing by 2! Commented Feb 14, 2011 at 12:35
  • 2
    @ScottGriffiths: Isn't that obvious? 41832 - 41830 is 2. Commented Feb 14, 2011 at 13:00
  • @ScottGriffiths: That's a good question (and already asked by Tim), but a different question from the one in your last comment. Commented Feb 14, 2011 at 14:01
  • 5
    That's a debug build of Python. Call configure with the --with-pydebug option when building Python, or install the python-dbg package on Debian or Ubuntu. Commented Feb 14, 2011 at 14:52

1 Answer 1

8

Your assignment worked by creating an entry in the globals() dictionary that has v as a key and "v" as a value. That's two references (one for the key and one for the value) although in this case they probably both refer to the same string "v".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.