[issue39105] Spam

2019-12-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
components:  -asyncio
nosy:  -asvetlov, yselivanov
stage:  -> resolved
status: open -> closed
title: Printer offline -> Spam

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39105] Printer offline

2019-12-19 Thread Printer offline


New submission from Printer offline :

This blog has increased the level of information sharing. I just simply loved 
this blog. It has helped me a lot. A great and learning blog. I am very 
satisfied after reading this. https://www.printer-offline.com/

--
components: asyncio
files: Roko-Logo-2-fi18353094x260.png
messages: 358698
nosy: Printer offline, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Printer offline
type: resource usage
versions: Python 3.8
Added file: https://bugs.python.org/file48795/Roko-Logo-2-fi18353094x260.png

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39104] ProcessPoolExecutor hangs on shutdown nowait with pickling failure

2019-12-19 Thread Thomas Moreau


Change by Thomas Moreau :


--
keywords: +patch
pull_requests: +17134
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17670

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39104] ProcessPoolExecutor hangs on shutdown nowait with pickling failure

2019-12-19 Thread Thomas Moreau


New submission from Thomas Moreau :

The attached scripts hangs on python3.7+.
This is due to the fact that the main process closes the communication channels 
directly while the queue_management_thread might still use them.

To prevent that, all the closing should be handled by the 
queue_management_thread.

--
components: Library (Lib)
files: main.py
messages: 358697
nosy: tomMoral
priority: normal
severity: normal
status: open
title: ProcessPoolExecutor hangs on shutdown nowait with pickling failure
versions: Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48794/main.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39103] [linux] strftime renders %Y with only 3 characters

2019-12-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +belopolsky, p-ganssle

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-19 Thread Ethan Furman


Change by Ethan Furman :


--
assignee:  -> ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Cython, producing different modules from the same .pyx

2019-12-19 Thread Greg Ewing

On 20/12/19 2:16 am, Lele Gaifax wrote:

My first approach has been duplicating the Extension() entry in the
setup.py(*), changing the first argument (that is, the name of the module).
Although that did produce the alternative binary module, it could not be
loaded because it contains the wrong PyInit_XXX(), where XXX is computed from
the .pyx name,


You could try creating a set of top-level .pyx stubs, each of
which just 'include' the real code.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


pytest 4.6.8 released!

2019-12-19 Thread Anthony Sottile
pytest 4.6.8 has just been released to PyPI.

This is a bug-fix release, being a drop-in replacement. To upgrade::

  pip install --upgrade pytest

The full changelog is available at
https://docs.pytest.org/en/latest/changelog.html.

Thanks to all who contributed to this release, among them:

* Anthony Sottile
* Bruno Oliveira
* Ryan Mast


Happy testing,
The pytest Development Team
--
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Thought experiment: Suppose someone proposed, "math.log(x) should take an 
optional default argument because it is inconvenient to a catch a ValueError if 
the input is non-positive".   Or more generally, what if someone proposed, 
"every function in Python that can raise a ValueError should offer a default 
argument."  One could imagine a use case for both of these proposals but that 
doesn't mean that the API extensions would be warranted.

Also, ISTM the analogy to min() and max() is imperfect.  Those aren't 
descriptive statistics.  For min() and max() we can know a priori that a 
probability is never lower than 0.0 or greater than 1.0 for example.

Lastly, in common cases where the input is a sequence (rather than just an 
iterator), we already have a ternary operator to does the job nicely:

   central_value = mean(data) if data else 'unknown'

For the less common case, a try/except is not an undue burden; after all, it is 
a basic core language feature.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39103] [linux] strftime renders %Y with only 3 characters

2019-12-19 Thread Jason R. Coombs


New submission from Jason R. Coombs :

On Python 3.8, there's a difference between how datetime.datetime.strftime 
renders %Y for years < 1000 between Linux and other platforms.

# Linux
$ docker run -it python python -c 'import datetime; 
print(datetime.date(900,1,1).strftime("%Y"))'   
900

# macOS
$ python -c 'import datetime; print(datetime.date(900,1,1).strftime("%Y"))' 

0900


According to the docs 
(https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior), 
one should expect `''` for year zero and so I'd expect `'0900'` for the 
year 900, so the macOS behavior looks correct to me.

--
components: Library (Lib)
messages: 358695
nosy: jaraco
priority: normal
severity: normal
status: open
title: [linux] strftime renders %Y with only 3 characters
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



How to improve epoll speed when recv from kernel via netlink?

2019-12-19 Thread lampahome
I tried to receive msg from kernel via netlink of socket.

And I use epoll to receive netlink events whenever it comes from kernel to
user space.

But I found the performance is poor e.g. epoll costs 90% time of execution
time after I profile it by cProfile module.

Are there any tips to improve this?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue39102] Increase Enum performance

2019-12-19 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +barry, eli.bendersky, ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-19 Thread Arseny Boykov


Change by Arseny Boykov :


--
keywords: +patch
pull_requests: +17133
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17669

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39102] Increase Enum performance

2019-12-19 Thread Arseny Boykov


New submission from Arseny Boykov :

Now enum has very poor speed on trying values and attributes access (especially 
when it comes to accessing members name/value attrs)

There are two major reasons why attrs access is slow:
  - All values/names access going through DynamicClassAttribute (x10 slower 
than accessing attr directly)
  - EnumMeta has __getattr__ which is slowing down even direct class attributes 
access (up to x6 slower)

However, there are no need to use it, as we could just set value and name to 
newly created enum members without affecting its class.

The main issue with values check is the slow _missing_ hook handling when it 
raising exception, which happens pretty much always, if value is not valid enum 
and we talking about vanilla Enum class.

Also I found Flag performance issue being fixed already:
https://bugs.python.org/issue38045
It's also related, because new Flag creation involves many member.name lookups


My proposal:
  - I think we should completely get rid of __getattr__ on Enum (~6x speed 
boost)
  - Rework DynamicClassAttribute so it could work without __getattr__ or 
perhaps completely get rid of it
  - Don't use DynamicClassAttribute for member.name and .value (~10x speed 
boost)
  - Think of faster handling of _missing_ hook  (~2x speed boost)
  - Make other improvements to the code


Proposed changes doesn't require changing public API or behaviour.

By far I were able to implement almost things proposed here and will be happy 
to make a PR.

--
components: Library (Lib)
files: benchmark_result.txt
messages: 358694
nosy: MrMrRobat
priority: normal
severity: normal
status: open
title: Increase Enum performance
type: performance
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48793/benchmark_result.txt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38815] test_ssl: test_min_max_version() fails on FreeBSD and Fedora

2019-12-19 Thread Kubilay Kocak


Kubilay Kocak  added the comment:

@Christian As current assignee, are you able to produce a test that fixes the 
remaining issue (per msg357792)? I can rebuild OpenSSL on the worker at your 
direction at any time to make the test fail again or provide you with an SSH 
account to assist

--
stage: patch review -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Eryk Sun


Eryk Sun  added the comment:

> I am not sure if it's possible to also support Windows.

For reference, FindFirstFileW doesn't support handle-relative names, and 
neither does CreateFileW. At a lower level in Windows NT, NtCreateFile has 
always supported handle-relative names, but CPython doesn't use the NT API.

fd support (not dirfd) could be added to listdir and scandir in Windows. A 
directory can be listed via GetFileInformationByHandleEx: 
FileFullDirectoryInfo. This doesn't query the short name, so it may perform 
better than FindFirstFileW. However, opening a directory with os.open can't be 
supported. VC++ still hasn't documented the _O_OBTAIN_DIR (0x2000) flag.

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38971] codecs.open leaks file descriptor when invalid encoding is passed

