Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!feeds.phibee-telecom.net!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.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'facts': 0.09; 'def': 0.12; 'declarations': 0.16; 'foo(object):': 0.16; 'subject:object': 0.16; 'subject:when': 0.16; 'preferred': 0.22; '---': 0.24; 'sort': 0.25; 'class.': 0.26; 'first,': 0.26; 'pass': 0.26; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'way?': 0.31; 'class': 0.32; 'there.': 0.32; 'run': 0.32; 'skip:_ 10': 0.34; 'maybe': 0.34; 'received:google.com': 0.35; '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; 'called': 0.40; '8bit%:6': 0.40; 'skip:x 10': 0.40; 'techniques': 0.66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=UA82zeIlaRsUWvCTTp4ZJ99ilr5zk9MAK9yOIygiiZs=; b=Y1P7GqF8K30VzXvEr6uG9i8Iz4mOVx2MIJaGOCJTWD61ws5PShbM962dFYIW+K/FcO jsbLEJRiiJSx/sONcSuIlZIk8gJkOalGzs1UHHTE7RGLjZFgimxEPZIPTVHivNHOM+mO /3aYW2pKaKBb3wfCTHlqwS29kKZ0x/4LP4+0pu5zeWcvOtBbxkWm+oVDzVJc7i5+YIxl HPkBQne+XtbxP1x+O3BVQ9vUuklfLBqwd3KWlkBQJulkMPqI1Wk50/8L0rev+HaUKO05 lSI6qBHBAoaYCs5SAc2kKtDMeOv6Er5wt3tPEUAQf5NFqPQrEbGGTQXYVs8ii50VJcNi W/Cw== MIME-Version: 1.0 X-Received: by 10.182.87.42 with SMTP id u10mr4482070obz.22.1389834580398; Wed, 15 Jan 2014 17:09:40 -0800 (PST) Date: Wed, 15 Jan 2014 20:09:40 -0500 Subject: data validation when creating an object From: Rita To: python-list@python.org Content-Type: multipart/alternative; boundary=089e013cba6276166704f00c1472 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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389834588 news.xs4all.nl 2876 [2001:888:2000:d::a6]:55947 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64032 --089e013cba6276166704f00c1472 Content-Type: text/plain; charset=ISO-8859-1 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. 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.-- --089e013cba6276166704f00c1472 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I would like to do some data validation when its goin= g to a class.

class Foo(object):
=A0 def= __init__(self):
=A0 =A0 pass

I know its= frowned upon to do work in the __init__() method and only declarations sho= uld be there.

So, should i create a function called validateDat= a(self) inside foo?=A0

I would call the object lik= e this

x=3DFoo()
x.validateData()
<= div>
Is this the preferred way? Is there a way I can run validate= Data() automatically, maybe put it in __init__? Or are there other techniqu= es people use for this sort of thing?


--
--- Get your facts first, then you can distort them as you ple= ase.-- --089e013cba6276166704f00c1472--