Re: K-means Python code analyse

2016-11-23 Thread dieter
Alex  writes:

> Can please anyone explaine me what do each of these code lines and how 
> k-means algorithm works?

How about searching "wikipedia"?
(--> "https://en.wikipedia.org/wiki/K-means_clustering;).

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


[issue28595] shlex.shlex should not augment wordchars

2016-11-23 Thread Evan

Evan added the comment:

I've created issue28784 to capture the documentation fixes. When I have more 
spare time, I'll work on a more complete patch.

--

___
Python tracker 

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



[issue28784] shlex.shlex punctuation_chars documentation should use posix=True

2016-11-23 Thread Evan

New submission from Evan:

(This discussion started on issue28595.)

The new punctuation_chars keyword argument is intended to provide 
"compatibility with the parsing performed by common Unix shells like bash, 
dash, and sh", however the documentation and examples do not mention that the 
user should also set posix=True (which defaults to False for shlex.shlex but 
True for shlex.split).

Longer term (over several releases), perhaps the default for posix could be 
changed from False to True. Alternatively, the punctuation_chars argument could 
also be added to shlex.split, which would avoid having to interact with 
shlex.shlex directly.

--
assignee: docs@python
components: Documentation
messages: 281612
nosy: docs@python, evan_, r.david.murray, vinay.sajip
priority: normal
severity: normal
status: open
title: shlex.shlex punctuation_chars documentation should use posix=True
type: behavior
versions: 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: Question about working with html entities in python 2 to use them as filenames

2016-11-23 Thread dieter
Steven Truppe  writes:

> type=  title =  Wizo - Anderster Full Album - YouTube
> type=  title =  Wizo - Bleib Tapfer / fürn Arsch Full
> Album - YouTube
> Traceback (most recent call last):
>   File "./music-fetcher.py", line 39, in 
> title = HTMLParser.HTMLParser().unescape(title)
>   File "/usr/lib/python2.7/HTMLParser.py", line 475, in unescape
> return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));",
> replaceEntities, s)
>   File "/usr/lib/python2.7/re.py", line 155, in sub
> return _compile(pattern, flags).sub(repl, string, count)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 23: ordinal not in range(128)

This looks like a bug with "HTMLParser" or a usage problem with its
"unescape" method.

I would use "lxml" in order to parse your HTML. It automatically converts
character references (like the above "&39;") and handles special
characters (like "ü") adequately. Under Python 2, "lxml" either returns text
data as "str" (if the result is fully ascii) or "unicode" (otherwise).

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


Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"Steven D'Aprano"  wrote in message 
news:58368358$0$1513$c3e8da3$54964...@news.astraweb.com...



On Thursday 24 November 2016 15:55, Frank Millman wrote:

> "Steve D'Aprano"  wrote in message
> news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com...
>
>> Even if the computation of the memoised value is done asynchronously, 
>> you
>> can easily split the computation off to a separate method (as you 
>> already

>> talked about doing!) and make getval() block until it returns.
>
> Surely that defeats the whole purpose of asyncio. Anything that blocks 
> holds
> up the entire process. I strenuously try to avoid blocking in any shape 
> or

> form.

Perhaps I'm not understanding your task correctly, but surely you have to 
wait
for the computation to occur at some point? Even if that's just you 
hitting

Refresh waiting for the value of the column to eventually show up.