2019-12-19 Thread Roundup Robot


Change by Roundup Robot :


--
keywords: +patch
pull_requests: +17132
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/17666

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ANN] pvlib-python v0.7.0: predicting power for solar energy

2019-12-19 Thread Dr. Mark Alexander Mikofski PhD
 pvlib has a new major release, v0.7.0

Release Notes:
https://pvlib-python.readthedocs.io/en/v0.7.0/whatsnew.html

PyPI:
https://pypi.org/project/pvlib/

Read the Docs:
https://pvlib-python.readthedocs.io/en/latest/

GitHub:
https://github.com/pvlib/pvlib-python

Here's a quick summary:

   - dropped support for Python-2.7
   - new `ivtools` module for fitting solar panel parameters
   - new implementation of the cloud wavelet variability model (WVM)
   - new functions for temperature and incidence angle modifier (IAM) models
   - updated solar panel and inverter parameters databases from National
   Renewable Energy Lab (NREL)

Also note this is a major release so there are a few breaking API changes.
Users should probably read the release notes and check their code before
updating:
https://pvlib-python.readthedocs.io/en/v0.7.0/whatsnew.html#api-breaking-changes


-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
--
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[issue39070] Uninstalling 3.8.0 fails but it says it succeeds..

2019-12-19 Thread Steve Dower


Steve Dower  added the comment:

The only issue I see in that log is an apparent failure communicating between 
the unelevated and the elevated components of the uninstaller. But that doesn't 
seem to have interfered with the rest of the process, so I'm at a bit of a loss.

Possibly it has gotten confused because of running as administrator to install 
the py.exe launcher for all users, but not the rest of it.

When you say the system asked for admin right - do you mean you had to 
authenticate as a different user? Or you had to click "Yes" to give it 
permissions?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: on sorting things

2019-12-19 Thread Chris Angelico
On Fri, Dec 20, 2019 at 8:06 AM Eli the Bearded <*@eli.users.panix.com> wrote:
>
> In comp.lang.python, Peter Otten  <__pete...@web.de> wrote:
> > Eli the Bearded wrote:
> >> But what caught my eye most, as someone relatively new to Python but
> >> with long experience in C in Perl, is sorting doesn't take a
>
> s/C in /C and/
>
> Ugh.
>
> >> *comparison* function, it takes a *key generator* function, and that
> >> function is supposed to transform the thing into something that the
> >> native comparison knows how to compare.
> >>
> >> This seems a strange choice, and I'm wondering if someone can explain
> >> the benefits of doing it that way to me.
> >
> > Python 2 started with a comparison function and then grew a key function.
> > With a key function you still have to compare items, you are just breaking
> > the comparison into two steps:
>
> [snip]
>
> Thanks for that good explanation. The benchmark comparison makes it
> very thorough.
>
> In my mind I gravitate towards the complicated sorts of sort that can be
> quickly compared for some sorts of keys and not as quickly for others.
>
> Consider a sort that first compares file size and if the same number of
> bytes, then compares file checksum. Any decently scaled real world
> implementation would memoize the checksum for speed, but only work it out
> for files that do not have a unique file size. The key method requires
> it worked out in advance for everything.
>
> But I see the key method handles the memoization under the hood for you,
> so those simpler, more common sorts of sort get an easy to see benefit.
>

I guess that's a strange situation that might actually need this kind
of optimization, but if you really do have that situation, you can
make a magical key that behaves the way you want.

class SizeChecksum:
def __init__(self, fn):
self.size = os.stat(fn).st_size
self._checksum = None
@property
def checksum(self):
if self._checksum is not None: return self._checksum
...
def __lt__(self, other):
if self.size != other.size: return self.size < other.size
return self.checksum < other.checksum

I can't remember exactly which comparison operators list.sort() uses,
so you'd want to add another function here for an equality check, or
maybe <=, or whichever is used. In any case, what matters is that the
weird situations can still be handled, albeit by largely falling back
on comparison semantics. But for the vast majority of situations, all
you need is a key function that returns a number, a string, or a tuple
of numbers and strings.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: on sorting things

2019-12-19 Thread Eli the Bearded
In comp.lang.python, Peter Otten  <__pete...@web.de> wrote:
> Eli the Bearded wrote:
>> But what caught my eye most, as someone relatively new to Python but
>> with long experience in C in Perl, is sorting doesn't take a

s/C in /C and/

Ugh.

>> *comparison* function, it takes a *key generator* function, and that
>> function is supposed to transform the thing into something that the
>> native comparison knows how to compare.
>> 
>> This seems a strange choice, and I'm wondering if someone can explain
>> the benefits of doing it that way to me.
> 
> Python 2 started with a comparison function and then grew a key function.
> With a key function you still have to compare items, you are just breaking 
> the comparison into two steps:

[snip]

Thanks for that good explanation. The benchmark comparison makes it
very thorough.

In my mind I gravitate towards the complicated sorts of sort that can be
quickly compared for some sorts of keys and not as quickly for others.

Consider a sort that first compares file size and if the same number of
bytes, then compares file checksum. Any decently scaled real world
implementation would memoize the checksum for speed, but only work it out
for files that do not have a unique file size. The key method requires
it worked out in advance for everything.

But I see the key method handles the memoization under the hood for you,
so those simpler, more common sorts of sort get an easy to see benefit.

Elijah
--
even memoizing the stat() calls would help for large lists
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue39101] IsolatedAsyncioTestCase freezes when exception is raised

2019-12-19 Thread Fabio Pugliese Ornellas


Change by Fabio Pugliese Ornellas :


--
type:  -> crash

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39101] IsolatedAsyncioTestCase freezes when exception is raised

2019-12-19 Thread Fabio Pugliese Ornellas


New submission from Fabio Pugliese Ornellas :

IsolatedAsyncioTestCase freezes whenever an exception that inherits from 
BaseException is raised:


import unittest
class TestHangsForever(unittest.IsolatedAsyncioTestCase):
async def test_hangs_forever(self):
raise BaseException("Hangs forever")
if __name__ == "__main__":
import unittest
unittest.main()

A kind of similar issue present on 3.7 was fixed on 3.8 here 
https://github.com/python/cpython/blob/3.8/Lib/asyncio/events.py#L84, where 
BaseExceptions would not be correctly handled by the event loop, this seems 
somewhat related.

I had a look at IsolatedAsyncioTestCase implementation, did not spot any 
obvious broken thing there, I could use some light here. Thanks.

--
components: asyncio
messages: 358690
nosy: asvetlov, fornellas, yselivanov
priority: normal
severity: normal
status: open
title: IsolatedAsyncioTestCase freezes when exception is raised
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39100] email.policy.SMTP throws AttributeError on invalid header

2019-12-19 Thread Anton Khirnov


New submission from Anton Khirnov :

When parsing a (broken) mail from linux-me...@vger.kernel.org (message-id 
20190212181908.horde.peighvv2khy9ekuy8ta8...@webmail.your-server.de, headers 
attached) with email.policy.SMTP, I get an AttributeError on trying to read the 
'to' header:

/usr/lib/python3.7/email/headerregistry.py in (.0)
345  mb.local_part or '',
346  mb.domain or '')
--> 347  for mb in addr.all_mailboxes]))
348 defects = list(address_list.all_defects)
349 else:

AttributeError: 'Group' object has no attribute 'local_part'

The header in question is:
To: unlisted-recipients:; (no To-header on input)

The problem seems to be that mb is a Group and not an Address, gets token_type 
of 'invalid-mailbox', but does not have the attributes local_part/domain that 
are expected in mailboxes. Copying the line

