Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'completeness': 0.07; 'parser': 0.07; 'setup.': 0.07; '__init__': 0.09; 'counting': 0.09; 'moreover,': 0.09; 'received:155': 0.09; 'stating': 0.09; 'python': 0.11; 'def': 0.12; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'empty,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'overriding': 0.16; 'received:155.180': 0.16; 'received:159': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'recipe': 0.16; 'securities,': 0.16; 'undefined.': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.18; 'options.': 0.19; 'import': 0.22; '(in': 0.22; 'to:name:python- list@python.org': 0.22; 'instance,': 0.24; 'fine': 0.24; 'define': 0.26; 'mention': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'idea': 0.28; 'specifically': 0.29; 'code': 0.31; 'class': 0.32; 'received:169.254': 0.32; 'comment': 0.34; 'skip:_ 10': 0.34; "i'd": 0.34; 'could': 0.34; 'but': 0.35; 'there': 0.35; 'acceptable': 0.36; 'accuracy': 0.36; 'method': 0.36; 'shows': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'received:169': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; '2nd': 0.60; 'information,': 0.61; 'purchase': 0.65; 'subject': 0.69; 'legal': 0.71; 'sale': 0.75; 'behavior': 0.77; '12.2': 0.84; 'received:169.254.8': 0.84; 'edition,': 0.91 X-DKIM: OpenDKIM Filter v2.1.3 sz2.jpmchase.com r7UHZk11013953 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1377884146; bh=1w6MxgoyS+V5g7a+27Q4KCNQjzADyiTCPbv3c6jgDhg=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:content-transfer-encoding:MIME-Version; b=TaeYywnhYTW5RqMsrt8bL3erP72fhLuZ5LsiDrUDieg9x1OXTmrvu7ySRjqBZK+Kx 8L2NgrS4wdky7HA3/E81+p2wBKSOr90IXVjxtcRht05TLmeu4SngajPsSxD8q/TXD/ r094KFe25tQofGBxk4SlYWgaLmnOLxLvYG+HYG4A= X-AuditID: a97c8566-b7f628e000000303-c9-5220d7f002cb From: "Prasad, Ramit" To: Neil Cerutti , "python-list@python.org" Subject: RE: sax.handler.Contenthandler.__init__ Thread-Topic: sax.handler.Contenthandler.__init__ Thread-Index: AQHOpaXfIgizdCKyhUqAjbOET62lcJmuAV2g Date: Fri, 30 Aug 2013 17:35:42 +0000 References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Type: text/plain; charset="us-ascii" content-transfer-encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFKsWRmVeSWpSXmKPExsUye4uJrO6H6wpBBrsuaFi8nfqH3eJI6zVW ByaPn6e/MHu8mP+GLYApqoHRJjEvL78ksSRVISW1ONlWySWzODknMTM3tUhBV8GrIDe/KD0x Ty85P1dJITPFVslESaEgJzE5NTc1r8RWKbGgIDUvRcmOSwED2ACVZeYppOYl56dk5qXbKnkG ++taWJha6hoq2YVkZBYrpOYmZuYoJGxkz5ja1cde8JKrYvXRC+wNjOs4uhg5OSQETCQWfVjN BmGLSVy4tx7I5uIQEjjCKNH2fS4zSEJI4BCjxJEnuRCJTYwS+34tYAJJsAkYShw/+4QdxBYR iJS4fv8wK4gtLGAgcbL9HBtE3FBi94MPrBC2kcTtKefAelkEVCX2nXsFtoBXIESi9eo3Johl ehItkzewgNicAvoSd36+A+tlBLru+6k1YDXMAuISt57MZ4K4WkBiyZ7zzBC2qMTLx/9YIWx5 iRdTXrJB1OtILNj9CcrWlli28DXUXkGJkzOfAO3iANqrJrFvvS2IKSHAJ7G9rXoCo8QsJMtm IRk0C8mgWUgGLWBkWcUoWZybnmGoV1xWpFdarJdVkJuckVicqpeXWrKJEZhkVta0pu1gvLvU 9hCjAAejEg9v4lKFICHWxLLiylxgOHMwK4nwPgo+HCjEm5JYWZValB9fVJqTWnyIsQoYZhOZ pUST84EJMK8k3tDYzMLA1NTQwMLQyIQqwkrivLO6pIOEBNKBKTU7NbUgtQhmORMHp1QD40bp lfwbBE+l8Z33YbDZuvjZ4SvW+y+/WfExR7LksZl10v5Kxge+R06lzKu7LvHjWcz3v2af+iZn Wv2dcn/zjLpi/d8PnvPsy+TwW63clNpzW/PjAaf8bX+aa45vKWz4u88sgGvvu7qO26vdww5Y PZOzCZM4YbiFce9TzQ7982lzxec0XePS4FRiKc5INNRiLipOBABSXiTnjQMAAA== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377884156 news.xs4all.nl 16001 [2001:888:2000:d::a6]:39550 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53307 Neil Cerutti wrote: > This code is from The Python Cookbook, 2nd edition, 12.2 Counting > Tags in a Document: > > from xml.sax.handler import ContentHandler > import xml.sax > class countHandler(ContentHandler): > def __init__(self): > self.tags=3D{} > def startElement(self, name, attr): > self.tags[name] =3D 1 + self.tags.get(name, 0) > > Isn't overriding __init__ a risky thing to do? The docs don't > mention it as a method I should override, and also don't define > what's in there or if I'd need to call the base class __init__. > Moreover, startDocument is provided for parser setup. > > As it happens, ContentHandler.__init__ isn't empty, so the above > code could fail if the parser isn't prepared for _locator to be > undefined. > > Is the above code is an acceptable idiom? > > -- > Neil Cerutti > -- I think this is a bad idea unless you want to avoid the parent class __init__ specifically (in which case a comment stating why is mandatory). I do not like that this recipe shows behavior that might be fine in this instance, but is not a good general practice. def __init__(self): super(ContentHandler, self).__init__() #OR ContentHandler.__init__(self) self.tags=3D{} I personally think the super() line is better of the two options. ~Ramit This email is confidential and subject to important disclaimers and conditio= ns including on offers for the purchase or sale of securities, accuracy and= completeness of information, viruses, confidentiality, legal privilege, and= legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclo= sures/email.