I'm a newbie to asyncio, but if I were doing this using threads, I'd have
getval() set the self._cached_value to "pending..." (say), start the
computation thread running, and then return. The computation thread will
eventually write the true value to _cached_value, and in the meantime the
getval() method (and hence __str__ will happily use the "pending..." 
value. The

only tricky part is to make sure you only start the thread once.



I am not really qualified to answer this - I *use* asyncio, but I don’t 
really understand what goes on under the covers.


With that caveat, here goes.

To me, the beauty of asyncio (or I suppose async in general) is that I don't 
have to worry about any of what you describe above.


I just have to 'await' whatever I am waiting for. There could be a long 
chain of function calls (which I suppose I should call coroutine calls) but 
at some point one of them is actually going to wait for some I/O, and yield 
control back to the event loop.


At that point, the entire chain is suspended, pending return of the value. 
Once received, control passes back down the chain to the originating 
coroutine, which can then carry on exactly where it left off.


Frank


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


[issue28728] test_host_resolution in test_socket fails

2016-11-23 Thread Martin Panter

Martin Panter added the comment:

Maybe worth looking at what name resolution stuff is enabled in 
/etc/nsswitch.conf. On the hosts line, my current computer (v basic setup) has

hosts: files dns myhostname

My guess is you have a plugin which is resolving these ip-address lookalikes.

--

___
Python tracker 

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



[issue27100] Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error

2016-11-23 Thread Raymond Hettinger

Raymond Hettinger added the comment:

> Since the patch is simple and fixes a regression introduced
> just before releasing beta 4, I'm fine with fixing it. We are
> trying to support tests warnings-free. Some buildbots can run 
> tests with -We.

+1

--

___
Python tracker 

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



[issue28728] test_host_resolution in test_socket fails

2016-11-23 Thread Xiang Zhang

Xiang Zhang added the comment:

Hi SilentGhost. I'm also using Ubuntu 16.10 but the test case doesn't fail.

cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.10
DISTRIB_CODENAME=yakkety
DISTRIB_DESCRIPTION="Ubuntu 16.10"

./python -Wa -m test -v test_socket | grep test_host_resolution
test_host_resolution (test.test_socket.GeneralModuleTests) ... ok

--
nosy: +xiang.zhang

___
Python tracker 

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



Re: Is this pythonic?

2016-11-23 Thread Steven D'Aprano
On Thursday 24 November 2016 15:55, Frank Millman wrote:

> "Steve D'Aprano"  wrote in message
> news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com...
> 
>> Even if the computation of the memoised value is done asynchronously, you
>> can easily split the computation off to a separate method (as you already
>> talked about doing!) and make getval() block until it returns.
> 
> Surely that defeats the whole purpose of asyncio. Anything that blocks holds
> up the entire process. I strenuously try to avoid blocking in any shape or
> form.

Perhaps I'm not understanding your task correctly, but surely you have to wait 
for the computation to occur at some point? Even if that's just you hitting 
Refresh waiting for the value of the column to eventually show up.

I'm a newbie to asyncio, but if I were doing this using threads, I'd have 
getval() set the self._cached_value to "pending..." (say), start the 
computation thread running, and then return. The computation thread will 
eventually write the true value to _cached_value, and in the meantime the 
getval() method (and hence __str__ will happily use the "pending..." value. The 
only tricky part is to make sure you only start the thread once.



-- 
Steven
299792.458 km/s — not just a good idea, it’s the law!

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


[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I prefer pygen_yf.patch (with addressing Yury's suggestions). It is much 
simpler, and in any case I want to change f_lasti to count words rather than 
bytes (issue27129). It would be again -1 at the start.

--

___
Python tracker 

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



Re: Random number help

2016-11-23 Thread Larry Hudson via Python-list

On 11/23/2016 11:17 AM, Thomas Grops wrote:

I need a way of generating a random number but there is a catch:

I don't want to include certain numbers, is this possible?

random.randint(1,100) works as it will randomly pick numbers between 1 and 100 
but say i don't want 48 to come out is there a way of doing this. It needs to 
be an integer too so not a list unless there is a way to convert list to int

Many Thanks Tom



Here's a possible generic approach:

#  Come up with a better name for this function
def randx(lo, hi, nw):  #  nw is a list of not-wanted ints
while True:
n = random.randint(lo, hi)
if n not in nw:
return n

Use it the same way as randint(), plus a list of the not-wanted values.
Short example:

---
nw = [1, 3, 5, 7, 9]  #  Odd numbers out
for i in range(10):
print(randx(1, 10, nw), end=' ')
print()
---

Here's the results I got for 3 runs...

4 4 4 8 10 6 8 2 4 8
8 4 2 4 6 8 2 4 8 8
10 6 6 4 4 4 8 2 8 4

Of course, the not-wanted list can be a single int, or even empty.

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


[issue25701] Document that tp_setattro and tp_setattr are used for deleting attributes

2016-11-23 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Please do this yourself. This is mainly your patch.

--

___
Python tracker 

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



Re: Quick help for a python newby, please

2016-11-23 Thread Wildman via Python-list
On Thu, 24 Nov 2016 14:49:27 +1100, Chris Angelico wrote:

> On Thu, Nov 24, 2016 at 2:41 PM, Wildman via Python-list
>  wrote:
>> Point taken.  I did miss the python3 part.
>>
>> I switched to raw_input because it handles an empty
>> input.  An empty input would trigger the ValueError.
>> No doubt with the correct code the same or similar
>> could be done with input().  My lack of experience
>> caused me to look for simpler solution and perhaps
>> the wrong one.
> 
> The exact same thing is true of input() in Python 3. In Python 2,
> input() is the same as eval(raw_input()), so don't use it ever [1].
> You can happily use input() in Py3, even if you get empty input.
> 
> I like to put this at the top of cross-version scripts:
> 
> try: input = raw_input
> except NameError: pass
> 
> Then you can proceed to use input() without worries.
> 
> ChrisA
> 
> [1] Yes, I'm aware there are times when evalling the user's input is
> what you want. In those cases, be explicit and use eval.

Understood.  Thank you.

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


[issue27100] Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error

2016-11-23 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Oh, how I missed this? I usually run tests with -Wa.

Since the patch is simple and fixes a regression introduced just before 
releasing beta 4, I'm fine with fixing it. We are trying to support tests 
warnings-free. Some buildbots can run tests with -We.

--

___
Python tracker 

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



Re: NameError

2016-11-23 Thread Nathan Ernst
I don't see anything in that output resembling an error, just a few
warnings that some features may no be available.

Have you tried importing pygame after you did that? That's what'll prove
one way or another that it worked.

Regards,
Nate

On Wed, Nov 23, 2016 at 10:48 PM, Cai Gengyang 
wrote:

> Yea, using Mac
>
> Following the instructions here for Mac ---https://bitbucket.org/
> pygame/pygame/issues/82/homebrew-on-leopard-fails-to-
> install#comment-627494
>
> GengYang Cai CaiGengYangs-MacBook-Pro:~ CaiGengYang$ brew install python
> ==> Installing dependencies for python: xz, pkg-config, readline, sqlite,
> ==> Installing python dependency: xz
> ==> Downloading https://homebrew.bintray.com/.
> ../xz-5.2.2.yosemite.bottle.ta
> 
> 100.0%
> ==> Pouring xz-5.2.2.yosemite.bottle.tar.gz
>  /usr/local/Cellar/xz/5.2.2: 91 files, 1.4M
> ==> Installing python dependency: pkg-config
> ==> Downloading https://homebrew.bintray.com/.
> ../pkg-config-0.29.1_1.yosemit
> 
> 100.0%
> ==> Pouring pkg-config-0.29.1_1.yosemite.bottle.tar.gz
>  /usr/local/Cellar/pkg-config/0.29.1_1: 10 files, 627.3K
> ==> Installing python dependency: readline
> ==> Downloading https://homebrew.bintray.com/.
> ../readline-6.3.8.yosemite.bot
> 
> 100.0%
> ==> Pouring readline-6.3.8.yosemite.bottle.tar.gz
> ==> Caveats
> This formula is keg-only, which means it was not symlinked into /usr/local.
>
> OS X provides the BSD libedit library, which shadows libreadline.
> In order to prevent conflicts when programs look for libreadline we are
> defaulting this GNU Readline installation to keg-only.
>
> Generally there are no consequences of this for you. If you build your
> own software and it requires this formula, you'll need to add to your
> build variables:
>
> LDFLAGS: -L/usr/local/opt/readline/lib
> CPPFLAGS: -I/usr/local/opt/readline/include
>
> ==> Summary
>  /usr/local/Cellar/readline/6.3.8: 46 files, 2M
> ==> Installing python dependency: sqlite
> ==> Downloading https://homebrew.bintray.com/.
> ../sqlite-3.13.0.yosemite.bott
> 
> 100.0%
> ==> Pouring sqlite-3.13.0.yosemite.bottle.tar.gz
> ==> Caveats
> This formula is keg-only, which means it was not symlinked into /usr/local.
>
> OS X provides an older sqlite3.
>
> Generally there are no consequences of this for you. If you build your
> own software and it requires this formula, you'll need to add to your
> build variables:
>
> LDFLAGS: -L/usr/local/opt/sqlite/lib
> CPPFLAGS: -I/usr/local/opt/sqlite/include
>
> ==> Summary
>  /usr/local/Cellar/sqlite/3.13.0: 10 files, 2.9M
> ==> Installing python dependency: gdbm
> ==> Downloading https://homebrew.bintray.com/.
> ../gdbm-1.12.yosemite.bottle.t
> 
> 100.0%
> ==> Pouring gdbm-1.12.yosemite.bottle.tar.gz
>  /usr/local/Cellar/gdbm/1.12: 18 files, 490.8K
> ==> Installing python dependency: openssl
> ==> Downloading https://homebrew.bintray.com/.
> ../openssl-1.0.2h_1.yosemite.b
> 
> 100.0%
> ==> Pouring openssl-1.0.2h_1.yosemite.bottle.tar.gz
> ==> Caveats
> A CA file has been bootstrapped using certificates from the system
> keychain. To add additional certificates, place .pem files in
> /usr/local/etc/openssl/certs
>
> and run
> /usr/local/opt/openssl/bin/c_rehash
>
> This formula is keg-only, which means it was not symlinked into /usr/local.
>
> Apple has deprecated use of OpenSSL in favor of its own TLS and crypto
> libraries
>
> Generally there are no consequences of this for you. If you build your
> own software and it requires this formula, you'll need to add to your
> build variables:
>
> LDFLAGS: -L/usr/local/opt/openssl/lib
> CPPFLAGS: -I/usr/local/opt/openssl/include
>
> ==> Summary
>  /usr/local/Cellar/openssl/1.0.2h_1: 1,691 files, 12.0M
> ==> Installing python
> Warning: Building python from source:
> The bottle needs the Apple Command Line Tools to be installed.
> You can install them, if desired, with:
> xcode-select --install
>
> ==> Downloading https://www.python.org/.../2.7.12/Python-2.7.12.tar.xz
> 
> 100.0%
> ==> Downloading https://bugs.python.org/file30805/issue10910-
> workaround.txt
> 
> 100.0%
> ==> Patching
> ==> Applying issue10910-workaround.txt
> patching file Include/pyport.h
> Hunk #1 succeeded at 713 (offset 14 lines).
> Hunk #2 succeeded at 736 (offset 14 lines).
> ==> ./configure --prefix=/usr/local/Cellar/python/2.7.12 --enable-ipv6
> --dataroo
> ==> make
> /usr/local/share/python/easy_install mecurial
>
> 

[issue27172] Undeprecate inspect.getfullargspec()

2016-11-23 Thread Ned Deily

Ned Deily added the comment:

Nick, that seems like the right thing to do.  Thanks for following up on it.

--
nosy: +larry
priority: normal -> release blocker
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: Is this pythonic?

2016-11-23 Thread Frank Millman
"Steve D'Aprano"  wrote in message 
news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com...



Even if the computation of the memoised value is done asynchronously, you
can easily split the computation off to a separate method (as you already
talked about doing!) and make getval() block until it returns.


Surely that defeats the whole purpose of asyncio. Anything that blocks holds 
up the entire process. I strenuously try to avoid blocking in any shape or 
form.



> I can say 'print(await obj.__str__())', and it works, but I lose the
> ability to include it in a larger print statement.


Any time you find yourself directly calling dunder methods, you're 
probably

doing it wrong. This is one of those times.


Yes. Having slept on it, I realise I over-reacted.

The __str__() method is convenient for me, but I only use it for testing and 
debugging to see what is going on. It is not part of my app per se.


I now realise that the solution is -

1. Keep the __str__ method, but replace calls to getval() with a direct 
reference to the underlying attribute. It means that any 'computable' 
objects that have not already been computed will return None, but that is ok 
for my purposes.


2. Write a separate method, retaining the calls to getval(), to be called 
independently using 'await' if I ever need to see the full result after 
computation.


Frank


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


Re: NameError

2016-11-23 Thread Cai Gengyang
Yea, using Mac 

Following the instructions here for Mac 
---https://bitbucket.org/pygame/pygame/issues/82/homebrew-on-leopard-fails-to-install#comment-627494

GengYang Cai CaiGengYangs-MacBook-Pro:~ CaiGengYang$ brew install python
==> Installing dependencies for python: xz, pkg-config, readline, sqlite,
==> Installing python dependency: xz
==> Downloading https://homebrew.bintray.com/.../xz-5.2.2.yosemite.bottle.ta
 100.0%
==> Pouring xz-5.2.2.yosemite.bottle.tar.gz
 /usr/local/Cellar/xz/5.2.2: 91 files, 1.4M
==> Installing python dependency: pkg-config
==> Downloading https://homebrew.bintray.com/.../pkg-config-0.29.1_1.yosemit
 100.0%
==> Pouring pkg-config-0.29.1_1.yosemite.bottle.tar.gz
 /usr/local/Cellar/pkg-config/0.29.1_1: 10 files, 627.3K
==> Installing python dependency: readline
==> Downloading https://homebrew.bintray.com/.../readline-6.3.8.yosemite.bot
 100.0%
==> Pouring readline-6.3.8.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/readline/lib
CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
 /usr/local/Cellar/readline/6.3.8: 46 files, 2M
==> Installing python dependency: sqlite
==> Downloading https://homebrew.bintray.com/.../sqlite-3.13.0.yosemite.bott
 100.0%
==> Pouring sqlite-3.13.0.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/sqlite/lib
CPPFLAGS: -I/usr/local/opt/sqlite/include

==> Summary
 /usr/local/Cellar/sqlite/3.13.0: 10 files, 2.9M
==> Installing python dependency: gdbm
==> Downloading https://homebrew.bintray.com/.../gdbm-1.12.yosemite.bottle.t
 100.0%
==> Pouring gdbm-1.12.yosemite.bottle.tar.gz
 /usr/local/Cellar/gdbm/1.12: 18 files, 490.8K
==> Installing python dependency: openssl
==> Downloading https://homebrew.bintray.com/.../openssl-1.0.2h_1.yosemite.b
 100.0%
==> Pouring openssl-1.0.2h_1.yosemite.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs

and run
/usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
 /usr/local/Cellar/openssl/1.0.2h_1: 1,691 files, 12.0M
==> Installing python
Warning: Building python from source:
The bottle needs the Apple Command Line Tools to be installed.
You can install them, if desired, with:
xcode-select --install

==> Downloading https://www.python.org/.../2.7.12/Python-2.7.12.tar.xz
 100.0%
==> Downloading https://bugs.python.org/file30805/issue10910-workaround.txt
 100.0%
==> Patching
==> Applying issue10910-workaround.txt
patching file Include/pyport.h
Hunk #1 succeeded at 713 (offset 14 lines).
Hunk #2 succeeded at 736 (offset 14 lines).
==> ./configure --prefix=/usr/local/Cellar/python/2.7.12 --enable-ipv6 --dataroo
==> make
/usr/local/share/python/easy_install mecurial

brew install sdl
brew install sdl_mixer
brew install sdl_ttf
brew install sdl_image

hg clone https://bitbucket.org/pygame/pygame
cd pygame
/usr/local/bin/python setup.py install


Does this work ?







On Thursday, November 24, 2016 at 12:00:18 PM UTC+8, Thomas Nyberg wrote:
> On 11/23/2016 10:02 PM, Cai Gengyang wrote:
> > I tried to import pygame by using these commands 
> > https://www.google.com.sg/#q=how+to+import+pygame
> >
> > but this is the error I got :
> >
> > CaiGengYangs-MacBook-Pro:~ 

[issue27172] Undeprecate inspect.getfullargspec()

2016-11-23 Thread Nick Coghlan

Nick Coghlan added the comment:

When we undeprecate this, we should remove and reword the deprecation warnings 
in the next 3.5 maintenance release as well.

I'll need to decide on a way to indicate in the docs that some versions of 
3.x.y will report a deprecation warning for getfullargspec() though - probably 
a "Changed in" note.

--
versions: +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: How to you convert list of tuples to string

2016-11-23 Thread Larry Hudson via Python-list

On 11/23/2016 03:09 AM, Ned Batchelder wrote:
[snip...]

Or using the new string formatting syntax:

msg = '{},{},{}:{}'.format(*item)

The *item in the format() unpacks the tuple.



"new" == "Introduced in 2.6, available since 2008" :)

--Ned.



Of course.  I probably should have said "newer" or "other".:-)

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


[issue27172] Undeprecate inspect.getfullargspec()

2016-11-23 Thread Nick Coghlan

Nick Coghlan added the comment:

This just came up in a discussion on a urllib3 patch, so I'd like to fix it for 
3.6.0rc1.

Ned, given that the code change here is just deleting the deprecation warning 
from getfullargspec() and rewording the one for getargspec(), does that seem OK 
for 3.6.0?

--
assignee:  -> ncoghlan
nosy: +ned.deily

___
Python tracker 

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



[issue27100] Attempting to use class with both __enter__ & __exit__ undefined yields __exit__ attribute error

2016-11-23 Thread Martin Panter

Martin Panter added the comment:

The tests changes also produce a DeprecationWarning:

==
ERROR: testEnterAttributeError1 (test.test_with.FailureTestCase)
--
Traceback (most recent call last):
  File "/home/proj/python/cpython/Lib/test/test_with.py", line 120, in 
testEnterAttributeError1
self.assertRaisesRegexp(AttributeError, '__enter__', fooLacksEnter)
  File "/home/proj/python/cpython/Lib/unittest/case.py", line 1311, in 
deprecated_func
DeprecationWarning, 2)
DeprecationWarning: Please use assertRaisesRegex instead.

The fix is simple and just affects the tests, but since most people don’t seem 
to worry about warnings, I guess this can wait for 3.6 to be released before 
committing the fix.

--
Added file: http://bugs.python.org/file45618/regexp-deprecated.patch

___
Python tracker 

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



Re: NameError

2016-11-23 Thread Thomas Nyberg

On 11/23/2016 10:02 PM, Cai Gengyang wrote:

I tried to import pygame by using these commands 
https://www.google.com.sg/#q=how+to+import+pygame

but this is the error I got :

CaiGengYangs-MacBook-Pro:~ CaiGengYang$ sudo apt-get install python-pygame
sudo: apt-get: command not found

Judging by your prompt it looks like you're on a Mac. The apt-get 
program is installed on some Linux distributions (probably your 
instructions are for Ubuntu). Here are some istructions for installing 
pygame for a Macbook:


http://pygame.org/wiki/macintosh

http://florian-berger.de/en/articles/installing-pygame-for-python-3-on-os-x/
https://jamesfriend.com.au/installing-pygame-python-3-mac-os-yosemite

Here's some info about getting a package manager like apt for Mac:


http://unix.stackexchange.com/questions/80711/how-to-install-apt-get-or-yum-on-mac-os-x

Hopefully this helps.

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


generating list of files matching condition

2016-11-23 Thread Seb
Hello,

Given a list of files:

In [81]: ec_files[0:10]
Out[81]: 

[u'EC_20160604002000.csv',
 u'EC_2016060401.csv',
 u'EC_20160604012000.csv',
 u'EC_20160604014000.csv',
 u'EC_2016060402.csv']

where the numbers are are a timestamp with format %Y%m%d%H%M%S, I'd like
to generate a list of matching files for each 2-hr period in a 2-h
frequency time series.  Ultimately I'm using Pandas to read and handle
the data in each group of files.  For the task of generating the files
for each 2-hr period, I've done the following:

beg_tstamp = pd.to_datetime(ec_files[0][-18:-4],
format="%Y%m%d%H%M%S")
end_tstamp = pd.to_datetime(ec_files[-1][-18:-4],
format="%Y%m%d%H%M%S")
tstamp_win = pd.date_range(beg_tstamp, end_tstamp, freq="2H")

So tstamp_win is the 2-hr frequency time series spanning the timestamps
in the files in ec_files.

I've generated the list of matching files for each tstamp_win using a
comprehension:

win_files = []
for i, w in enumerate(tstamp_win):
nextw = w + pd.Timedelta(2, "h")
ifiles = [x for x in ec_files if
  pd.to_datetime(x[-18:-4], format="%Y%m%d%H%M%S") >= w and
  pd.to_datetime(x[-18:-4], format="%Y%m%d%H%M%S") < nextw]
win_files.append(ifiles)

However, this is proving very slow, and was wondering whether there's a
better/faster way to do this.  Any tips would be appreciated.


-- 
Seb

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


Re: Quick help for a python newby, please

2016-11-23 Thread Chris Angelico
On Thu, Nov 24, 2016 at 2:41 PM, Wildman via Python-list
 wrote:
> Point taken.  I did miss the python3 part.
>
> I switched to raw_input because it handles an empty
> input.  An empty input would trigger the ValueError.
> No doubt with the correct code the same or similar
> could be done with input().  My lack of experience
> caused me to look for simpler solution and perhaps
> the wrong one.

The exact same thing is true of input() in Python 3. In Python 2,
input() is the same as eval(raw_input()), so don't use it ever [1].
You can happily use input() in Py3, even if you get empty input.

I like to put this at the top of cross-version scripts:

try: input = raw_input
except NameError: pass

Then you can proceed to use input() without worries.

ChrisA

[1] Yes, I'm aware there are times when evalling the user's input is
what you want. In those cases, be explicit and use eval.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Quick help for a python newby, please

2016-11-23 Thread Wildman via Python-list
On Thu, 24 Nov 2016 11:59:17 +1100, Chris Angelico wrote:

> On Thu, Nov 24, 2016 at 10:02 AM, Wildman via Python-list
>  wrote:
>> Try the code that is below:
>>
>> import datetime
>> from datetime import date
>>
>> today = date.today()
>> person = input("Enter your name: ")
>> byear = raw_input("Enter the four-digit year you were born: ")
> 
> Please take care of Python versions. The OP said Python 3, and you've
> kept one input() call, but then you've used raw_input for the rest.
> These should all be input() calls in Py3.
> 
> ChrisA

Point taken.  I did miss the python3 part.

I switched to raw_input because it handles an empty
input.  An empty input would trigger the ValueError.
No doubt with the correct code the same or similar
could be done with input().  My lack of experience
caused me to look for simpler solution and perhaps
the wrong one.

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


[issue10721] Remove HTTP 0.9 server support

2016-11-23 Thread Martin Panter

Martin Panter added the comment:

V4 patch adjusting to recent code change.

Raymond: Given the problems caused by the current code, would you reconsider 
your opposition?

Otherwise, what do you think should be the future of the code? Should we fix it 
so that it handles real HTTP 0.9 requests, or just admit that it doesn’t 
implement the protocol properly.

--
Added file: http://bugs.python.org/file45617/http09server.v4.patch

___
Python tracker 

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



Re: NameError

2016-11-23 Thread Cai Gengyang
I tried to import pygame by using these commands 
https://www.google.com.sg/#q=how+to+import+pygame

but this is the error I got :

CaiGengYangs-MacBook-Pro:~ CaiGengYang$ sudo apt-get install python-pygame
sudo: apt-get: command not found



On Thursday, November 24, 2016 at 10:54:20 AM UTC+8, Joel Goldstick wrote:
> On Wed, Nov 23, 2016 at 9:44 PM, Cai Gengyang  wrote:
>  pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
> > Traceback (most recent call last):
> > File "", line 1, in 
> > pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
> > NameError: name 'pygame' is not defined
> >
> > How to solve this error ?
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> have you imported pygame?
> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: NameError

2016-11-23 Thread Joel Goldstick
On Wed, Nov 23, 2016 at 9:44 PM, Cai Gengyang  wrote:
 pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
> Traceback (most recent call last):
> File "", line 1, in 
> pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
> NameError: name 'pygame' is not defined
>
> How to solve this error ?
> --
> https://mail.python.org/mailman/listinfo/python-list

have you imported pygame?

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


NameError

2016-11-23 Thread Cai Gengyang
>>> pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
Traceback (most recent call last):
File "", line 1, in 
pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
NameError: name 'pygame' is not defined

How to solve this error ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reposting On Python-List PROHIBITED

2016-11-23 Thread Steve D'Aprano
On Thu, 24 Nov 2016 10:28 am, Lawrence D’Oliveiro wrote:

> To the controllers of Python-List:
> 
> I never asked to be on your list. I never consented to having my postings
> appear on your list. And I certainly didn’t agree to any conditions you
> might impose on members on your list.

comp.lang.python is set up as a mirror of the mailing list. By posting to
comp.lang.python, you are mailing the python-list@python.org mailing list.


> Therefore, to see you take offence at something I said, and use that as an
> excuse to “ban” me from your list, is an act of breathtaking hypocrisy.

It really isn't. It is perhaps an act of ignorance on your part to fail to
realise that you are posting to the mailing list, although I believe you
have been told this before. Repeatedly.


> As 
> far as I am concerned, it is you lot who should be banned from
> comp.lang.python. You are reusing its content inappropriately and without
> authorization. What you are doing must be stopped.

This newsgroup is a mirror of the mailing list, not the other way around.



-- 
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: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
On Wed, 23 Nov 2016 10:11 pm, Frank Millman wrote:

> Gah! The law of unintended consequences strikes again!
> 
> As I mentioned, the class in question represents a database column. 

Yes, you mentioned that.

> A 
> separate class represents a database row. I have a __str__() method on the
> 'row' class that prints a nicely formatted representation of the object
> with all of its column objects and their values.

You didn't mention that, but it shouldn't matter.

 
> With the above changes, I had to turn getval() into a coroutine.

You what?

I'm gobsmacked by this assertion. Nobody else seems to have commented on
this, so perhaps I'm missing something, but this strikes me as astonishing.
Nothing in your earlier post even hinted that you were using coroutines or
async, and as sure as the day is long memoisation doesn't force you to
start.

Even if the computation of the memoised value is done asynchronously, you
can easily split the computation off to a separate method (as you already
talked about doing!) and make getval() block until it returns.


[...]
> I can say 'print(await obj.__str__())', and it works, but I lose the
> ability to include it in a larger print statement.

Any time you find yourself directly calling dunder methods, you're probably
doing it wrong. This is one of those times.




-- 
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


[issue28771] Update documented signatures of tp_get/setattr

2016-11-23 Thread Martin Panter

Martin Panter added the comment:

Python 2 patch is on top of the patch for Issue 25701

--
dependencies: +Document that tp_setattro and tp_setattr are used for deleting 
attributes

___
Python tracker 

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



[issue28771] Update documented signatures of tp_get/setattr

2016-11-23 Thread Martin Panter

Martin Panter added the comment:

In Python 2, charbufferproc was changed to use non-const char ** in revision 
dba6494735d0 (perhaps by accident). Otherwise, this patch is the same as for 
Python 3. I have added a sentence about using NULL for deletion in the patch.

--
Added file: http://bugs.python.org/file45616/typeobj-sigs.v2.py2.patch

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread Yury Selivanov

Yury Selivanov added the comment:

> f_lasti being -2 has always been my preference, lasti.patch lgtm

How about we commit pygen_yf.patch to 3.6 and whatever else in 3.7?  

lasti.patch is too invasive for 3.6 at this point, -1 for it in 3.6.

--

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread Demur Rumed

Demur Rumed added the comment:

I had considered this, for some reason I didn't realize code[1] could be equal 
to YIELD_FROM, felt it'd always be false

f_lasti being -2 has always been my preference, lasti.patch lgtm

--

___
Python tracker 

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



Re: Reposting On Python-List PROHIBITED

2016-11-23 Thread Michael Torrie
On 11/23/2016 04:31 PM, mm0fmf wrote:
> On 23/11/2016 23:28, Lawrence D’Oliveiro wrote:
>> Therefore, to see you take offence at something I said, and use
>> that as an excuse to “ban” me from your list, is an act of
>> breathtaking hypocrisy. As far as I am concerned, it is you lot who
>> should be banned from comp.lang.python. You are reusing its content
>> inappropriately and without authorization. What you are doing must
>> be stopped.

Oh wow.

Well the poor fellow can rest easy knowing that stuff he posts to the
newsgroup is indeed not going to the mailing list.

Personally it wouldn't hurt my feelings if comp.lang.python was cut
loose from the mailing list entirely, though I know many posters would
disagree and others would desire to drop the mailing list part.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28773] typing.FrozenSet missing in documentation.

