[issue28147] Unbounded memory growth resizing split-table dicts

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

[cherrypicked for 3.6.0rc2]

--
priority: release blocker -> deferred blocker

___
Python tracker 

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



[issue28979] What's New entry on compact dict mentions "faster" implementation

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

[cherrypicked for 3.6.0rc2]

--
priority: release blocker -> 
resolution:  -> fixed
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



[issue28089] asyncio: Document that TCP_NODELAY is now used by default

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

[cherrypicked for 3.6.0rc2]

--
priority: deferred blocker -> 

___
Python tracker 

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



[issue28783] Embedded/nuget packages incorrectly reference bdist_wininst

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

[cherrypicked for 3.6.0rc2]

--
priority: release blocker -> 
resolution:  -> fixed
stage: commit 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



[issue28896] Embeddable zip allows Windows registry to override module location

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

[cherrypicked for 3.6.0rc2]

--
priority: release blocker -> 

___
Python tracker 

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



[issue28898] Can't compile gdb with Python 3.6

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

[cherrypicked for 3.6.0rc2]

--
assignee: ned.deily -> 
priority: release blocker -> 
resolution:  -> fixed
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



[issue28635] Update What's New for 3.6

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

[cherrypicked for 3.6.0r2]

--

___
Python tracker 

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



[issue28896] Embeddable zip allows Windows registry to override module location

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 6249350e654a by Steve Dower in branch '3.6':
Issue #28896: Deprecate WindowsRegistryFinder
https://hg.python.org/cpython/rev/6249350e654a

--

___
Python tracker 

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



[issue28089] asyncio: Document that TCP_NODELAY is now used by default

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset dfd1019f75f9 by Yury Selivanov in branch '3.6':
Issue #28089: Document TCP_NODELAY in asyncio
https://hg.python.org/cpython/rev/dfd1019f75f9

--

___
Python tracker 

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



[issue28898] Can't compile gdb with Python 3.6

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d6c8803c55b4 by Benjamin Peterson in branch '3.6':
guard HAVE_LONG_LONG definition to prevent redefinition (#28898)
https://hg.python.org/cpython/rev/d6c8803c55b4

New changeset 9d0765c22bed by Ned Deily in branch '3.6':
Issue #28898: add Misc/NEWS entry
https://hg.python.org/cpython/rev/9d0765c22bed

--

___
Python tracker 

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



[issue28147] Unbounded memory growth resizing split-table dicts

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset b70b2d3f3167 by Victor Stinner in branch '3.6':
Fix a memory leak in split-table dictionaries
https://hg.python.org/cpython/rev/b70b2d3f3167

--

___
Python tracker 

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



[issue28091] Document PEP 525 & 530

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5a11263bb612 by Yury Selivanov in branch '3.6':
Issue #28091: Document PEP 525 & PEP 530.
https://hg.python.org/cpython/rev/5a11263bb612

--

___
Python tracker 

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



[issue28783] Embedded/nuget packages incorrectly reference bdist_wininst

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 1f69fb337288 by Steve Dower in branch '3.6':
Issue #28783: Replaces bdist_wininst in nuget packages with stub
https://hg.python.org/cpython/rev/1f69fb337288

--

___
Python tracker 

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



[issue28635] Update What's New for 3.6

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset cb4ad88fdc91 by Yury Selivanov in branch '3.6':
Issue #28635: Drop the note that whatsnew is incomplete
https://hg.python.org/cpython/rev/cb4ad88fdc91

New changeset c4d6ef15bb7c by Yury Selivanov in branch '3.6':
Issue #28635: asyncio-related fixes and additions.
https://hg.python.org/cpython/rev/c4d6ef15bb7c

--

___
Python tracker 

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



[issue28979] What's New entry on compact dict mentions "faster" implementation

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 911cc601089d by Victor Stinner in branch '3.6':
Issue #28979: Fix What's New in Python 3.6, dict
https://hg.python.org/cpython/rev/911cc601089d

--

___
Python tracker 

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



[issue28900] update 'docs for other versions'

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 257a1c7f9507 by Ned Deily in branch '3.6':
Issue #28900: Update documentation sidebar for 3.6.0rc.
https://hg.python.org/cpython/rev/257a1c7f9507

--

___
Python tracker 

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



[issue28977] Document PyObject_CallFunction() special case more explicitly

2016-12-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

"O" is not the only special case. "S" and "N" unpack a tuple argument too. "O&" 
converter should return a tuple, otherwise it is an error. All other format 
codes are illegal for single argument.

I would just deprecate this feature (in PyObject_CallFunction, not in 
Py_BuildValue). The behavior of PyObject_CallFunction with a single argument 
can be made more consistent and useful.

--

___
Python tracker 

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



[issue28961] unittest.mock._Call ignores `name` parameter

2016-12-15 Thread Jiajun Huang

Jiajun Huang added the comment:

code and test case has been updated.

--
Added file: http://bugs.python.org/file45922/mock.patch

___
Python tracker 

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



[issue28689] OpenSSL 1.1.0c test failures

2016-12-15 Thread Christian Heimes

Christian Heimes added the comment:

Thanks, Ned!

To clarify, it's not jus the test suite. OpenSSL 1.1.0c broke the ssl module.

--

___
Python tracker 

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



[issue28971] nntplib is broken when responses are longer than _MAXLINE

2016-12-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The limit to readline() was added to prevent consuming an excessive amount of 
memory. But this doesn't help in case of long multiline responses, since all 
lines are accumulated in a list in memory. A malicious server could cause a 
client consuming an excessive amount of memory by sending large number of short 
lines instead of one long line.

Christian, what are you think about this?

--

___
Python tracker 

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



[issue28968] xml rpc server fails with connection reset by peer error no 104

2016-12-15 Thread Manish Singh

Manish Singh added the comment:

Hi David Murray,
Thanks for replying.

I have mentioned that my client and server are running on same host. So 
communication is going through localhost address.

I have checked for possible reasons of connection reset by peer error, below 
are the possible causes,

1) The machine is connected to the network, and the network is not responsive. 
2) The other side of the connection is not running normally. 
3) There are not enough system resources available. Free up system resources if 
they are running low. 

Possibility for 1 and 2 are not applicable as it is loopback communication.

For Possibility 3, I have already checked system resource and there are enough 
resources. 

You can check below stack overflow link.
http://stackoverflow.com/questions/1434451/what-does-connection-reset-by-peer-mean?rq=1

--

___
Python tracker 

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



[issue28985] sqlite3 authorizer codes constants not up to date

2016-12-15 Thread Berker Peksag

Berker Peksag added the comment:

Looks good to me. Thanks for the patch, Dingyuan.

Since this is an enhancement request, we can only commit your patch to the 
default branch so I updated the versions field accordingly.

--
nosy: +berker.peksag
stage:  -> patch review
versions:  -Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

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



Re: A routine to calc Shannon's info entropy. I'm open to improvements/suggestions.

2016-12-15 Thread Steve D'Aprano
On Fri, 16 Dec 2016 09:21 am, DFS wrote:

> Code is based on the formula and results here:
> http://www.shannonentropy.netmark.pl
[...]
> Seems to work fine.
> 
> Any suggestions to improve the code?


- Separate the calculation logic from the display logic as much
  as practical.

- Modular programming: use functions to make it easier to test and easier
  to modify the program in the future, e.g. to add command line options.

- Use standard tools where possible.

- Better, more descriptive names.

- Avoid global variables unless really needed.

- More error checking.

- Errors should exit with a non-zero return code, and should print to
  stderr rather than stdout.

You end up with about twice as much code, but hopefully it is easier to
understand, and it should certainly be easier to debug and maintain if you
decide to change it.



# --- cut ---

# only needed in Python 2
from __future__ import division

import sys
import math
import string

from collections import Counter


def fatal_error(errmsg):
# Python 3 syntax
print(errmsg, file=sys.stderr)
## Python 2 syntax
## print >>sys.stderr, errmsg
sys.exit(1)


def display_header(msg):
print()
print("%s characters in '%s'" % (len(msg), msg))
print()
print(" #   Char  Freq   DistD*log2(D)  H(X) sum")
print("---      --  --  --")


def display_row(row_number, c, freq, dist, entropy, running_total):
args = (row_number, c, freq, dist, entropy, running_total)
template = "%3d  %-4c  %4d  %6.3f  %10.3f  %10.5f"
print(template % args)


def entropy(c, freqs, num_symbols):
"""Return the entropy of character c from frequency table freqs."""
f = freqs[c]/num_symbols
return -f*math.log(f, 2)


