Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45522
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <drsalists@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'argument': 0.05; 'explicitly': 0.05; '"""': 0.07; 'class,': 0.07; 'debugging': 0.07; 'method.': 0.07; 'pypy': 0.07; '51,': 0.09; 'subject:instance': 0.09; 'subject:method': 0.09; 'python': 0.11; 'def': 0.12; "%s'": 0.16; '(false,': 0.16; 'add(self,': 0.16; 'complaining': 0.16; 'key):': 0.16; 'node)': 0.16; 'node.': 0.16; 'placeholder': 0.16; 'skip:" 80': 0.16; 'subclass': 0.16; 'subject: \n ': 0.16; 'to:name:python list': 0.16; 'typeerror:': 0.16; 'unbound': 0.16; '<': 0.19; 'print': 0.22; 'error': 0.23; 'adds': 0.24; 'code:': 0.26; 'skip:" 20': 0.27; 'point': 0.28; 'errors': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'getting': 0.31; '3.x': 0.31; 'node': 0.31; 'file': 0.32; 'thanks!': 0.32; '(most': 0.33; 'skip:& 30': 0.33; 'skip:b 30': 0.33; 'subject: (': 0.35; 'subject:with': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'returning': 0.36; 'method': 0.36; 'being': 0.38; 'skip:& 10': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'first': 0.61; 'different': 0.65; 'containing': 0.69; '8bit%:100': 0.72; 'is\xa0': 0.84; 'subject:nothing': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; 'subject:add': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=cVWcdUfij19/XLful3nB54B676BS9AlUXBrhFHtiic8=; b=yQJFlUgxWXIA8pjK8xcyW281iNjtUQqqaimpMZ4CEORrImBYWcNHq4yH8jCKGKTn6t SrTPpP48xCE/oBSfsxdTaHF4E8oolFVQLSoFwN/S991kCv6P5hcuTsjPxY1ynMgVt1G0 M5mLUaEgCMHM6qAMeLcfuKXOhwkC6D9up0hdYh0jXiXs/DNgeWNMdhNnSf+bdUQpWHgL e7V7waFohUKfNT83vL5Z1dQscAAlLEvIpcZR/GWcK94/GlPiONYrvH3DdruauQ+AwbO3 I6zneGYyX41zJ5cuAaz3ts4FNHouIVInU/1tUZruin2IlTtEuBQ0ZWzmB+KSWezElAr5 8UgQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.49.15.103 with SMTP id w7mr33489598qec.46.1368903672354; Sat, 18 May 2013 12:01:12 -0700 (PDT) |
| Date | Sat, 18 May 2013 12:01:12 -0700 |
| Subject | TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead) |
| From | Dan Stromberg <drsalists@gmail.com> |
| To | Python List <python-list@python.org> |
| Content-Type | multipart/alternative; boundary=047d7bd757441f7b0a04dd02b936 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1812.1368903676.3114.python-list@python.org> (permalink) |
| Lines | 111 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1368903676 news.xs4all.nl 15928 [2001:888:2000:d::a6]:40730 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45522 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
I'm getting the error in the subject, from the following code:
def add(self, key):
"""
Adds a node containing I{key} to the subtree
rooted at I{self}, returning the added node.
"""
node = self.find(key)
if not node:
node.key = key
# placeholder
node.left, node.right = self.__class__(parent=node),
self.__class__(parent=node)
return (False, node)
else:
if random.random() < 0.5:
print('node.left is %s' % node.left)
return BinaryTree.add(self=node.left, key=key)
else:
print('node.right is %s' % node.left)
return BinaryTree.add(self=node.right, key=key)
The above add() method is part of a BinaryTree(object) class, whose
subclass is RedBlackTree.
We need to explicitly call BinaryTree.add() with an explict self, to avoid
inappropriately calling RedBlackTree.add().; BinaryTree.add() is being
called with a RedBlackTree instance as self.
The debugging print and traceback look like:
node.left is 0 -1 red
Traceback (most recent call last):
File "app_main.py", line 51, in run_toplevel
File "test-red_black_tree_mod", line 328, in <module>
test()
File "test-red_black_tree_mod", line 316, in test
all_good &= test_duplicates()
File "test-red_black_tree_mod", line 194, in test_duplicates
tree.add(value)
File
"/home/dstromberg/src/home-svn/red-black-tree-mod/trunk/duncan/red_black_bag_mod.py",
line 919, in add
(replaced, node) = super(RedBlackTree, self).add(key=key)
File
"/home/dstromberg/src/home-svn/red-black-tree-mod/trunk/duncan/red_black_bag_mod.py",
line 376, in add
return BinaryTree.add(self=node.left, key=key)
TypeError: unbound method add() must be called with BinaryTree instance as
first argument (got nothing instead)
Why is it complaining that .add() is getting nothing, when node.left isn't
None? As you can see above the traceback, it's got a value represented by
"node.left is 0 -1 red".
python 2.x, python 3.x and pypy all give this same error, though jython
errors out at a different point in the same method.
Thanks!
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead) Dan Stromberg <drsalists@gmail.com> - 2013-05-18 12:01 -0700
csiph-web