2016-11-23 Thread Ned Deily

Ned Deily added the comment:

Guido, doc fixes are welcome!

--

___
Python tracker 

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



[issue25701] Document that tp_setattro and tp_setattr are used for deleting attributes

2016-11-23 Thread Martin Panter

Martin Panter added the comment:

The 2.7 patch looks okay to me. I confirmed that sq_ass_slice gets called to 
delete slices, and I presume the other stuff is similar to Python 3. Do you 
want to commit this to 2.7 Serhiy?

--
stage: patch review -> commit review

___
Python tracker 

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



Re: Quick help for a python newby, please

2016-11-23 Thread Chris Angelico
On Thu, Nov 24, 2016 at 10:02 AM, Wildman via Python-list
 wrote:
> Try the code that is below:
>
> import datetime
> from datetime import date
>
> today = date.today()
> person = input("Enter your name: ")
> byear = raw_input("Enter the four-digit year you were born: ")

Please take care of Python versions. The OP said Python 3, and you've
kept one input() call, but then you've used raw_input for the rest.
These should all be input() calls in Py3.

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


[issue28773] typing.FrozenSet missing in documentation.

2016-11-23 Thread Guido van Rossum

Guido van Rossum added the comment:

Ned: does the ban on non-critical commits to the 3.6 branch also apply to doc 
patches?

