Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33097 > unrolled thread
| Started by | Jennie <nameDOTportua@gmail.com> |
|---|---|
| First post | 2012-11-10 20:33 +0100 |
| Last post | 2012-11-11 16:32 -0800 |
| Articles | 7 on this page of 27 — 11 participants |
Back to article view | Back to comp.lang.python
Method default argument whose type is the class not yet defined Jennie <nameDOTportua@gmail.com> - 2012-11-10 20:33 +0100
Re: Method default argument whose type is the class not yet defined Chris Angelico <rosuav@gmail.com> - 2012-11-11 06:56 +1100
Re: Method default argument whose type is the class not yet defined Terry Reedy <tjreedy@udel.edu> - 2012-11-10 15:29 -0500
Re: Method default argument whose type is the class not yet defined Jennie <nameDOTportua@gmail.com> - 2012-11-10 21:51 +0100
Re: Method default argument whose type is the class not yet defined Dave Angel <d@davea.name> - 2012-11-10 17:30 -0500
Re: Method default argument whose type is the class not yet defined Jennie <marco.buttu@gmail.com> - 2012-11-10 21:51 +0100
Re: Method default argument whose type is the class not yet defined Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-11 01:13 +0000
Re: Method default argument whose type is the class not yet defined Chris Angelico <rosuav@gmail.com> - 2012-11-11 13:13 +1100
Re: Method default argument whose type is the class not yet defined Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-10 19:43 -0700
Re: Method default argument whose type is the class not yet defined Roy Smith <roy@panix.com> - 2012-11-10 21:53 -0500
Re: Method default argument whose type is the class not yet defined Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-10 23:43 -0700
Re: Method default argument whose type is the class not yet defined Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-10 23:45 -0700
Re: Method default argument whose type is the class not yet defined Chris Angelico <rosuav@gmail.com> - 2012-11-11 13:47 +1100
Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-11 14:21 +0000
Re: Method default argument whose type is the class not yet defined Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-11 22:31 +0000
Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-12 00:31 +0000
Re: Method default argument whose type is the class not yet defined Steve Howell <showell30@yahoo.com> - 2012-11-11 16:56 -0800
Re: Method default argument whose type is the class not yet defined Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-12 04:46 +0000
Re: Method default argument whose type is the class not yet defined Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-12 01:10 +0000
Re: Method default argument whose type is the class not yet defined Roy Smith <roy@panix.com> - 2012-11-11 20:15 -0500
Re: Method default argument whose type is the class not yet defined Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-12 01:35 +0000
Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-12 01:18 +0000
Re: Method default argument whose type is the class not yet defined Roy Smith <roy@panix.com> - 2012-11-11 20:34 -0500
Re: Method default argument whose type is the class not yet defined Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-12 01:29 +0000
Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-12 01:50 +0000
Re: Method default argument whose type is the class not yet defined Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-11 01:23 +0000
Re: Method default argument whose type is the class not yet defined Steve Howell <showell30@yahoo.com> - 2012-11-11 16:32 -0800
Page 2 of 2 — ← Prev page 1 [2]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-11-12 01:35 +0000 |
| Message-ID | <mailman.3573.1352684098.27098.python-list@python.org> |
| In reply to | #33159 |
On 12/11/2012 01:15, Roy Smith wrote:
> In article <mailman.3570.1352682390.27098.python-list@python.org>,
> Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>
>> On 12/11/2012 00:31, Oscar Benjamin wrote:
>>>
>>> Plain wrong. Vectors are not defined *from any origin*.
>>>
>>
>> So when the Captain says "full speed ahead, steer 245 degrees", you
>> haven't the faintest idea where you're going, because you have no origin?
>
> Vectors have a length ("full speed ahead") and a direction ("245
> degrees"). What they don't have is a fixed location in space. The
> captain didn't say, "Full speed ahead, steer 245 degrees, from 45.0N,
> 20.0W".
>
> In other words, you are correct. The order, "full speed ahead, steer
> 245 degrees", doesn't give you the faintest idea of where you're going.
> If you were the helmsman, after you executed that order, without any
> additional information (such as your current location), you would have
> no idea what piece of land you will hit, or when you will hit it, if you
> maintain your current course and speed.
>
Thank you for your explanation.
--
Cheers.
Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2012-11-12 01:18 +0000 |
| Message-ID | <mailman.3571.1352683098.27098.python-list@python.org> |
| In reply to | #33144 |
On 12 November 2012 01:10, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: > On 12/11/2012 00:31, Oscar Benjamin wrote: >> >> >> Plain wrong. Vectors are not defined *from any origin*. >> > > So when the Captain says "full speed ahead, steer 245 degrees", you haven't > the faintest idea where you're going, because you have no origin? As Steve has just explained, the origin has nothing to do with the orientation of the coordinate system. But then I'm assuming you meant that 245 degrees was a bearing relative to North. Was it supposed to be relative to my current angle? Truthfully I wouldn't know what to do without asking the captain a couple more questions. Oscar
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2012-11-11 20:34 -0500 |
| Message-ID | <roy-588CCB.20340811112012@news.panix.com> |
| In reply to | #33160 |
In article <mailman.3571.1352683098.27098.python-list@python.org>, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote: > But then I'm assuming you meant that 245 degrees was a bearing > relative to North. Was it supposed to be relative to my current angle? > Truthfully I wouldn't know what to do without asking the captain a > couple more questions. Granted, this requires some domain-specific knowledge, but an order to "steer 245 degrees" means relative to north (and, technically, it's a heading, not a bearing, but that's another discussion). If the captain wanted you to change you heading relative to your current heading, he would say something like, "turn left 10 degrees" (that may not be strictly the correct wording).
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-11-12 01:29 +0000 |
| Message-ID | <mailman.3572.1352683700.27098.python-list@python.org> |
| In reply to | #33144 |
On 12/11/2012 01:18, Oscar Benjamin wrote: > On 12 November 2012 01:10, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: >> On 12/11/2012 00:31, Oscar Benjamin wrote: >>> >>> >>> Plain wrong. Vectors are not defined *from any origin*. >>> >> >> So when the Captain says "full speed ahead, steer 245 degrees", you haven't >> the faintest idea where you're going, because you have no origin? > > As Steve has just explained, the origin has nothing to do with the > orientation of the coordinate system. > > But then I'm assuming you meant that 245 degrees was a bearing > relative to North. Was it supposed to be relative to my current angle? > Truthfully I wouldn't know what to do without asking the captain a > couple more questions. > > > Oscar > The only good acedemic is a dead acedemic? -- Cheers. Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2012-11-12 01:50 +0000 |
| Message-ID | <mailman.3574.1352685058.27098.python-list@python.org> |
| In reply to | #33144 |
On 12 November 2012 01:29, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: > On 12/11/2012 01:18, Oscar Benjamin wrote: >> >> On 12 November 2012 01:10, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: >>> >>> On 12/11/2012 00:31, Oscar Benjamin wrote: >>>> >>>> Plain wrong. Vectors are not defined *from any origin*. >>> >>> So when the Captain says "full speed ahead, steer 245 degrees", you >>> haven't >>> the faintest idea where you're going, because you have no origin? >> >> >> As Steve has just explained, the origin has nothing to do with the >> orientation of the coordinate system. >> >> But then I'm assuming you meant that 245 degrees was a bearing >> relative to North. Was it supposed to be relative to my current angle? >> Truthfully I wouldn't know what to do without asking the captain a >> couple more questions. > > The only good acedemic is a dead acedemic? Is that what happens when people ask questions on your ship: "it's the plank for him with the questions-askin'!" I'm glad you're not my captain. Oscar
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2012-11-11 01:23 +0000 |
| Message-ID | <mailman.3547.1352596990.27098.python-list@python.org> |
| In reply to | #33097 |
On 10 November 2012 19:33, Jennie <nameDOTportua@gmail.com> wrote:
> What is the best solution to solve the following problem in Python 3.3?
>
> import math
>>>> class Point:
> ... def __init__(self, x=0, y=0):
> ... self.x = x
> ... self.y = y
> ... def __sub__(self, other):
> ... return Point(self.x - other.x, self.y - other.y)
> ... def distance(self, point=Point()):
> ... """Return the distance from `point`."""
> ... return math.sqrt((self - point).x ** 2 + (self - point).y ** 2)
> ...
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 5, in Point
> NameError: name 'Point' is not defined
I would use namedtuple and make it so that an ordinary tuple could be
used as in place of a Point instance:
>>> import math
>>> from collections import namedtuple
>>> class Point(namedtuple('Point', ['x', 'y'])):
... def distance(self, other=(0, 0)):
... (myx, myy), (theirx, theiry) = self, other
... return math.sqrt((myx - theirx) ** 2 + (myy - theiry) ** 2)
...
>>> p = Point(3, 4)
>>> p.distance()
5.0
>>> p2 = Point(4, 5)
>>> p.distance(p2)
1.4142135623730951
Oscar
[toc] | [prev] | [next] | [standalone]
| From | Steve Howell <showell30@yahoo.com> |
|---|---|
| Date | 2012-11-11 16:32 -0800 |
| Message-ID | <5eac62e4-9fe9-4185-be4f-1035d42cd165@me7g2000pbb.googlegroups.com> |
| In reply to | #33097 |
On Nov 10, 11:33 am, Jennie <nameDOTpor...@gmail.com> wrote: > What is the best solution to solve the following problem in Python 3.3? > > import math > >>> class Point: > ... def __init__(self, x=0, y=0): > ... self.x = x > ... self.y = y > ... def __sub__(self, other): > ... return Point(self.x - other.x, self.y - other.y) > ... def distance(self, point=Point()): > ... """Return the distance from `point`.""" > ... return math.sqrt((self - point).x ** 2 + (self - point).y ** 2) Before you do anything else, introduce a Vector class into your app. The difference between two Points is not a Point; it's a Vector. Create a magnitude() method in your Vector class, then make your Point.distance return the results of Vector.magnitude(self - other). To define the distance of a point from the origin, don't make your distance() method have default arguments; instead, define another method called distance_from_origin().
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web