def display_results(freqs, Hs, num_symbols):
"""Display results including entropy of each symbol.

Returns the total entropy of the message.
"""
# Display rows with uppercase first, then lower, then digits.
upper = sorted(filter(str.isupper, freqs))
lower = sorted(filter(str.islower, freqs))
digits = sorted(filter(str.isdigit, freqs))
assert set(upper + lower + digits) == set(freqs)
count = 1
running_total = 0.0
for chars in (upper, lower, digits):
for c in chars:
f = freqs[c]
H = Hs[c]
running_total += H
display_row(count, c, f, f/num_symbols, H, running_total)
count += 1
total = running_total
print()
print("The Shannon entropy of your message is %.5f" % total)
print("The metric entropy of your message is %.5f"% (total/num_symbols))
return total


def main(args=None):
if args is None:
args = sys.argv[1:]
if len(args) != 1:
fatal_error("too many or too few arguments")
msg = args[0]
if not msg.isalnum():
fatal_error("only alphanumeric symbols supported")
display_header(msg)
frequencies = Counter(msg)
num_symbols = len(msg)
# Calculate the entropy of each symbol and the total entropy.
entropies = {}
for c in frequencies:
H = entropy(c, frequencies, num_symbols)
entropies[c] = H
total = display_results(frequencies, entropies, num_symbols)



if __name__ == "__main__":
# Only run when module is being used as a script.
main()


# --- cut ---





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: just started

2016-12-15 Thread Chris Angelico
On Fri, Dec 16, 2016 at 3:29 PM,   wrote:
> 2) if I wish to install extra libraries, in particularly SciPy, what's best 
> way of doing it? From command line I see the following commands: pip3 and 
> pip3.5. I guess pip3.5 is for python3.5 ? Can I use pip3 and pip3.5 
> interchangeably, or pip3 will only install things for python3, and not 3.5?
>
> Are all these command equivalent?
>
> pip3 install --user numpy scipy matplotlib
> pip3.5 install --user numpy scipy matplotlib
>
> python3.5 -m pip install numpy scipy matplotlib

In theory, "pip3" will install into the default "python3", whichever
that is. However, in practice, it's entirely possible that it installs
into a very different Python from the one you're expecting. The most
reliable form is the latter; whatever command you use to start Python,
add "-m pip" to it, and you know you're talking to that same
installation.

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


just started

2016-12-15 Thread metal . suomi
Hi everybody, I have just installed python 3.5.2 (downloaded from 
https://www.python.org/) on my mac (El Capitan). 

1) I see from command line that older version of python are already available 
on my machine (python, python2.6, python2.7, python3, python3.5). I guess some 
might have been installed as part of Xcode (?) or via macport (? despite I 
never explicitly asked for python).

2) if I wish to install extra libraries, in particularly SciPy, what's best way 
of doing it? From command line I see the following commands: pip3 and pip3.5. I 
guess pip3.5 is for python3.5 ? Can I use pip3 and pip3.5 interchangeably, or 
pip3 will only install things for python3, and not 3.5?

Are all these command equivalent?

pip3 install --user numpy scipy matplotlib
pip3.5 install --user numpy scipy matplotlib

python3.5 -m pip install numpy scipy matplotlib


3) I also see this command to install it from macport, although not sure it 
will be ok given I didn't install python3.5 via macport but from downaloaded 
package?

sudo port install py35-numpy py35-scipy py35-matplotlib py35-ipython +notebook 
py35-pandas py35-sympy py35-nose

Thanks! I'm going through a very confused start, with too many version and too 
many commands to guess the right way of doing.

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


[issue28689] OpenSSL 1.1.0c test failures

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

I added the following text to the "Notes on this release" section for the 
3.6.0rc1 release page and will copy it to future 3.6.x release pages until 
sometime after a fixed 1.1.0 is released:

"If you are building Python from source, beware that the OpenSSL 1.1.0c 
release, the most recent as of this update, is known to cause Python 3.6 test 
suite failures and its use should be avoided without additional patches. It is 
expected that the next release of the OpenSSL 1.1.0 series will fix these 
problems. See http://bugs.python.org/issue28689 for more information."

https://www.python.org/downloads/release/python-360rc1/

I'm closing this issue for now; feel free to reopen if there is something else 
you plan to do with it.

--
priority: release blocker -> 
resolution:  -> fixed
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



[issue28985] sqlite3 authorizer codes constants not up to date

2016-12-15 Thread Dingyuan Wang

New submission from Dingyuan Wang:

We have the sqlite3.set_authorizer function, where the first argument to its 
callback is one of the Authorizer Action Codes that the SQLite documentations 
defines[1]. However, the constants in the sqlite3 module is not up to date. The 
code in _sqlite/module.c haven't been updated since June, 2006.

According to the SQLite Changelog[2] and digging through the history,

* 2006-08-12 (3.3.7) added SQLITE_CREATE_VTABLE, SQLITE_DROP_VTABLE
* 2006-10-09 (3.3.8) added SQLITE_FUNCTION
* 2009-01-12 (3.6.8) added SQLITE_SAVEPOINT
* 2014-02-03 (3.8.3) added SQLITE_RECURSIVE

The constants above should be present in the module. The documentation[3] says, 
"All necessary constants are available in the sqlite3 module."

[1] https://sqlite.org/c3ref/c_alter_table.html
[2] https://sqlite.org/changes.html
[3] 
https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.set_authorizer

--
components: Library (Lib)
files: sqlite3.patch
keywords: patch
messages: 283363
nosy: gumblex
priority: normal
severity: normal
status: open
title: sqlite3 authorizer codes constants not up to date
type: enhancement
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45921/sqlite3.patch

___
Python tracker 

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



Re: Unicode script

2016-12-15 Thread MRAB

On 2016-12-15 21:57, Terry Reedy wrote:

On 12/15/2016 1:06 PM, MRAB wrote:

On 2016-12-15 16:53, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt



Interestingly, there's issue 6331 "Add unicode script info to the
unicode database". Looks like it didn't make it into Python 3.6.


https://bugs.python.org/issue6331
Opened in 2009 with patch and 2 revisions for 2.x.  At least the Python
code needs to be updated.

Approved in principle by Martin, then unicodedata curator, but no longer
active.  Neither, very much, are the other 2 listed in the Expert's index.

 From what I could see, both the Python API (there is no doc patch yet)