--
nosy: +ned.deily

___
Python tracker 

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



[issue10379] locale.format() input regression

2016-11-23 Thread Eric V. Smith

Changes by Eric V. Smith :


--
assignee: docs@python -> 
keywords: +easy
stage:  -> needs patch
type:  -> behavior

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread STINNER Victor

STINNER Victor added the comment:

> Another much larger change would be to change f_lasti to -2...

Attached lasti.patch implements this idea. I consider that it makes the C code 
simpler because getting the next instruction (f_lasti + 2) doesn't require a 
special case anymore.

My patch keeps f_lasti == -1 at the Python level for backward compatibility.

lasti.patch is only a backward incompatible change at the C level.

--

Between pygen_yf.patch and lasti.patch, I prefer lasti.patch even if 3.6 is at 
its last beta version before the final version. I prefer to fix the C API. 
Later it will be much harder to fix it.

--

I read again the wordcode issue #26647:

I wrote on the review of wpy7.patch: "The overall change LGTM, but I'm no more 
100% sure that starting f_lasti=-1 is safe."
http://bugs.python.org/review/26647/#msg17

I wrote: "IMHO it's ok to break the C API, but I would prefer to keep the 
backward compatibility for the Python API (replace any negative number with -1 
for the Python API)."
http://bugs.python.org/issue26647#msg262758

Serhiy: "I think we should make yet few related changes: (...) * Change 
f_lasti, tb_lasti etc to count code units instead of bytes."
http://bugs.python.org/issue26647#msg262758

--
Added file: http://bugs.python.org/file45615/lasti.patch

___
Python tracker 

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



Re: Reposting On Python-List PROHIBITED

2016-11-23 Thread mm0fmf

On 23/11/2016 23:28, Lawrence D’Oliveiro wrote:

To the controllers of Python-List:

I never asked to be on your list. I never consented to having my postings 
appear on your list. And I certainly didn’t agree to any conditions you might 
impose on members on your list.

Therefore, to see you take offence at something I said, and use that as an 
excuse to “ban” me from your list, is an act of breathtaking hypocrisy. As far 
as I am concerned, it is you lot who should be banned from comp.lang.python. 
You are reusing its content inappropriately and without authorization. What you 
are doing must be stopped.



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


[issue27153] Default value shown by argparse.ArgumentDefaultsHelpFormatter is backwards for action='store_false'

2016-11-23 Thread paul j3

Changes by paul j3 :


--
nosy: +paul.j3

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread STINNER Victor

STINNER Victor added the comment:

It would be nice if Demur Rumed and/or Serhiy Storchaka can review  
pygen_yf.patch since Demur wrote the wordcode patch and Serhiy reviewed the 
wordcode patch.

--
nosy: +Demur Rumed

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread STINNER Victor

Changes by STINNER Victor :


--
keywords: +patch
Added file: http://bugs.python.org/file45614/pygen_yf.patch

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread STINNER Victor

STINNER Victor added the comment:

Oh wow, the bug is tricky.

_PyGen_yf() checks if the next instruction is YIELD_FROM using code[f_lasti+2]. 
The problem is that WORDCODE kept f_lasti == -1 for a frame not executed yet: 
f_lasti+2 is 1 in this case.

Problem: code[1] is not an operation code, but the argment. Python 3.6 bytecode 
now uses the "wordcode" format: 16-bit units of (operation, argument).

The obvious and simple fix is to add a special case for f_lasti==-1 in 
_PyGen_yf(): see attached patch.

pygen_yf.patch fixes the crash.

--

Another much larger change would be to change f_lasti to -2... In the rewiew of 
the huge WORDCODE patch, if I recall correctly, I asked Demur to use -1 for 
backward compatibility. Or maybe I asked to kept the backward compatibility at 
the Python level using a getter converting -2 to -1... I don't recall correctly.

See http://bugs.python.org/issue26647 for wordcode.

--

___
Python tracker 

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



Re: Quick help for a python newby, please

2016-11-23 Thread Wildman via Python-list
On Wed, 23 Nov 2016 06:18:38 -0800, jones.dayton wrote:

> I'm just learning, so please excuse my ignorance for
> what I know is a simple issue...
> 
> I'm writing a "Hello, World" type of script to see how
> things work in python3.  I'm asking for input to get a
> person's birthday, then I want to compare that to
> "today" and see how many days have past.
> 
> --code--
> from datetime import datetime, date
> 
> person = input("Enter your name: ")
> bmonth = int(input("Enter the numerical month you were born: "))
> bday = int(input("Enter the numerical day of the month you were born: "))
> byear = int(input("Enter the year you were born: "))
> 
> today = date.today()
> -- end --
> 
> I know to get what I want, I need to do something like:
> d0 = date(2008, 8, 18)
> d1 = date(2008, 9, 26)
> delta = d0 - d1
> print(delta.days)
> 
> 
> but how do I replace the "2008, 8, 18" and "2008, 9, 26" with *my* values?  
> I've tried several things (which I can't remember all of) but usually end up 
> with an error like this:
> 
>...
> delta = (b - a)
> TypeError: unsupported operand type(s) for -: 'str' and 'str'

Try the code that is below:

import datetime
from datetime import date

today = date.today()
person = input("Enter your name: ")
byear = raw_input("Enter the four-digit year you were born: ")
bmonth = raw_input("Enter the month (1-12)you were born: ")
bday = raw_input("Enter the day (1-31) you were born: ")
try:
birthdate = date(int(byear), int(bmonth), int(bday))
dif = (today - birthdate).days
print person + "'s birthday was " + str(dif) + " days ago."
except ValueError:
print "The date you entered is not valid!"

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


[issue28742] argparse.ArgumentDefaultsHelpFormatter sometimes provides inaccurate documentation of defaults, so they should be overrideable

2016-11-23 Thread paul j3

paul j3 added the comment:

I might accept a patch that tweaks the ArgumentDefaultsHelpFormatter class, but 
adding a parameter that must propagate through all the Action classes in just 
plain wrong.  

Users are confused by the many Action parameters as it is.  And based on 
StackOverFlow questions, I'd say there are lots of custom Action classes.  We 
cannot make a change that might break those!

One possibility is to tweak the `%(default)s` test to something like:

 if '(default` not in action.help:

Then the user who is not happy with the '%(default)s` display could just write 
a help like:

 help = 'my help text (default: mycustomvalue)'

In other words, embed the bypass mechanism entirely in the 'help' string and 
the Formatter class.  The mechanism would have to be something that is simple 
to explain, and be unlikely to interfere with existing uses of this Formatter.

And to play it safe, I'd suggest field testing a SmarterDefaultsHelpFormatter 
class first - one that implements a change like this, without touching the 
existing class.

Keep in mind that ArgumentDefaultsHelpFormatter is never essential.  The 
argparse developer can always add the '%(default)s` strings to selected 'help' 
lines.  He can even do this in utility functions that know more about the 
underlying program semantics.  I don't think this proposed enhancement gives 
the end user any added control.  

If you want to make a stronger case for this enhancement, find other cases 
where it would be useful.  So far you are just arguing that '(default= True)' 
for a 'store_false' Action may convey the wrong sense to users.  As 
r.david.murray argued, this problem can be minimized with a proper phrasing of 
the help string.

Another thought - 'store_false' is just a subclass of 'store_const'.  You could 
use that class instead with a different set of 'const' and 'default' values. 
e.g. ('Yes','No', or 'not-False', 'not-True').

--
nosy: +paul.j3

___
Python tracker 

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



Re: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
On Wed, 23 Nov 2016 11:27 pm, Frank Millman wrote:

> It is a bit like quantum theory. I have no way of telling whether the
> computation has been carried out without looking at it, but the act of
> looking at it triggers the computation. I can tell, of course, by looking
> at the underlying attribute, but not by using the public methods.

Then give it a public method (or better, a property) to tell.


@property
def needs_computation(self):
return not hasattr(self, '_cached_value')




-- 
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


[issue10379] locale.format() input regression

2016-11-23 Thread Eric V. Smith

Changes by Eric V. Smith :


--
versions: +Python 3.5, Python 3.6 -Python 3.3, Python 3.4

___
Python tracker 

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



[issue28765] _sre.compile(): be more strict on types of indexgroup and groupindex

2016-11-23 Thread STINNER Victor

STINNER Victor added the comment:

An optimization must not change the behaviour of Python.

--

___
Python tracker 

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



[issue28765] _sre.compile(): be more strict on types of indexgroup and groupindex

2016-11-23 Thread STINNER Victor

STINNER Victor added the comment:

> I don't like it because it adds a cumbersome code for guarding against a case 
> that doesn't happen in practice.

Hum, sorry, I don't understand what is the issue with adding a few addition 
checks in the constructor? Is it a matter of speed?


> This is just unpythonic.

Wait, what? I asked you to add checks to not break the Python semantics. If you 
want to be "Pythonic": you must support the Python semantics, so support when 
__getitem__, __len__, etc. are replaced.

I don't understand your "unpythonic" argument.


> _sre.compile() is a private function and it is called only with exact types.

Right. So what is the problem with adding more sanity checks?


> Even if it would called with subtypes, most subtypes don't override __len__ 
> and __getitem__. This restriction is too strong.

It's a matter of respecting the Python semantics.

--

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread Yury Selivanov

Yury Selivanov added the comment:

Wow, Martin, this is a very interesting one.  Thanks so much for tracking this 
down and reducing the test case.

So far this doesn't seem to be related to async/await: the interpreter stack 
seems to enter some strange state under some conditions, and async/await just 
happens to be the thing that explodes.

To those trying to debug this: you don't need asyncio, just replace 
`loop.run_until_complete(main())` with `main().send(None)`.

--

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread Yury Selivanov

Changes by Yury Selivanov :


--
nosy: +serhiy.storchaka

___
Python tracker 

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



Re: Is this pythonic?

2016-11-23 Thread Gregory Ewing

Frank Millman wrote:
For the time being I will use 'print(await obj.__str__())', as this is a 
good compromise.


It seems more like a very *bad* compromise to me.

I can't see how this gains you anything over just doing
print(await obj.getvalue()), and you lose the ability to
do anything that calls __str__ implicitly.

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


[issue28682] Bytes support in os.fwalk()

2016-11-23 Thread Zac Medico

Changes by Zac Medico :


--
nosy: +zmedico

___
Python tracker 

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



[issue28532] Show sys.version when -V option is supplied twice.

2016-11-23 Thread Martin Panter

Martin Panter added the comment:

Looks good to me

--

___
Python tracker 

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



[issue10379] locale.format() input regression

2016-11-23 Thread Wolfgang Maier

Changes by Wolfgang Maier :


--
nosy: +wolma

___
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-11-23 Thread Steve Dower

Steve Dower added the comment:

Thanks.

For reference, the setuptools issue is 
https://github.com/pypa/setuptools/issues/857

A setuptools install from source should be fixed by this change, though an 
install from a wheel (which is now typical, unfortunately) requires a separate 
fix. But we've done our part now.

--
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



[issue28783] Embedded/nuget packages incorrectly reference bdist_wininst

2016-11-23 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f7aa200bed8d by Steve Dower in branch '3.5':
Issue #28783: Embedded and nuget packages incorrect reference missing 
bdist_wininst command.
https://hg.python.org/cpython/rev/f7aa200bed8d

New changeset a3755890545c by Steve Dower in branch '3.6':
Issue #28783: Embedded and nuget packages incorrect reference missing 
bdist_wininst command.
https://hg.python.org/cpython/rev/a3755890545c

New changeset 831f73efe3a6 by Steve Dower in branch 'default':
Issue #28783: Embedded and nuget packages incorrect reference missing 
bdist_wininst command.
https://hg.python.org/cpython/rev/831f73efe3a6

--
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: Random number help

2016-11-23 Thread Thomas Grops via Python-list
Thankyou for all your help I have managed to pick a way that works from your 
suggestions :D
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Random number help

2016-11-23 Thread MRAB

On 2016-11-23 19:29, Chris Kaynor wrote:

On Wed, Nov 23, 2016 at 11:17 AM, Thomas Grops via Python-list
 wrote:

I need a way of generating a random number but there is a catch:

I don't want to include certain numbers, is this possible?

random.randint(1,100) works as it will randomly pick numbers between 1 and 100 
but say i don't want 48 to come out is there a way of doing this. It needs to 
be an integer too so not a list unless there is a way to convert list to int