local_part = domain = route = addr_spec = display_name

from InvalidMailbox to Group fixes this, but it is not clear to me this is the 
right solution, so not sending a patch.

--
components: email
files: mail.eml
messages: 358689
nosy: barry, elenril, r.david.murray
priority: normal
severity: normal
status: open
title: email.policy.SMTP throws AttributeError on invalid header
type: behavior
Added file: https://bugs.python.org/file48792/mail.eml

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


Giampaolo Rodola'  added the comment:

Good point, I didn't consider that. I suppose you're right. =)
Closing.

--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Benjamin Peterson


Benjamin Peterson  added the comment:

Why not just os.open the directory yourself and pass it to os.scandir?

--
nosy: +benjamin.peterson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


Change by Giampaolo Rodola' :


--
keywords: +patch
pull_requests: +17131
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17664

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39099] scandir.dirfd() method

2019-12-19 Thread Giampaolo Rodola'


New submission from Giampaolo Rodola' :

PR in attachment adds a new dirfd() method to the scandir() object (POSIX 
only). This can be be passed to os.* functions supporting the "dir_fd" 
parameter, and avoid opening a new fd as in:

>>> dirfd = os.open("basename", os.O_RDONLY, dir_fd=topfd)

At the moment I am not sure if it's possible to also support Windows.

--
components: Library (Lib)
messages: 358686
nosy: giampaolo.rodola
priority: normal
severity: normal
status: open
title: scandir.dirfd() method
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: INHERITANCE in python3

2019-12-19 Thread Ethan Furman

On 12/19/2019 06:22 AM, Pieter van Oostrum wrote:

Random832 writes:

On Wed, Dec 18, 2019, at 23:10, wrote:


[vahid asadi]

my problem here is why this attribute is not recognize by python and it
raise an traceback error that said 'there is no such p.family
attribute'. although i use multiple   inheritance with 'super ' it not
works. thanks for your help.

class Username:
def __init__(self, name, *args):
 self.name= name

class Userfamily:
 def __init__(self, family, *args):
self.family = family

class Person(Username, Userfamily):
 def __init__(self, *args):
super().__init__(*args)

p = Person("v", "aaa")
print(p.name)
print(p.family)


[Random32]

The Username class also needs to call super(). In general, super() is
intended to be used with all classes that might be part of a multiple
inheritance hierarchy, not just the derived one.


[Pieter van Oostrum]

Just for safety, also add it* to the Userfamily class.



* a call to super()  (in case anybody else misreads that like I did)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Cython, producing different modules from the same .pyx

2019-12-19 Thread Ethan Furman

On 12/19/2019 05:16 AM, Lele Gaifax wrote:


in my package, I would like to compile and distribute two different extension
modules starting from the same .pyx file, just with different compilation
flags and libraries.


If you don't get an answer here, you can try the Cython Users group:

  https://groups.google.com/forum/#!forum/cython-users

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


[issue39093] tkinter objects garbage collected from non-tkinter thread cause panic and core dump

2019-12-19 Thread obserience


obserience  added the comment:

My proposed fix isn't compatible with a lot of current Tkinter using code. It 
was a naive first attempt and breaks existing code and doesn't completely solve 
the problem.

Variables currently retain a reference to the TCL interpreter self._tk and 
aren't linked into the widget tree or otherwise accessible to any cleanup logic.

Existing code:
-may expect the self.tk attribute of destroyed widgets to still be set

Existing code (after calling root.destroy()):
-calls methods like Tk.quit() which runs Tcl commands requiring self.tk to 
still be there
--Idle does this "# (Needed for clean exit on Windows 98)" <--apparently
---is this still the case??
-may call get() and set() on Variable instances (this currently works)


Given this it might be better to track all references to the TCL interpreter in 
a separate data structure and add a Tk.cleanup() method that gets rid of them 
all with documentation indicating all calls after this will fail. Alternate 
implementation of this deallocates the TCL interpreter in the _tkinter.c 
bindings with the same results.

One of the core issues here is that the cause of the crash is asynchronous 
signal handlers installed by the TCL library and necessary for the TCL 
interpreter to run at all. If you can run TCL commands, the crash can still be 
triggered.

###separate issue###
The Tk.Quit() doc is wrong. Current inline docs say that it destroys all 
widgets, which it does not. All it seems to do is cause mainloop to return 
after which mainloop can be called again and the GUI resumes functioning. This 
has caused problems when the main thread doesn't exit since the GUI continues 
to exist but is frozen. (See quit_behavior.py)

--
Added file: https://bugs.python.org/file48791/quit_behavior.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



ANN: SciPy 1.4.1

2019-12-19 Thread Tyler Reddy
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Hi all,

On behalf of the SciPy development team I'm pleased to announce
the release of SciPy 1.4.1, which is a bug fix release.

Sources and binary wheels can be found at:
https://pypi.org/project/scipy/
and at: https://github.com/scipy/scipy/releases/tag/v1.4.1

One of a few ways to install this release with pip:

pip install scipy==1.4.1

==
SciPy 1.4.1 Release Notes
==

SciPy 1.4.1 is a bug-fix release with no new features
compared to 1.4.0. Importantly, it aims to fix a problem
where an older version of pybind11 may cause a segmentation
fault when imported alongside incompatible libraries.

Authors
==

* Ralf Gommers
* Tyler Reddy

Issues closed for 1.4.1
-

* `#11237 `__: Seg fault when
importing torch

Pull requests for 1.4.1


* `#11238 `__: BLD: update
minimum pybind11 version to 2.4.0.

Checksums
=

MD5
~~~

82a6df2d23315b9e7f7ab334ae4ed98d
 scipy-1.4.1-cp35-cp35m-macosx_10_6_intel.whl
68a72f96918911586cc3b01566c8719a  scipy-1.4.1-cp35-cp35m-manylinux1_i686.whl
644e69ec76bc34276117aa377df6b56b
 scipy-1.4.1-cp35-cp35m-manylinux1_x86_64.whl
94a4cc9c9b0b9fdfd5159317a34ecf04  scipy-1.4.1-cp35-cp35m-win32.whl
00a88c31baa15561b726182b46a90bbf  scipy-1.4.1-cp35-cp35m-win_amd64.whl
f1ae0ec2394531c043dd66a4d87644ae
 scipy-1.4.1-cp36-cp36m-macosx_10_6_intel.whl
f02e63505e14c1c353f01bf5355bdb6b  scipy-1.4.1-cp36-cp36m-manylinux1_i686.whl
200f038910b0f92671d2ff5cb170f51b
 scipy-1.4.1-cp36-cp36m-manylinux1_x86_64.whl
5b2fb317f0105f1b6538a37405d6346e  scipy-1.4.1-cp36-cp36m-win32.whl
2820bc38feb01d1d8a161eb07000a5b2  scipy-1.4.1-cp36-cp36m-win_amd64.whl
a26c022bb638cbb105789e9586032cc7
 scipy-1.4.1-cp37-cp37m-macosx_10_6_intel.whl
b84878cf6419acbcc6bf9dcce8ed1ff7  scipy-1.4.1-cp37-cp37m-manylinux1_i686.whl
b2a9ee8c5ee393f6a52eb387163ad785
 scipy-1.4.1-cp37-cp37m-manylinux1_x86_64.whl
6f1c29d57a33d2cfd2991672543afda9  scipy-1.4.1-cp37-cp37m-win32.whl
2d5e0b3953d4e0a141f8897b39fc70c8  scipy-1.4.1-cp37-cp37m-win_amd64.whl
5fedfcb8736f41938681c8e7ef5737b8
 scipy-1.4.1-cp38-cp38-macosx_10_9_x86_64.whl