and internal implementation need more work.  If I were to get involved,
I would look at the APIs of PyICU (see Eryk Sun's post) and the
unicodescript module on PyPI (mention by Pander Musubi, on the issue).

For what it's worth, the post has prompted me to get back to a module I 
started which will report such Unicode properties, essentially the ones 
that the regex module supports. It just needs a few more tweaks and 
packaging up...


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


[issue28879] smtplib send_message should add Date header if it is missing, per RFC5322

2016-12-15 Thread R. David Murray

R. David Murray added the comment:

Sure the comments can be updated.  Some of them elsewhere have been already.

The reason for the email library to have a validation function is that it has 
an 'SMTP' policy that is designed to produce valid SMTP messages when the 
message is serialized.  (It also has an HTTP policy that is designed to produce 
valid HTTP header blocks...though I'm sure there are bugs there as well).  
These policies are relatively new, even newer than the send_message method of 
smtplib.

If this gets done it time it could be fixed in 3.5...Larry is planning the 
final non-security-fix 3.5 release some time after 3.6.0 final goes out the 
door, as is our tradition.  After that it could only go into what will very 
shortly be the maintenance release (3.6) and the next feature release (3.7).

To contribute, create a diff against the tip of the default branch and post it 
here.  (We will be switching to github "soon", but posting a patch here will 
always work).  See docs.python.org/devguide for more details on contributing.

--

___
Python tracker 

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



[issue28879] smtplib send_message should add Date header if it is missing, per RFC5322

2016-12-15 Thread Eric Lafontaine

Eric Lafontaine added the comment:

Hi all,

Thanks for the enlightment.  I never figured that there was a send_message 
function XD.  Never needed it and it's true that the example in the email 
library use sendmail and not send_message.
https://docs.python.org/2/library/smtplib.html#smtplib.SMTP.sendmail
https://docs.python.org/3.5/library/smtplib.html#smtplib.SMTP.send_message

This function is fairly recent (python 3.2) from what I see.

Reading the documentation of the python 3.5 send_message function :
"[...] If from_addr is None or to_addrs is None, send_message fills those 
arguments with addresses extracted from the headers of msg as specified in RFC 
5322: from_addr is set to the Sender field if it is present, and otherwise to 
the From field. to_addrs combines the values (if any) of the To, Cc, and Bcc 
fields from msg. "

As we're already using this function for convenience of the RFC 5322, then I 
agree to add it.  We should also modify the doc & comment inside the code to 
make it clear that date is added if absent and following RFC 5322. (I've looked 
at the source and the send_message only mention RFC2822 in the comments, no RFC 
5322).

Finally, why would we want to add a validate fonction to the email library?  
What would it do ? validate that we respect a certain RFC?  Who other than 
SMTPlib would use it?  I would like to understand the reasonning behind it.  

Again, all this are opinions to let the discussion continue :).

For now, what I see we need to do (this bullet point list is intended to be 
expanded with what you think we need to do):
- implement a patch for the code to add a missing "Date" field if it doesn't 
exist
- Modify the documentation at the SMTPLib for the send_message to mention that 
it add missing date using the email.utils.formatdate
- Modify the comment of the send_message code to mention RFC 5322 in there 
(ideally with the section of the RFC).
- Fix it on all Python3 versions?  It should have been supported since 3.2 
right?

As it's my first time trying to contribute... I still don't know how to do so...

Regards,
Eric Lafontaine
eric.lafontai...@gmail.com <= if you can help me outside of this discussion to 
contribute, it would be my pleasure.

--

___
Python tracker 

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



[issue28794] inspect.isasyncgen and inspect.isasyncgenfunction aren't documented

2016-12-15 Thread Berker Peksag

Berker Peksag added the comment:

Thanks for the patch, but these two functions have already been documented in 
78c8f450b84c. Closing this as 'out of date'.

--
nosy: +berker.peksag
resolution:  -> out of date
stage: commit review -> resolved
status: open -> closed
type:  -> enhancement

___
Python tracker 

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



[issue28972] Document all "python -m" utilities

2016-12-15 Thread Eric Lafontaine

Eric Lafontaine added the comment:

Hi,

I believe it's already done.  The only thing that people tends to forget is 
that doing python -m "module.script(.py)" is only doing the equivalent of 
"python module/script.py". 

I believe it's clear though ;
https://docs.python.org/3/using/cmdline.html#cmdoption-m

Any module that anyone has done can do it, so it would be up to the module 
developer to put it in the README/Description of the module to describe how to 
use it.  That's what I think

BTW, I'm just giving my opinion out of contributing.  Please don't see it as a 
denial as it's not the case.  Python strive to be clearer but has 20 years of 
existence.  Enhancing it is hard.

Regards,
Eric Lafontaine

--
nosy: +Eric Lafontaine

___
Python tracker 

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



[issue28983] Python 3.5.2 won't install on my computer

2016-12-15 Thread Rhesa Browning

Rhesa Browning added the comment:

I went through your instructions without any improvement.  I first uninstalled 
the program.  Then I reinstalled without the items that you listed the tcl/tk 
and pip.  The error message still came up just like before.  Then I typed the 
two programs you gave me into the command prompt.  A message asked me for 
permission to uninstall the program, which I accepted.  Then I got an error 
message that said the program only works for products that are already 
installed.

If I try to open python now, I get the same error message "The program can't 
start because python35.dll is missing from your computer."

--

___
Python tracker 

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



Re: The right way to 'call' a class attribute inside the same class

2016-12-15 Thread Chris Angelico
On Fri, Dec 16, 2016 at 11:36 AM, Erik  wrote:
> On 12/12/16 23:23, Chris Angelico wrote:
>>
>> In JavaScript, it's normal to talk about "calling a function as a
>> constructor". When you do, there is a 'this' object before you start.
>
>
> No there isn't. There is an implicit binding of a variable called "this"
> based on the syntactic sugar of whether you're calling a function as method
> on an object or not.
>
> In "strict" mode, this has been redefined to be "undefined" (i.e., there is
> no object) for when you're not - otherwise it will be a binding to the
> global "document" object (and in Node.js, I think something else entirely.
> It's a mess ...).

I'm talking about when you call a function as a constructor: "new
Foo()". Doesn't that have a 'this' object before the function starts?

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


[issue28982] multiprocessing.Queue.get(block=True, timeout=0) always raises queue.Empty

2016-12-15 Thread Josh Rosenberg

Josh Rosenberg added the comment:

That argument combination appears to be undefined in the docs, the only cases 
covered are:

block truthy, timeout is None

block truthy, timeout is positive

block falsy, (timeout unspecified)

The case of block truthy, timeout <= 0 is not documented.

Saying "Block for a result, but not for any length of time" is a tad strange; 
I'd be inclined to make it an error, not a synonym for block == False.

--
nosy: +josh.r

___
Python tracker 

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



[issue28984] json.dump + indent creates trailing extra spaces

2016-12-15 Thread Ned Deily

Ned Deily added the comment:

I agree with Josh's assessment. Sorry!

--
nosy: +ned.deily
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



[issue28969] lru_cache is not threadsafe

2016-12-15 Thread Josh Rosenberg

Changes by Josh Rosenberg :


--
nosy: +josh.r

___
Python tracker 

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



[issue28984] json.dump + indent creates trailing extra spaces

2016-12-15 Thread Josh Rosenberg

Josh Rosenberg added the comment:

This is documented behavior for Python 2 ( 
https://docs.python.org/2/library/json.html#basic-usage ):

>Note: Since the default item separator is ', ', the output might include 
>trailing whitespace when indent is specified. You can use separators=(',', ': 
>') to avoid this.

and also:

If specified, separators should be an (item_separator, key_separator) tuple. By 
default, (', ', ': ') are used. To get the most compact JSON representation, 
you should specify (',', ':') to eliminate whitespace.

Python 3 gives a different guarantee (dynamically chosen default separators 
based on the value of indent), and it follows that contract.

Given it's clearly documented, easily worked around, and largely harmless, I 
see no strong argument for backporting the Python 3 behavior to the legacy 
codebase.

--
nosy: +josh.r

___
Python tracker 

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



Re: The right way to 'call' a class attribute inside the same class

2016-12-15 Thread Erik

On 12/12/16 23:23, Chris Angelico wrote:

In JavaScript, it's normal to talk about "calling a function as a
constructor". When you do, there is a 'this' object before you start.


No there isn't. There is an implicit binding of a variable called "this" 
based on the syntactic sugar of whether you're calling a function as 
method on an object or not.


In "strict" mode, this has been redefined to be "undefined" (i.e., there 
is no object) for when you're not - otherwise it will be a binding to 
the global "document" object (and in Node.js, I think something else 
entirely. It's a mess ...).



Ultimately, every language has slightly different semantics


You're not wrong ;)

E.

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


Re: The right way to 'call' a class attribute inside the same class

2016-12-15 Thread Erik

On 13/12/16 06:14, Gregory Ewing wrote:

Ned Batchelder wrote:

if a C++ constructor raises an exception, will the corresponding
destructor
be run, or not? (No, because it never finished making an object of
type T.)


So it just leaks any memory that's been allocated by
the partially-run constructor?


If you're referring to resources in general that a constructor (in the 
C++ sense) allocates - memory, file descriptors, whatever - then it's up 
to the constructor to release those resources before throwing the 
exception should something fail. Destructors are not executed for 
objects that were not constructed.


If the constructor is not written to that standard, then yes - it will 
leak resources.


The memory allocated for the _object_ itself will be released though.

Regards, E.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python constructors have particular semantics2c and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Steve D'Aprano
On Fri, 16 Dec 2016 08:09 am, Terry Reedy wrote:

> The __init__ function *is* an 'instance method', but not a (bound)
> method object.  The distinction is important.  I admit that 'instance
> method' can be confusing if one does not understand the contextual
> meaning of the two words.  A 'method' is a function that is a class
> attribute. Being a method normally adds special behavior to the
> function.  An 'instance method', the default status of a method,  takes
> an *instance of the class* (or subclass) as first parameter.  A 'class
> method' (relatively rare) takes the *class* (or subclass) as first
> parameter.   A 'static method' (very rare) takes neither as first
> parameter and is really just a function.

I think that what Terry might be trying to get at is that there's actually
two distinct but related meanings for "instance method" in the context of
Python. (Other languages may be different.)

(Terry, forgive me if I'm misinterpreting what you are saying.)

The first is an object of type types.MethodType. Because functions and
methods are first-class values in Python, such instance methods could be
stuffed into lists, attached as attributes to unrelated objects, bound to
variables, etc. Instance methods are just a data type, and could come from
anywhere.

Proof of concept:

py> class X(object):
... pass
...
py> x = X()
py> from types import MethodType
py> def method(self):
... print("method bound to", self)
...
py> x.surprise = MethodType(method, "Hello world!")
py> x.surprise()
method bound to Hello world!


But the usual meaning of "instance method" is a function defined inside a
class body (with exceptions below):

class X(object):
def method(self):
...


That is *conceptually* an instance method even if the implementation uses an
object of different type. In Python 2, retrieving "method" from either the
class or the instance returns something which matches both definitions of
object:

X.method returns an "unbound method", an object of type MethodType;
X().method returns a "bound method", also an object of type MethodType.


But in Python 3, it is recognised that there is little or no conceptual
difference between an unbound method and a function, and the implementation
is changed:

X.method returns an "unbound method", an object of type FunctionType;
X().method returns a "bound method", an object of type MethodType.


But whether the implementation is a special form of MethodType or just
FunctionType, the object is still conceptually an instance method.


The exceptions to the "function defined inside a class body" rule includes
two built-in types used as decorators:

classmethod
staticmethod

which are deemed to be "kinds of methods" but not *instance* methods. In
Python, we call them "class methods" and "static methods", but in other
languages they may not exist at all or have other names.

(In Java, the closest equivalent to "class method" is called a "static
method".)



Adding to the complexity, the __name__ of MethodType is just "method", and
the __name__ of FunctionType is just "function", so introspecting the
objects (looking at their repr() etc) may give slightly different results.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


[issue28984] json.dump + indent creates trailing extra spaces

2016-12-15 Thread Knut

New submission from Knut:

module json
python 2.7.12

json.dump(..., indent=4, sort_keys=True) gives me:

{
"size": {
"total": 19106,X
"code": 18614,X
"data": 492
},X
"next_item": 10
}


The "X" mark extra trailing space characters which are needless.

--
components: Library (Lib)
messages: 283354
nosy: voxspox
priority: normal
severity: normal
status: open
title: json.dump + indent creates trailing extra spaces
type: resource usage
versions: Python 2.7

___
Python tracker 

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



[issue28091] Document PEP 525 & 530

2016-12-15 Thread Yury Selivanov

Changes by Yury Selivanov :


--
title: Document PEP 525 -> Document PEP 525 & 530

___
Python tracker 

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



[issue28635] Update What's New for 3.6

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 418ba3a0f090 by Yury Selivanov in branch '3.6':
Issue #28635: asyncio-related fixes and additions.
https://hg.python.org/cpython/rev/418ba3a0f090

New changeset 83eb8053a4e1 by Yury Selivanov in branch 'default':
Merge 3.6 (issue #28635)
https://hg.python.org/cpython/rev/83eb8053a4e1

--

___
Python tracker 

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



[issue28983] Python 3.5.2 won't install on my computer

2016-12-15 Thread Steve Dower

Steve Dower added the comment:

(For anyone who comes here later, those last two commands are specially crafted 
for this situation based on the attached log files. You'll likely need 
different commands for whatever your situation is.)

--

___
Python tracker 

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



[issue28983] Python 3.5.2 won't install on my computer

2016-12-15 Thread Steve Dower

Steve Dower added the comment:

It looks like you have a partial install there, possibly from an earlier 
version.

Do you see a "Python" entry in Programs and Features? If so, running a Repair 
on that may help, or removing it.

If you don't see another entry there, installing Python without tcl/tk support 
(which seems to be breaking when it gets up to doing shortcuts) and without pip 
support may get you to the end of an install, at which point you can run a 
repair that should bring back the missing files.

As a last resort, running these commands from the command line might also help 
clean things up:

msiexec /x {EB0611B2-7F10-4D97-BCF2-DCAAB1199498}
msiexec /x {5DB2183B-62D3-407F-BBC1-EAD2F36283FA}

If you get as far as running these, I'd keep running them repeatedly until you 
start getting errors (this is to make sure you aren't decreasing a reference 
count from 3 to 2 - we want it to go all the way to 0).

--

___
Python tracker 

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



[issue28090] Document PEP 530

2016-12-15 Thread Yury Selivanov

Yury Selivanov added the comment:

Closing this one, the issue was resolved as part of #28091.

--
priority: deferred blocker -> normal
resolution:  -> fixed
stage: needs patch -> resolved
status: open -> closed
superseder:  -> Document PEP 525

___
Python tracker 

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



[issue28091] Document PEP 525

2016-12-15 Thread Yury Selivanov

Yury Selivanov added the comment:

Pushed.  Thanks a lot, Eric, very good job!  (BTW, please enable trailing 
whitespace trimming in your editor)

Ned, maybe you want to cherry-pick this commit to 3.6.0, but I guess most 
people just use docs.python.org, so it's not that important.

--
resolution:  -> fixed
stage: needs patch -> 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



[issue28091] Document PEP 525

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 78c8f450b84c by Yury Selivanov in branch '3.6':
Issue #28091: Document PEP 525 & PEP 530.
https://hg.python.org/cpython/rev/78c8f450b84c

New changeset 6bf84e661e69 by Yury Selivanov in branch 'default':
Merge 3.6 (issue #28091)
https://hg.python.org/cpython/rev/6bf84e661e69

--
nosy: +python-dev

___
Python tracker 

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



[issue28983] Python 3.5.2 won't install on my computer

2016-12-15 Thread eryk sun

Changes by eryk sun :


--
components: +Installation, Windows
nosy: +paul.moore, steve.dower, tim.golden, zach.ware
type: performance -> behavior

___
Python tracker 

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



[issue28879] smtplib send_message should add Date header if it is missing, per RFC5322

2016-12-15 Thread Maciej Szulik

Maciej Szulik added the comment:

I've chatted a bit with David about this feature. Here are some thoughts:
- check what SMTP standard says about some validation rules
- add validate method, probably into email package

--

___
Python tracker 

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



[issue28983] Python 3.5.2 won't install on my computer

2016-12-15 Thread Rhesa Browning

New submission from Rhesa Browning:

When I install Python, I get an error message saying that the python35.dll file 
doesn't exist on my computer. That is at far as it goes.  I have attached a RAR 
folder with the logs from the times I tried to install.

--
files: Python installation archive.rar
messages: 283346
nosy: Rhesa Browning
priority: normal
severity: normal
status: open
title: Python 3.5.2 won't install on my computer
type: performance
versions: Python 3.5
Added file: http://bugs.python.org/file45920/Python installation archive.rar

___
Python tracker 

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



Re: Unicode script

2016-12-15 Thread Terry Reedy

On 12/15/2016 1:06 PM, MRAB wrote:

On 2016-12-15 16:53, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt



Interestingly, there's issue 6331 "Add unicode script info to the
unicode database". Looks like it didn't make it into Python 3.6.


https://bugs.python.org/issue6331
Opened in 2009 with patch and 2 revisions for 2.x.  At least the Python 
code needs to be updated.


Approved in principle by Martin, then unicodedata curator, but no longer 
active.  Neither, very much, are the other 2 listed in the Expert's index.


From what I could see, both the Python API (there is no doc patch yet) 
and internal implementation need more work.  If I were to get involved, 
I would look at the APIs of PyICU (see Eryk Sun's post) and the 
unicodescript module on PyPI (mention by Pander Musubi, on the issue).


--
Terry Jan Reedy


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


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Thomas Nyberg

On 12/15/2016 12:48 PM, Terry Reedy wrote:

On 12/15/2016 12:27 PM, Thomas Nyberg wrote:


I haven't dealt with a data structure exactly like this, but it's
basically a sparse array.


A sparse array has at least half missing values.  This one has none on
the defined domain, but contiguous dupicates.



I'm sorry for devolving into semantics, but there certainly isn't a 
single definition of "sparse array" out there. For example, the 
definition in wikipedia (https://en.wikipedia.org/wiki/Sparse_array) 
doesn't agree with you:


"In computer science, a sparse array is an array in which most of the 
elements have the default value (usually 0 or null)."


Personally my usage of sparse arrays in scipy has _always_ had all 
defined values it's just that the default value was 0. I never deal with 
"missing" values.



(I'm sure it has a name somewhere in the
academic literature, but I couldn't find it with a quick search right
now...)


'Sparse array' is the name for sparse arrays.  I cannot think of one for
blocks of duplicates.



Yeah that's why I said "basically a sparse array". It has the same 
defining characteristics. It is a situation where you have a large 
number of values associated to a small number of values in such a way 
that you can fairly easily describe the association without needing to 
simply write out all pairs. For regular sparse arrays it's easy because 
you associate them to a single value by default and only specify the 
ones that aren't. In this case that doesn't work, but due to the fact 
that you have long runs of repeated values you can use that to encode 
and compress the mapping.


Still not sure what to call it. I like D'Arcy's idea of subclassing a 
dict in combination with Peter's idea of using bisect (I had no idea 
that module existed!) so maybe I'll change my own not so great 
terminology to "basically a sparse map".


Cheers,
Thomas
--
https://mail.python.org/mailman/listinfo/python-list


[issue28518] execute("begin immediate") throwing OperationalError

2016-12-15 Thread Aviv Palivoda

Aviv Palivoda added the comment:

I think that adding Serhiy patch in addition to the documentation improvement 
in issue #8145 would be the best way to proceed. This will insure no regression 
problems.
We can add a warning when someone try to use BEGIN, ROLLBACK, SAVEPOINT, and 
RELEASE without changing the isolation_level to None.

--

___
Python tracker 

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



Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Terry Reedy

On 12/15/2016 2:04 PM, Ian Kelly wrote:

On Thu, Dec 15, 2016 at 11:05 AM, Terry Reedy  wrote:

On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote:


According to
,
“Foo.__init__” is _not_ an instance method.  Were it an instance
method, the following would not happen:



This link points to subsection 9.3.4. Method Objects


| >>> class Foo:
| ... def __init__ (self):
| ... pass
| ...
| >>> Foo.__init__.__self__
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: 'function' object has no attribute '__self__'



You have misread the docs.  Foo.__init__ is the function. Foo().__init__ is
a method object with the attribute __self__.  You omitted the ()s.


I think this is actually the point that Thomas was making. He was
responding to the assertion that "Foo.__init__" is an instance method
and demonstrating that it's false because Foo is the class, not an
instance of Foo.


The __init__ function *is* an 'instance method', but not a (bound) 
method object.  The distinction is important.  I admit that 'instance 
method' can be confusing if one does not understand the contextual 
meaning of the two words.  A 'method' is a function that is a class 
attribute. Being a method normally adds special behavior to the 
function.  An 'instance method', the default status of a method,  takes 
an *instance of the class* (or subclass) as first parameter.  A 'class 
method' (relatively rare) takes the *class* (or subclass) as first 
parameter.   A 'static method' (very rare) takes neither as first 
parameter and is really just a function.


--
Terry Jan Reedy


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


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Terry Reedy

On 12/15/2016 12:27 PM, Thomas Nyberg wrote:

On 12/15/2016 09:06 AM, Steve D'Aprano wrote:

Has anyone dealt with data like this and could give a recommendation
of the
right data structure to use?



I haven't dealt with a data structure exactly like this, but it's
basically a sparse array.


A sparse array has at least half missing values.  This one has none on 
the defined domain, but contiguous dupicates.


> (I'm sure it has a name somewhere in the

academic literature, but I couldn't find it with a quick search right
now...)


'Sparse array' is the name for sparse arrays.  I cannot think of one for 
blocks of duplicates.


--
Terry Jan Reedy

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


[issue28982] multiprocessing.Queue.get(block=True, timeout=0) always raises queue.Empty

2016-12-15 Thread Ryan Brindley

New submission from Ryan Brindley:

Hey dev team,

According to the following test, `q.get(True, 0)` always raises queue.Empty.

from multiprocessing import Queue
q = Queue()
q.put('foo')
q.get(True, 0)  # raises Empty

This result throws me off as I was expecting a similar result to the underlying 
poll/select timeout where 0 actually just means non-blocking.

After reviewing Lib/multiprocessing/queues.py, I found the condition where the 
timeout, after the adjustment for the time required to acquire the lock, would 
not even call poll() if it was less than 0.

So, linked is a simple PR that I'm offering as a suggested fix/behavior-change 
of Queue.get's handling of timeout=0 to match the underlying poll/select 
handling (aka non-blocking).

Cheers,

Ryan Brindley

--
components: Library (Lib)
messages: 283344
nosy: Ryan Brindley
priority: normal
pull_requests: 5
severity: normal
status: open
title: multiprocessing.Queue.get(block=True, timeout=0) always raises 
queue.Empty
type: behavior
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: Mapping with continguous ranges of keys

2016-12-15 Thread Terry Reedy

On 12/15/2016 12:06 PM, Steve D'Aprano wrote:

I have some key:value data where the keys often are found in contiguous
ranges with identical values. For example:

{1: "foo",
 2: "foo",
 3: "foo",
 # same for keys 4 through 99
 100: "foo",
 101: "bar",
 102: "bar",
 103: "foobar",
 104: "bar",
 105: "foo",
}


For this particular example (untested):

def lookup(n):
F, B, FB = 'foo', 'bar', 'foobar'  # Ensure value objects reused
if 1 <= n <= 100:
return F
elif 101 <= n <= 105:
return (B, B, FB, B, F')[n - 101]
else:
raise ValueError('n must be in range(1, 106)')


So in this case, the keys 1 through 100, plus 105, all have the same value.

I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.



Has anyone dealt with data like this and could give a recommendation of the
right data structure to use?

The obvious way is to explicitly list each key, in a regular dict. But I
wonder whether there are alternatives which may be better (faster, more
memory efficient)?


If, as in the example, the keys comprise a contiguous sequence of ints, 
the 'obvious' way to me is sequence of values.  A tuple of constants 
gets compiled and will load quickly from a .pyc file.  4 or 8 bytes per 
entry times 1 or 2 million entries is usually tolerable on a gigabyte 
machine.


Or trade time for space with binary search or search in explicit binary 
tree.  Or combine binary search and indexed lookup as I did above.



--
Terry Jan Reedy

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


[issue28982] multiprocessing.Queue.get(block=True, timeout=0) always raises queue.Empty

2016-12-15 Thread Ned Deily

Changes by Ned Deily :


--
nosy: +davin

___
Python tracker 

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



RE: Re: Install Problem

2016-12-15 Thread Rhesa Browning
Eryk sun.  I have not been able to find the temp folder.  I am doing this on a 
work computer and don't have access to all the folders.  Some are hidden.

-Original Message-
From: eryk sun [mailto:eryk...@gmail.com] 
Sent: Tuesday, December 13, 2016 3:49 PM
To: Python-list@python.org
Cc: Rhesa Browning 
Subject: [EXTERNAL] Re: Install Problem

On Tue, Dec 13, 2016 at 8:37 PM, Rhesa Browning  wrote:
> I have been trying to install Python 3.5.2 onto my computer.  I have 
> installed and uninstalled and resinstalled several times.  Every time 
> I get an error message saying that the python35.dll doesn't exist on my 
> computer so it can't open Python.
> How can this problem be fixed?

Please open an issue at bugs.python.org. Zip the installation logs ("Python 
3.5.2*.log") from your %temp% folder, and upload them to the issue.
3M security scanners have not detected any malicious content in this message.

To report this email as SPAM, please forward it to s...@websense.com
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26919] on Android python fails to decode/encode command line arguments

2016-12-15 Thread Xavier de Gaye

Changes by Xavier de Gaye :


--
resolution:  -> fixed
stage: commit 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



Re: Re: Install Problem

2016-12-15 Thread eryk sun
On Thu, Dec 15, 2016 at 8:24 PM, Rhesa Browning  wrote:
> I have not been able to find the temp folder.  I am doing this on a work 
> computer
> and don't have access to all the folders.  Some are hidden.

Enter %temp% in Explorer's location bar or the Win+R dialog.
-- 
https://mail.python.org/mailman/listinfo/python-list


A comparatively efficient software for embedding secret information bits into nataural language texts

2016-12-15 Thread Mok-Kong Shen


WORDLISTTEXTSTEGANOGRAPHY is a new software (employing an extensive
English word list) which, while performing linguistic steganography,
also involves pseudo-random separation of the word list into two
sublists (for denoting 0 and 1 bits) that are dependent on dynamic
session-key materials, thus furnishing simultaneously substantial
cryptographical security for the embedded stego bits.

The software has a stegobit embedding rate of roughly 0.5 or higher
per word of cover-text which the user composes to be as natural as
possible under the guidance of the software. To my knowledge there
is currently no other linguistic stego software that could compete
with it, when both the naturalness of the cover texts and the
stegobit embedding rate are taken into consideration as evaluation
criteria.

The software in Python with a GUI coded in tkinter is available at:
http://s13.zetaboards.com/Crypto/topic/9024439/1/

For comments and critiques I should be very grateful.

M. K. Shen
--
https://mail.python.org/mailman/listinfo/python-list


[issue28794] inspect.isasyncgen and inspect.isasyncgenfunction aren't documented

2016-12-15 Thread Emanuel Barry

Emanuel Barry added the comment:

LGTM. Thanks for the patch!

--
nosy: +ebarry
stage:  -> commit review

___
Python tracker 

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



[issue26919] on Android python fails to decode/encode command line arguments

2016-12-15 Thread Xavier de Gaye

Xavier de Gaye added the comment:

Forgot the issue number in the commit message for the default branch, the 
corresponding changeset is 80a041d39c20.

--

___
Python tracker 

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



[issue26919] on Android python fails to decode/encode command line arguments

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset e5360d413ce4 by Xavier de Gaye in branch '3.6':
Issue #26919: On Android, operating system data is now always encoded/decoded
https://hg.python.org/cpython/rev/e5360d413ce4

--
nosy: +python-dev

___
Python tracker 

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



Re: Unicode script

2016-12-15 Thread Terry Reedy

On 12/15/2016 11:53 AM, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".

Is this information available from Python?




Yes, though not as nicely as you probably want.  (Have you searched for 
existing 3rd party modules?)  As near as I can tell, there is no direct 
'script' property in the unicodedatabase.


Option 1: unicodedata module, from char name

>>> import unicodedata as ucd
>>> ucd.name('\u03be')
'GREEK SMALL LETTER XI'
>>> ucd.name('\u0061')
'LATIN SMALL LETTER A'

In most cases, the non-common char names start with a script name.
In some cases, the script name is 2 or w words.

>>> ucd.name('\U00010A60')
'OLD SOUTH ARABIAN LETTER HE'

In a few cases, the script name is embedded in the name.
>>> ucd.name('\U0001F200')
'SQUARE HIRAGANA HOKA'

Occasionally the script name is omitted.
>>> ucd.name('\u3300')
'SQUARE APAATO'  # Katakana

To bad the Unicode Consortium did not use a consistent name scheme:
script [, subscript]: character

LATIN: SMALL LETTER A
ARABIAN, OLD SOUTH: LETTER HE
KATAKANA: SQUARE APAATO


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt


Option 2: Fetch the above Scripts.txt.

Suboption 1: Turn Scripts.txt into a list of lines.  The lines could be 
condensed to codepoint or codepoint range, script.  Write a function 
that takes a character or codepoint and linearly scans the list for a 
matching line.  This makes each lookup O(number-of-lines).


Suboption 2. Turn Scripts.txt into a list of scripts, with codepoint 
being the index.  This takes more preparation, but makes each lookup 
O(1).  Once the preparation is done, the list could be turned into a 
tuple and saved as a .py file, with the tuple being a compiled constant 
in a .pyc file.


To avoid bloat, make sure that multiple entries for a script use the 
same string object instead of multiple equal strings.  (CPython string 
interning might do this automatically, but cross-implementation code 
should not depend on this.)  The difference is


scripts = [..., 'Han', 'Han', 'Han', ...] # multiple strings
versus
HAN = 'Han'
scripts = [..., HAN, HAN, HAN, ...]  # multiple references to one string

On a 64 bit OS, the latter would use 8 x defined codepoints (about 
200,000) bytes.  Assuming such does not already exits, it might be worth 
making such a module available on PyPI.



http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt


Essentially, ditto, except that I would use a dict rather than a 
sequence as there are only about 400 codepoints involved.


--
Terry Jan Reedy


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


[issue26919] on Android python fails to decode/encode command line arguments

2016-12-15 Thread Xavier de Gaye

Xavier de Gaye added the comment:

The patch fixes also the following errors in test_warnings:

==
FAIL: test_nonascii (test.test_warnings.CEnvironmentVariableTests)
--
Traceback (most recent call last):
  File 
"/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_warnings/__init__.py", 
line 1072, in test_nonascii
"['ignore:Deprecaci\xf3nWarning']".encode('utf-8'))
AssertionError: b"['ignore:Deprecaci\\udcc3\\udcb3nWarning']" != 
b"['ignore:Deprecaci\xc3\xb3nWarning']"

==
FAIL: test_nonascii (test.test_warnings.PyEnvironmentVariableTests)
--
Traceback (most recent call last):
  File 
"/sdcard/org.bitbucket.pyona/lib/python3.7/test/test_warnings/__init__.py", 
line 1072, in test_nonascii
"['ignore:Deprecaci\xf3nWarning']".encode('utf-8'))
AssertionError: b"['ignore:Deprecaci\\udcc3\\udcb3nWarning']" != 
b"['ignore:Deprecaci\xc3\xb3nWarning']"

--

--

___
Python tracker 

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



Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Ian Kelly
On Thu, Dec 15, 2016 at 11:05 AM, Terry Reedy  wrote:
> On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote:
>
>> According to
>> ,
>> “Foo.__init__” is _not_ an instance method.  Were it an instance
>> method, the following would not happen:
>
>
> This link points to subsection 9.3.4. Method Objects
>
>> | >>> class Foo:
>> | ... def __init__ (self):
>> | ... pass
>> | ...
>> | >>> Foo.__init__.__self__
>> | Traceback (most recent call last):
>> |   File "", line 1, in 
>> | AttributeError: 'function' object has no attribute '__self__'
>
>
> You have misread the docs.  Foo.__init__ is the function. Foo().__init__ is
> a method object with the attribute __self__.  You omitted the ()s.

I think this is actually the point that Thomas was making. He was
responding to the assertion that "Foo.__init__" is an instance method
and demonstrating that it's false because Foo is the class, not an
instance of Foo.

If I've observed anything about Thomas over the years he's been
posting here, it's that he's extremely literal and will pick apart
tiny irrelevant nuances to the point of being (or at least appearing)
trollish.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Wildman via Python-list
On Thu, 15 Dec 2016 11:11:51 -0500, Jed Mack wrote:

> We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
> which are members of a school network.
> 
> 
> 
> The program seems to install correctly, but when we try to run the program
> it stops and give an error message saying:
> 
> 
> 
> *Fatal Python error: Py_Initialize: unable to load the file system codec*
> 
> *Traceback (most recent call last):*
> 
> *  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
> module>*
> 
> *zipimport.ZipImportError: can't find module 'codecs'*
> 
> 
> 
> 
> 
> On a Windows 7 PCs, on the same network, the program runs with no problems.
> 
> 
> 
> We have no one here who is familiar with Python.  Do you have any
> additional information on this error, and suggestions for fixing it?
> 
> 
> 
> We have a teacher who needs this program on Windows 10 PCs for students to
> use beginning January 3.
> 
> 
> 
> Thanks,
> 
> Jed Mack

You might try adding the installation folders to the path, if it
hasn't been done already.  Change 'python' to the actual folder name.

C:\python
C:\python\Lib\site-packages
C:\python\Scripts

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Reading python list as a newsgroup (was ...)

2016-12-15 Thread Terry Reedy

On 12/15/2016 6:23 AM, skybuck2...@hotmail.com wrote:


Anyway... my ISP has problems accessing their newsserver. ...


If you want to read python-list as a news group, you might try 
news.gmane.org.  About once a year, it goes down for a few hours to a 
day, but has otherwise been dependable.  I found it when my ISP dropped 
newsgroup access around a decade ago.


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


Re: Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Tim Golden

On 15/12/2016 16:11, Jed Mack wrote:

We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
which are members of a school network.

The program seems to install correctly, but when we try to run the program
it stops and give an error message saying:

*Fatal Python error: Py_Initialize: unable to load the file system codec*

*Traceback (most recent call last):*

*  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
module>*

*zipimport.ZipImportError: can't find module 'codecs'*

On a Windows 7 PCs, on the same network, the program runs with no problems.

We have no one here who is familiar with Python.  Do you have any
additional information on this error, and suggestions for fixing it?

We have a teacher who needs this program on Windows 10 PCs for students to
use beginning January 3.


This most often seems to happen when there is another instance of Python 
installed (or, possibly, previously installed and partly uninstalled). 
Especially: look for environment variables which could be left over from 
such an installation, particularly PYTHONHOME.


NB it's possible for Python to have been installed as part of some OEM 
software, ie not as part of your school's own installation protocol.


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


Re: Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Terry Reedy

On 12/15/2016 11:11 AM, Jed Mack wrote:

We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
which are members of a school network.

The program seems to install correctly,


Is Python installed on each machine or on a network server?
Rather precisely, how was Python installed?
What installation package was downloaded?  From where?
How was it run?

> but when we try to run the program

it stops and give an error message saying:

*Fatal Python error: Py_Initialize: unable to load the file system codec*

*Traceback (most recent call last):*

*  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
module>*


The line is
import codecs


*zipimport.ZipImportError: can't find module 'codecs'*


This says that the stdlib is in the form of a zipfile instead of the 
normal /lib directory.  I don't know how one gets that result on 
Windows.  It appears that the zipped library is missing the file.



On a Windows 7 PCs, on the same network, the program runs with no problems.


Same Python version?  Same installation file?  Run the same way?


We have no one here who is familiar with Python.  Do you have any
additional information on this error, and suggestions for fixing it?



We have a teacher who needs this program on Windows 10 PCs for students to
use beginning January 3.


We appreciate that you are trying to use current Python to teach.  I 
hope we are able to solve the problem, given more information.


--
Terry Jan Reedy

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


[issue28147] Unbounded memory growth resizing split-table dicts

2016-12-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I asked a question about the change in _PyObjectDict_SetItem. It is not clear 
to me.

--

___
Python tracker 

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



Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-15 Thread Peter Pearson
On Wed, 14 Dec 2016 11:50:30 -0600, Skip Montanaro wrote:
> On Wed, Dec 14, 2016 at 11:40 AM, Peter Pearson
> wrote:
>> Train your fingers to use C-[.
>
> As I recall, the location of the Ctrl key was one of the differences
> between Sun and PC101 keyboards. Doesn't matter so much now, as Sun
> has gone the way of the dodo, but it moved around more for me than ESC
> over the years.

Absolutely right.  Random migrations of the Ctrl key annoyed so many
of us set-in-our-ways geezers that Linux distributions always seem to
come with an easily activated option to put the Ctrl key where it
belongs, namely to the left of the A, right where God put it on Adam's
ASR 33.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28981] distutils/check.py overzealous catch block hides errors

2016-12-15 Thread Matt Bogosian

New submission from Matt Bogosian:

>From (e.g) 
>https://github.com/python/cpython/blob/2.7/Lib/distutils/command/check.py#L145:

{{{
try:
parser.parse(data, document)
except AttributeError as e:  # <- this could happen anywhere inside 
parser.parse
reporter.messages.append(
(-1, 'Could not finish the parsing: %s.' % e, '', {}))
}}}

Without a stack trace, diagnosing problems like #23063 becomes unnecessarily 
difficult. See also:

* https://sourceforge.net/p/docutils/bugs/270/
* https://sourceforge.net/p/docutils/bugs/302/

I'd offer a patch, but I'm not sure what is meant to be signaled by the 
`AttributeError`. (Could `parser.parse` not exist? Is it something else?)

--
components: Distutils
messages: 283338
nosy: dstufft, eric.araujo, posita
priority: normal
severity: normal
status: open
title: distutils/check.py overzealous catch block hides errors
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5

___
Python tracker 

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



Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Terry Reedy

On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote:


According to , 
“Foo.__init__” is _not_ an instance method.  Were it an instance
method, the following would not happen:


This link points to subsection 9.3.4. Method Objects


| >>> class Foo:
| ... def __init__ (self):
| ... pass
| ...
| >>> Foo.__init__.__self__
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: 'function' object has no attribute '__self__'


You have misread the docs.  Foo.__init__ is the function. 
Foo().__init__ is a method object with the attribute __self__.  You 
omitted the ()s.


>>> class C:
def __init__(self): pass


>>> ci = C().__init__
>>> ci.__self__
<__main__.C object at 0x01E38A750E80>


Because “Instance method objects have attributes, too: m.__self__ is the
instance object with the method m() […]”.


This line is from section 9.7. Odds and Ends. In this quote, 'm' is a 
method object, the result of 'instance.method, not a function.  In 
Python 2, 'm' would have been called a 'bound method', as opposed to an 
unbound method.  Since the latter were eliminated in 3.x, the adjective 
is no longer needed.




--
Terry Jan Reedy


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


Re: Unicode script

2016-12-15 Thread MRAB

On 2016-12-15 16:53, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt


Interestingly, there's issue 6331 "Add unicode script info to the 
unicode database". Looks like it didn't make it into Python 3.6.


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


[issue28147] Unbounded memory growth resizing split-table dicts

2016-12-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I think this can be tested without _testcapi. See an example in issue28894.

--

___
Python tracker 

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



Re: Unicode script

2016-12-15 Thread Joel Goldstick
I think this might be what you want:
https://docs.python.org/3/howto/unicode.html#unicode-properties

On Thu, Dec 15, 2016 at 11:53 AM, Steve D'Aprano
 wrote:
> Suppose I have a Unicode character, and I want to determine the script or
> scripts it belongs to.
>
> For example:
>
> U+0033 DIGIT THREE "3" belongs to the script "COMMON";
> U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
> U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".
>
>
> Is this information available from Python?
>
>
> More about Unicode scripts:
>
> http://www.unicode.org/reports/tr24/
> http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
> http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode script

2016-12-15 Thread eryk sun
On Thu, Dec 15, 2016 at 4:53 PM, Steve D'Aprano
 wrote:
> Suppose I have a Unicode character, and I want to determine the script or
> scripts it belongs to.
>
> For example:
>
> U+0033 DIGIT THREE "3" belongs to the script "COMMON";
> U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
> U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".
>
> Is this information available from Python?

Tools/makunicodedata.py doesn't include data from "Scripts.txt". If
adding an external dependency is ok, then you can use PyICU. For
example:

>>> icu.Script.getScript('\u0033').getName()
'Common'
>>> icu.Script.getScript('\u0061').getName()
'Latin'
>>> icu.Script.getScript('\u03be').getName()
'Greek'

There isn't documentation specific to Python, so you'll have to figure
things out experimentally with reference to the C API.

http://icu-project.org/apiref/icu4c
http://icu-project.org/apiref/icu4c/uscript_8h.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Peter Otten
Steve D'Aprano wrote:

> I have some key:value data where the keys often are found in contiguous
> ranges with identical values. For example:
> 
> {1: "foo",
>  2: "foo",
>  3: "foo",
>  # same for keys 4 through 99
>  100: "foo",
>  101: "bar",
>  102: "bar",
>  103: "foobar",
>  104: "bar",
>  105: "foo",
> }
> 
> 
> So in this case, the keys 1 through 100, plus 105, all have the same
> value.
> 
> I have about a million or two keys, with a few hundred or perhaps a few
> thousand distinct values. The size of each contiguous group of keys with
> the same value can vary from 1 to perhaps a hundred or so.
> 
> Has anyone dealt with data like this and could give a recommendation of
> the right data structure to use?
> 
> The obvious way is to explicitly list each key, in a regular dict. But I
> wonder whether there are alternatives which may be better (faster, more
> memory efficient)?

Use a list, either directly if there are no big holes

>>> r = range(10**5)
>>> sys.getsizeof(list(r))/sys.getsizeof(dict(zip(r, r)))
0.14306676635590074


or indirectly:

ranges_list = [
1,
101,
103,
104,
105,
106,
]

index_to_value = {
1: "foo",
2: "bar",
3: "foobar",
4: "bar",
5: "foo",
}

def get(key, default="missing"):
index = bisect.bisect(ranges_list, key)
return index_to_value.get(index, default)


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


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Thomas Nyberg

On 12/15/2016 09:06 AM, Steve D'Aprano wrote:

Has anyone dealt with data like this and could give a recommendation of the
right data structure to use?



I haven't dealt with a data structure exactly like this, but it's 
basically a sparse array. (I'm sure it has a name somewhere in the 
academic literature, but I couldn't find it with a quick search right 
now...)


My solution to what you're asking for would be to have a list of 
key-value pairs, only adding a key to the list if it "changes" the 
value. I.e. your data structure would be this:


l = [
(1, "foo"),
(101, "bar"),
(103, "foobar"),
(104, "bar"),
(105, "foo"),
]

Then the only thing you need to do is define the lookup function. I 
would basically just do a binary search on the first values in the 
tuples. I.e. if "n" is your integer, you check if the middle values of 
the list l has it's first element as less than or greater than your 
value. Then you split l in two and do the same thing. Do this until you 
either find your value, or you find a value less than your value with 
the added property that the next value is greater than your value. After 
that you spit out the final second value.


There might be better ways to find the keys, but I think this approach 
is probably your best bet.


Cheers,
Thomas
--
https://mail.python.org/mailman/listinfo/python-list


Re: Mapping with continguous ranges of keys

2016-12-15 Thread D'Arcy Cain

On 2016-12-15 12:06 PM, Steve D'Aprano wrote:

I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.


There isn't enough info in your post to be sure but if those values are 
constant then you might be able to subclass dict and write a new 
__getitem__ that checks for specific ranges and calls the superclass 
only if not in the known ranges.  For example:


class MyDict(dict):
  def __getitem__(self, key):
if isinstance(key, int) and key >= 1 and key <= 100:
  return "foo"
return dict.__getitem__(self, key)

Obviously that middle section can be as complex as you need.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
--
https://mail.python.org/mailman/listinfo/python-list


Mapping with continguous ranges of keys

2016-12-15 Thread Steve D'Aprano
I have some key:value data where the keys often are found in contiguous
ranges with identical values. For example:

{1: "foo",
 2: "foo",
 3: "foo",
 # same for keys 4 through 99
 100: "foo",
 101: "bar",
 102: "bar",
 103: "foobar",
 104: "bar",
 105: "foo", 
}


So in this case, the keys 1 through 100, plus 105, all have the same value.

I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.

Has anyone dealt with data like this and could give a recommendation of the
right data structure to use?

The obvious way is to explicitly list each key, in a regular dict. But I
wonder whether there are alternatives which may be better (faster, more
memory efficient)?


Thanks,


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Python3, column names from array - numpy or pandas

2016-12-15 Thread Rhodri James

On 15/12/16 01:56, renjith madhavan wrote:

I have a dataset in the below format.

id  A   B   C   D   E
100 1   0   0   0   0
101 0   1   1   0   0
102 1   0   0   0   0
103 0   0   0   1   1

I would like to convert this into below:
100, A
101, B C
102, A
103, D E

How do I do this ? I tried numpy argsort but I am new to Python and finding 
this challenging.
Appreciate any help in this.



Numpy or pandas?  Neither, this is a straightforward bit of text 
manipulation you can do without needing to import anything.  I wouldn't 
bother considering either unless your dataset is massive and speed is 
anything of an issue.


with open("data.txt") as datafile:
# First line needs handling separately
line = next(datafile)
columns = line.split()[1:]
# Now iterate through the rest
for line in datafile:
results = []
for col, val in zip(columns, line.split()[1:]:
 if val == "1":
 results.append(col)
print("{0}, {1}".format(data[0], " ".join(results)))

Obviously there's no defensive coding for blank lines or unexpected data 
in there, and if want to use the results later on you probably want to 
stash them in a dictionary, but that will do the job.


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


Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Thomas 'PointedEars' Lahn
Ben Finney wrote:

> Chris Angelico  writes:
>> On Tue, Dec 13, 2016 at 10:17 AM, Ben Finney 
>> wrote:
>> > If the differences didn't matter I would agree that “overly
>> > pedantic” is fair. But those differences trip up newcomers. Thinking
>> > of ‘Foo.__init__’ leads people to wonder where the ‘self’ attribute
>> > came from – am I not meant to be constructing it? — and to attempt
>> > to return that instance. And when the time comes to lean about
>> > ‘__new__’ the confusion continues, because the newcomer has been
>> > told that something *else* is the constructor, so what's this?
>>
>> In JavaScript [different semantics apply].
>>
>> Ultimately, every language has slightly different semantics […], so
>> you have to learn that the "constructor" might have slightly different
>> semantics.

Actually, that is an inverse semantic fallacy.  There *is* always *some* 
common semantics to a the same term used in different domains; that is *why* 
it is used across domains (here: across object-oriented programming 
languages).  The common semantics here appears to be, as I substantiated by 
the FOLDOC reference, that a constructor initializes an object/instance.

“construct” does _not_ mean the same as “create” (make); understood 
literally, it means “heap together”, “build” (from Latin «construo», from 
«com» “together” + «struo» “I heap up, pile”).  A “constructor” is then the 
person or (here) the thing that “heaps together”.  ISTM that it “heaps 
together” the properties/attributes so that the object can be useful.

This is the same in Python as in several other OOPLs inasfar as that I can 
use super() or the superclass’ name to call the parent …what? – yes, the 
parent *constructor* of the class, i.e. the superclass’ (or in python, one 
of the superclass’) *constructor* from a class’ *constructor* (yes, I 
insist; see below) to initialize inherited attributes.

> Please read again the message you extracted that quote from. I already
> said I'm not claiming some other programming language's semantics should
> dictate Python's.
> 
> 
> What I'm saying is that in Python, there *already are* different
> semantics for a constructor, and they don't match the semantics of
> ‘Foo.__init__’.

Yes, *you* are saying that.
 
> In Python, a constructor for a class is a class method.

Says who, *you*?

> ‘Foo.__new__’ is a constructor. ‘Foo.__init__’ is an instance method, so
> it's not a constructor.

According to , 
“Foo.__init__” is _not_ an instance method.  Were it an instance 
method, the following would not happen:

| >>> class Foo:
| ... def __init__ (self):
| ... pass
| ...
| >>> Foo.__init__.__self__
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: 'function' object has no attribute '__self__'

Because “Instance method objects have attributes, too: m.__self__ is the 
instance object with the method m() […]”.

“Ex falso quodlibet”, “wishful thinking”, and “circular reasoning” come to 
mind here: *You* say that a constructor is a class method in Python, then 
*you* define __init__() to be an instance method, therefore __init__() 
*cannot* qualify anymore as a constructor.  So your wish is fulfilled, *far 
from reality*.

[If one would instantiate Foo, *then* the __init__() method of the instance 
would be an instance method (which is tautological):

| >>> Foo().__init__.__self__
| <__main__.Foo object at 0x7f86d73e8ef0>

]
 
> In Python, a constructor for a class makes the instance where it didn't
> already exist. ‘Foo.__new__’ is a constructor. ‘Foo.__init__’ requires
> the instance to already be constructed, so it's not a constructor.

You are also limiting the meaning of “constructor” in OOP to “create the 
instance” so that __init__() does not fit your definition of what is a 
constructor in Python in that regard as well.  But as I showed, not only 
does “constructor” not need to mean that, it can also mean much more than 
that.

So your reasoning is doubly invalid.
 
> I'm showing that Python classes *already have* constructors,

By *your* definition that you have *construed* (no pun intended) to fit your 
argument.

> and ‘Foo.__init__’ doesn't qualify because it doesn't have the semantics 
> of Python constructors.

By *your* definition.  That does not mean that your definition is correct, 
or that your reasoning is valid.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Jed Mack
We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
which are members of a school network.



The program seems to install correctly, but when we try to run the program
it stops and give an error message saying:



*Fatal Python error: Py_Initialize: unable to load the file system codec*

*Traceback (most recent call last):*

*  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
module>*

*zipimport.ZipImportError: can't find module 'codecs'*





On a Windows 7 PCs, on the same network, the program runs with no problems.



We have no one here who is familiar with Python.  Do you have any
additional information on this error, and suggestions for fixing it?



We have a teacher who needs this program on Windows 10 PCs for students to
use beginning January 3.



Thanks,

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


Unicode script

2016-12-15 Thread Steve D'Aprano
Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Best attack order for groups of numbers trying to destroy each other, given a victory chance for number to number attack.

2016-12-15 Thread Random832
On Thu, Dec 15, 2016, at 08:31, Dennis Lee Bieber wrote:
>   As for my posts disappearing: I run with "X-NoArchive" set. I have from
> before Google absorbed DejaNews. Back then, most news-servers expired
> posts
> on some periodic basis (my ISP tended to hold text groups for 30 days or
> so, binaries groups cycled in less than 36 hours). When DejaNews arrived,
> many objected to the non-expiration facet:
> https://en.wikipedia.org/wiki/Google_Groups#Deja_News

As I recall, what most people *actually* said they objected to was the
fact that they profited from showing ads. X-No-Archive was just a
convenient blunt weapon to hit them with.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28870] Reduce stack consumption of PyObject_CallFunctionObjArgs() and like

2016-12-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I have tested all three patches with the stack_overflow.py script. The only 
affected are recursive Python implementations of __call__, __getitem__ and 
__iter__.

unpatched   less_stack  alloca  subfunc

test_python_call9696987698809876
test_python_getitem 988410264   988010688
test_python_iterator7812805283128872

--

___
Python tracker 

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



[issue28147] Unbounded memory growth resizing split-table dicts

2016-12-15 Thread STINNER Victor

STINNER Victor added the comment:

I dislike pushing a change written by another core dev, I prefer that he/she 
directly push it, but we are out of time. Ned asked to first push to Python 3.6 
to get a confirmation of buildbots, before being able to ask for a cherry-pick 
in 3.6.0 final.

Anyway, thanks for the fix Naoki!

--

___
Python tracker 

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



[issue28147] Unbounded memory growth resizing split-table dicts

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 85be9dcc16a8 by Victor Stinner in branch '3.6':
Fix a memory leak in split-table dictionaries
https://hg.python.org/cpython/rev/85be9dcc16a8

--
nosy: +python-dev

___
Python tracker 

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



[issue11322] encoding package's normalize_encoding() function is too slow

2016-12-15 Thread STINNER Victor

STINNER Victor added the comment:

Oh, while reading Mercurial history, I found a note that I wrote:

"It's not exactly the same than encodings.normalize_encoding(): the C function 
also converts to lowercase."

IHMO it's fine to modify encodings.normalize_encoding() to also convert to 
lower-case.

--

___
Python tracker 

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



[issue23063] `python setup.py check --restructuredtext --strict --metadata` fails with: `warning: check: Could not finish the parsing.` if the RST document uses code or code-block directives.

2016-12-15 Thread Matt Bogosian

Changes by Matt Bogosian :


--
nosy: +posita

___
Python tracker 

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



[issue27810] Add METH_FASTCALL: new calling convention for C functions

2016-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ecd218c41cd4 by Victor Stinner in branch 'default':
Use _PyDict_NewPresized() in _PyStack_AsDict()
https://hg.python.org/cpython/rev/ecd218c41cd4

--

___
Python tracker 

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



[issue28979] What's New entry on compact dict mentions "faster" implementation

2016-12-15 Thread Ned Deily

Changes by Ned Deily :


--
priority: normal -> release blocker

___
Python tracker 

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



[issue28976] incorrect description that dose not conform to the actual behavior

2016-12-15 Thread woo yoo

Changes by woo yoo :


--
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

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



[issue28976] incorrect description that dose not conform to the actual behavior

2016-12-15 Thread woo yoo

woo yoo added the comment:

I think i understand you now.My english needs to improve.Thanks for your 
patience.

--

___
Python tracker 

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



  1   2   3   >