Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64042

Re: data validation when creating an object

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rmorgan466@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; '16,': 0.03; 'context': 0.07; '__init__': 0.09; 'facts': 0.09; 'filename': 0.09; 'logic': 0.09; 'that).': 0.09; 'types:': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; '%r"': 0.16; 'early.': 0.16; 'responses.': 0.16; 'simpson': 0.16; 'somewhere.': 0.16; 'str()': 0.16; 'subject:object': 0.16; 'subject:when': 0.16; 'supplied': 0.16; 'typeerror:': 0.16; 'utterly': 0.16; 'validation.': 0.16; 'value;': 0.16; 'exception': 0.16; 'size,': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '&lt;': 0.19; 'passing': 0.19; 'thu,': 0.19; '>>>': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; '&gt;&gt;&gt;': 0.24; '---': 0.24; 'cc:2**0': 0.24; '&gt;': 0.26; '15,': 0.26; 'first,': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'raise': 0.29; 'errors': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; '"",': 0.31; 'fast.': 0.31; 'values.': 0.31; 'file': 0.32; 'another': 0.32; 'url:python': 0.33; '(most': 0.33; 'skip:_ 10': 0.34; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:data': 0.36; 'url:listinfo': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'reports': 0.37; 'wrong': 0.37; 'skip:& 10': 0.38; 'checks': 0.38; 'pm,': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; "couldn't": 0.39; 'itself': 0.39; 'url:mail': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'read': 0.60; 'simple': 0.61; 'received:': 0.65; 'to:addr:gmail.com': 0.65; 'receive': 0.70; 'therefore': 0.72; 'obvious': 0.74; 'selective': 0.84; 'responses': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=z5CXm74oj6YJabHpbqAbxLCf/rca3SAsKIdMzmKzqUs=; b=SLMcGHiLJKrzI9g2Dy5GjJkhS7V7CsLK2bx4LUV/uN0iW94D/oCMpKbmUHMewQyZTD IBNu3YXiUDPO5P7UfZdkpyt0Xl2q6EnQ8yJZPVMhxPIN0j05KnTfZea/vLbD6NLEqYv2 H36+GF4quYD5XBFjQVI3+cUxlneiLcJt7O7jUOU3dVYZ2WtO6Og2SQfRVZ5fTxO8+fQH deIW71yWilZxM2Jlmd2becQ6fBe4JV/HOctD/tHDJJA5z91/UZU8lE+emQNq+h9dq6I3 EwYaeaZwkBSkyi6TFw5sZ8H5V0xdZGSmIt5n4voWLOGPzRwcfFQpKVQkUgDz2T69bRjV Y7/A==
MIME-Version 1.0
X-Received by 10.60.58.134 with SMTP id r6mr4681659oeq.17.1389841279638; Wed, 15 Jan 2014 19:01:19 -0800 (PST)
In-Reply-To <CAPTjJmoRR_ih3D=vRsEpazFgQ5Cqs28xqRtwPs4a5wwRowvD0g@mail.gmail.com>
References <CAOF-KfigMrCKz+O9_o6C+PBk6OB8hjOkUTWPW9PLfpobYO_kTw@mail.gmail.com> <20140116012542.GA5065@cskk.homeip.net> <CAPTjJmoRR_ih3D=vRsEpazFgQ5Cqs28xqRtwPs4a5wwRowvD0g@mail.gmail.com>
Date Wed, 15 Jan 2014 22:01:19 -0500
Subject Re: data validation when creating an object
From Rita <rmorgan466@gmail.com>
To Chris Angelico <rosuav@gmail.com>
Content-Type multipart/alternative; boundary=089e013c71e4c4610a04f00da315
Cc "python-list@python.org" <python-list@python.org>
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5563.1389841288.18130.python-list@python.org> (permalink)
Lines 114
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389841289 news.xs4all.nl 2836 [2001:888:2000:d::a6]:39150
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64042

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Unfortunately, I couldn't find the reference but I know I read it
somewhere. Even with a selective search I wasn't able to find it. I think I
read it in context of module/class test case writing.



I will keep your responses in mind therefore I will put logic in __init__
for data validation.

thanks again for the responses.





On Wed, Jan 15, 2014 at 8:46 PM, Chris Angelico <rosuav@gmail.com> wrote:

> On Thu, Jan 16, 2014 at 12:25 PM, Cameron Simpson <cs@zip.com.au> wrote:
> > However, I would also have obvious validity checks in __init__
> > itself on the supplied values. Eg:
> >
> >   def __init__(self, size, lifetime):
> >     if size < 1:
> >       raise ValueError("size must be >= 1, received: %r" % (size,))
> >     if lifetime <= 0:
> >       raise ValueError("lifetime must be > 0, received: %r" %
> (lifetime,))
> >
> > Trivial, fast. Fails early. Note that the exception reports the
> > receive value; very handy for simple errors like passing utterly
> > the wrong thing (eg a filename when you wanted a counter, or something
> > like that).
>
> With code like this, passing a filename as the size will raise TypeError
> on Py3:
>
> >>> size = "test.txt"
> >>> size < 1
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: unorderable types: str() < int()
>
> Yet another advantage of Py3 :)
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
--- Get your facts first, then you can distort them as you please.--

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: data validation when creating an object Rita <rmorgan466@gmail.com> - 2014-01-15 22:01 -0500

csiph-web