19ae0bc89a8a88045bfdcdac8eba300a  scipy-1.4.1-cp38-cp38-manylinux1_i686.whl
6ab0a834e656cd7314cfe28392fcebb4
 scipy-1.4.1-cp38-cp38-manylinux1_x86_64.whl
f8fd48b50c20fbc56e4af6c418b6c239  scipy-1.4.1-cp38-cp38-win32.whl
10b3e0755feb71100ed7a0a7c06ed69c  scipy-1.4.1-cp38-cp38-win_amd64.whl
3a97689656f33f67614000459ec08585  scipy-1.4.1.tar.gz
27608d42755c1acb097c7ab3616aafe0  scipy-1.4.1.tar.xz
2586c8563cd6693161e13a0ad6fffe06  scipy-1.4.1.zip

SHA256
~~

c5cac0c0387272ee0e789e94a570ac51deb01c796b37fb2aad1fb13f85e2f97d
 scipy-1.4.1-cp35-cp35m-macosx_10_6_intel.whl
a144811318853a23d32a07bc7fd5561ff0cac5da643d96ed94a4ffe967d89672
 scipy-1.4.1-cp35-cp35m-manylinux1_i686.whl
71eb180f22c49066f25d6df16f8709f215723317cc951d99e54dc88020ea57be
 scipy-1.4.1-cp35-cp35m-manylinux1_x86_64.whl
770254a280d741dd3436919d47e35712fb081a6ff8bafc0f319382b954b77802
 scipy-1.4.1-cp35-cp35m-win32.whl
a1aae70d52d0b074d8121333bc807a485f9f1e6a69742010b33780df2e60cfe0
 scipy-1.4.1-cp35-cp35m-win_amd64.whl
bb517872058a1f087c4528e7429b4a44533a902644987e7b2fe35ecc223bc408
 scipy-1.4.1-cp36-cp36m-macosx_10_6_intel.whl
dba8306f6da99e37ea08c08fef6e274b5bf8567bb094d1dbe86a20e532aca088
 scipy-1.4.1-cp36-cp36m-manylinux1_i686.whl
386086e2972ed2db17cebf88610aab7d7f6e2c0ca30042dc9a89cf18dcc363fa
 scipy-1.4.1-cp36-cp36m-manylinux1_x86_64.whl
8d3bc3993b8e4be7eade6dcc6fd59a412d96d3a33fa42b0fa45dc9e24495ede9
 scipy-1.4.1-cp36-cp36m-win32.whl
dc60bb302f48acf6da8cacfa17d52c63c5415302a9ee77b3b21618090521
 scipy-1.4.1-cp36-cp36m-win_amd64.whl
787cc50cab3020a865640aba3485e9fbd161d4d3b0d03a967df1a2881320512d
 scipy-1.4.1-cp37-cp37m-macosx_10_6_intel.whl
0902a620a381f101e184a958459b36d3ee50f5effd186db76e131cbefcbb96f7
 scipy-1.4.1-cp37-cp37m-manylinux1_i686.whl
00af72998a46c25bdb5824d2b729e7dabec0c765f9deb0b504f928591f5ff9d4
 scipy-1.4.1-cp37-cp37m-manylinux1_x86_64.whl
9508a7c628a165c2c835f2497837bf6ac80eb25291055f56c129df3c943cbaf8
 scipy-1.4.1-cp37-cp37m-win32.whl
a2d6df9eb074af7f08866598e4ef068a2b310d98f87dc23bd1b90ec7bdcec802
 scipy-1.4.1-cp37-cp37m-win_amd64.whl
3092857f36b690a321a662fe5496cb816a7f4eecd875e1d36793d92d3f884073
 scipy-1.4.1-cp38-cp38-macosx_10_9_x86_64.whl
8a07760d5c7f3a92e440ad3aedcc98891e915ce857664282ae3c0220f3301eb6
 scipy-1.4.1-cp38-cp38-manylinux1_i686.whl
1e3190466d669d658233e8a583b854f6386dd62d655539b77b3fa25bfb2abb70
 scipy-1.4.1-cp38-cp38-manylinux1_x86_64.whl
cc971a82ea1170e677443108703a2ec9ff0f70752258d0e9f5433d00dda01f59
 scipy-1.4.1-cp38-cp38-win32.whl
2cce3f9847a1a51019e8c5b47620da93950e58ebc611f13e0d11f4980ca5fecb
 scipy-1.4.1-cp38-cp38-win_amd64.whl
dee1bbf3a6c8f73b6b218cb28eed8dd13347ea2f87d572ce19b289d6fd3fbc59
 scipy-1.4.1.tar.gz

[issue32888] Improve exception message in ast.literal_eval

2019-12-19 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17130
pull_request: https://github.com/python/cpython/pull/17662

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38980] Compile libpython with -fno-semantic-interposition

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

Pablo:
> I have seen people using LD_PRELOAD (...) to interpose faster versions of 
> some functions or to collect metrics (although there are better ways).

IMHO if someone has to go so far into "hacking" Python, they should recompile 
Python with specific options. I'm not sure that using LD_PRELOAD to get "faster 
versions of some functions" is the best approach in term of performance, but I 
expect it to be convenient :-)


Charalampos:
> I think it will add to the complexity of the --with-optimizations flag which 
> already implies PGO and LTO.

It doesn't enable LTO, only PGO :-) We had to disable LTO because of multiple 
compiler bugs last years.


Serhiy:
> I am sure some C API functions are purposed to be overridden.

Is it a theorical use case, or are you aware of such use case being currently 
used in the wild?


Ammar Askar:
> Just for a quick datapoint: llvm/clang do this by default and you need an 
> explicit `-fsemantic-interposition` to disable it 
> http://lists.llvm.org/pipermail/llvm-dev/2016-November/107625.html

Oh, that's really interesting, thanks!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread STINNER Victor

STINNER Victor  added the comment:

Thanks Paul Sokolovsky for the bug report and thanks Batuhan Taşkaya for the 
fix ;-)

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread miss-islington

miss-islington  added the comment:


New changeset eba61f33d60cc63e35d5f5fcada837a66c89774a by Miss Islington (bot) 
(Batuhan Taşkaya) in branch '3.8':
[3.8] bpo-38316: Fix co_stacksize documentation (GH-16983) (GH-17661)
https://github.com/python/cpython/commit/eba61f33d60cc63e35d5f5fcada837a66c89774a


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread miss-islington

miss-islington  added the comment:


New changeset 917419f58b2869d71691c5ba54a9e02e5dcf73b2 by Miss Islington (bot) 
(Batuhan Taşkaya) in branch '3.7':
[3.7] bpo-38316: Fix co_stacksize documentation (GH-16983). (GH-17660)
https://github.com/python/cpython/commit/917419f58b2869d71691c5ba54a9e02e5dcf73b2


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17128
pull_request: https://github.com/python/cpython/pull/17660

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38316] docs: Code object's "co_stacksize" field is described with mistake

2019-12-19 Thread Batuhan


Change by Batuhan :


--
pull_requests: +17129
pull_request: https://github.com/python/cpython/pull/17661

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: hexdump module installation error

2019-12-19 Thread Pieter van Oostrum
tommy yama  writes:

> user@USERnoMacBook-Air LibraBrowser % python3 hexdump.py
>
> /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python:
> can't open file 'hexdump.py': [Errno 2] No such file or directory
>
> user@USERnoMacBook-Air LibraBrowser %

Could it be that your pip3 belongs to a different Python than the one above 
(for example a Python 3.8 or 3.6)? What is the output of 'pip3 --version' 
(without quotes)?