There are a few ways to accomplish this, depending on the exact
requirements. Here are some basic ideas:
- Generate a list of all valid values, and take the one at a random
index. random.sample may be useful. This is guaranteed to complete
(and in only one try), but generally takes extra memory. It is also a
reasonably easy way to sample without replacement (remove the picked
item each time).
- Generate a random number from the larger range, and retry if you get
one in the invalid set. Basically akin to rolling a die, and rerolling
until you don't get a 6. This could theoretically take forever,
however it is often good enough in practice. This will become more and
more inefficient as set of invalid values grows (especially if the
invalid set is a superset of the whole range)

Another way is to map a shorter range to the desired numbers using an 
offset:


r = random.randint(1, 99)
if r >= 48:
r += 1

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


Re: Random number help

2016-11-23 Thread Thomas Grops via Python-list
On Wednesday, 23 November 2016 19:30:21 UTC, Chris Kaynor  wrote:
> On Wed, Nov 23, 2016 at 11:17 AM, Thomas Grops via Python-list
>  wrote:
> > I need a way of generating a random number but there is a catch:
> >
> > I don't want to include certain numbers, is this possible?
> >
> > random.randint(1,100) works as it will randomly pick numbers between 1 and 
> > 100 but say i don't want 48 to come out is there a way of doing this. It 
> > needs to be an integer too so not a list unless there is a way to convert 
> > list to int
> 
> There are a few ways to accomplish this, depending on the exact
> requirements. Here are some basic ideas:
> - Generate a list of all valid values, and take the one at a random
> index. random.sample may be useful. This is guaranteed to complete
> (and in only one try), but generally takes extra memory. It is also a
> reasonably easy way to sample without replacement (remove the picked
> item each time).
> - Generate a random number from the larger range, and retry if you get
> one in the invalid set. Basically akin to rolling a die, and rerolling
> until you don't get a 6. This could theoretically take forever,
> however it is often good enough in practice. This will become more and
> more inefficient as set of invalid values grows (especially if the
> invalid set is a superset of the whole range)

many thanks but am I missing something when I use a list it returns a value 
with the type list not integer? I need an integer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Random number help

2016-11-23 Thread Thomas Grops via Python-list
On Wednesday, 23 November 2016 19:30:04 UTC, Thomas Nyberg  wrote:
> On 11/23/2016 02:17 PM, Thomas Grops via Python-list wrote:
> > I need a way of generating a random number but there is a catch:
> >
> > I don't want to include certain numbers, is this possible?
> >
> > random.randint(1,100) works as it will randomly pick numbers between 1 and 
> > 100 but say i don't want 48 to come out is there a way of doing this. It 
> > needs to be an integer too so not a list unless there is a way to convert 
> > list to int
> >
> > Many Thanks Tom
> >
> If you specifically want to exclude 48, you could create the list of 
> acceptable numbers and make a random choice from it. For example:
> 
>  >>> import random
>  >>> l = list(range(1, 48)) + list(range(49, 101))
>  >>> random.choice(l)
> 64
> 
> Cheers,
> Thomas

Thankyou, I just tried this but it seems to be printing every value excluding 
48, I am just after a single value
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28783] Embedded/nuget packages incorrectly reference bdist_wininst

2016-11-23 Thread Steve Dower

Steve Dower added the comment:

A convenient test is:

python.exe -c "import distutils.core; distutils.core.setup()" --help-comm
ands

Without the fix, it raises "distutils.errors.DistutilsModuleError: invalid 
command 'bdist_wininst'".

But yes, unfortunately the fix is not particularly direct here. I've validated 
that it works, and since it really only has to work on my machine (right now) 
that's actually pretty good coverage :)

--

___
Python tracker 

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



Re: Random number help

2016-11-23 Thread Achilleas Michailidis


You can use a while statement until you get a number out of your 
excluded numbers


excludedNumbers = [1,2,3,4]
randomNumber = random.randomint(1,100)

while randomNumber in excludedNumbers:
randomNumber = random.randomint(1,100)

After the while you have a number outside the excluded numbers




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


Re: Random number help

2016-11-23 Thread Chris Kaynor
On Wed, Nov 23, 2016 at 11:17 AM, Thomas Grops via Python-list
 wrote:
> I need a way of generating a random number but there is a catch:
>
> I don't want to include certain numbers, is this possible?
>
> random.randint(1,100) works as it will randomly pick numbers between 1 and 
> 100 but say i don't want 48 to come out is there a way of doing this. It 
> needs to be an integer too so not a list unless there is a way to convert 
> list to int

There are a few ways to accomplish this, depending on the exact
requirements. Here are some basic ideas:
- Generate a list of all valid values, and take the one at a random
index. random.sample may be useful. This is guaranteed to complete
(and in only one try), but generally takes extra memory. It is also a
reasonably easy way to sample without replacement (remove the picked
item each time).
- Generate a random number from the larger range, and retry if you get
one in the invalid set. Basically akin to rolling a die, and rerolling
until you don't get a 6. This could theoretically take forever,
however it is often good enough in practice. This will become more and
more inefficient as set of invalid values grows (especially if the
invalid set is a superset of the whole range)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Random number help

2016-11-23 Thread Thomas Nyberg

On 11/23/2016 02:17 PM, Thomas Grops via Python-list wrote:

I need a way of generating a random number but there is a catch:

I don't want to include certain numbers, is this possible?

random.randint(1,100) works as it will randomly pick numbers between 1 and 100 
but say i don't want 48 to come out is there a way of doing this. It needs to 
be an integer too so not a list unless there is a way to convert list to int

Many Thanks Tom

If you specifically want to exclude 48, you could create the list of 
acceptable numbers and make a random choice from it. For example:


>>> import random
>>> l = list(range(1, 48)) + list(range(49, 101))
>>> random.choice(l)
64

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


Re: Random number help

2016-11-23 Thread Marko Rauhamaa
Thomas Grops :

> random.randint(1,100) works as it will randomly pick numbers between 1
> and 100 but say i don't want 48 to come out is there a way of doing
> this. It needs to be an integer too so not a list unless there is a way
> to convert list to int

   r = 48
   while r == 48:
   r = random.randint(1, 100)


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


[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread Ned Deily

Ned Deily added the comment:

FWIW, hg bisect finds:

changeset 103444:a77756e480c2: bad
The first bad revision is:
changeset:   103444:a77756e480c2
parent:  103442:914a81781291
user:Victor Stinner 
date:Fri Sep 09 10:17:08 2016 -0700
summary: Rework CALL_FUNCTION* opcodes

Also, FWIW, the successful runs prior to this revision report:

base_events.py:481: ResourceWarning: unclosed event loop 
<_UnixSelectorEventLoop running=False closed=False debug=False>

--
nosy: +haypo

___
Python tracker 

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



Random number help

2016-11-23 Thread Thomas Grops via Python-list
I need a way of generating a random number but there is a catch:

I don't want to include certain numbers, is this possible?

random.randint(1,100) works as it will randomly pick numbers between 1 and 100 
but say i don't want 48 to come out is there a way of doing this. It needs to 
be an integer too so not a list unless there is a way to convert list to int

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


[issue28783] Embedded/nuget packages incorrectly reference bdist_wininst

2016-11-23 Thread Paul Moore

Paul Moore added the comment:

I've had a look. I agree in principle with the change, and the code looks OK on 
inspection, although I can't really test it. As it's only a change to one of 
the scripts in tools/msi, this seems like a low-risk change to me, so I'm OK 
with it.

--

___
Python tracker 

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



Re: Can I print 2 calendars side by side?

2016-11-23 Thread Dayton Jones
Perfect!  Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28781] On Installation of 3.5 Python get error message

2016-11-23 Thread Steve Dower

Steve Dower added the comment:

Do you see a "Repair" option when running the installer again?

If not, open Programs and Features and find Python there, double-click it and 
select "Repair".

Otherwise, you should have a set of log files in your %TEMP% directory (sort by 
date and they all start with "Python"). If you can bundle those up and attach 
them to this issue, I can take a closer look.

--

___
Python tracker 

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



Re: Can I print 2 calendars side by side?

2016-11-23 Thread MRAB

On 2016-11-23 18:02, Dayton Jones wrote:

I'd like to be able to display 2 calendars side by side, instead of stacked... 
is this possible?

for instance:

print(calendar.month(year_a,month))
print()
print(calendar.month(year_b,month))

prints:
 June 1971
Mo Tu We Th Fr Sa Su
1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30


 June 2017
Mo Tu We Th Fr Sa Su
  1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30



but what I would like is:
 June 1971   June 2017
Mo Tu We Th Fr Sa SuMo Tu We Th Fr Sa Su
1  2  3  4  5  6  1  2  3  4
 7  8  9 10 11 12 13 5  6  7  8  9 10 11
14 15 16 17 18 19 2012 13 14 15 16 17 18
21 22 23 24 25 26 2719 20 21 22 23 24 25
28 29 3026 27 28 29 30


The functions return strings, so you can split them into lines:

rows_a = calendar.month(year_a, month).splitlines()
rows_b = calendar.month(year_b, month).splitlines()

You can then zip them together:

rows = ['{}{}'.format(row_a, row_b) for row_a, row_b in zip(rows_a, 
rows_b)]


However:

1. The 2 months might have a different number of rows. 'zip' will 
truncate to the shorter one, so use itertools.zip_longest instead (give 
it a fillvalue of '').


2. The lines aren't all the same length, so you'll need to pad the 
left-hand one to the correct length (20 characters) to make everything 
line-up.


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


