Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Greg Ewing
David Teresi wrote: One of the features I miss from languages such as C# is namespaces that work across files - it makes it a lot easier to organize code IMO. Maybe for the writer, but not for the reader. I like the fact that in Python I can usually tell which file a given class or function is

Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Nick Coghlan
On 9 June 2018 at 14:46, Jelle Zijlstra wrote: > > > 2018-06-08 20:27 GMT-07:00 Alex Walters : > >> Why not... >> >> cool_namespace = SomeNamespaceContextManager() >> >> with cool_namespace: >> def foo(): >> pass >> >> advantage being it introduces no new keyword. The 'disadvantage'

Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Jelle Zijlstra
2018-06-08 20:27 GMT-07:00 Alex Walters : > Why not... > > cool_namespace = SomeNamespaceContextManager() > > with cool_namespace: > def foo(): > pass > > advantage being it introduces no new keyword. The 'disadvantage' is it > would change semantics of the with statement (as would

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Wes Turner
On Fri, Jun 8, 2018 at 11:44 PM Robert Kern wrote: > On 6/8/18 01:45, Robert Vanden Eynde wrote: > > - Thanks for pointing out a language (Julia) that already had a name > convention. > > Interestingly they don't have a atan2d function. Choosing the same > convention as > > another language is a

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Robert Kern
On 6/8/18 01:45, Robert Vanden Eynde wrote: - Thanks for pointing out a language (Julia) that already had a name convention. Interestingly they don't have a atan2d function. Choosing the same convention as another language is a big plus. For what it's worth, scipy calls them sindg, cosdg,

Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Alex Walters
> -Original Message- > From: Python-ideas list=sdamon@python.org> On Behalf Of David Teresi > Sent: Friday, June 8, 2018 2:42 PM > To: python-ideas@python.org > Subject: [Python-ideas] A "within" keyword > > One of the features I miss from languages such as C# is namespaces that >

Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Terry Reedy
On 6/8/2018 6:07 PM, Michael Selik wrote: You can use ``eval`` to run an expression, swapping in a different globals and/or locals namespace. Will this serve your purpose? In [1]: import types In [2]: ns = types.SimpleNamespace(a=1) In [3]: eval('a', ns.__dict__) Out[3]: 1

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Wes Turner
# Python, NumPy, SymPy, mpmath, sage trigonometric functions https://en.wikipedia.org/wiki/Trigonometric_functions ## Python math module https://docs.python.org/3/library/math.html#trigonometric-functions - degrees(radians): Float degrees - radians(degrees): Float degrees ## NumPy

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread Greg Ewing
Jamie Willis wrote: What about just supporting filtering syntax at the top level? for x range(50) if x % 2: print(x) It would be more general and probably easier to support this: for x in range(50): if x % 2: print(x) i.e. just relax the requirement that a statement following on the same

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 11:11:09PM +0200, Adam Bartoš wrote: > But if there are both sin and dsin, and you ask about the difference > between them, the obvious answer would be that one takes radians and the > other takes degrees. The point that the degrees version is additionally > exact on

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 08:45:54AM +, Robert Vanden Eynde wrote: > from math import sin, tau > from fractions import Fraction > sin(Fraction(1,6) * tau) > sindeg(Fraction(1,6) * 360) > > These already work today by the way. You obviously have a different understanding of the words "already

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Robert Vanden Eynde
- Thanks for pointing out a language (Julia) that already had a name convention. Interestingly they don't have a atan2d function. Choosing the same convention as another language is a big plus. - Adding trig function using floats between 0 and 1 is nice, currently one needs to do sin(tau * t)

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Richard Damon
On 6/8/18 5:11 PM, Adam Bartoš wrote: > Steven D'Aprano wrote: > > On Fri, Jun 08, 2018 at 10:53:34AM +0200, Adam Bartoš wrote: > >> Wouldn't sin(45 * DEG) where DEG = 2 * math.pi / 360 be better that > >> sind(45)? This way we woudn't have to introduce new functions. (The > problem > >> with

Re: [Python-ideas] Allow popping of slices

2018-06-08 Thread Michael Selik
On Tuesday, June 5, 2018 at 12:19:53 AM UTC-7, Ben Rudiak-Gould wrote: > > When the loop is simple enough I can write > > items = [... for item in items] > > and when it's complicated enough it probably makes sense to split it > into a separate function. But I've many times wished that I

Re: [Python-ideas] Add dict.append and dict.extend

2018-06-08 Thread Michael Selik
On Monday, June 4, 2018 at 11:29:15 PM UTC-7, Ben Rudiak-Gould wrote: > > One example (or family of examples) is any situation where you would > have a UNIQUE constraint on an indexed column in a database. If the > values in a column should always be distinct, like the usernames in a > table of

Re: [Python-ideas] A real life example of "given"

2018-06-08 Thread Michael Selik
What's wrong with making this two lines? In [1]: import random In [2]: xs = [10, 20, 30] In [3]: def foo(x): ...: return [x + i for i in range(3)] ...: ...: In [4]: def bar(y): ...: if random.random() < 0.3: ...: return

Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Michael Selik
You can use ``eval`` to run an expression, swapping in a different globals and/or locals namespace. Will this serve your purpose? In [1]: import types In [2]: ns = types.SimpleNamespace(a=1) In [3]: eval('a', ns.__dict__) Out[3]: 1 https://docs.python.org/3/library/functions.html#eval On Fri,

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Adam Bartoš
Steven D'Aprano wrote: > On Fri, Jun 08, 2018 at 10:53:34AM +0200, Adam Bartoš wrote: >> Wouldn't sin(45 * DEG) where DEG = 2 * math.pi / 360 be better that >> sind(45)? This way we woudn't have to introduce new functions. (The problem >> with nonexact results for nice angles is a separate issue.)

Re: [Python-ideas] A "within" keyword

2018-06-08 Thread Rhodri James
On 08/06/18 19:41, David Teresi wrote: One of the features I miss from languages such as C# is namespaces that work across files - it makes it a lot easier to organize code IMO. Here's an idea I had - it might not be the best idea, just throwing this out there: a "within" keyword that lets you

[Python-ideas] A "within" keyword

2018-06-08 Thread David Teresi
One of the features I miss from languages such as C# is namespaces that work across files - it makes it a lot easier to organize code IMO. Here's an idea I had - it might not be the best idea, just throwing this out there: a "within" keyword that lets you execute code inside a namespace. For

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 10:12:01AM -0400, Randy Diaz wrote: > I think that the keyword do would solve problems that occur when people > want a simple way to run a command over an iterable but they dont want to > store the data. Why does it have to be a keyword? I like this pair of functions:

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread Todd
On Fri, Jun 8, 2018, 10:12 Randy Diaz wrote: > I think that the keyword do would solve problems that occur when people > want a simple way to run a command over an iterable but they dont want to > store the data. > > example: > > do print(x) for x in range(50) > - > this above

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread Jamie Willis
What about just supporting filtering syntax at the top level? for x range(50) if x % 2: print(x) It's a minor syntactic change which is very flexible and consistent with the existing comprehension syntax. Could even extend to allow multiple iterators as per a comprehension On Fri, 8 Jun 2018,

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread Jacco van Dorp
Given that an exhaust method for generators didn't make it, I dont think a keyword has more chance. For reference, that exhaust method would have looked like: (print (x) for x in range(50)).exhaust() and be defined as: def exhaust(self): for _ in self: pass Also, there was some more

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread MRAB
On 2018-06-08 15:12, Randy Diaz wrote: I think that the keyword do would solve problems that occur when people want a simple way to run a command over an iterable but they dont want to store the data. example: do print(x) for x in range(50)      - this above command will not return

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread Jamie Willis
I don't see how this is different to just: for x in range(50): print(x) Can you elaborate further? Jamie On Jun 8 2018, at 3:12 pm, Randy Diaz wrote: > > I think that the keyword do would solve problems that occur when people want > a simple way to run a command over an iterable but they dont

[Python-ideas] Fwd: New suggested built in keyword: do

2018-06-08 Thread Randy Diaz
I think that the keyword do would solve problems that occur when people want a simple way to run a command over an iterable but they dont want to store the data. example: do print(x) for x in range(50) - this above command will not return anything and will just run the command that

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Jacco van Dorp
2018-06-08 15:19 GMT+02:00 Hugh Fisher : >> Julia provides a full set of trigonometric functions in both radians and >> degrees: >> >> https://docs.julialang.org/en/release-0.4/manual/mathematical-operations/#trigonometric-and-hyperbolic-functions >> >> They use sind, cosd, tand etc for the

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Kyle Lahnakoski
On 2018-06-08 01:44, Yuval Greenfield wrote: > On Thu, Jun 7, 2018 at 10:38 PM Stephen J. Turnbull > > wrote: > > > 6.123233995736766e-17 > >>> > > is good enough for government work, including at the local public high > school. > > >

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Hugh Fisher
> Date: Fri, 8 Jun 2018 15:45:31 +1000 > From: Steven D'Aprano > To: python-ideas@python.org > Subject: Re: [Python-ideas] Trigonometry in degrees > Message-ID: <20180608054530.gc12...@ando.pearwood.info> > Content-Type: text/plain; charset=us-ascii > > On Fri, Jun 08, 2018 at 08:17:02AM +1000,

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 06:34:25PM +1200, Greg Ewing wrote: > I'm not sure what all the fuss is about: > > >>> from math import pi, sin > >>> sin(pi/2) > 1.0 Try cos(pi/2) or sin(pi/6). Or try: sin(pi/4) == sqrt(2)/2 tan(pi/4) == 1 tan(pi/3) == sqrt(3) And even tan(pi/2), which ought to be

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 10:53:34AM +0200, Adam Bartoš wrote: > Wouldn't sin(45 * DEG) where DEG = 2 * math.pi / 360 be better that > sind(45)? This way we woudn't have to introduce new functions. (The problem > with nonexact results for nice angles is a separate issue.) But that's not a separate

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Adam Bartoš
Wouldn't sin(45 * DEG) where DEG = 2 * math.pi / 360 be better that sind(45)? This way we woudn't have to introduce new functions. (The problem with nonexact results for nice angles is a separate issue.) Regards, Adam Bartoš ___ Python-ideas mailing

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 03:55:34PM +1000, Chris Angelico wrote: > On Fri, Jun 8, 2018 at 3:45 PM, Steven D'Aprano wrote: > > Although personally I prefer the look of d as a prefix: > > > > dsin, dcos, dtan > > > > That's more obviously pronounced "d(egrees) sin" etc rather than "sined" > >

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Jacco van Dorp
Or when students get stuff e-17 out of a function, you teach them what floating point numbers are and what gotcha's they can expect. The simple version is "value is stored as a float, and a float gets rounding errors below e-16", or for the more inquisitive minds you give them nice places like

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Greg Ewing
Steven D'Aprano wrote: Even old-school scientific calcuators without the fancy CAS symbolic maths are capable of having cos(90) return zero in degree mode. FWIW, my Casio fx-100 (over 30 years old) produces exactly 1 for both sin(90°) and sin(pi/2) for its version of pi. -- Greg

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Greg Ewing
Chris Angelico wrote: The math module would need a hyperbolic sine function which accepts an argument in; Except that the argument to hyperbolic trig functions is not an angle in any normal sense of the word, so expressing it in degrees makes little sense. (However I do like the idea of a

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Greg Ewing
Stephen J. Turnbull wrote: Since Pi is irrational, Pi/4 is too, so it definitely cannot be represented. Making a correction to a number that "looks like" Pi/4 is against this philosophy. I'm not sure what all the fuss is about: >>> from math import pi, sin >>> sin(pi/2) 1.0 >>> sin(pi/2 + 2

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 02:37:33PM +0900, Stephen J. Turnbull wrote: > My bias is that people who want to program this kind of thing just > need to learn about floating point numbers and be aware that they're > going to have to accept that > > >>> from math import cos, radians > >>>

Re: [Python-ideas] Trigonometry in degrees

2018-06-08 Thread Steven D'Aprano
On Thu, Jun 07, 2018 at 10:39:06PM -0400, Richard Damon wrote: > First I feel the need to point out that radians are actually fairly > fundamental in trigonometry, so there is good reasons for the base > functions to be based on radians. The fact that the arc length of the > angle on the unit