-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue39096] Description of "Format Specification Mini-Language" not accurate for Decimal

2019-12-19 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +eric.smith, mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: INHERITANCE in python3

2019-12-19 Thread Pieter van Oostrum
Random832  writes:

> On Wed, Dec 18, 2019, at 23:10, vahid asadi via Python-list wrote:
>> HI guys this is my first post on python mailing lists ever and i glad 
>> to do this.
>> my problem here is why this attribute is not recognize by python and it 
>> raise an traceback error that said 'there is no such p.family 
>> attribute'. although i use multiple   inheritance with 'super ' it not 
>> works. thanks for your help.
>> 
>> ``` class Username:    def __init__(self,name,*args):        self.name 
>> = name
>> class Userfamily:    def __init__(self,family,*args):        
>> self.family = family
>> class Person(Username,Userfamily):    def __init__(self,*args):        
>> super().__init__(*args)
>> 
>> 
>> p = Person("v","aaa")print(p.name)print(p.family)```

Please next time, supply a properly indented Python source, with only normal 
ASCII spaces, not no-break spaces, i.e. exactly like in your Python source code.
>
> The Username class also needs to call super(). In general, super() is
> intended to be used with all classes that might be part of a multiple
> inheritance hierarchy, not just the derived one.

Just for safety, also add it to the Userfamily class.
-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Understanding of GIL

2019-12-19 Thread onlinejudge95
Hi Devs,

I am currently writing some custom Django commands for data updation, my
workflow is like

Fetch data from *PostgreSQL*.
Call *Elasticsearch* for searching based on the data fetched from
*PostgreSQL*.
Query *PostgreSQL* and do an upsert behavior.
I am using pandas data frame to hold my data during processing.

The host we are using to run this jobs has a *CPython* interpreter as given
by

`platform.python_implementation()`

I want to confirm whether *multithreading* would be a better choice here,
given the fact that GIL is the biggest blocker(I agree it has to be there)
for the same in CPython interpreters.

In case further information is required do let me know.

Thanks
onlinejudge95
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-19 Thread tommy yama
Yes. thanks for your enthusiasm. i may raise this in the git

On Thu, Dec 19, 2019 at 12:46 PM Rhodri James  wrote:

> On 19/12/2019 12:43, tommy yama wrote:
> > Thanks for your quick response i did not expect.
> > I hope you see the error below in my response as i just copy and paste
> it.
> >
> > "no module named 'hexdump'."
> >
> > In addition, i tried to execute python3 hexdump.py. However, no such file
> > directory.
> >
> > from hexdump import hexdump
> >
> > ModuleNotFoundError: No module named 'hexdump'
> >
> > user@USERnoMacBook-Air LibraBrowser % python3 hexdump.py
> >
> >
> /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python:
> > can't open file 'hexdump.py': [Errno 2] No such file or directory
> >
> > user@USERnoMacBook-Air LibraBrowser %
>
> Huh.  You've done a "pip3 install hexdump" so I don't know what might be
> happening here.  Sorry.
>
> --
> Rhodri James *-* Kynesim Ltd
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-19 Thread Chris Angelico
On Thu, Dec 19, 2019 at 11:44 PM tommy yama  wrote:
>
> Hi Rhodri,
>
> Thanks for your quick response i did not expect.
> I hope you see the error below in my response as i just copy and paste it.
>
> "no module named 'hexdump'."
>
> In addition, i tried to execute python3 hexdump.py. However, no such file
> directory.
>
>from hexdump import hexdump
>

Did you, at some point, have a file called hexdump.py that you were
playing with? Sometimes, even after you delete a file with a
conflicting name, its .pyc file hangs around. Blow away the
__pycache__ directory to get rid of it.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue34850] Emit a syntax warning for "is" with a literal

2019-12-19 Thread thautwarm


thautwarm  added the comment:

Thanks.
However, unfortunately, this warning seems impossible to suppress.

Use following example:

  import warnings
  warnings.filterwarnings('ignore')

  warnings.warn(SyntaxWarning("test"))

  def f(x):
return x is 5

  print(f(5))

I succeeded in suppressing my own  SyntaxWarning("test") , but the output is 
still:
  
  python a.py
  a.py:7: SyntaxWarning: "is" with a literal. Did you mean "=="?
return x is 5
  True

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Cython, producing different modules from the same .pyx

2019-12-19 Thread Lele Gaifax
Hi all,

in my package, I would like to compile and distribute two different extension
modules starting from the same .pyx file, just with different compilation
flags and libraries.

My first approach has been duplicating the Extension() entry in the
setup.py(*), changing the first argument (that is, the name of the module).
Although that did produce the alternative binary module, it could not be
loaded because it contains the wrong PyInit_XXX(), where XXX is computed from
the .pyx name, in my case "parser".

I tried looking at Cython documentation, and even its sources, but couldn't
find a way to alter that name.

Did I miss something, or is the only way to duplicate the source .pyx file to
a different name?

Thanks in advance,
ciao, lele.

(*) https://github.com/lelit/pglast/blob/master/setup.py#L76
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue39098] OSError: handle is closed in ProcessPoolExecutor on shutdown(wait=False)

2019-12-19 Thread Patrick Buxton


New submission from Patrick Buxton :

When shutting down a ProcessPoolExecutor with wait=False, an `OSError: handle 
is closed` is raised.

The error can be replicated with a script as simple as:

```
from concurrent.futures import ProcessPoolExecutor

e = ProcessPoolExecutor()
e.submit(id)
e.shutdown(wait=False)

--
components: Library (Lib)
messages: 358679
nosy: patbuxton
priority: normal
severity: normal
status: open
title: OSError: handle is closed in ProcessPoolExecutor  on shutdown(wait=False)
type: crash
versions: Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[RELEASE] Python 3.8.1, 3.7.6, 3.6.10, and 3.9.0a2 are now available!

2019-12-19 Thread Łukasz Langa
from locale import seasons_greetings
seasons_greetings()

On behalf of the entire Python development community, and the currently serving 
Python release team in particular, I'm pleased to announce the unprecedented 
combined release of no less than four versions of Python. Let's dig in!


Python 3.8.1

Python 3.8.1 is the first maintenance release of Python 3.8.

The Python 3.8 series is the newest feature release of the Python language, and 
it contains many new features and optimizations. You can find Python 3.8.1 here:

https://www.python.org/downloads/release/python-381/ 


See the “What’s New in Python 3.8 
” document for more information 
about features included in the 3.8 series. Detailed information about all 
changes made in 3.8.1 can be found in its change log 
.

Maintenance releases for the 3.8 series will continue at regular bi-monthly 
intervals, with 3.8.2 planned for February 2020.



Python 3.7.6

Python 3.7.6, the next bugfix release of Python 3.7, is also available. You can 
find the release files, a link to the change log, and more information here:

https://www.python.org/downloads/release/python-376/ 




Python 3.9.0a2

An early developer preview of Python 3.9 is also ready: 
https://www.python.org/downloads/release/python-390a2/ 


Python 3.9 is still in development. This releasee, 3.9.0a2 is the second of six 
planned alpha releases. Alpha releases are intended to make it easier to test 
the current state of new features and bug fixes and to test the release 
process. During the alpha phase, features may be added up until the start of 
the beta phase (2020-05-18) and, if necessary, may be modified or deleted up 
until the release candidate phase (2020-08-10). Please keep in mind that this 
is a preview release and its use is not recommended for production environments.


Python 3.6.10

And, one more thing: Python 3.6.10, the next security fix release of Python 
3.6, is also available:

https://www.python.org/downloads/release/python-3610/ 




We hope you enjoy all those!

Thanks to all of the many volunteers who help make Python Development and these 
releases possible! Please consider supporting our efforts by volunteering 
yourself or through organization contributions to the Python Software 
Foundation.

https://www.python.org/psf/ 


Your friendly release team,
Ned Deily
Steve Dower
Łukasz Langa


signature.asc
Description: Message signed with OpenPGP
--
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[issue11245] Implementation of IMAP IDLE in imaplib?

2019-12-19 Thread Josh de Kock


Josh de Kock  added the comment:

Hi, I'm new to python but I had a go at implementing this for imaplib(1) using 
a different approach. It works but it has a couple issues (see patch), I would 
appreciate any thoughts/improvements.

--
nosy: +jdek
versions: +Python 3.9 -Python 3.6
Added file: 
https://bugs.python.org/file48790/0001-Add-IDLE-support-to-imaplib.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: hexdump module installation error

2019-12-19 Thread Rhodri James

On 19/12/2019 12:43, tommy yama wrote:

Thanks for your quick response i did not expect.
I hope you see the error below in my response as i just copy and paste it.

"no module named 'hexdump'."

In addition, i tried to execute python3 hexdump.py. However, no such file
directory.

from hexdump import hexdump

ModuleNotFoundError: No module named 'hexdump'

user@USERnoMacBook-Air LibraBrowser % python3 hexdump.py

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python:
can't open file 'hexdump.py': [Errno 2] No such file or directory

user@USERnoMacBook-Air LibraBrowser %


Huh.  You've done a "pip3 install hexdump" so I don't know what might be 
happening here.  Sorry.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-19 Thread tommy yama
Hi Rhodri,

Thanks for your quick response i did not expect.
I hope you see the error below in my response as i just copy and paste it.

"no module named 'hexdump'."

In addition, i tried to execute python3 hexdump.py. However, no such file
directory.

   from hexdump import hexdump

ModuleNotFoundError: No module named 'hexdump'

user@USERnoMacBook-Air LibraBrowser % python3 hexdump.py

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python:
can't open file 'hexdump.py': [Errno 2] No such file or directory

user@USERnoMacBook-Air LibraBrowser %

Cheers,



On Thu, Dec 19, 2019 at 12:21 PM Rhodri James  wrote:

> On 19/12/2019 11:23, tommy yama wrote:
> > Thanks for your kind response.
> > The error was simply "module Hexdump was not found".
>
> Several things:
>
> a) Did it really say "module Hexdump was not found"?  "hexdump" and
> "Hexdump" are not the same things; module names are case-sensitive.
>
> b) There will have been a whole load more stack trace that might be
> useful to us.  I should have been clearer when I asked you to copy and
> paste the error that I really meant the whole of the complaint that
> Python made to you, not just the final error message!  Apologies for that.
>
> c) I would much prefer it if you didn't top-post, but interleaved your
> replies like I've done here.  I find it hard to follow top-posted
> messages because they reverse the normal flow of conversation.
>
> >
> >
> > On Wed, Dec 18, 2019 at 11:39 PM Rhodri James 
> wrote:
> >
> >> On 18/12/2019 02:23, tommy yama wrote:
> >>> Hi,
> >>>
> >>> This sounds familiar to somebody?
> >>> After upgrading my mac OS to Catalina, this persists even after pip3
> >>> install hexdump.
> >>>
> >>> [image: image.png]
> >>
> >> I'm afraid this is a text-only mailing list.  Your screenshot has been
> >> stripped out before any of us saw it.  Could you copy and paste (DON'T
> >> retype!) the error instead, so we can all read it?
> >>
> >> --
> >> Rhodri James *-* Kynesim Ltd
> >> --
> >> https://mail.python.org/mailman/listinfo/python-list
> >>
> >
>
>
> --
> Rhodri James *-* Kynesim Ltd
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Change by Inada Naoki :


--
keywords: +patch
pull_requests: +17127
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17659

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39097] The description of multiprocessing.cpu_count() is not accurate in the documentation

2019-12-19 Thread songyuc


songyuc <466309...@qq.com> added the comment:

Hi, Andrew!
Thanks for your explanation! I am sorry about my unfamiliarity about the 
shortcut, as a student from China whose mother tongue is not English. So I am 
not quite familiar with the English customs in Computer engineering.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: hexdump module installation error

2019-12-19 Thread Rhodri James

On 19/12/2019 11:23, tommy yama wrote:

Thanks for your kind response.
The error was simply "module Hexdump was not found".


Several things:

a) Did it really say "module Hexdump was not found"?  "hexdump" and 
"Hexdump" are not the same things; module names are case-sensitive.


b) There will have been a whole load more stack trace that might be 
useful to us.  I should have been clearer when I asked you to copy and 
paste the error that I really meant the whole of the complaint that 
Python made to you, not just the final error message!  Apologies for that.


c) I would much prefer it if you didn't top-post, but interleaved your 
replies like I've done here.  I find it hard to follow top-posted 
messages because they reverse the normal flow of conversation.





On Wed, Dec 18, 2019 at 11:39 PM Rhodri James  wrote:


On 18/12/2019 02:23, tommy yama wrote:

Hi,

This sounds familiar to somebody?
After upgrading my mac OS to Catalina, this persists even after pip3
install hexdump.

[image: image.png]


I'm afraid this is a text-only mailing list.  Your screenshot has been
stripped out before any of us saw it.  Could you copy and paste (DON'T
retype!) the error instead, so we can all read it?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list






--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to specific multiple dtypes in numpy.ndarray?

2019-12-19 Thread Thomas Jollans
On 19/12/2019 11.52, lampahome wrote:
> I meet performance is low when I use struct.unpack to unpack binary data.
>
> So I tried to use numpy.ndarray
> But meet error when I want to unpack multiple dtypes
>
> Can anyone teach me~
>
> Code like below:
> # python3
> import struct
> import numpy as np
> s1 = struct.Struct("@QIQ")
> ss1 = s1.pack(1,11,111)
> np.ndarray((3,), [('Q','I','Q')], ss1)
> # ValueError: mismatch in size of old and new data-descriptor.

A numpy array always has ONE dtype for ALL array elements.

If you read an array of structs, you can define a structured type, where
each element of your struct must have a name.

The error you're seeing is (as you know) because you're not setting up
your dtype in the right way. Let's fix it:

> In [2]: np.dtype([('Q', 'I',
> 'Q')])
>  
>
> ---
> ValueError    Traceback (most recent call
> last)
>  in 
> > 1 np.dtype([('Q', 'I', 'Q')])
>
> ValueError: mismatch in size of old and new data-descriptor
>
> In [3]: np.dtype([('field1', 'Q'), ('field2', 'I'), ('field3',
> 'Q')])   
> Out[3]: dtype([('field1', '
> In [4]:   
>
>

... and now let's put it all together!

s1 = struct.Struct("@QIQ")
ss1 = s1.pack(1,11,111)
struct_dtype = np.dtype([('field1', 'Q'), ('field2', 'I'), ('field3', 'Q')])
a = np.frombuffer(ss1, dtype=struct_dtype)

I'm using the frombuffer() function deliberately so I don't have to
figure out the shape of the final array (which is (1,), not (3,), by the
way).

And hey presto: it raises an exception!

> ValueError: buffer size must be a multiple of element size

Your example shows a difference between the default behaviour of numpy's
structured dtype and the struct module: packing! By default, numpy
structured dtypes are closely packed, i.e. nothing is aligned to useful
memory boundaries.

struct_type.itemsize == 20

The struct module, on the other hand, tries to guess where the C
compiler would put its padding.

len(ss1) == 24

We can tell numpy to do the same:

struct_dtype = np.dtype([('field1', 'Q'), ('field2', 'I'), ('field3',
'Q')], align=True)

and then

a = np.frombuffer(ss1, dtype=struct_dtype)

works and produces

array([(1, 11, 111)],
  dtype={'names':['field1','field2','field3'],
'formats':['https://mail.python.org/mailman/listinfo/python-list


[issue39097] The description of multiprocessing.cpu_count() is not accurate in the documentation

2019-12-19 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

While your suggestion is technically correct, CPU as a shortcut for "logical 
processor" is very common in software engineering.

For me, "number of CPU threads" is more unclear than just "number of CPUs"

--
nosy: +asvetlov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39097] The description of multiprocessing.cpu_count() is not accurate in the documentation

2019-12-19 Thread songyuc


New submission from songyuc <466309...@qq.com>:

In the documentation of Python 3.7, the description of 
multiprocessing.cpu_count() is "Return the number of CPUs in the system.", but, 
in fact, this function return the CPU threads number.

--
assignee: docs@python
components: Documentation
messages: 358675
nosy: docs@python, songyuc
priority: normal
severity: normal
status: open
type: enhancement
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: hexdump module installation error

2019-12-19 Thread tommy yama
Thanks for your kind response.
The error was simply "module Hexdump was not found".

Regards,


On Wed, Dec 18, 2019 at 11:39 PM Rhodri James  wrote:

> On 18/12/2019 02:23, tommy yama wrote:
> > Hi,
> >
> > This sounds familiar to somebody?
> > After upgrading my mac OS to Catalina, this persists even after pip3
> > install hexdump.
> >
> > [image: image.png]
>
> I'm afraid this is a text-only mailing list.  Your screenshot has been
> stripped out before any of us saw it.  Could you copy and paste (DON'T
> retype!) the error instead, so we can all read it?
>
> --
> Rhodri James *-* Kynesim Ltd
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

TL;DR: I'm not likely to accept this feature request without at least one of 
(1) a practical use-case, (2) prior art in other statistics software, or (3) a 
strong mathematical justification for why this is meaningful and useful.


I'm not categorically against this idea, but it seems a bit fishy to me. If you 
have no data, how do you know what default value to give that would be 
appropriate for your (non-existent) observations?

It might help if you could show a real-life example of how, and why, you would 
use this, and how you would choose the default?

Another possibility would be to find prior-art: another language, library or 
stats calculator which already offers this feature.

Alternatively, a mathematical/statistical justification for a default. For 
example, the empty sum is normally taken as 0 and the empty product as 1. R 
returns either a NAN or NA for the empty mean (depending on precisely how you 
calculate it).

While I'm personally sympathetic to the nuisance factor of having to wrap code 
in try...except blocks (my *personal* preference would have been for mean to 
return NAN on empty input) I think you will need to make a stronger case than 
just the analogy with min and max.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Inada Naoki  added the comment:

> Don't you need to DECREF bytes somehow, at least, in case of failure?

Thanks.  I will create a pull request with suggested changes.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

> I've tried think of other solutions, such as a generic wrapper for such 
> functions or a helper to check whether an iterable is empty, and they all 
> turn out to be very clunky to use and un-Pythonic.

So the main use case would be to detect an empty iterable in an efficient 
fashion? Something like the following code?

sentinel = objet()
avg = mean(data, default=sentinel)
if avg is sentinel:
   ... # special code path

Why not adding a statistics.StatisticsError subclass for empty set (ex: 
StatisticsEmptyError)? Something like:

try:
   avg = mean(data)
except statistics.StatisticsEmptyError:
   ... # special code path, ex: avg = default

Or is there another use case for the proposed default parameter?

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



How to specific multiple dtypes in numpy.ndarray?

2019-12-19 Thread lampahome
I meet performance is low when I use struct.unpack to unpack binary data.

So I tried to use numpy.ndarray
But meet error when I want to unpack multiple dtypes

Can anyone teach me~

Code like below:
# python3
import struct
import numpy as np
s1 = struct.Struct("@QIQ")
ss1 = s1.pack(1,11,111)
np.ndarray((3,), [('Q','I','Q')], ss1)
# ValueError: mismatch in size of old and new data-descriptor.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue39094] Add a default to statistics.mean and related functions

2019-12-19 Thread Mark Dickinson


Mark Dickinson  added the comment:

What would the proposal look like for `statistics.stdev`? There you need at 
least two data points to compute a result, and a user might want to do 
different things for an empty dataset versus a single data point.

--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

return PyBytesType.tp_as_buffer(bytes, view, PyBUF_CONTIG_RO);

Don't you need to DECREF bytes somehow, at least, in case of failure?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39096] Description of "Format Specification Mini-Language" not accurate for Decimal

2019-12-19 Thread Michael Amrhein


Michael Amrhein  added the comment:

For a discussion of the different behaviour of float and Decimal see 
https://bugs.python.org/issue39077.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-19 Thread Michael Amrhein


Michael Amrhein  added the comment:

Created new issue for tracking the deficiencies in the documentation:
https://bugs.python.org/issue39096.

--
resolution:  -> wont fix
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39096] Description of "Format Specification Mini-Language" not accurate for Decimal

2019-12-19 Thread Michael Amrhein


New submission from Michael Amrhein :

The description of the "Format Specification Mini-Language" states for float 
and Decimal regarding presentation type 'f':
"The default precision is 6."
Regarding presentation type None it reads:
"Similar to 'g', except that fixed-point notation, when used, has at least one 
digit past the decimal point."
While both statements are accurate for float, they don't hold for Decimal.
In order to preserve the information about the decimal exponent, in both cases 
Decimal formatting displays as many fractional digits as dictated by it's 
exponent.

--
assignee: docs@python
components: Documentation
messages: 358667
nosy: docs@python, mamrhein
priority: normal
severity: normal
status: open
title: Description of "Format Specification Mini-Language" not accurate for 
Decimal
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Inada Naoki  added the comment:

s/return NULL/return -1/g

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Inada Naoki


Inada Naoki  added the comment:

> Would it be possible to use a "container" object like a Py_buffer? Is there a 
> way to customize the code executed when a Py_buffer is "released"?

It looks nice idea!  Py_buffer.obj is decref-ed when releasing the buffer.
https://docs.python.org/3/c-api/buffer.html#c.PyBuffer_Release


int PyUnicode_GetUTF8Buffer(PyObject *unicode, Py_buffer *view)
{
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return NULL;
}
if (PyUnicode_READY(unicode) == -1) {
return NULL;
}

if (PyUnicode_UTF8(unicode) != NULL) {
return PyBuffer_FillInfo(view, unicode,
 PyUnicode_UTF8(unicode),
 PyUnicode_UTF8_LENGTH(unicode),
 1, PyBUF_CONTIG_RO);
}
PyObject *bytes = _PyUnicode_AsUTF8String(unicode, NULL);
if (bytes == NULL) {
return NULL;
}
return PyBytesType.tp_as_buffer(bytes, view, PyBUF_CONTIG_RO);
}

--
nosy:  -skrah

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

> Would it be possible to use a "container" object like a Py_buffer?

Looks like a good idea.

int PyUnicode_GetUTF8Buffer(Py_buffer *view, const char *errors)

--
nosy: +skrah

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

> The returned object is the owner of the *utf8*.  You need to Py_DECREF() it 
> after
> you finished to using the *utf8*.  The owner may be not the unicode.

Would it be possible to use a "container" object like a Py_buffer? Is there a 
way to customize the code executed when a Py_buffer is "released"?

Py_buffer would be nice since it already has a pointer attribute (data) and a 
length attribute, and there is an API to "release" a Py_buffer. It can be 
marked as read-only, etc.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39087] [C API] No efficient C API to get UTF-8 string from unicode object.

2019-12-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Do you mean some concrete code? Several times I wished similar feature. To get 
a UTF-8 cache if it exists and encode to UTF-8 without creating a cache 
otherwise. 

The private _PyUnicode_UTF8() macro could help

if ((s = _PyUnicode_UTF8(str))) {
size = _PyUnicode_UTF8_LENGTH(str);
tmpbytes = NULL;
}
else {
tmpbytes = _PyUnicode_AsUTF8String(str, "replace");
s = PyBytes_AS_STRING(tmpbytes);
size = PyBytes_GET_SIZE(tmpbytes);
}

but it is not even available outside of unicodeobject.c.

PyUnicode_BorrowUTF8() looks too complex for the public API. I am not sure that 
it will be easy to implement it in PyPy. It also does not cover all use cases 
-- sometimes you want to convert to UTF-8 but does not use any memory 
allocation at all (either use an existing buffer or raise an error if there is 
no cached UTF-8 or the string is not ASCII).

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[RELEASE] Python 3.8.1, 3.7.6, 3.6.10, and 3.9.0a2 are now available!

2019-12-19 Thread Łukasz Langa
from locale import seasons_greetings
seasons_greetings()

On behalf of the entire Python development community, and the currently serving 
Python release team in particular, I'm pleased to announce the unprecedented 
combined release of no less than four versions of Python. Let's dig in!


Python 3.8.1

Python 3.8.1 is the first maintenance release of Python 3.8.

The Python 3.8 series is the newest feature release of the Python language, and 
it contains many new features and optimizations. You can find Python 3.8.1 here:

https://www.python.org/downloads/release/python-381/ 


See the “What’s New in Python 3.8 
” document for more information 
about features included in the 3.8 series. Detailed information about all 
changes made in 3.8.1 can be found in its change log 
.

Maintenance releases for the 3.8 series will continue at regular bi-monthly 
intervals, with 3.8.2 planned for February 2020.



Python 3.7.6

Python 3.7.6, the next bugfix release of Python 3.7, is also available. You can 
find the release files, a link to the change log, and more information here:

https://www.python.org/downloads/release/python-376/ 




Python 3.9.0a2

An early developer preview of Python 3.9 is also ready: 
https://www.python.org/downloads/release/python-390a2/ 


Python 3.9 is still in development. This releasee, 3.9.0a2 is the second of six 
planned alpha releases. Alpha releases are intended to make it easier to test 
the current state of new features and bug fixes and to test the release 
process. During the alpha phase, features may be added up until the start of 
the beta phase (2020-05-18) and, if necessary, may be modified or deleted up 
until the release candidate phase (2020-08-10). Please keep in mind that this 
is a preview release and its use is not recommended for production environments.


Python 3.6.10

And, one more thing: Python 3.6.10, the next security fix release of Python 
3.6, is also available:

https://www.python.org/downloads/release/python-3610/ 




We hope you enjoy all those!

Thanks to all of the many volunteers who help make Python Development and these 
releases possible! Please consider supporting our efforts by volunteering 
yourself or through organization contributions to the Python Software 
Foundation.

https://www.python.org/psf/ 


Your friendly release team,
Ned Deily
Steve Dower
Łukasz Langa


signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue20443] __code__. co_filename should always be an absolute path

2019-12-19 Thread STINNER Victor


STINNER Victor  added the comment:

I reverted my change, so I remove "release blocker" priority.

--
priority: release blocker -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: on sorting things

2019-12-19 Thread Peter Otten
Eli the Bearded wrote:

> I recently saw a link to an old post on a blog and then started looking
> at the newer posts. This one:
> 
> https://leancrew.com/all-this/2019/11/the-key-to-sorting-in-python/
> 
> discusses ways to deal with useful sorting of movie / television show
> titles. Some initial words should be re-ordered for sorting purposes
> (_Adventures of Huckleberry Finn, The_), roman numbers should sort like
> regular numbers (_Rocky V_ comes before _Rocky IX_), and something needs
> to be done about sorting accented vowels.
> 
> But what caught my eye most, as someone relatively new to Python but
> with long experience in C in Perl, is sorting doesn't take a
> *comparison* function, it takes a *key generator* function, and that
> function is supposed to transform the thing into something that the
> native comparison knows how to compare.
> 
> This seems a strange choice, and I'm wondering if someone can explain
> the benefits of doing it that way to me.

Python 2 started with a comparison function and then grew a key function.
With a key function you still have to compare items, you are just breaking 
the comparison into two steps:

- Calculate the key. This can be slow as it has to be done once per item.
- Compare the items. The key is usually a string or tuple, and for those
  the comparison runs C code which is a bit faster. The gain is even greater
  as the comparison is performed much more often.

The disadvantages of the key-based approach are that some comparison 
functions cannot naturally be rewritten in this way and that memory usage is 
a bit higher. Both are typically "expert" problems, so the developers 
decided to "nudge" users to consider keys first.

Now take a look at this example written in Python 2:

import random
import time
import contextlib

@contextlib.contextmanager
def measure(message):
start = time.time()
yield
span = time.time() - start
print message.format(span)

with open("/usr/share/dict/words") as f:
words = f.read().splitlines()
random.shuffle(words)

def key_lower(a):
global key_calls
key_calls += 1
return a.lower()

def cmp_lower(a, b):
global cmp_calls
cmp_calls += 1
return cmp(a.lower(), b.lower())

key_calls = 0
cmp_calls = 0

with measure("cmp-based sort took {} secs"):
words[:].sort(cmp_lower)

with measure("key-bases sort took {} secs"):
words[:].sort(key=key_lower)

print "cmp called", cmp_calls, "times"
print "key called", key_calls, "times"

$ python2 sort_demo.py 
cmp-based sort took 1.50221800804 secs
key-bases sort took 0.293763160706 secs
cmp called 1516111 times
key called 99171 times


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: on sorting things

2019-12-19 Thread Chris Angelico
On Thu, Dec 19, 2019 at 6:36 PM Eli the Bearded <*@eli.users.panix.com> wrote:
>
> I recently saw a link to an old post on a blog and then started looking
> at the newer posts. This one:
>
> https://leancrew.com/all-this/2019/11/the-key-to-sorting-in-python/
>
> discusses ways to deal with useful sorting of movie / television show
> titles. Some initial words should be re-ordered for sorting purposes
> (_Adventures of Huckleberry Finn, The_), roman numbers should sort like
> regular numbers (_Rocky V_ comes before _Rocky IX_), and something needs
> to be done about sorting accented vowels.
>
> But what caught my eye most, as someone relatively new to Python but
> with long experience in C in Perl, is sorting doesn't take a
> *comparison* function, it takes a *key generator* function, and that
> function is supposed to transform the thing into something that the
> native comparison knows how to compare.
>
> This seems a strange choice, and I'm wondering if someone can explain
> the benefits of doing it that way to me.
>

If you provide a comparison function, it has to be called for every
pair that need to be compared. Plus, it usually has to be written such
that it does the same thing twice:

arrayInJavaScript.sort((x, y) => x.some_attr[0] > y.some_attr[0])

python_list.sort(key=lambda x: x.some_attr[0])

Thirdly, a key function can easily handle three-way comparisons,
whereas a comparison function usually just offers two-way - it's
harder to write a comparison function for -1, 0, 1 returns. So the
sort is much less likely to be stable.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list