Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed4.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'facts': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'language.': 0.14; '10+': 0.16; 'declarations': 0.16; 'foo(object):': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:object': 0.16; 'subject:when': 0.16; 'language': 0.16; 'wrote:': 0.18; 'preferred': 0.22; 'header:User-Agent:1': 0.23; '---': 0.24; 'sort': 0.25; "i've": 0.25; 'class.': 0.26; 'first,': 0.26; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'please.': 0.31; 'way?': 0.31; 'class': 0.32; 'there.': 0.32; 'run': 0.32; 'skip:_ 10': 0.34; 'maybe': 0.34; 'could': 0.34; 'there': 0.35; 'subject:data': 0.36; 'method': 0.36; 'should': 0.36; 'so,': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'skip:x 10': 0.40; 'our': 0.64; 'techniques': 0.66; 'rita': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: data validation when creating an object Date: Thu, 16 Jan 2014 01:26:54 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-21-70.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389835628 news.xs4all.nl 2861 [2001:888:2000:d::a6]:35660 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64036 On 16/01/2014 01:09, Rita wrote: > I would like to do some data validation when its going to a class. > > class Foo(object): > def __init__(self): > pass > > I know its frowned upon to do work in the __init__() method and only > declarations should be there. In the 10+ years that I've been using Python I don't ever recall seeing this, could we have a reference please. > > So, should i create a function called validateData(self) inside foo? > > I would call the object like this > > x=Foo() > x.validateData() > > Is this the preferred way? Is there a way I can run validateData() > automatically, maybe put it in __init__? Or are there other techniques > people use for this sort of thing? > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence