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


Groups > comp.lang.python > #18278

Re: mutually exclusive arguments to a constructor

From Adam Funk <a24061@ducksburg.com>
Newsgroups comp.lang.python
Subject Re: mutually exclusive arguments to a constructor
Date 2011-12-31 20:55 +0000
Organization $CABAL
Message-ID <de94t8x025.ln2@news.ducksburg.com> (permalink)
References <g6k1t8xg0a.ln2@news.ducksburg.com> <gd.usenet-3A3312.22005830122011@dwarf.main.lan>

Show all headers | View raw


On 2011-12-30, Günther Dietrich wrote:

> Adam Funk <a24061@ducksburg.com> wrote:
>
>>Suppose I'm creating a class that represents a bearing or azimuth,
>>created either from a string of traditional bearing notation
>>("N24d30mE") or from a number indicating the angle in degrees as
>>usually measured in trigonometry (65.5, measured counter-clockwise
>>from the x-axis).  The class will have methods to return the same
>>bearing in various formats.
...
> You can determine the type of the input data by using isinstance() and 
> take the appropriate actions depending on this decision:
>
>>>> class MyClass(object):
> ...     def __init__(self, input_data):
> ...         if isinstance(input_data, basestring):
> ...             print "Do actions for string type input"
> ...         elif isinstance(input_data, float):
> ...             print "Do actions for float type input"
> ...     def get_output_data(self):
> ...         return "output data"

Aha, I think I like this approach best, partly because I realized
after writing my post that it might also be good to accept strings
representing "pure" angles (e.g., "65d30m").  So I think I'll use
isinstance *and then* check the input string against some regexes to
determine whether it's in traditional surveying notation or trig
notation in DMS.


-- 
The generation of random numbers is too important to be left to
chance.                                     [Robert R. Coveyou]

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


Thread

mutually exclusive arguments to a constructor Adam Funk <a24061@ducksburg.com> - 2011-12-30 20:40 +0000
  Re: mutually exclusive arguments to a constructor "Günther Dietrich" <gd.usenet@spamfence.net> - 2011-12-30 22:00 +0100
    Re: mutually exclusive arguments to a constructor Adam Funk <a24061@ducksburg.com> - 2011-12-31 20:55 +0000
  Re: mutually exclusive arguments to a constructor Mel Wilson <mwilson@the-wire.com> - 2011-12-30 16:08 -0500
  Re: mutually exclusive arguments to a constructor Arnaud Delobelle <arnodel@gmail.com> - 2011-12-30 21:14 +0000
  Re: mutually exclusive arguments to a constructor Jason Friedman <jason@powerpull.net> - 2011-12-30 21:18 +0000
    Re: mutually exclusive arguments to a constructor Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-30 22:21 +0000
  Re: mutually exclusive arguments to a constructor Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-30 22:13 +0000
  Re: mutually exclusive arguments to a constructor Roy Smith <roy@panix.com> - 2011-12-30 18:24 -0500
    Re: mutually exclusive arguments to a constructor Chris Angelico <rosuav@gmail.com> - 2011-12-31 10:36 +1100
      Re: mutually exclusive arguments to a constructor Roy Smith <roy@panix.com> - 2011-12-30 18:39 -0500
        Re: mutually exclusive arguments to a constructor Chris Angelico <rosuav@gmail.com> - 2011-12-31 10:47 +1100
    Re: mutually exclusive arguments to a constructor Adam Funk <a24061@ducksburg.com> - 2011-12-31 20:59 +0000

csiph-web