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


Groups > comp.lang.python > #89521

Re: Not possible to hide local variables

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.python
Subject Re: Not possible to hide local variables
Organization Decebal Computing
References <874mo0zoz2.fsf@Equus.decebal.nl> <mailman.58.1430208384.3680.python-list@python.org>
Date 2015-04-29 08:25 +0200
Message-ID <87lhhbxxg1.fsf@Equus.decebal.nl> (permalink)

Show all headers | View raw


Op Tuesday 28 Apr 2015 10:06 CEST schreef Chris Angelico:

> In fact, it's not really your problem if someone gives you a length
> that isn't a simple integer. In the first place, they might give you
> a subclass of int, so a better check would be this:
>
> if not isinstance(length, int):
> raise ValueError("length should be integral")

Good tip: I implemented it.


> (note that I'm avoiding the multiple-argument syntax which doesn't
> work in Python 3;

I already did this with print. Are there other statements I have to
take care for the possible problems with Python 3? I do not use Python
3, but that does not mean it is not a good idea to make my modules
work with it.


> if ParameterError is a subclass of ValueError you
> could use that instead, but ValueError works)

Was the wrong error: should have been TypeError. I find this strange:
Python is compiled, but I get only an error when this statement is
reached.


> You don't even need to check that it's an integer. If you get
> something that can't be compared against 0, they'll get an instant
> exception; otherwise, the exception might come up later. But it's
> still not your problem. You could skip the nonnegativity check too,
> but that's good documentation. (I'm assuming that ought to be
> checking 'length', as there is no 'n' in your example.)

Yep, silly mistake. I now check for greater or equal two. A moving
average of length one is not very useful.

I am of the school that it is good to check as much as possible.
(Without going over the top.)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


Thread

Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-28 09:33 +0200
  Re: Not possible to hide local variables Ethan Furman <ethan@stoneleaf.us> - 2015-04-28 00:56 -0700
    Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:16 +0200
      Re: Not possible to hide local variables Michael Torrie <torriem@gmail.com> - 2015-04-29 21:10 -0600
  Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-28 18:06 +1000
    Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:25 +0200
      Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-29 17:36 +1000
  Re: Not possible to hide local variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-28 18:37 +1000
    Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-28 18:44 +1000
    Re: Not possible to hide local variables Marko Rauhamaa <marko@pacujo.net> - 2015-04-28 12:20 +0300
    Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:32 +0200
      Re: Not possible to hide local variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 14:05 +1000
        Re: Not possible to hide local variables Marko Rauhamaa <marko@pacujo.net> - 2015-04-30 08:10 +0300
          Re: Not possible to hide local variables Chris Angelico <rosuav@gmail.com> - 2015-04-30 16:01 +1000
  Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 08:14 +0200
  Re: Not possible to hide local variables Grant Edwards <invalid@invalid.invalid> - 2015-04-29 14:16 +0000
    Re: Not possible to hide local variables Dave Angel <davea@davea.name> - 2015-04-29 22:31 -0400
    Re: Not possible to hide local variables Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-04-30 08:53 -0400
      Re: Not possible to hide local variables Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 16:50 +0200

csiph-web