Re: Can I print 2 calendars side by side?

2016-11-23 Thread Peter Otten
Dayton Jones wrote:

> I'd like to be able to display 2 calendars side by side, instead of
> stacked... is this possible?

I'm too lazy to look around for a ready-to-use solution, so here's my own:

$ cat side_by_side.py
from itertools import zip_longest

def zip_lines(*columns, sep="  "):
columns = [c.splitlines() for c in columns]
widths = [max(len(s) for s in c) for c in columns]
return "\n".join(
sep.join(c.ljust(w) for c, w in zip(row, widths))
for row in zip_longest(*columns, fillvalue="")
)

if __name__ == "__main__":
import calendar

print(zip_lines(calendar.month(2016, 1), calendar.month(2015, 1)))
print()

columns = [calendar.month(2016, month) for month in range(6, 9)]
print(zip_lines(*columns, sep="  |  "))
$ python3 side_by_side.py 
January 2016  January 2015
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
 1  2  31  2  3  4
 4  5  6  7  8  9 10   5  6  7  8  9 10 11
11 12 13 14 15 16 17  12 13 14 15 16 17 18
18 19 20 21 22 23 24  19 20 21 22 23 24 25
25 26 27 28 29 30 31  26 27 28 29 30 31   

 June 2016|   July 2016|  August 2016 
Mo Tu We Th Fr Sa Su  |  Mo Tu We Th Fr Sa Su  |  Mo Tu We Th Fr Sa Su
   1  2  3  4  5  |   1  2  3  |   1  2  3  4  5  6  7
 6  7  8  9 10 11 12  |   4  5  6  7  8  9 10  |   8  9 10 11 12 13 14
13 14 15 16 17 18 19  |  11 12 13 14 15 16 17  |  15 16 17 18 19 20 21
20 21 22 23 24 25 26  |  18 19 20 21 22 23 24  |  22 23 24 25 26 27 28
27 28 29 30   |  25 26 27 28 29 30 31  |  29 30 31


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


[issue28673] pyro4 with more than 15 threads often crashes 2.7.12

2016-11-23 Thread Irmen de Jong

Irmen de Jong added the comment:

Due to lack of example code to reproduce the issue, and because I'm mildly 
interested in this bug because it mentions Pyro4 (because I'm the author of 
that) I've tried to crash my system myself using Pyro4 and a simple torture 
test but it trucked on just fine. 
Pyro4 is not doing any "strange" things as far as I am aware. It does have its 
own (simple) thread pool of regular Python threads that are handling incoming 
proxy connections.
(Had Pyro4 been doing weird things I suppose Python itself still should never 
core dump on the user but rather raise a regular exception if something was 
wrong)

--
nosy: +irmen

___
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-11-23 Thread Ned Deily

Ned Deily added the comment:

I'd like one of the other Windows folks to review it but, in principle, LGTM.

--

___
Python tracker 

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



Re: Can I print 2 calendars side by side?

2016-11-23 Thread Tim Chase
On 2016-11-23 10:02, Dayton Jones wrote:
> I'd like to be able to display 2 calendars side by side, instead of
> stacked... is this possible?
> 
> for instance:
> 
> print(calendar.month(year_a,month))
> print()
> print(calendar.month(year_b,month))
> 
> prints:
>  June 1971
> Mo Tu We Th Fr Sa Su
> 1  2  3  4  5  6
>  7  8  9 10 11 12 13
> 14 15 16 17 18 19 20
> 21 22 23 24 25 26 27
> 28 29 30
> 
> 
>  June 2017
> Mo Tu We Th Fr Sa Su
>   1  2  3  4
>  5  6  7  8  9 10 11
> 12 13 14 15 16 17 18
> 19 20 21 22 23 24 25
> 26 27 28 29 30
> 
> 
> but what I would like is:
>  June 1971   June 2017
> Mo Tu We Th Fr Sa SuMo Tu We Th Fr Sa Su
> 1  2  3  4  5  6  1  2  3  4
>  7  8  9 10 11 12 13 5  6  7  8  9 10 11
> 14 15 16 17 18 19 2012 13 14 15 16 17 18
> 21 22 23 24 25 26 2719 20 21 22 23 24 25
> 28 29 3026 27 28 29 30

This seems to do the trick for me

  from itertools import izip_longest
  print ('\n'.join(
"%-24s %s" % (week1, week2)
for week1, week2
in izip_longest(
  month(1971, 6).splitlines(),
  month(2017, 6).splitlines(),
  fillvalue='',
  )
))

Adjust the "-24" to put your desired amount of padding between the
calendars (needs to be at least 21=3 character-columns per day * 7
days per week).  If you want more than two weeks, you can generalize
it:

  dates = [
month(1971, 6),
month(2001, 6),
month(2017, 6),
]

  print ('\n'.join(
'  '.join(w.ljust(21) for w in weeks)
for weeks
in izip_longest(
  *[cal.splitlines() for cal in dates],
  fillvalue=''
  )
))

Hope this helps,

-tkc



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


[issue28781] On Installation of 3.5 Python get error message

2016-11-23 Thread Ned Deily

Changes by Ned Deily :


--
components: +Windows
nosy: +paul.moore, steve.dower, tim.golden, zach.ware

___
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-11-23 Thread Steve Dower

Steve Dower added the comment:

The full fix may also require updating setuptools, which I'm pursuing, but we 
also should stop referring to a module that isn't there.

--

___
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-11-23 Thread Steve Dower

New submission from Steve Dower:

For the embedded zip and nuget releases, I've omitted bdist_wininst. However, I 
forgot to remove the reference to it from distutils.command.__init__.__all__, 
and so setuptools will occasionally crash trying to import it.

This patch updates Tools/msi/make_zip.py to exclude the default 
distutils.command.__init__ and substitute a copy that does not have the added 
reference in it.

Doing something "smarter" in the actual Lib/distutils/command/__init__.py isn't 
really an option. The only reliable option is to import the module eagerly, 
which I don't want to do. Including bdist_wininst in these packages is also a 
bad option (I considered completely removing distutils from them, but it has 
*some* uses - can't say the same for bdist_wininst though).

Ned - I'd like to apply this change to 3.6. The patch is against 3.5, and there 
may be some subtle differences when I merge it forward (not every change to 
make_zip.py has been backported), but the intent is well captured here. If this 
is not applied to 3.6, then the packages will not be reliably usable with 
pip/setuptools, which is one of the intended uses (particularly for the nuget 
package).

--
assignee: steve.dower
components: Windows
files: no_bdist_wininst.patch
keywords: patch
messages: 281576
nosy: ned.deily, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
stage: patch review
status: open
title: Embedded/nuget packages incorrectly reference bdist_wininst
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45613/no_bdist_wininst.patch

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread R. David Murray

R. David Murray added the comment:

I'm marking this as a release blocker since it is a (new) segfault.

--
nosy: +ned.deily, r.david.murray
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



K-means Python code analyse

2016-11-23 Thread Alex
Can please anyone explaine me what do each of these code lines and how k-means 
algorithm works?


from scipy.cluster.vq import *
from scipy.misc import imresize
from pylab import *
from PIL import Image
steps = 500 
im = array(Image.open("empire.jpg"))
dx = im.shape[0] / steps
dy = im.shape[1] / steps
# compute color features for each region
features = []
for x in range(steps): 
for y in range(steps):
R = mean(im[x*dx:(x+1)*dx,y*dy:(y+1)*dy,0])
G = mean(im[x*dx:(x+1)*dx,y*dy:(y+1)*dy,1])
B = mean(im[x*dx:(x+1)*dx,y*dy:(y+1)*dy,2])
features.append([R,G,B]) 
features = array(features,"f") # make into array
# cluster
centroids,variance = kmeans(features,3)
code,distance = vq(features,centroids)
# create image with cluster labels
codeim = code.reshape(steps,steps)
codeim = imresize(codeim,im.shape[:2],interp="nearest")
figure()
imshow(codeim)
show()
-- 
https://mail.python.org/mailman/listinfo/python-list


Can I print 2 calendars side by side?

2016-11-23 Thread Dayton Jones
I'd like to be able to display 2 calendars side by side, instead of stacked... 
is this possible?

for instance:

print(calendar.month(year_a,month))
print()
print(calendar.month(year_b,month))

prints:
 June 1971
Mo Tu We Th Fr Sa Su
1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30


 June 2017
Mo Tu We Th Fr Sa Su
  1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30



but what I would like is:
 June 1971   June 2017
Mo Tu We Th Fr Sa SuMo Tu We Th Fr Sa Su
1  2  3  4  5  6  1  2  3  4
 7  8  9 10 11 12 13 5  6  7  8  9 10 11
14 15 16 17 18 19 2012 13 14 15 16 17 18
21 22 23 24 25 26 2719 20 21 22 23 24 25
28 29 3026 27 28 29 30
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28722] doctest example exit status

2016-11-23 Thread R. David Murray

R. David Murray added the comment:

Rajiv is suggesting an improvement to the documentation.  I think it is a 
reasonable thought, but probably not a good idea on closer examination.  The 
example introduces the basic doctest concepts, and goes on to say that this is 
not the mostly likely way to make use of doctest (and indeed it is not common). 
 So complicating the example and the explanation would be counterproductive to 
the intent of the text, in my opinion.

--
nosy: +r.david.murray

___
Python tracker 

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



