Re: [Python-Dev] range objects in 3.x

2011-09-25 Thread Guido van Rossum
On Sat, Sep 24, 2011 at 10:21 PM, Steven D'Aprano  wrote:
> Guido van Rossum wrote:
>> I believe this API is fundamentally wrong for float ranges, even if
>> it's great for int ranges, and I will fight against adding it to the
>> stdlib in that form.
>
> I wasn't proposing it to be in the standard lib, it was just an idle comment
> triggered by the OP's question. But I'm gratified it has started an
> interesting discussion.
>
> Whether the most float-friendly or not, the start/stop/step API is the most
> obvious and user-friendly for at least one use-case: graphing of functions.

It *appears* that. But the flaws make for hard-to-debug edge cases
(when an extra point unexpectedly appears). I've debugged a few bits
of charting code, and there are enough other causes for confusing
output that we don't need this problem.

> It is natural to say something like "draw a graph starting at 0, sampling
> every 0.1 unit, and stop when you get past 3". My HP-48 graphing calculator
> does exactly that: you must specify the start and stop coordinates, and an
> optional step size. By default, the step size is calculated for you assuming
> you want one point plotted per pixel. Given that the calculator display is
> both low-resolution and fixed size, that makes sense as the default, but you
> can set the step size manually if desired.

Yeah, but the HP uses decimal internally.

It's just as easy for the user to specify the number of steps, and it
has the advantage of not having the edge case problems. And you know
how many points you'll get.

> start/stop/step is also familiar for users of Excel and other spreadsheets'
> Fill>Series command.

Not sure I want to follow Excel's example for *anything*.

> Numeric integration is an interesting case, because generally you want
> multiple iterations, interpolating between the points previously seen until
> you reach some desired level of accuracy. E.g.:
>
> #1:  0.0, 0.5, 1.0
> #2:  0.25, 0.75
> #3:  0.125, 0.375, 0.625, 0.875

So double the number of steps each time. Seems simpler to me
(manipulating ints instead of floats).

> For integration, I would probably want both APIs.
>
>
>> Maybe we can come up with a better API, and e.g. specify begin and end
>> points and the number of subdivisions?
>
> Thanks to Mark Dickinson for suggesting using Fraction, I have this:
>
> http://code.activestate.com/recipes/577878-generate-equally-spaced-floats/

Nice one!

-- 
--Guido van Rossum (python.org/~guido)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] cpython: Issue #12981: rewrite multiprocessing_{sendfd, recvfd} in Python.

2011-09-25 Thread Nick Coghlan
On Sun, Sep 25, 2011 at 4:04 AM, charles-francois.natali
 wrote:
> +if not(sys.platform == 'win32' or (hasattr(socket, 'CMSG_LEN') and
> +                                   hasattr(socket, 'SCM_RIGHTS'))):
>     raise ImportError('pickling of connections not supported')

I'm pretty sure the functionality checks for CMSG_LEN and SCM_RIGHTS
mean the platform check for Windows is now redundant.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] cpython: Issue #12981: rewrite multiprocessing_{sendfd, recvfd} in Python.

2011-09-25 Thread Charles-François Natali
> On Sun, Sep 25, 2011 at 4:04 AM, charles-francois.natali
>  wrote:
>> +if not(sys.platform == 'win32' or (hasattr(socket, 'CMSG_LEN') and
>> +                                   hasattr(socket, 'SCM_RIGHTS'))):
>>     raise ImportError('pickling of connections not supported')
>
> I'm pretty sure the functionality checks for CMSG_LEN and SCM_RIGHTS
> mean the platform check for Windows is now redundant.
>

I'm not sure I understand what you mean.
FD passing is supported on Unix with sendmsg/SCM_RIGHTS, and on
Windows using whatever Windows uses for that purpose (see
http://hg.python.org/cpython/file/2b47f0146639/Lib/multiprocessing/reduction.py#l63).
If we remove the check for Windows, an ImportError will be raised
systematically, unless you suggest that Windows does support
sendmsg/SCM_RIGHTS (I somehow doubt Windows supports Unix domain
sockets, but I don't know Windows at all).

cf
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com