[Python-ideas] Re: Fwd: Optional kwarg for sequence methods in random module

2019-08-18 Thread Steven D'Aprano
On Sat, Aug 17, 2019 at 09:02:54AM +0200, Patryk Gałczyński wrote: > Hi! > > Recently I encountered a situation when I needed to pick a random > population sample but with specific distribution function - paretovariate in > this particular case. Let me see if I understand... you have a paretovari

[Python-ideas] Re: Fwd: Optional kwarg for sequence methods in random module

2019-08-18 Thread Senhaji Rhazi hamza
Hey Steven, I think there is a way to map x <- [1; + inf] to y <- [0;1] by putting y = 1/x But i think there is another issue to consider : for example if we want to sort : random.choice(['a', 'b', 'c'], random=lambda: random.paretovariate(1.75)), we should have a mapping between the elements of

[Python-ideas] Re: Fwd: Optional kwarg for sequence methods in random module

2019-08-18 Thread Richard Damon
> On Aug 18, 2019, at 9:20 AM, Senhaji Rhazi hamza > wrote: > > Hey Steven, > > I think there is a way to map x <- [1; + inf] to y <- [0;1] by putting y = 1/x > One big issue with using that mapping is it doesn’t preserve many of the characteristics of the initial distribution. If the x di

[Python-ideas] Re: Namespace context managers

2019-08-18 Thread Niklas Rosenstein
You may be interested in this working example of a @namespace decorator (for functions though, not for classes). https://stackoverflow.com/a/52358426/791713 — @namespace def mynamespace(): eggs = 'spam' class Bar: def hello(self): print("Hello, World!") assert mynamespace.eggs == 'spam' mynamesp

[Python-ideas] Re: Fwd: Optional kwarg for sequence methods in random module

2019-08-18 Thread Andrew Barnert via Python-ideas
On Aug 18, 2019, at 06:20, Senhaji Rhazi hamza wrote: > > Hey Steven, > > I think there is a way to map x <- [1; + inf] to y <- [0;1] by putting y = 1/x Well, that gives you a distribution from (0, 1] instead of [0. 1), which is technically not legal as a substitute for random, even though i

[Python-ideas] Re: Namespace context managers

2019-08-18 Thread Ricky Teachey
The Zen of python could potentially be interpreted to heartily endorse adding nested namespaces to modules: Namespaces are one honking great idea — let’s do more of those! One concern about the implementation, from the sys documentation: "*CPython implementation detail:* The settrace()