[issue28782] SEGFAULT when running a given coroutine

2016-11-23 Thread Martin Richard

New submission from Martin Richard:

Hi,

I stumbled upon a SEGFAULT while trying Python 3.6.0 on a project using
asyncio. I can't really figure out what's happening, so I reduced the original
code triggering the bug down to a reproducible case (which looks a bit clunky,
sorry). The case has been tested on two Linux systems (Archlinux and Debian),
and with several versions of Python.

The bug appears between 3.6.0a4 (most recent version tested not affected) and
3.60b1 (so before the C asyncio module I believe), and is not fixed in the
current repository tip (changeset: 105345:3addf93f4111).

I also produced a traceback using gdb (see bellow).

The segfault happens around the "await" in the body of Cursor._read_data(),
interestingly, if I change anything in the body of the method, the SEGFAULT
disappears and the code works as expected. Also, it seems that calling it from
an other coroutine (main() in the example) is required to trigger the bug.

Cheers,
Martin


Case (also attached as test.py) : 
import asyncio

loop = asyncio.get_event_loop()


class Connection:
def read_until(self, *args, **kwargs):
return self

async def all(self):
return b"\n"


class Cursor:
def __init__(self):
self._connection = Connection()
self._max_bytes = 100
self._data = bytearray()

async def _read_data(self):
# XXX segfault there, if I change anything in the code, it works...
while True:
data = await self._connection.read_until(
b'\n', max_bytes=self._max_bytes).all()
self._max_bytes -= len(data)
if data == b'\n':
break
self._data.extend(data)


async def main():
await Cursor()._read_data()


loop.run_until_complete(main())


Traceback extract (with Python3.6.0b4, --with-pydebug on Linux):

Program received signal SIGSEGV, Segmentation fault.
0x0046d177 in _PyGen_yf (gen=gen@entry=0x734bdaf8) at 
Objects/genobject.c:361
361 Py_INCREF(yf);
(gdb) bt
#0  0x0046d177 in _PyGen_yf (gen=gen@entry=0x734bdaf8) at 
Objects/genobject.c:361
#1  0x0052f49c in _PyEval_EvalFrameDefault (f=0x767067d8, 
throwflag=)
at Python/ceval.c:1992
#2  0x0052a0fc in PyEval_EvalFrameEx (f=f@entry=0x767067d8, 
throwflag=throwflag@entry=0)
at Python/ceval.c:718
#3  0x0046d393 in gen_send_ex (gen=gen@entry=0x734bdc08, 
arg=, 
exc=exc@entry=0, closing=closing@entry=0) at Objects/genobject.c:189
#4  0x0046de8d in _PyGen_Send (gen=gen@entry=0x734bdc08, 
arg=)
at Objects/genobject.c:308
#5  0x7384ba2c in task_step_impl (task=task@entry=0x73263bd8, 
exc=exc@entry=0x0)
at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:1963
#6  0x7384c72e in task_step (task=0x73263bd8, exc=0x0)
at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:2247
#7  0x7384ca79 in task_call_step (arg=, task=)
at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:1848
#8  TaskSendMethWrapper_call (o=, args=, 
kwds=)
at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:1167
#9  0x00446702 in PyObject_Call (func=0x737d7f60, 
args=0x77fb8058, kwargs=0x0)
at Objects/abstract.c:2246
#10 0x005295c8 in do_call_core (func=func@entry=0x737d7f60, 
callargs=callargs@entry=0x77fb8058, kwdict=kwdict@entry=0x0) at 
Python/ceval.c:5054
#11 0x00534c64 in _PyEval_EvalFrameDefault (f=0xb4cb48, 
throwflag=)
at Python/ceval.c:3354
#12 0x0052a0fc in PyEval_EvalFrameEx (f=f@entry=0xb4cb48, 
throwflag=throwflag@entry=0)
at Python/ceval.c:718
#13 0x0052a1cc in _PyFunction_FastCall (co=, 
args=0xb4c5b0, nargs=nargs@entry=1, 
globals=) at Python/ceval.c:4867
(...)

--
components: Interpreter Core
files: test.py
messages: 281573
nosy: martius, yselivanov
priority: normal
severity: normal
status: open
title: SEGFAULT when running a given coroutine
type: crash
versions: Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45612/test.py

___
Python tracker 

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



Re: How to concatenate strings in different lists

2016-11-23 Thread Thomas Nyberg

On 11/23/2016 12:40 PM, Daiyue Weng wrote:

Hi, I am wondering how to concatenate corresponding strings in two lists,
assuming that the lists are of same length, e.g.

val_1 = ['a', 'b', 'c']
val_2 = ['A', 'B', 'C']

# concatenate corresponding strings in 'val_1' and 'val_2'
# and put results in another list 'val' so that
# val = ['aA', 'bB', 'cC']

cheers


Hello,

The easiest is probably first to zip them (i.e. pair the corresponding 
pieces together) and then to join them as you normally would with lists 
of strings:


>>> print([''.join(pair) for pair in zip(val_1, val_2)])
['aA', 'bB', 'cC']

That uses list comprehensions which might be a bit confusing. In two 
steps, you could do the following


>>> pairs = zip(val_1, val_2)
>>> catted_strings = []
>>> for pair in pairs:
catted_string = ''.join(pair)
catted_strings.append(catted_string)
>>> print(catted_strings)
['aA', 'bB', 'cC']

Hope this this helps.

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


Re: How to concatenate strings in different lists

2016-11-23 Thread Joonas Liik
On 23 November 2016 at 19:40, Daiyue Weng  wrote:
> Hi, I am wondering how to concatenate corresponding strings in two lists,
> assuming that the lists are of same length, e.g.
>
> val_1 = ['a', 'b', 'c']
> val_2 = ['A', 'B', 'C']
>
> # concatenate corresponding strings in 'val_1' and 'val_2'
> # and put results in another list 'val' so that
> # val = ['aA', 'bB', 'cC']
>
> cheers
> --
> https://mail.python.org/mailman/listinfo/python-list

one way to do it:

val = [''.join(pair) for pair in zip(val_1, val2)]
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue9216] FIPS support for hashlib

2016-11-23 Thread Gregory P. Smith

Changes by Gregory P. Smith :


--
nosy:  -gregory.p.smith

___
Python tracker 

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



[issue9216] FIPS support for hashlib

2016-11-23 Thread Doug Hellmann

Changes by Doug Hellmann :


--
nosy: +doughellmann

___
Python tracker 

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



How to concatenate strings in different lists

2016-11-23 Thread Daiyue Weng
Hi, I am wondering how to concatenate corresponding strings in two lists,
assuming that the lists are of same length, e.g.

val_1 = ['a', 'b', 'c']
val_2 = ['A', 'B', 'C']

# concatenate corresponding strings in 'val_1' and 'val_2'
# and put results in another list 'val' so that
# val = ['aA', 'bB', 'cC']

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


[issue22298] Lib/warnings.py _show_warning does not protect against being called with a file like object which is closed

2016-11-23 Thread Wolfgang Maier

Wolfgang Maier added the comment:

Issue23016 fixed the "AttributeError: 'NoneType' object has no attribute 
'write'" problem when sys.stderr is None.
With that it's now possible and good practice to set sys.stderr = None when 
closing it, just as Antoine suggested.
Should this issue be closed then?

--

___
Python tracker 

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



Re: Quick help for a python newby, please

2016-11-23 Thread justin walters
On Wed, Nov 23, 2016 at 7:13 AM, Dayton Jones 
wrote:

> ah...yes, but then how could I strip the rest (h:m:s) from it?
>
> Enter the numerical month you were born: 3
> Enter the numerical day of the month you were born: 30
> Enter the year you were born: 1989
> 10100 days, 0:00:00
> --
> https://mail.python.org/mailman/listinfo/python-list
>


You'll probably want to use `timedelta`:
https://docs.python.org/3.4/library/datetime.html#timedelta-objects
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28722] doctest example exit status

2016-11-23 Thread Berker Peksag

Berker Peksag added the comment:

Hi Rajiv, thanks for the report, but this is already possible by default. I 
will use the factorial example from 
https://docs.python.org/3.5/library/doctest.html to demonstrate it:

$ python -m doctest example.py
$ echo $?
0

Now change the following line

>>> [factorial(n) for n in range(6)]

to

>>> [factorial(n) for n in range(5)]

and run the script again:

$ python -m doctest example.py
[...]
***Test Failed*** 1 failures.
$ echo $?
1

--
nosy: +berker.peksag
resolution:  -> not a bug
stage:  -> 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



[issue28779] set_forkserver_preload() can crash the forkserver if preloaded module instantiate multiprocessing classes

2016-11-23 Thread Antoine Pitrou

Changes by Antoine Pitrou :


Added file: http://bugs.python.org/file45611/forkserver_preload.patch

___
Python tracker 

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



[issue28779] set_forkserver_preload() can crash the forkserver if preloaded module instantiate multiprocessing classes

2016-11-23 Thread Antoine Pitrou

Changes by Antoine Pitrou :


Removed file: http://bugs.python.org/file45610/forkserver_preload.patch

___
Python tracker 

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



[issue28779] set_forkserver_preload() can crash the forkserver if preloaded module instantiate multiprocessing classes

2016-11-23 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Here is a patch.

--
keywords: +patch
Added file: http://bugs.python.org/file45610/forkserver_preload.patch

___
Python tracker 

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



  1   2   >