Re: GoPiGo script

2015-11-02 Thread hakugin . gin
On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
> On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@casema.nl wrote:
> > I tried to use def loop(): now for to restart the script.
> > but its only restart "fwd()" print ("forward 1x") and then stop.
> > It does not look further for the if function.
> > Is there another way to restart this script ?
> > I also tried with (while True:) but that does nothing.
> > 
> > Thanks
> 
> 
> 

Ignore that last suggestion... between auto correct and other things there are 
some issues with it.

Try this instead:

from gopigo import *
from time import sleep

# Boolean variable for the "while" loop
KEEP_GOING = True

enable_servo()
mindist = 80
servo(90)

set_right_speed(150)
set_left_speed(105)

def MainLoop():
  # A check statement can be added to set KEEP_GOING to False
  # and allow the function to end
while KEEP_GOING:
fwd()
print("forward1x")
if mindist > us_dist(15):
bwd()
print("backward1x",us_dist(15)
sleep(2)
left_rot()
print("left rot",us_dist(15))
sleep(3)
stop()
if mindist < us_dist(15):
fwd()
print("forward2x",us_dist(15))
time.sleep(2)
stop()

# This is a simple check to determine if the script was run by itself
# or if it was imported by another script. If it was imported it will
# fail this check and not run the code but will allow access to the
# function defined above.
if __name__ == '__main__':
MainLoop()

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


[issue25495] binascii documentation incorrect

2015-11-02 Thread Mouse

Mouse added the comment:

1. I concede knowing nothing about the early Python library implementation, 
functionality, or even purpose.

2. I don't think it makes sense now to either refer to PEM. We'd be two decades 
too late for that (well, 27 years, to be precise :). See
 https://en.wikipedia.org/wiki/Privacy-enhanced_Electronic_Mail

3. I don't think we are in position to tell programmers how to split a string 
of characters into 76-long chunks. Not to mention that the example you gave is 
likely to suffer in performance (just count those function calls), compared to 
other methods, and won't reflect well on the authors.

Here's one possible doc version:

'''
Convert binary data to the base 64 encoding defined in :rfc:`4648`. The return 
value includes a trailing newline ``b"\n"`` if *newline* is true.

If the output is used as Base64 transfer encoding for MIME (:rfc: 2045), base 
64 output should be broken into lines at most 76 characters long to be 
compliant. Base64 encoding standard does not limit the maximum encoded line 
length.
'''

--

___
Python tracker 

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



Re: GoPiGo script

2015-11-02 Thread input/ldompeling
Thank you for the explanation for it.
I must tell you that  i yust beginning with python.
I bought the book beginning programming with python.









In reply to "Dennis Lee Bieber" who wrote the following:

> On Mon, 02 Nov 2015 13:29:04 GMT, input/ldompel...@casema.nl declaimed the
> following:
> 
> > I tried to use def loop(): now for to restart the script.
> > but its only restart "fwd()" print ("forward 1x") and then stop.
> 
> > def loop():
> >fwd()
> >print ("forward 1x")
> >time.sleep(2)
> >stop()
> > 
> > if mindist > us_dist(15):
> 
>  Which is exactly what you told it to do. You have defined a function
> containing four statements: fwd(), print(), sleep(), and stop(); after
> executing the stop the function will return to where it was called -- the
> end of your program.
> 
>  All of your"if" statements will be executed after "loop" is defined
> (but not executed) and before the call to "loop" at the bottom. They are
> NOT part of "loop". Please reread the Python language reference manual,
> focusing on the part that describes indentation and block structuring.
> 
> 
> > loop()
> > 
> 
>  Also, just calling something "loop" does not make it a loop. This
> function will be called just one time and then the program will exit.
> --
>  Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/




-- 
- --- -- -
Posted with NewsLeecher v7.0 Beta 2
Web @ http://www.newsleecher.com/?usenet
--- -  -- -

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


[issue25525] Deallocation scheme for memoryview is unsafe

2015-11-02 Thread Stefan Krah

Stefan Krah added the comment:

Thanks, no big problem.  The thing is that the parts I wrote
(Modules/_decimal/*, Objects/memoryobject.c, Modules/_testbuffer.c)
have been audited rather heavily and have 100% code coverage
with a privately maintained patch that inserts allocation
failures.

There are even tests in test_memoryview() / test_buffer() for
breaking up reference cycles.

So I'd really prefer not to have things labeled as potential issues
when there are none. That also applies to the PyMem_NEW() "potential
overflow" fix in _testbuffer.c where overflow was impossible.

Thus, I'll probably revert that at some point, not out of
hostility, but just because it's not my approach to software
development (in the _testbuffer case, I view the 'len' parameter
as a constrained type in the Ada sense where 0 <= len <= ndim = 64).

--

___
Python tracker 

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



[issue25474] Weird behavior when setting f_trace in a context manager

2015-11-02 Thread Fred Gansevles

Fred Gansevles added the comment:

Xavier, thanks! you found it.
If I look the code again, I see that with zero, one, four and five
the context-manager (i.e. Context()) and the target (one .. five) are on
the same code-line
In the case of two and three they are on a different line.

Now, with the dependency of the trace function on the *physical line* it all 
make sense.

Fred.

--
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: Python 2 vs Python 3 for teaching

2015-11-02 Thread Chris Angelico
On Tue, Nov 3, 2015 at 12:15 AM, beliavsky--- via Python-list
 wrote:
> I think Python 2.x is still used more than Python 3.x in scientific 
> computing. The Python books I have in this area, such as "Python for Finance: 
> Analyze Big Financial Data" and "Python for Data Analysis", still use Python 
> 2.x . An aspiring computational scientist, data scientist, or financial quant 
> may still be better off learning Python 2.x but using print(x) rather than 
> print x and doing other things to future-proof his code.
>

That doesn't mean that Python 3 *can't* be used. Far as I know, all
the key libraries (numpy, pandas, statsmodels, scipy) are available
for Python 3 as well. Recommending the use of Python 2 simply because
all the books you have teach Python 2 is a purely circular argument.

But yes. If you're going to use Py2, aim for the common subset. Good
Py2 code is a lot more similar to good Py3 code than an enumeration of
language-level differences would suggest.

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


Re: same problem even after repair

2015-11-02 Thread Sibylle Koczian

Am 02.11.2015 um 13:35 schrieb Daniel Joffe:


Didn't you see the answers to your first posting? All of them earlier 
than this.


Sibylle


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


Re: help

2015-11-02 Thread Ian Kelly
On Nov 2, 2015 7:31 AM, "Gabe Clark"  wrote:
>
> i am currently running python 3.5 in my programming class and when ever i
> go to open one of my saved files or a file saved by some one else this new
> tab pops up and says modify, repair, or uninstall i have uninstalled and
> repaired it multiple times to no success please help

Check the Windows file association for .py files (you are saving your files
with the .py extension, right?). From the description it sounds like .py
has somehow become associated with the Python installer rather than the
Python interpreter.

If you're familiar with the command line, you can run the script by running
Python specifically and passing the script as a command-line argument.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25483] Improve f-string implementation: FORMAT_VALUE opcode

2015-11-02 Thread Eric V. Smith

Eric V. Smith added the comment:

Right, they're the same because it's a single bit. You 'and' with a mask to get 
the bits you want, and you 'or' together the values. It's an old habit left 
over from my bit-twiddling days.

I guess the test could really be:

have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC;

to make it more clear what I'm doing.

It's easier to see the same thing with the FVC_MASK and FVC_* values, since 
that field is multiple bits.

--

___
Python tracker 

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



[issue25495] binascii documentation incorrect

2015-11-02 Thread R. David Murray

R. David Murray added the comment:

Add a parenthetical "(57 bytes of the input per line)" and I'll be happy with 
that.

--

___
Python tracker 

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



[issue25495] binascii documentation incorrect

2015-11-02 Thread Mouse

Mouse added the comment:

And even those constraints depend on the use. E.g. X.509 does not have those.

--

___
Python tracker 

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



Re: Python 2 vs Python 3 for teaching

2015-11-02 Thread beliavsky--- via Python-list
I think Python 2.x is still used more than Python 3.x in scientific computing. 
The Python books I have in this area, such as "Python for Finance: Analyze Big 
Financial Data" and "Python for Data Analysis", still use Python 2.x . An 
aspiring computational scientist, data scientist, or financial quant may still 
be better off learning Python 2.x but using print(x) rather than print x and 
doing other things to future-proof his code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GoPiGo script

2015-11-02 Thread hakugin . gin
On Monday, November 2, 2015 at 9:28:35 AM UTC-5, input/ld...@casema.nl wrote:
> He mike,
> 
> Thank you or making this script.
> Only I get errors for sleep.
> I also tried to change it to time.sleep() but that also gives errors.
> 
> File "test05.py", line 23
> sleep(2)
> ^
> SyntaxError: invalid syntax
> ---
> 

And this is why I shouldn't code while tired hahaha...

I reviewed the code I submitted and found a couple of other errors. If you are 
changing the "sleep()" lines to "time.sleep()" you will need to change the line 
"from time import sleep" to "import time", otherwise you will most likely 
encounter something like:

Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'time' is not defined

Since you are just beginning with Python I would suggest reading various entry 
level books such as Python 101 by Mike Driscoll, which I have read and own. I 
am not Mike Driscoll, but his book and blog, http://www.blog.pythonlibrary.org/ 
have been extremely helpful. There are MANY resources available for learning 
the Python programming language out there, including 
https://wiki.python.org/moin/BeginnersGuide
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GoPiGo script

2015-11-02 Thread input/ldompeling
I tried to use def loop(): now for to restart the script.
but its only restart "fwd()" print ("forward 1x") and then stop.
It does not look further for the if function.
Is there another way to restart this script ?
I also tried with (while True:) but that does nothing.

Thanks


---
from  gopigo import *
import time


set_right_speed(150)
set_left_speed(105)

enable_servo
mindist = 80
servo(90)
def loop():
fwd()
print ("forward 1x")
time.sleep(2)
stop()

if mindist > us_dist(15):
bwd()
print ("backward 1x",us_dist(15))
time.sleep(2)
left_rot()
print("left rot",us_dist(15))
time.sleep(3)
stop()

if mindist < us_dist(15):
fwd()
print("forward 2x",us_dist(15))
time.sleep(2)
stop()

#for x in range(3):

if mindist > us_dist(15):
bwd()
print("backward 2x",us_dist(15))
time.sleep(2)
stop()
right()

else:
 fwd()
 print("forward else",us_dist(15))
 time.sleep(4)
 stop()

if mindist > us_dist(15):
bwd()
print("backward 3x")
time.sleep(2)
stop()
left_rot()
print("left rot")
time.sleep(1)
stop()
mindist = 80
loop()

































In reply to "Peter Pearson" who wrote the following:

> On Fri, 30 Oct 2015 16:58:16 GMT, input/ldompel...@casema.nl wrote:
> > The GoPiGo is a little robot on wheels.
> > 
> > I want that this script restart when its ends.
> > I tried with "while True"and"return"and also "continue"
> > But those functions gives me errors.
> > What for function else can I use to restart this script.
> > 
> [snip]
> > 
> > from gopigo import *
> > import time
> > 
> > 
> > set_right_speed(150)
> > set_left_speed(105)
> > 
> > while True:
> 
> Is this the "while True" that gave you errors?  I think it
> should, since a "while" should be followed by an indented block
> of code.  Perhaps you should use this "while True" to replace
> the "for x in range(3)" near the bottom.
> 
> > #def test():
> > enable_servo()
> > mindist = 80
> > servo(90)
> > fwd()#wheels go forward
> > print ("forward1x")
> > #time.sleep(5)
> > #stop()
> > 
> > if mindist > us_dist(15):
> >  #enc_tgt(1,1,72)
> > bwd()#wheels go backward
> > print ("backward1x",us_dist(15))
> > time.sleep(2)
> > left_rot()#wheels rotate left
> > print("left rot",us_dist(15))
> > time.sleep(3)
> > stop()
> > 
> > if mindist < us_dist(15):
> >#enc_tgt(1,1,72)
> > fwd()#wheels go forward
> > print("forward2x",us_dist(15))
> > time.sleep(2)
> > stop()
> > 
> > for x in range(3):
> > 
> > if mindist > us_dist(15):
> >  bwd()#wheels go backward
> >  print("backward2x",us_dist(15))
> 
> In future questions, it might help if you explained which of these
> print statements you would like to see executed how many times.
> 
> --
> To email me, substitute nowhere->runbox, invalid->com.




-- 
- --- -- -
Posted with NewsLeecher v7.0 Beta 2
Web @ http://www.newsleecher.com/?usenet
--- -  -- -

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


[issue25483] Improve f-string implementation: FORMAT_VALUE opcode

2015-11-02 Thread Eric V. Smith

Eric V. Smith added the comment:

Some formatting improvements.

I removed one of the optimizations I was doing, because it's also done in 
PyObject_Format(). I plan on moving other optimizations into PyObject_Format(), 
but I'll open a separate issue for that.

I swapped the order of the parameters on the stack, so that I could use the 
micro-optimization of TOP() and SET_TOP().

I'll commit this shortly.

--
Added file: http://bugs.python.org/file40928/format-opcode-3.diff

___
Python tracker 

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



[issue25523] Correct "a" article to "an" article

2015-11-02 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Martin for your review.

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



[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread R. David Murray

R. David Murray added the comment:

I don't see a link to a greenlet issue, and setuptools is not maintained as 
part of the stdlib.  It sounds like we should close this until and if the 
greenlet project can point us to a specific problem with the stdlib distutils.

--
resolution:  -> third party
status: open -> pending

___
Python tracker 

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



[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Kracekumar Ramaraj

Kracekumar Ramaraj added the comment:

I have created an issue in setuptools repo: 
https://bitbucket.org/pypa/setuptools/issues/455/unable-to-build-extension-in-python-35.

--

___
Python tracker 

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



[issue25495] binascii documentation incorrect

2015-11-02 Thread Mouse

Mouse added the comment:

Let's not insinuate anything about the input. This is about what constraints on 
the OUTPUT MAY be there, not a tutorial from the 80-ties on how one might 
accomplish it.

--

___
Python tracker 

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



Re: GoPiGo script

2015-11-02 Thread hakugin . gin
On Monday, November 2, 2015 at 10:21:46 AM UTC-5, MRAB wrote:
> On 2015-11-02 14:28, input/ldom...@casema.nl wrote:
> > He mike,
> >
> > Thank you or making this script.
> > Only I get errors for sleep.
> > I also tried to change it to time.sleep() but that also gives errors.
> >
> > File "test05.py", line 23
> >  sleep(2)
> >  ^
> > SyntaxError: invalid syntax
> > ---
> >
> The previous line is missing a ")"; it should end with two of them, not
> just one.
> 

Yep, I shouldn't code while tired... I also forgot to change line 31 from 
"time.sleep(2)" to "sleep(2)".

> > In reply to "haku...@gmail.com" who wrote the following:
> >
> >> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
> >> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@casema.nl
> >> > wrote:
> >> > > I tried to use def loop(): now for to restart the script.
> >> > > but its only restart "fwd()" print ("forward 1x") and then stop.
> >> > > It does not look further for the if function.
> >> > > Is there another way to restart this script ?
> >> > > I also tried with (while True:) but that does nothing.
> >> > >
> >> > > Thanks
> >> >
> >> > 
> >> >
> >>
> >> Ignore that last suggestion... between auto correct and other things there
> > are
> >> some issues with it.
> >>
> >> Try this instead:
> >>
> >> from gopigo import *
> >> from time import sleep
> >>
> >> # Boolean variable for the "while" loop
> >> KEEP_GOING = True
> >>
> >> enable_servo()
> >> mindist = 80
> >> servo(90)
> >>
> >> set_right_speed(150)
> >> set_left_speed(105)
> >>
> >> def MainLoop():
> >>   # A check statement can be added to set KEEP_GOING to False
> >>   # and allow the function to end
> >> while KEEP_GOING:
> >> fwd()
> >> print("forward1x")
> >> if mindist > us_dist(15):
> >> bwd()
> >> print("backward1x",us_dist(15)
> >> sleep(2)
> >> left_rot()
> >> print("left rot",us_dist(15))
> >> sleep(3)
> >> stop()
> >> if mindist < us_dist(15):
> >> fwd()
> >> print("forward2x",us_dist(15))
> >> time.sleep(2)
> >> stop()
> >>
> >> # This is a simple check to determine if the script was run by itself
> >> # or if it was imported by another script. If it was imported it will
> >> # fail this check and not run the code but will allow access to the
> >> # function defined above.
> >> if __name__ == '__main__':
> >> MainLoop()
> >>

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


[issue25534] SimpleHTTPServer throwed an exception due to negtive st_mtime attr in file

2015-11-02 Thread Sean Wang

New submission from Sean Wang:

I transfered a file from remote Debian host to my local Windows 10 host using 
SecureFX.
I found that the file's last modifed date was ‎1900‎/‎1‎/1‎,‏‎0:00:00 on 
Windows.

I tried to serve this file to be downloaded, and it crashed as follows:
Exception happened during processing of request from ('192.168.1.102', 50978)

Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\SocketServer.py", line 655, in __init__
self.handle()
  File "C:\Python27\lib\BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
  File "C:\Python27\lib\BaseHTTPServer.py", line 328, in handle_one_request
method()
  File "C:\Python27\lib\SimpleHTTPServer.py", line 45, in do_GET
f = self.send_head()
  File "C:\Python27\lib\SimpleHTTPServer.py", line 103, in send_head
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
  File "C:\Python27\lib\BaseHTTPServer.py", line 468, in date_time_string
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
ValueError: (22, 'Invalid argument')

I have checked the source code, and found it was because of the last modifed 
date of the file, I got this in console:

>>> os.fstat(f.fileno())
nt.stat_result(st_mode=33206, st_ino=4785074604093500L, st_dev=0L, st_nlink=1, 
st_uid=0, st_gid=0, st_size=3406L, st_atime=1446477520L, st_mtime=-2209017600L, 
st_ctime=1446370767L)

-2209017600L cannot be handled by "time.gmtime()" method and it throwed 
error

--
components: Library (Lib)
messages: 253926
nosy: Sean.Wang
priority: normal
severity: normal
status: open
title: SimpleHTTPServer throwed an exception due to negtive st_mtime attr in 
file
type: crash
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



[issue25533] Make pkgutil.iter_modules() yield built-in modules

2015-11-02 Thread R. David Murray

R. David Murray added the comment:

IMO, definitely this should not be changed by default.  An alternative to a 
boolean flag would be a new function (iter_all_modules?).

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



help

2015-11-02 Thread Gabe Clark
i am currently running python 3.5 in my programming class and when ever i
go to open one of my saved files or a file saved by some one else this new
tab pops up and says modify, repair, or uninstall i have uninstalled and
repaired it multiple times to no success please help
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GoPiGo script

2015-11-02 Thread input/ldompeling
He mike,

Thank you or making this script.
Only I get errors for sleep.
I also tried to change it to time.sleep() but that also gives errors.

File "test05.py", line 23
sleep(2)
^
SyntaxError: invalid syntax
---

In reply to "hakugin@gmail.com" who wrote the following:

> On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
> > On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@casema.nl 
> > wrote:
> > > I tried to use def loop(): now for to restart the script.
> > > but its only restart "fwd()" print ("forward 1x") and then stop.
> > > It does not look further for the if function.
> > > Is there another way to restart this script ?
> > > I also tried with (while True:) but that does nothing.
> > > 
> > > Thanks
> > 
> > 
> > 
> 
> Ignore that last suggestion... between auto correct and other things there 
are
> some issues with it.
> 
> Try this instead:
> 
> from gopigo import *
> from time import sleep
> 
> # Boolean variable for the "while" loop
> KEEP_GOING = True
> 
> enable_servo()
> mindist = 80
> servo(90)
> 
> set_right_speed(150)
> set_left_speed(105)
> 
> def MainLoop():
>   # A check statement can be added to set KEEP_GOING to False
>   # and allow the function to end
> while KEEP_GOING:
> fwd()
> print("forward1x")
> if mindist > us_dist(15):
> bwd()
> print("backward1x",us_dist(15)
> sleep(2)
> left_rot()
> print("left rot",us_dist(15))
> sleep(3)
> stop()
> if mindist < us_dist(15):
> fwd()
> print("forward2x",us_dist(15))
> time.sleep(2)
> stop()
> 
> # This is a simple check to determine if the script was run by itself
> # or if it was imported by another script. If it was imported it will
> # fail this check and not run the code but will allow access to the
> # function defined above.
> if __name__ == '__main__':
> MainLoop()
> 
> - Mike




-- 
- --- -- -
Posted with NewsLeecher v7.0 Beta 2
Web @ http://www.newsleecher.com/?usenet
--- -  -- -

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


Re: GoPiGo script

2015-11-02 Thread MRAB

On 2015-11-02 14:28, input/ldompel...@casema.nl wrote:

He mike,

Thank you or making this script.
Only I get errors for sleep.
I also tried to change it to time.sleep() but that also gives errors.

File "test05.py", line 23
 sleep(2)
 ^
SyntaxError: invalid syntax
---


The previous line is missing a ")"; it should end with two of them, not
just one.


In reply to "hakugin@gmail.com" who wrote the following:


On Monday, November 2, 2015 at 8:45:35 AM UTC-5, hakug...@gmail.com wrote:
> On Monday, November 2, 2015 at 8:29:26 AM UTC-5, input/ld...@casema.nl
> wrote:
> > I tried to use def loop(): now for to restart the script.
> > but its only restart "fwd()" print ("forward 1x") and then stop.
> > It does not look further for the if function.
> > Is there another way to restart this script ?
> > I also tried with (while True:) but that does nothing.
> >
> > Thanks
>
> 
>

Ignore that last suggestion... between auto correct and other things there

are

some issues with it.

Try this instead:

from gopigo import *
from time import sleep

# Boolean variable for the "while" loop
KEEP_GOING = True

enable_servo()
mindist = 80
servo(90)

set_right_speed(150)
set_left_speed(105)

def MainLoop():
  # A check statement can be added to set KEEP_GOING to False
  # and allow the function to end
while KEEP_GOING:
fwd()
print("forward1x")
if mindist > us_dist(15):
bwd()
print("backward1x",us_dist(15)
sleep(2)
left_rot()
print("left rot",us_dist(15))
sleep(3)
stop()
if mindist < us_dist(15):
fwd()
print("forward2x",us_dist(15))
time.sleep(2)
stop()

# This is a simple check to determine if the script was run by itself
# or if it was imported by another script. If it was imported it will
# fail this check and not run the code but will allow access to the
# function defined above.
if __name__ == '__main__':
MainLoop()



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


[issue25193] itertools.accumulate should have an optional initializer argument

2015-11-02 Thread Alun Champion

Alun Champion added the comment:

Understandable, though it would have also made the first order recurrence 
relationships more accurate, e.g. annualized interest on an initial balance:

accumulate(repeat(None), lambda: bal, _: bal*1.05, initializer=1000)

vs. artificially repeating 1000:

accumulate(repeat(1000), lambda: bal, _: bal*1.05)

Or, if the initialiser is expensive:

accumulate(chain([1000], repeat(None)), lambda: bal, _: bal*1.05)

--

___
Python tracker 

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



[issue25533] Make pkgutil.iter_modules() yield built-in modules

2015-11-02 Thread R. David Murray

Changes by R. David Murray :


--
nosy: +brett.cannon

___
Python tracker 

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



[issue25495] binascii documentation incorrect

2015-11-02 Thread R. David Murray

R. David Murray added the comment:

Please take a look at the Examples section of this:

   http://perldoc.perl.org/MIME/Base64.html

Looks kind of like Martin's suggestion :)

--

___
Python tracker 

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



[issue25483] Improve f-string implementation: FORMAT_VALUE opcode

2015-11-02 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It looks to me that FVS_MASK and FVS_HAVE_SPEC are duplicates. FVS_HAVE_SPEC is 
set but FVS_MASK is tested.

--

___
Python tracker 

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



[issue25474] Weird behavior when setting f_trace in a context manager

2015-11-02 Thread Xavier de Gaye

Xavier de Gaye added the comment:

The difference lies in the line numbers. When tracing lines, the interpreter 
operates on the basis of physical lines, not logical lines 
(https://docs.python.org/3/reference/lexical_analysis.html#line-structure).  
The local trace function is called on the first instruction of each physical 
line (see the comment in maybe_call_line_trace() in Python/ceval.c).

In the first case of as_context.py, the 'zero' case, we have:

 25  74 SETUP_EXCEPT49 (to 126)

 27  77 LOAD_NAME6 (Context)
 80 CALL_FUNCTION0 (0 positional, 0 keyword pair)
 83 SETUP_WITH  20 (to 106)
 86 STORE_NAME   7 (zero)

 28  89 LOAD_NAME8 (print)
 92 LOAD_CONST   5 ('zero')
 95 LOAD_NAME7 (zero)
 ...

After 'CALL_FUNCTION' has been run and the trace function set up, the __raise() 
local trace function is invoked for the first time upon running the 'LOAD_NAME' 
instruction, since 'SETUP_WITH' and 'STORE_NAME' are not the first instruction 
of line 27.

In the 'two' case, we have:

 41 >>  214 SETUP_EXCEPT49 (to 266)

 42 217 LOAD_NAME6 (Context)
220 CALL_FUNCTION0 (0 positional, 0 keyword pair)
223 SETUP_WITH  20 (to 246)

 43 226 STORE_NAME  11 (two)

 44 229 LOAD_NAME8 (print)
232 LOAD_CONST   9 ('two')
235 LOAD_NAME   11 (two)


Here the __raise() local trace function is invoked for the first time upon 
running the 'STORE_NAME' instruction.

--

___
Python tracker 

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



[issue25534] SimpleHTTPServer throwed an exception due to negtive st_mtime attr in file

2015-11-02 Thread Sean Wang

Sean Wang added the comment:

upload a sample test file

--
Added file: http://bugs.python.org/file40929/test

___
Python tracker 

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



[issue25483] Improve f-string implementation: FORMAT_VALUE opcode

2015-11-02 Thread Stefan Krah

Stefan Krah added the comment:

The MASK idiom is nice and I think it's good to be exposed to
it from time to time.

--
nosy: +skrah

___
Python tracker 

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



[issue25523] Correct "a" article to "an" article

2015-11-02 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 75df8b0a2cd1 by Serhiy Storchaka in branch '3.4':
Issue #25523: Further a-to-an corrections.
https://hg.python.org/cpython/rev/75df8b0a2cd1

New changeset 68edc7baeef7 by Serhiy Storchaka in branch '3.5':
Issue #25523: Merge a-to-an corrections from 3.4.
https://hg.python.org/cpython/rev/68edc7baeef7

New changeset a0d0f968b020 by Serhiy Storchaka in branch '3.5':
Issue #25523: Further a-to-an corrections new in 3.5.
https://hg.python.org/cpython/rev/a0d0f968b020

New changeset 72cca30f4707 by Serhiy Storchaka in branch 'default':
Issue #25523: Merge a-to-an corrections from 3.5.
https://hg.python.org/cpython/rev/72cca30f4707

New changeset e8f3c011e2b4 by Serhiy Storchaka in branch '2.7':
Issue #25523: Backported a-to-an corrections.
https://hg.python.org/cpython/rev/e8f3c011e2b4

--

___
Python tracker 

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



same problem even after repair

2015-11-02 Thread Daniel Joffe


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


need help understanding a python program

2015-11-02 Thread Lee Bradley
http://pastebin.com/ndDYjYe1

The above link takes you to a very interesting way of solving the classic game 
of Bulls and Cows. It uses an entropy-based decision algorithm. I realize this 
is asking a lot but I am not yet proficient enough in python to follow some of 
the methods.

There is a fair amount on the internet on both the game and on entropy-based 
machine learning. I will provide further information if anyone is interested.

For now I am looking for someone who can dig into this code and explain what's 
going on. I understand a lot of it but not enough to really *get it*.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25536] use sys.platform instead of os.name in asyncio docs consistently

2015-11-02 Thread Guido van Rossum

Guido van Rossum added the comment:

Sounds good. I'll commit this.

--

___
Python tracker 

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



[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Ned Deily

Changes by Ned Deily :


--
Removed message: http://bugs.python.org/msg253937

___
Python tracker 

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



[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Ned Deily

Ned Deily added the comment:

As David notes, this issue does not document any problems with Python 3.5 
itself.  I see at least two issues here.  One, you are using virtualenv, a 
third-party package, rather than Python's built-in venv.  It appears that the 
most recent release of virtualenv on PyPI, virtualenv 13.1.2, includes outdated 
wheels of other third-party products, in particular, of wheel: 0.24, instead of 
the current 0.26 (https://pypi.python.org/pypi/wheel).  If you update wheel in 
your virtualenv that should fix the "assert tag == supported_tags[0]" issue.  
Suggest you open an issue against virtualenv to ask that they update their 
vendored packages or perhaps not include them.  Another problem, when using the 
python.org python3.5, is with the install script of the uwsgi, uwsgiconfig.py.  
The script does some machinations to figure out what compiler it is using.  
Unfortunately, it seems to get confused by the fact that, with the last several 
major releases of Xcode, Apple no long ships gcc but does provi
 de a gcc alias that actually invokes clang.  If you override the CC value and 
explictly set CC=clang, the uwsgi install seems to work correctly with the 
python.org OS X 3.5.0.  You should probably open an issue with the uwsgi 
project about that.  I do not have a homebrew installation handy to check, so 
if there are other problems after updating wheel in your virtualenv (or 
switching to use builtin venv) and using CC=clang, suggest you ask on a 
homebrew forum.

--

___
Python tracker 

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



[issue25535] collections.Counter methods return Counter objects instead of subclass objects

2015-11-02 Thread R. David Murray

R. David Murray added the comment:

This indeed looks like a bug to me, but I won't be surprised if Raymond says it 
was done on purpose.  On the other hand originally the binary operator mothods 
didn't correctly return NotImplemented for non-Counters, so perhaps it is just 
an oversight. 

I'm not sure what the backward compatibility consequences would be of changing 
it.

--
nosy: +r.david.murray, rhettinger
title: collections.Counter methods return Counter objects -> 
collections.Counter methods return Counter objects instead of subclass objects

___
Python tracker 

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



[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Ned Deily

Ned Deily added the comment:

As David notes, this issue does not document any problems with Python 3.5 
itself.  I see at least two issues here.  One, you are using virtualenv, a 
third-party package, rather than Python's built-in venv.  It appears that the 
most recent release of virtualenv on PyPI, virtualenv 13.1.2, includes outdated 
wheels of other third-party products, in particular, of wheel: 0.24, instead of 
the current 0.36 (https://pypi.python.org/pypi/wheel).  If you update wheel in 
your virtualenv that should fix the "assert tag == supported_tags[0]" issue.  
Suggest you open an issue against virtualenv to ask that they update their 
vendored packages or perhaps not include them.  Another problem, when using the 
python.org python3.5, is with the install script of the uwsgi, uwsgiconfig.py.  
The script does some machinations to figure out what compiler it is using.  
Unfortunately, it seems to get confused by the fact that, with the last several 
major releases of Xcode, Apple no long ships gcc but does provi
 de a gcc alias that actually invokes clang.  If you override the CC value and 
explictly set CC=clang, the uwsgi install seems to work correctly with the 
python.org OS X 3.5.0.  I do not have a homebrew installation handy to check, 
so if there are other problems after updating wheel in your virtualenv (or 
switching to use builtin venv) and using CC=clang, suggest you ask on a 
homebrew forum.

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



[issue25535] collections.Counter methods return Counter objects instead of subclass objects

2015-11-02 Thread Mark Dickinson

Mark Dickinson added the comment:

I'm fairly sure that this behaviour is deliberate, and (more-or-less) 
consistently applied throughout the builtin and standard library types. If you 
create a subclass C of list, then concatenation of two instances of C still 
gives a result of type list. Similarly, if you subclass Decimal then arithmetic 
operations on instances of your subclass still return a Decimal instance. If 
you want operations to return instances of the subclass, it's up to you to 
override those operations in your subclass.

Having the Counter operations automatically return an instance of the subclass 
would mean placing restrictions on the signature of the constructor of any such 
subclass, which may be undesirable. (A subclass may want to require additional 
arguments in its constructor.)

--
nosy: +mark.dickinson

___
Python tracker 

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



[issue24306] Backport py.exe to 3.4

2015-11-02 Thread Steve Dower

Steve Dower added the comment:

So with the 3.5 launcher being installed all-users by default, the attached 
patch is a good option.

I'm not able to build 3.4 entirely, but I made the modification to the MSI 
directly and it works fine, so I intend to go ahead and apply it (with some 
extra line wrapping for formatting purposes) before 3.4.4

Unfortunately, I believe upgrades from 3.4.3 to 3.4.4 may remove the 3.5 
launcher and then replace it with the 3.4 one. Unfortunately, there's no way to 
prevent this. Subsequently repairing or installing 3.5 should bring back the 
newer one.

Martin - any concerns here?

--

___
Python tracker 

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



Re: need help understanding a python program

2015-11-02 Thread Ben Finney
Lee Bradley  writes:

> http://pastebin.com/ndDYjYe1

We much prefer to discuss code in the context of plain text messages
right here, because this forum is archived longer than the expected
lifetime of content hosted on other services.

> For now I am looking for someone who can dig into this code and
> explain what's going on. I understand a lot of it but not enough to
> really *get it*.

Could you discuss your own impressions of it so far, with (parts of) the
code pasted here as plain text for context of your commentary?

-- 
 \   Moriarty: “Forty thousand million billion dollars? That money |
  `\must be worth a fortune!” —The Goon Show, _The Sale of |
_o__)   Manhattan_ |
Ben Finney

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


Re: Modern recommended exception handling practices?

2015-11-02 Thread Steven D'Aprano
Hi Vasudev, and welcome.

Sorry for the delay in replying to your questions. My answers inline, below.


On Fri, 30 Oct 2015 04:43 am, vasudevram wrote:

> Are there any modern (i.e. for current versions of Python 2 and 3)
> recommended exception handling practices?

When you say "modern", it sounds like you want to contrast them with "old
fashioned and obsolete" exception-handling practices. I don't know if there
are any obsolete exception-handling practices in Python.

I would follow these rules, as best I am able to:


(1) Remember that, in general, exception catching is very course-grained.
You can catch a particular kind of exception, but you don't know which
specific line of code or expression caused it, the reason why, or where in
the `try` block it was raised. The entire `try` clause is as fine-grained
as you get.

One consequence is that it is easy to write exceptional handling code which
is wrong and buggy:

http://blogs.msdn.com/b/oldnewthing/archive/2004/04/22/118161.aspx

http://blogs.msdn.com/b/oldnewthing/archive/2005/01/14/352949.aspx


To avoid this, the `try` block should cover the least amount of code
possible. For example, suppose you have this:

try:
result = calculate(mylist.index(x), func(key))
except ValueError:
# thrown by mylist.index if x is not found
result = "x not found"


That code is probably unsafe, because you can't be sure that either
func(key) or calculate(...) itself might not throw a ValueError. Unless you
can guarantee that there are no circumstances where that might happen, or
if it doesn't matter which of the three expressions throws the ValueError,
you are better off writing this:

try:
idx = mylist.index(x)
except ValueError:
result = "x not found"
else:
result = calculate(idx, func(key))


(2) Catch only the exceptions that you expect and can genuinely recover
from. Don't use `try...except` as a way to cover up and hide the fact that
an error occurred.

One of my favourite quotes about programming is this one:

   "I find it amusing when novice programmers believe their main
job is preventing programs from crashing. ... More experienced
programmers realize that correct code is great, code that
crashes could use improvement, but incorrect code that doesn’t
crash is a horrible nightmare."
-- Chris Smith

In context of Python, "crash" means "raise an exception". Exceptions are
your best friend: they show you were your bugs are. How can you fix bugs if
you don't know where they are?

You should only catch the exceptions that you expect to occur, and can
recover from. Everything else should be allowed to raise an exception, so
you can *see* that something is broken. Now you know that something in your
code has a bug, and needs to be fixed.

Consequently, you should never (well, *almost* never) be tempted to write a
bare `except` clause, or even `except Exception`. They are almost always
too broad, and catch too much.

Bare `except` clauses are very possibly *literally the worst* thing that you
can write in Python:

https://realpython.com/blog/python/the-most-diabolical-python-antipattern/


(3) One exception to rule (2) is that sometimes it is useful to surround
your entire main program with a `try...except`, for the purposes of logging
errors and presenting a nice clean error message to your users:

try:
main()
except Exception as err:
# Catch any and all unexpected exceptions.
log(err)
alert("A serious problem has occurred and MyApplication must quit. " 
  "Please contact the help desk on 999-999-999.")
sys.exit(1)


(4) Remember that Python matches exceptions from top down, so more specific
exceptions (subclasses of a less specific exception) need to come first. So
if we write this:

try:
...
except Exception:
print("something unexpected occurred")
except TypeError:
print("this is expected")


the TypeError will be caught by the first except clause, and treated as
something unexpected. Swap the order of the except clauses, and you will be
fine:

try:
...
except TypeError:
print("this is expected")
except Exception:
print("something unexpected occurred")


(5) Remember that often you can avoid exceptions instead of catching
them. "Look Before You Leap" (LBYL) may be a perfectly good alternative:

if item in mylist:
idx = mylist.index(item)
process(idx)
else:
result = "not found"


but be sensitive to the amount of work done. The above code searches the
list twice instead of just once.


(6) In general, you can consider setting up a "try" block to be practically
free in Python (which is the opposite to Java, where exception handling is
always expensive). If no exception occurs, there is virtually no difference
in speed between:

func(x)

and

try:
func(x)
except:
pass


but if an exception 

[issue25455] Some repr implementations don't check for self-referential structures

2015-11-02 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Changing PyObject_Repr is too course; it affects a broad class of objects other 
than containers, and it risks unknown impacts to larges swaths of third-party 
code use this venerable API.  It is also a break with the long established 
history of recursion detection being a responsibility of the individual types 
(i.e. the code in sets, lists, dicts, etc.)

The three cases listed here should be fixed individually.

--
nosy: +rhettinger

___
Python tracker 

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



Re: Unbuffered stderr in Python 3

2015-11-02 Thread Nobody
On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote:

> In Python 2, stderr is unbuffered.
> 
> In most other environments (the shell, C...) stderr is unbuffered.
> 
> It is usually considered a bad, bad thing for stderr to be buffered. What
> happens if your application is killed before the buffer fills up? The
> errors in the buffer will be lost.
> 
> So how come Python 3 has line buffered stderr? And more importantly, how
> can I turn buffering off?

It's probably related to the fact that std{in,out,err} are Unicode
streams. 

> type(sys.stderr)

> type(sys.stderr.buffer)

> type(sys.stderr.buffer.raw)


It appears that you can turn it off with:

sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
or:
sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach())

This results in a sys.stderr which appears to work and whose
.line_buffering property is False.

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


[issue25540] virtual conf file encoding error on windows

2015-11-02 Thread tanbro

New submission from tanbro:

When create a new `venv` on windows, sometimes an `UnicodeDecodeError` occurred.

It seems that, it is caused by the system module `site`.

In `Lib/site.py`, line 468::

with open(virtual_conf) as f:
for line in f:
line = line.strip()

The file `virtual_conf` was open with encoding `gbk` which is my windows 
default encoding, but in fact, the file is an `utf-8` one, so i think it should 
be::

with open(virtual_conf, encoding='utf-8') as f:
for line in f:
line = line.strip()

--
messages: 253968
nosy: tanbro
priority: normal
severity: normal
status: open
title: virtual conf file encoding error on windows
type: crash
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: Modern recommended exception handling practices?

2015-11-02 Thread Chris Angelico
On Tue, Nov 3, 2015 at 5:47 PM, Steven D'Aprano  wrote:
> On Fri, 30 Oct 2015 04:43 am, vasudevram wrote:
>
>> Are there any modern (i.e. for current versions of Python 2 and 3)
>> recommended exception handling practices?
>
> When you say "modern", it sounds like you want to contrast them with "old
> fashioned and obsolete" exception-handling practices. I don't know if there
> are any obsolete exception-handling practices in Python.

Aside from string exceptions and the "except Type, e:" syntax, I would
agree with you. Actually, I can't think of any "obsolete
exception-handling practices" in any language. Exception handling is
pretty straight-forward: you raise an exception in one place, and you
catch it in another.

> Bare `except` clauses are very possibly *literally the worst* thing that you
> can write in Python:
>
> https://realpython.com/blog/python/the-most-diabolical-python-antipattern/

I would actually like to disallow the bare except, in the same way
that I would disallow the Py2 input() function. In the rare cases
where you really do want to catch *every* exception (eg at a boundary
between a web server and a request handler, where you would log the
exception and return a 500), it should be spelled "except
BaseException [as e]:", same as you should use "eval(raw_input())" in
those extremely rare cases where you actually want to take keyboard
input and evaluate it.

But more generally, the over-broad exception handler is a nasty anti-pattern.

> (5) Remember that often you can avoid exceptions instead of catching
> them. "Look Before You Leap" (LBYL) may be a perfectly good alternative:
>
> if item in mylist:
> idx = mylist.index(item)
> process(idx)
> else:
> result = "not found"
>
>
> but be sensitive to the amount of work done. The above code searches the
> list twice instead of just once.

Not to mention having race condition possibilities. There are a few
places where this is useful, though:

start_time = time()
work_done = do_some_work()
time_spent = time()-start_time or 1
print(f"Did {work_done} jobs in {time_spent} secs: {work_done/time_spent} j/s")

The "or 1" is a quick check that means we don't divide by zero. The
performance figure becomes meaningless, but if this is a rare case,
that's probably fine.

> (7) So which is faster, LBYL or catching the exception? That is extremely
> sensitive to not just the specific operations being performed, but how
> often the exceptional cases occur. In general, you must measure your code
> to know.
>
> But as a very rough rule of thumb, consider looking up a key in a dict:
>
> if key in mydict:
> result = mydict[key]
>
> versus
>
> try:
> result = mydict[key]
> except KeyError:
> pass
>
>
> In my experience, catching the KeyError is about ten times more costly than
> testing for the key's presence. So if your keys are missing more than one
> time in ten, it's probably better to use LBYL.

This is actually a tribute to dict performance for key lookup (since
that's one of the important operations in a hashtable). It's NOT the
case for a list.


Exceptions are the "other way" to return something. In a function that
always returns a string, returning None is distinguishable (in the
same way that a C function can return a NULL pointer); in a function
that returns absolutely any object, the only way to signal "no object
to return" is to raise an exception. That's why StopIteration exists,
for instance. Exceptions are a normal part of program flow - they
signal an "exceptional condition" in some small area, but it's normal
to cope with exceptional conditions.

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


Re: Modern recommended exception handling practices?

2015-11-02 Thread Chris Angelico
On Tue, Nov 3, 2015 at 6:22 PM, Steven D'Aprano  wrote:
> A lot can happen in the few microseconds between
> checking for the existence of the file and actually opening it -- the file
> could be renamed or deleted.

And a lot of microseconds can happen between two opcodes, too. Even
inside a Python script, it's possible for threads or other arbitrary
code execution to get in your way:

if "foo" in counters:
# context switch here!
process(counters["foo"])

Garbage collection can happen at any time. Here's an (admittedly
arbitrary) example of how the above could be broken:

>>> class X:
... def __init__(self, name, dict):
... self.dict = dict; self.name = name
... self.dict[self.name] = 0
... def frob(self):
... self.dict[self.name] += 1
... def __del__(self):
... del self.dict[self.name]
...
>>> counters = {}
>>> x = X("foo", counters)
>>> x.refcycle = x
>>> counters
{'foo': 0}
>>> del x
>>> counters
{'foo': 0}
>>> gc.collect()
10
>>> counters
{}

If the cycle-detecting garbage collector happens to be called
immediately after the 'if', you'll get an exception.

So I suppose what you might do is this:

try:
# Optimization: Since a lot of these names won't be
# in the dict, we check first rather than relying on the
# exception. Since counters get removed in the __del__
# method, we can't depend 100% on the 'in' check,
# but an unnecessary try block is cheap.
if "foo" in counters:
process(counters["foo"])
except KeyError:
pass

But any time you need a block comment to justify your code, you'd
better be REALLY sure the performance benefit is worth the complexity.

For reliability, expect exceptions.

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


[issue25455] Some repr implementations don't check for self-referential structures

2015-11-02 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Yet one example:

>>> import io
>>> class BR(io.BufferedReader):
... @property
... def name(self):
... return self
... 
>>> repr(BR(io.BytesIO()))
Segmentation fault

The same is for other file-like objects.

--

___
Python tracker 

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



Re: Regular expressions

2015-11-02 Thread Steven D'Aprano
On Tue, 3 Nov 2015 03:23 pm, ru...@yahoo.com wrote:

> Regular expressions should be learned by every programmer or by anyone
> who wants to use computers as a tool.  They are a fundamental part of
> computer science and are used in all sorts of matching and searching
> from compilers down to your work-a-day text editor.

You are absolutely right.

If only regular expressions weren't such an overly-terse, cryptic
mini-language, with all but no debugging capabilities, they would be great.

If only there wasn't an extensive culture of regular expression abuse within
programming communities, they would be fine.

All technologies are open to abuse. But we don't say:

  Some people, when confronted with a problem, think "I know, I'll use
  arithmetic." Now they have two problems.

because abuse of arithmetic is rare. It's hard to misuse it, and while
arithmetic can be complicated, it's rare for programmers to abuse it. But
the same cannot be said for regexes -- they are regularly misused, abused,
and down-right hard to use right even when you have a good reason for using
them:

http://www.thedailywtf.com/articles/Irregular_Expression

http://blog.codinghorror.com/regex-use-vs-regex-abuse/

http://psung.blogspot.com.au/2008/01/wonderful-abuse-of-regular-expressions.html


If there is one person who has done more to create a regex culture, it is
Larry Wall, inventor of Perl. Even Larry Wall says that regexes are
overused and their syntax is harmful, and he has recreated them for Perl 6:

http://www.perl.com/pub/2002/06/04/apo5.html

Oh, and the icing on the cake, regexes can be a security vulnerability too:

https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS



-- 
Steven

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


[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Alexey Borzenkov

Alexey Borzenkov added the comment:

I created a simple gist that can show the problem: 
https://gist.github.com/snaury/ea167713b1804ffbaf5a (testme.sh builds Python 
3.5, creates a venv, install greenlet and tries to compile an extension)

--

___
Python tracker 

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



Re: GoPiGo script

2015-11-02 Thread Robin Koch

Am 02.11.2015 um 15:32 schrieb input/ldompel...@casema.nl:


Thank you for the explanation for it.
I must tell you that  i yust beginning with python.
I bought the book beginning programming with python.


Have you programming experience with other languages?

Well, the very first thing you should have learned is the basic syntax 
of Python. (That's how a program has to be written to work properly.)


And one of those first things is that python code is structured not by 
braces (like many other programming languages), but by intendation (as 
mentioned by others before).


That means that everything "depending" of a line somehow has to be 
intended deeper than that line.


Those lines are typically lines starting with "if", "for", "while", 
"def" or other keywords and end with a colon.


In your code the ifs and fors (and the following lines) are correctly 
intended. But you are using the "while" and "def" kind of wrong.


Let me give an example (note that the line numbers are only for this 
posting to prevent funny formating business and to talk about the single 
lines!):


01 for i in [1,2,3]:
02 print('A')
03 print('B')
04 print('C')

The first line (01) starts a loop. (Starting with a for, ending with a 
colon.) For every entry in the given list "something" is supposed to be 
repeated. But what is repeated and what isn't?


Easy: All following *intended* lines (02-03) are repeated.
Line 04 isn't intended and marks the point where the loop ends.

The output of the above is:

A
B
A
B
A
B
C


If we change the code just a tiny bit:

01 for i in [1,2,3]:
02 print('A')
03 print('B')
04 print('C')

(Notice, that the only change is the removed whitespace in line 03.)

only line 02 is repeated:

A
A
A
B
C


That works also for if and while:

01 if False:
02 print("This isn't printed.")
03 print("This neigther.")
03 print("But this is!")

01 c = 1
02 while c < 10:
03 print(c)
04 c = c*2
05 print("done")

prints

1
2
4
8
done


And of course those are mixable:

01 for a in [3,5,7]:
02b = 1
03while a*b < 10:
04  if a*b % 2 != 0:
05print(a*b)
06b = b+1
07print("Next a")
08 print("done")

prints:

3
9
Next a
5
Next a
7
Next a
done


And this is where your problems seems to be.

You start with

"while True:"

which does start an endless loop.

But: As explained it only repeats the lines theat follow and are intended!

In your original post the next line isn't intended at all, which is 
considered an error.
In your second attempt you intended only the first 5 lines. So those 
(and only those) are repeated.


The next line ("if mindist > us_dist(15):") wasn't intended and 
therefore *not* repeated.


If you just learning programming with Python you migth want to start 
with smaller examples to understand the syntax better.

Do you understand what the script is supposed to do in every line?

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


[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Alexey Borzenkov

Alexey Borzenkov added the comment:

I have reproduced this problem on Linux with pyvenv, isn't that part of Python 
3.5?

--

___
Python tracker 

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



[issue25535] collections.Counter methods return Counter objects instead of subclass objects

2015-11-02 Thread R. David Murray

R. David Murray added the comment:

OK, good point.  Perhaps we should turn this into a feature request to replace 
the calls to Counter with a call to an overridable method to make subclassing 
in this way possible without massive cut and paste.

--

___
Python tracker 

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



[issue25535] collections.Counter methods return Counter objects instead of subclass objects

2015-11-02 Thread Mark Dickinson

Mark Dickinson added the comment:

Relevant post from Tim Peters back in 2005, on the subject of subclassing 
datetime and timedelta:

"""
Yes, and all builtin Python types work that way.  For example,
int.__add__ or float.__add__ applied to a subclass of int or float
will return an int or float; similarly for a subclass of str.  This
was Guido's decision, based on that an implementation of any method in
a base class has no idea what requirements may exist for invoking a
subclass's constructor.  For example, a subclass may restrict the
values of constructor arguments, or require more arguments than a base
class constructor; it may permute the order of positional arguments in
the base class constructor; it may even be "a feature" that a subclass
constructor gives a different meaning to an argument it shares with
the base class constructor.  Since there isn't a way to guess, Python
does a safe thing instead.
"""

Source: https://mail.python.org/pipermail/python-list/2005-January/311610.html

--

___
Python tracker 

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



ANN: numexpr 2.4.6 released

2015-11-02 Thread Francesc Alted
Hi,

This is a quick release fixing some reported problems in the 2.4.5 version
that I announced a few hours ago.  Hope I have fixed the main issues now.
Now, the official announcement:

=
 Announcing Numexpr 2.4.6
=

Numexpr is a fast numerical expression evaluator for NumPy.  With it,
expressions that operate on arrays (like "3*a+4*b") are accelerated
and use less memory than doing the same calculation in Python.

It wears multi-threaded capabilities, as well as support for Intel's
MKL (Math Kernel Library), which allows an extremely fast evaluation
of transcendental functions (sin, cos, tan, exp, log...)  while
squeezing the last drop of performance out of your multi-core
processors.  Look here for a some benchmarks of numexpr using MKL:

https://github.com/pydata/numexpr/wiki/NumexprMKL

Its only dependency is NumPy (MKL is optional), so it works well as an
easy-to-deploy, easy-to-use, computational engine for projects that
don't want to adopt other solutions requiring more heavy dependencies.

What's new
==

This is a quick maintenance version that offers better handling of
MSVC symbols (#168, Francesc Alted), as well as fising some
UserWarnings in Solaris (#189, Graham Jones).

In case you want to know more in detail what has changed in this
version, see:

https://github.com/pydata/numexpr/blob/master/RELEASE_NOTES.rst

Where I can find Numexpr?
=

The project is hosted at GitHub in:

https://github.com/pydata/numexpr

You can get the packages from PyPI as well (but not for RC releases):

http://pypi.python.org/pypi/numexpr

Share your experience
=

Let us know of any bugs, suggestions, gripes, kudos, etc. you may
have.


Enjoy data!

-- 
Francesc Alted
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: np_utils 0.4

2015-11-02 Thread David N. Mashburn

Announcing np_utils version 0.4

Github: https://github.com/davidmashburn/np_utils
Bitbucket: https://bitbucket.org/davidmashburn/np_utils
PyPI: https://pypi.python.org/pypi/np_utils

np_utils is a growing collection of succinct but powerful utility functions
focused around extending numpy in important ways, but also includes a 
number

of useful list, functional, and general purpose utilities.

Small set of highlights (there are many, many more):
* *NEW in 0.4* A succinct but fast and flexible groupby implementation
  (np_groupby)
* A wrapper around np_groupby specifically tailored to common operations on
  record arrays (rec_groupby)
* A function to partition an array into n-sized chunks (partitionNumpy)
* A function to easily build a centered grid with a certain number of 
steps in

  each dimension (build_grid)
* A simple n-dimensional interpolation system for arrays that lines up with
  standard indexing when integers are passed (interpNumpy)
* A one-liner to make a new nd-array and paste in values from an existing
  nd-array with an offset (shapeShift)
* A function to add a border to an array (addBorder)
* A function to scale an nd-array by integer multiples, like an image 
up-scale

  (shape_multiply)
* A utility to enable numpy-like fancy indexing to regular lists, including
  jagged nested lists (fancyIndexingList, fL for short)
* A "flatten" function for nested lists (flatten)
* A "deletecases" function for lists
* A groupby for regular lists (groupByFunction)
* Tools for analyzing connections and connection chains in lists
  (getElementConnections, getChainsFromConnections)
* An interpolation function for lists (interp)
* Functions for deep operations on nested lists (listAdd, listMul, etc)
* A generic slice generator supporting every option imaginable: 0- and 1-
  based indexing, optional end point inclusion, strict/liberal bounds 
checking
* Functional utilities like compose, identity, docAppend, conversion 
between
  splat and non-splat (convertToSingleArgFun & convertToMultiArgFun), 
and even

  an implementation of Jsoftware's "fork"
* "Drawing" functions for ND-arrays:
  - Hyper-rectangles (NDRectangle)
  - ND Bresenham lines -lines to ND-arrays (BresenhamFunction)
  - Circles and Spheres (ImageCircle, ImageSphere)
  - A novel ND-Bresenham *triangular-plane*-drawing algorithm
(BresenhamTriangle) supporting one of my other projects, SWS4D
* Many others!

Documentation is handled at the docstring level and is thorough with 
included

examples, but there is little in the way of over-arching docs. The only
dependency is numpy itself, and functions are meant to be relatively
independent so that other projects can cherry-pick them as needed.
The API is always subject to change, but has remained fairly stable --
mostly due to my own heavy dependence on the module

A unit test suite is in progress, thoroughly covering a small but important
set of the functions (notably groupby, build_grid, partitionNumpy).

A number of functions have been inspired or taken verbatim from excellent
examples on StackOverflow -- in these cases, links are provided.

Suggestions are welcome and encouraged! (algorithms, style, code 
organization,
documentation, projects that could benefit from some/ all of these 
functions,

inclusions, mergers, etc)

This project supports work that I did at Vanderbilt University and am doing
at Pluralsight, LLC.

Cheers!
-David Mashburn

https://github.com/davidmashburn/np_utils;>np_utils 0.4 
- a growing collection of succinct but powerful utility functions 
focused around extending numpy in important ways, but also includes a 
number of useful list, functional, and general purpose utilities. 
(02-Nov-15)

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

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


[issue25083] Python can sometimes create incorrect .pyc files

2015-11-02 Thread tzickel

tzickel added the comment:

1. You are correct the issue I am talking about is in parsing source files 
(Altough because python caches them as .pyc it's a worse situation).
2. The example you give is EINTR handling (which is mostly handling interrupted 
I/O operations by signals and retrying them) the real I/O error checking in 
that get_line is I belive in the next ferror check there. It might be nice to 
have EINTR checking (and retry) when reading the source file as well, but that 
is a secondary issue.
3. As for your recommendation for changing Py_UniversalNewlineFgets, you can 
see that both it's documentation says "Note that we need no error handling: 
fgets() treats error and eof identically." and since it seems like a low-level 
function that does not have any python stuff like exception handling, and in 
it's current signature it can't return an error (it simply returns the buffer, 
or NULL if nothing was read).
4. As for why putting it in that position, basically there could be a few I/O 
paths, besides Py_UniversalNewlineFget, such as codec decoding in fp_readl (via 
decoding_fgets) that can fail in I/O as well. Looking at the code again (while 
not tested), maybe the check can be actually moved to the end of decoding_fgets 
in tokenizer.c i.e. if there is an ferror in tok->fp in the end of 
decoding_fgets then to return error_ret(tok); there, but then double eyes need 
to be sure that no other code path can have an I/O error. I am not an expert on 
the layout of tokenizer (read it mostly to figure out this bug) so if that's 
better it can be moved I guess.

--

___
Python tracker 

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



[issue25516] threading.Condition._is_owned() is wrong when using threading.Lock

2015-11-02 Thread Nir Soffer

Changes by Nir Soffer :


--
nosy: +haypo, pitrou

___
Python tracker 

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



Re: How to handle exceptions properly in a pythonic way?

2015-11-02 Thread John Gordon
In <4b303213-62e2-42d4-b2f6-4fc1f6025...@googlegroups.com> zljubi...@gmail.com 
writes:

> Let's say that I have the following simple function:

> def get_html(url):

> wpage = requests.get(url)
> 
> return wpage.text

> How to handle exceptions properly that can arise during execution of the
> requests.get(url)?

The best way is probably to do nothing at all, and let the caller handle
any exceptions.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


How to handle exceptions properly in a pythonic way?

2015-11-02 Thread zljubisic
Let's say that I have the following simple function:

def get_html(url):

wpage = requests.get(url)

return wpage.text

How to handle exceptions properly that can arise during execution of the 
requests.get(url)?

If I call this function with

try:
html = get_html('www.abc.com/index.html')
except ConnectionError:
service_exception
else:
continue_with_the_code

and ConnectionError exception happens I can handle the exception with 
service_exception part of the code.

I could also put some try/except block in get_html function, but the only 
purpose why should I do it,  is to log the url and re rise the error. Is there 
any other reason why should I do this?
 
def get_html(url):

try:
wpage = requests.get(url)
except ConnectionError:
flog('warning', 'ConnectionError exception', log_except=True)
raise

return 

Anyway, whenever I am calling the get_html function I should put it in the 
try/except block and handle all exceptions.
Now which exceptions? Can I know them in advance or I should wait for one to 
happened and then put it in caller except block?

Let's say that I have called get_html function hundred times in try/except 
block with ConnectionError part, and now I found a new exception that can 
happen during execution of the requests.get(url) command. What should I do now?
Should I put the same except block that handles that new exception in every and 
each of these hundred calls? 

I could also handle all exceptions in get_html function, and in case that I am 
not able to get the html, I can return None. 

def get_html(url):

try:
wpage = requests.get(url)
except ConnectionError:
flog('warning', 'ConnectionError exception', log_except=True)
raise
except Exception as e:
flog("warning", "{0}   [wpage = requests.get(url) {1}]".format(e, url), 
log_except=True)
raise
else:

if wpage.status_code == requests.codes.ok:
flog('debug', 'wpage.status_code = %s' % wpage.status_code)
html = wpage.text
else:
flog('debug', 'url = %s' % url)
html = None

return html


Now caller should only check if function has returned something other than 
None. Caller doesn't need try/except block anymore. Something like this:

if get_html('www.abc.com/index.html') is not None:
I_am_sure_that_html_has_been_downloaded_correctly


Now if I want to catch a new exception, I can catch it in get_html function, 
which is the only change in the program.

I have read some articles that returning None is not a good approach, so I am 
confused.

How to handle exceptions properly in a pythonic way?

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


[issue25539] python3 fail on parsing http header

2015-11-02 Thread 신동원

New submission from 신동원:

I tried to login some website using requests session, but it failed because of 
parsing header.
This is header data of problem. It contains two line of continuous CRLF between 
the data.

Date: Mon, 02 Nov 2015 08:45:48 GMT
Server: Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/0.9.8e-fips-rhel5 DAV/2 
PHP/5.2.16 mod_fastcgi/2.4.6
X-Powered-By: PHP/5.2.16
P3P: CP="NOI CURa ADMa DEVa TAIa OUR DELa BUS IND PHY ONL UNI COM NAV INT DEM 
PRE"

P3P : CP="ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT 
DEM CNT STA POL HEA PRE LOC OTC"
Set-Cookie: PHPSESSID=**; path=/
Set-Cookie: PHPSESSID=**; path=/
Content-Length: 81
Connection: close
Content-Type: text/html

function parse_headers in http.client, parsing exits when it meet CRLF. 
(https://hg.python.org/cpython/file/tip/Lib/http/client.py#l197)
Is it standard? Same code works well in python2, or even similar code in ruby.

--
components: Library (Lib)
messages: 253966
nosy: 신동원
priority: normal
severity: normal
status: open
title: python3 fail on parsing http header
type: crash
versions: 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



[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Kracekumar Ramaraj

Kracekumar Ramaraj added the comment:

Updating wheel to latest version fixed assertion issue but uwsgi installation 
still fails.

Virtualenv has updated to latest whhel version 
https://github.com/pypa/virtualenv/blob/develop/virtualenv_support/wheel-0.26.0-py2.py3-none-any.whl.
 Also, my example used `python -m venv`, this is part of stdlib and using 
`pyvenv-3.5` produced same result.

Explicitly setting `CC=clang` in OSX didn't help 
https://gist.github.com/kracekumar/270533354d62be46f77d and also on Ubuntu 
14.04 produces same error with gcc and clang.

I have opened an issue in uwsgi https://github.com/unbit/uwsgi/issues/1100.

--

___
Python tracker 

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



Re: Modern recommended exception handling practices?

2015-11-02 Thread Steven D'Aprano
On Tue, 3 Nov 2015 06:16 pm, Chris Angelico wrote:

> Not to mention having race condition possibilities.

Arrggghhh! I knew there was something else I wanted to say.

You're right. Sometimes you *have* to use exception handling code. Take this
for example:


if os.path.exists(pathname):
f = open(pathname)

That might be good enough for a quick and dirty script, but it's wrong,
because there's a race condition between the time you check whether the
file exists and the time you actually try to open it. (There are other
problems too: just because the file exists doesn't mean you have read
permission to it.) A lot can happen in the few microseconds between
checking for the existence of the file and actually opening it -- the file
could be renamed or deleted.

https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use


-- 
Steven

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


Re: python doesn't install

2015-11-02 Thread Dave Farrance
Tim Golden  wrote:

>I'm afraid you've been bitten by the fact that we no longer support 
>Windows XP and haven't communicated this very well. We have a new 
>version of the installer almost ready for release which indicates this 
>much earlier (and more obviously). I'm afraid if you're on XP you're 
>limited to Python 3.4 and earlier, all of which are perfectly usable I'm 
>happy to say!

I've been reading the comments about Python and XP on this group -- and
I must say that I'm thinking: Doesn't pretty much every other Windows
software package tell you the minimum requirements -- because that's the
first thing you'd want to know?

So I've Googled for "python 3.5 minimum requirements":

1st hit: "Using Python on Windows -- Python 3.5.0 documentation"
and a few paragraphs down that page there's:
"Python on XP --  7 Minutes to Hello World by Richard Dooling, 2006"
which says how easy it is to install on XP.

2nd hit: "Download Python -- Python.org"
There's download links but nothing about XP, but there's a link for
"Information about specific ports" -- so click on "Windows"
and no information actually, just more download links.

3rd hit: "Welcome to Python.org"
There's download links and no info about minimum requirements.

And so on down the page of Google hits.

Yes, I've read the justifications. Why list all the non-supported OSs?
And the explanation about each version of Python being supported just
for the supported versions of Windows upon its release is in the
documentation -- somewhere.  But it still seems to me that stating the
minimum requirements in a place that people would tend to look for it is
a... minimum requirement.

If the developers really are determined not to mention specific versions
of Windows (If it was me, I'd have probably mentioned that the most
recent version required Vista somewhere on the download page), then
maybe adding the comment about matching the release date of Python to
the supported versions of Windows to the download pages would give
people some sort of clue as to what's going on.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python doesn't install

2015-11-02 Thread Tim Golden
On 02/11/2015 06:16, Tim Golden wrote:
> On 02/11/2015 00:08, Daniel Joffe wrote:
>> WinXP...32 bits...professional
>>
>> I keep getting message
>>
>>
>> note also that there is no place on the install box to start...you just
>> click somewhere, and the install started.
>>
> 
> I'm afraid you've been bitten by the fact that we no longer support
> Windows XP and haven't communicated this very well. We have a new
> version of the installer almost ready for release which indicates this
> much earlier (and more obviously). I'm afraid if you're on XP you're
> limited to Python 3.4 and earlier, all of which are perfectly usable I'm
> happy to say!

Sorry, I omitted to say that you can download the latest Python 3.4 from
here:

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

TJG



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


[issue25474] Weird behavior when setting f_trace in a context manager

2015-11-02 Thread Fred Gansevles

Fred Gansevles added the comment:

Xavier, thanks for looking at my post.
But, since all six invocations of the context manager are the same
- I did an 'ast.parse' and 'ast.dump' and the the six calls were *exactly* the 
same (save lineno and col_offset) - why does 'zero', 'one', 'four' and 'five' 
get assigned but 'two' and 'three' not ?

--

___
Python tracker 

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



Unbuffered stderr in Python 3

2015-11-02 Thread Steven D'Aprano
In Python 2, stderr is unbuffered.

In most other environments (the shell, C...) stderr is unbuffered.

It is usually considered a bad, bad thing for stderr to be buffered. What 
happens if your application is killed before the buffer fills up? The errors 
in the buffer will be lost.

So how come Python 3 has line buffered stderr? And more importantly, how can 
I turn buffering off?

I don't want to use the -u unbuffered command line switch, because that 
effects stdout as well. I'm happy for stdout to remain buffered.


Here is the function I'm using to test this in in the interactive 
interpreter:

import sys, time

def test():
# Simulate a slow calculation that prints status and/or error
# messages to stderr.
for i in range(10):
print(i, file=sys.stderr, end="")
time.sleep(2)
print("", file=sys.stderr)


Running it pauses for 20 seconds, then displays "0123456789" in one go. What 
I expect is to see the digits arrive individually.

I tried this:

py> sys.stderr.line_buffering = False
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: readonly attribute


Next I tried this:

py> sys.stderr.buffer.line_buffering = False


which succeeded, but has no effect on print: it still buffers.




-- 
Steve

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


[issue25495] binascii documentation incorrect

2015-11-02 Thread Mouse

Mouse added the comment:

1. I am OK with the following text, modeling referred Perldoc:

b2a_base64( $bytes, $eol );

Encode data by calling the encode_base64() function. The first argument is the 
byte string to encode. 

The second argument is optional, and provides the line-ending sequence to use. 
When it is given, the returned encoded string is broken into lines of no more 
than 76 characters each and it will end with $eol unless it is empty. Pass an 
empty string, or no second argument at all if you do not want the encoded 
string to be broken into lines.

2. I already had people telling me that "Python-3 doc prohibits input longer 
than 57 bytes, even though it doesn't currently enforce it". Please help 
putting end to spreading of this confusion.

--

___
Python tracker 

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



Re: installer user interface glitch ?

2015-11-02 Thread rurpy--- via Python-list
On Sunday, November 1, 2015 at 2:48:58 PM UTC-7, Laura Creighton wrote:
> Actually, adding the XP - do not look here --
> message for several webpages has been on the pydotorg
> todo list for more than a week now.
> 
> Not sure why it hasn't happened.
> 
> Thank you for the reminder.

You're welcome.  And thanks for the reasonable response.  Everytime
I post to this list it is like stepping into Alice's Wonderland so
it is a nice change.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Puzzled

2015-11-02 Thread Robinson, Wendy
[cid:image001.png@01D11543.5ED11D50]



Wendy Robinson

Audit Analyst

(916) 566-4994 phone







NOTICE OF CONFIDENTIALITY: This email is for the sole use of the intended 
recipient and may contain material that is confidential and protected by state 
and federal regulations.  If you are not the intended recipient please 
immediately delete it and contact the sender.



-Original Message-
From: Laura Creighton [mailto:l...@openend.se]
Sent: Sunday, November 01, 2015 2:21 AM
To: Robinson, Wendy
Cc: 'python-list@python.org'; l...@openend.se
Subject: Re: Puzzled



In a message of Fri, 30 Oct 2015 09:20:23 -0700, "Robinson, Wendy" writes:

>Hi there,

>I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic 
>programs successfully.

>This morning I rebooted my computer and can't get a single one to work.  The 
>interpreter seems to be fine and the environment variables look correct.  But 
>every py file I try to run at the >>> prompt gives me a NameError.

>

>I tried running the Repair installation, but that did not help.

>

>Any suggestions?

>

>Thank you

>

>Wendy Robinson

>Audit Analyst

>(916) 566-4994 phone



Paste in the Full traceback you get from the console.

Also check and see that the console is actually running the 3.5 you installed, 
and not some other python, like 2.7 you might have lying around.



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


[issue25536] use sys.platform instead of os.name in asyncio docs consistently

2015-11-02 Thread Guido van Rossum

Guido van Rossum added the comment:

Fixed in 3.4, 3.5, 3.6 by these commits: 193327cabbbc, e2400d5d67e7, 
40ce5f4b8835.

--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

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



[issue25533] Make pkgutil.iter_modules() yield built-in modules

2015-11-02 Thread Brett Cannon

Brett Cannon added the comment:

How would this handle frozen modules?

--

___
Python tracker 

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



[issue25535] collections.Counter methods return Counter objects

2015-11-02 Thread Rob Malouf

New submission from Rob Malouf:

Several collections.Counter methods return Counter objects, which is leads to 
wrong or at least confusing behavior when Counter is subclassed.  For example, 
nltk.FreqDist is a subclass of Counter:

>>> x = nltk.FreqDist(['a','a','b','b','b'])
>>> y = nltk.FreqDist(['b','b','b','b','b'])
>>> z = x + y
>>> z.__class__


This applies to __add__(), __sub__(), __or__(), __and__(), __pos__(), and 
__neg__().  

In contrast, the copy() method does (what I think is) the right thing:

>>> x.copy().__class__


--
components: Library (Lib)
messages: 253930
nosy: rmalouf
priority: normal
severity: normal
status: open
title: collections.Counter methods return Counter objects
type: behavior
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



[issue25536] use sys.platform instead of os.name in asyncio docs consistently

2015-11-02 Thread Akira Li

New submission from Akira Li:

asyncio code uses "sys.platform == 'win32'" to detect OS.
asyncio docs use both os.name and sys.platform.

As far as I can tell there is no *practical* difference
between "os.name == 'nt" and "sys.platform == 'win32'"
for choosing asyncio.ProactorEventLoop()

I've attached a patch that replaces all os.name occurrences
in asyncio docs with sys.platform.

--
components: asyncio
files: doc-asyncio-os.name->sys.platform.patch
keywords: patch
messages: 253931
nosy: akira, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: use sys.platform instead of os.name in asyncio docs consistently
versions: Python 3.4, Python 3.5, Python 3.6
Added file: 
http://bugs.python.org/file40930/doc-asyncio-os.name->sys.platform.patch

___
Python tracker 

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



[issue25531] greenlet header file is missing inside virtualenv

2015-11-02 Thread Ned Deily

Ned Deily added the comment:

Alexey, thanks for the simplified test case.  I'll look at it further.

--
resolution: third party -> 
stage: resolved -> 
status: closed -> open

___
Python tracker 

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



[issue25157] Installing Python 3.5.0 32bit on Windows 8.1 64bit system gives Error 0x80240017

2015-11-02 Thread Giampaolo Rodola'

Changes by Giampaolo Rodola' :


--
nosy: +giampaolo.rodola

___
Python tracker 

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



Re: How to handle exceptions properly in a pythonic way?

2015-11-02 Thread Ian Kelly
On Mon, Nov 2, 2015 at 12:24 PM,   wrote:
> I have read some articles that returning None is not a good approach, so I am 
> confused.
>
> How to handle exceptions properly in a pythonic way?

I'm having a hard time understanding what question you're asking. You
have a lot of discussion about where to handle exceptions, but the
examples that you show are of logging the the exception and re-raising
it, which is a good practice but distinct from handling the exception.

Then you seem to be asking about the practice of returning None as an
alternative to propagating the exception, but the example you show
only returns None in a case where no exception was raised in the first
place.

None is arguably reasonable to return when it makes sense as a
non-exceptional value in the context. For example, if you're looking
up a policy that may or may not exist, then your get_policy function
might return None to indicate no value. If get_policy fails because of
an RPC timeout however, then it needs to raise an exception rather
than possibly incorrectly returning "no policy".

In comparison, if you're returning something that should always have a
value, then you should never return None. In such a case, None would
indicate that something went wrong, but it lacks any information about
*what* went wrong. An exception, on the other hand, is ideal for
carrying that sort of information. Returning None in such a scenario
is also risky in that the caller may not be expecting None and may try
to treat it as a normal value. In some cases this may even appear to
work until something breaks in a completely different part of the
code.

In the example given, the case where None is returned is clearly an
exceptional case (non-success) even though no exception was raised by
requests.get. You should raise an exception there instead of returning
None to allow the caller better control over the situation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GoPiGo script

2015-11-02 Thread Larry Hudson via Python-list

On 11/02/2015 11:31 AM, Robin Koch wrote:

Am 02.11.2015 um 15:32 schrieb input/ldompel...@casema.nl:


Thank you for the explanation for it.
I must tell you that  i yust beginning with python.
I bought the book beginning programming with python.


Have you programming experience with other languages?

Well, the very first thing you should have learned is the basic syntax of 
Python. (That's how a
program has to be written to work properly.)

And one of those first things is that python code is structured not by braces 
(like many other
programming languages), but by intendation (as mentioned by others before).

 ^^^

[snip a lot of text, also using the word intend...]

The word you want is indent not intend.
Intend means something entirely different,
and is not a Python term.

 -=- Larry -=-

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


[issue25537] Call `isinstance` instead of `issubclass` during exception handling

2015-11-02 Thread Sjoerd Job Postmus

New submission from Sjoerd Job Postmus:

Currently Python2.7 calls `PyObject_IsSubclass` during exception handling. This 
allows some virtual-base-class machinery to make Python believe a certain class 
should match an exception while it in reality does not.

However, this does not necessarily give one really enough granularity when 
dealing with base libraries which are not as granular in raising exceptions as 
one would like (the Python base library before PEP3151 comes to mind).

Currently I used the trick of calling `isinstance(sys.exc_info()[1], cls)` in 
the `__subclasscheck__`, which is sort-of a great work-around.[*].

This method is great for sort-of emulating PEP3151 in Python2.7, and similar 
work can be done for other libraries: making the exception classes appear more 
granular based on properties of the instance of the exception.

My belief is that by calling the `isinstance` during exception handling, one 
can use virtual base classes (or should I say virtual base instances) to their 
fullest potential in writing cleaner code.

I think this is important because exception-handling is already a place where 
messy code is likely to occur, and we need all the support we can get in making 
it just a tad less messy.[**]

Note: Python3.5 calls `PyType_IsSubtype`, which has #12029 open for a change 
towards `PyObject_IsSubclass`. As soon as (or before) that's implemented, I'd 
like to propose a similar change for Python3.5+: call `PyObject_IsInstance` 
when the raised exception is an instance.

[*] See https://github.com/sjoerdjob/exhacktion/ for how I use the described 
hack to somewhat emulate PEP3151 in Python2.7.
[**] One question that comes to mind is: why not just write a wrapper around 
the offending library. (1): If it's the base library, almost nobody is going to 
bother. (2): even if it's not the base library, the wrapper will likely be even 
more function calls, which may cost performance in both the good and the bad 
cases, instead of just the bad cases.

--
components: Interpreter Core
messages: 253946
nosy: sjoerdjob
priority: normal
severity: normal
status: open
title: Call `isinstance` instead of `issubclass` during exception handling
type: enhancement
versions: Python 2.7, 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



Nikola v7.7.3 is out!

2015-11-02 Thread Chris Warrick
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

On behalf of the Nikola team, I am pleased to announce the immediate
availability of Nikola v7.7.3. It fixes some bugs and adds new
features.

What is Nikola?
===

Nikola is a static site and blog generator, written in Python.
It can use Mako and Jinja2 templates, and input in many popular markup
formats, such as reStructuredText and Markdown — and can even turn
Jupyter (IPython) Notebooks into blog posts! It also supports image
galleries, and is multilingual. Nikola is flexible, and page builds
are extremely fast, courtesy of doit (which is rebuilding only what
has been changed).

Find out more at the website: https://getnikola.com/

Downloads
=

Install using `pip install Nikola` or download tarballs on GitHub and 
PyPI:

https://github.com/getnikola/nikola/releases/tag/v7.7.3
https://pypi.python.org/pypi/Nikola/7.7.3

Changes
===

Features
- 

* Recommend ``ghp-import2`` (better packaging) (Issue #2152)
* New ``TAGS_INDEX_PATH`` option for overwriting the path
  of the tag index list page.
* Support for ``~~strikethrough~~`` in Markdown (Issue #2149)
* Hungarian translation (by Baptiste Darthenay)
* ``serve`` and ``auto`` publishes DNS Service Discovery records
  to the local network announcing they’re running web servers.


Bugfixes
- 

* Implement translating ``DATE_FORMAT`` properly
* Remove superfluous translatability for a boolean (Issue #2140)
* Pass messages to post-list template (Issue #2156)
* Changed default log level from INFO to NOTICE (``nikola check`` is
  less chatty)
* Fix support for panorama images in gallery(Issue #2143)
* Support "maps.world.World" and similar charts in Pygal (Issue #2142)
* Capitalize "UTF-8" properly in locale guessing (Issue #2137)

- -- 
Chris Warrick 
PGP: 5EAAEA16
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQEcBAEBCAAGBQJWM5hDAAoJEHECPb1equoW+pcIAKeFvSMon3mHX1aINa63WhY3
uVz1hZdXOQAAgY4wx1kplWJ4AvDPzv43Lh5Zv3SuZxtMcGfn0pRy6ZbjKPY9Bwcg
WEOFX/CBaL0cDT4+kySv5f52dpyOqL3Vn3VNjjpNb44WKX4L6RHA4QUxsENqVwCo
2V04XlkuJ+bwXBfaKalaGXBdXk9KWuYCo/HtcPaU37IZ4oPDV8SBjV71KvWpY6YF
CowBmoR2aSwvY0T5WSX72YSxTcrLefZ22y/cTlDBEW+rxX/DaUTsTIuds1fYyDaa
2qahqJp2dCTKnVgwDsUUX1FTdrxoFWsDn0vp2M69uLLerYDWRYLXKDL0Mymjf9E=
=m2Gk
-END PGP SIGNATURE-

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

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


[ANN] Python 3 Cheat Sheet v2.0

2015-11-02 Thread Laurent Pointal via Python-announce-list
Hello,

I just updated my one recto-verso sheet Python 3 Cheat Sheet

https://perso.limsi.fr/pointal/python:memento

Many modifications and enhancements (bytes, literal ints, assignment 
complement, conversion tricks, cleaning sequences indexing, complement on 
boolean logic, modules import, exceptions, small organization charts for flow 
control, complement on list dict set methods, string methods, complment on 
files).

Still available in english and in french.

As the document become more dense, old version is kept online if prefered.

A+
L.Pointal.

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

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


Re: python doesn't install

2015-11-02 Thread Chris Warrick
On 2 November 2015 at 09:28, Dave Farrance  wrote:
> Yes, I've read the justifications. Why list all the non-supported OSs?
> And the explanation about each version of Python being supported just
> for the supported versions of Windows upon its release is in the
> documentation -- somewhere.  But it still seems to me that stating the
> minimum requirements in a place that people would tend to look for it is
> a... minimum requirement.
>
> If the developers really are determined not to mention specific versions
> of Windows (If it was me, I'd have probably mentioned that the most
> recent version required Vista somewhere on the download page), then
> maybe adding the comment about matching the release date of Python to
> the supported versions of Windows to the download pages would give
> people some sort of clue as to what's going on.
> --
> https://mail.python.org/mailman/listinfo/python-list

This could be resolved in one line of HTML or reST. Windows XP is
still in use, and it was supported one minor version ago. Surely it
wouldn’t hurt to add a “Warning: Windows XP is ancient, and Python 3.5
does not support it — upgrade to a newer OS or use 3.4.3 instead”
notice to the download page?

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue25523] Correct "a" article to "an" article

2015-11-02 Thread Martin Panter

Martin Panter added the comment:

Thanks Serhiy. My pass over the files missed most cases where there was a line 
break involved, and certain punctuation and markup, which you picked up on.

I skipped the /Lib/msilib/schema.py file in my patch because it was part of the 
data rather than a comment, and I wasn’t sure what it is for. It seems to be a 
generated file from some Windows source. But I see other people have made 
similar corrections, so it might be okay.

I left a couple of comments. Apart from those, the rest look good to me.

--

___
Python tracker 

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



[issue24379] operator.subscript

2015-11-02 Thread Martin Panter

Martin Panter added the comment:

On the mailing list, Antoine also suggested removing __slots__ completely as 
another workaround. I agree that it doesn’t seem important for a singleton, 
though in the review comments a couple people seemed to want __slots__.

--

___
Python tracker 

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



ANN: numexpr 2.4.5 released

2015-11-02 Thread Francesc Alted
=
 Announcing Numexpr 2.4.5
=

Numexpr is a fast numerical expression evaluator for NumPy.  With it,
expressions that operate on arrays (like "3*a+4*b") are accelerated
and use less memory than doing the same calculation in Python.

It wears multi-threaded capabilities, as well as support for Intel's
MKL (Math Kernel Library), which allows an extremely fast evaluation
of transcendental functions (sin, cos, tan, exp, log...)  while
squeezing the last drop of performance out of your multi-core
processors.  Look here for a some benchmarks of numexpr using MKL:

https://github.com/pydata/numexpr/wiki/NumexprMKL

Its only dependency is NumPy (MKL is optional), so it works well as an
easy-to-deploy, easy-to-use, computational engine for projects that
don't want to adopt other solutions requiring more heavy dependencies.

What's new
==

This is a maintenance release where an important bug in multithreading
code has been fixed (#185 Benedikt Reinartz, Francesc Alted).  Also,
many harmless warnings (overflow/underflow, divide by zero and others)
in the test suite have been silenced  (#183, Francesc Alted).

In case you want to know more in detail what has changed in this
version, see:

https://github.com/pydata/numexpr/blob/master/RELEASE_NOTES.rst

Where I can find Numexpr?
=

The project is hosted at GitHub in:

https://github.com/pydata/numexpr

You can get the packages from PyPI as well (but not for RC releases):

http://pypi.python.org/pypi/numexpr

Share your experience
=

Let us know of any bugs, suggestions, gripes, kudos, etc. you may
have.


Enjoy data!

-- 
Francesc Alted
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

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


[issue25474] Weird behavior when setting f_trace in a context manager

2015-11-02 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Thank you Xavier.  I guess the lesson is that physical line tracing works best 
(and most as one would hope or expect) when physical lines are logical lines 
(or compound statement header lines).

--
resolution:  -> not a bug
stage: test needed -> resolved

___
Python tracker 

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



[issue25535] collections.Counter methods return Counter objects instead of subclass objects

2015-11-02 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
assignee:  -> rhettinger

___
Python tracker 

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



[issue25534] SimpleHTTPServer throwed an exception due to negtive st_mtime attr in file

2015-11-02 Thread Martin Panter

Martin Panter added the comment:

I think your test file’s time is lost on the web server. On Linux it is pretty 
easy to make a file with an arbitrary time; maybe Windows has an equivalent:

$ touch -d "1 Jan 1900" test

I experimented with Wine, and it seems gmtime() raises ValueError on Python 2 
and OSError on Python 3 for negative times, but under Linux negative times are 
handled successfully. (Wine seems to wrap the st_mtime field to a 32-bit 
unsigned value though, so I am unable to reproduce the original problem.)

The “time” module documentation says “The functions in this module may not 
handle dates and times before the epoch”, so maybe the HTTP module should be 
fixed to handle a ValueError (or OSError on Python 3).

--
components: +Windows
nosy: +martin.panter, paul.moore, steve.dower, tim.golden, zach.ware
stage:  -> needs patch
type: crash -> behavior

___
Python tracker 

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



[issue25498] Python 3.4.3 core dump with simple sample code

2015-11-02 Thread Martin Panter

Martin Panter added the comment:

I tend to agree with Serhiy about Eryksun’s patch. I understand it solves the 
current problem, and continues to protect against this scenario:

>>> b = bytearray(b"a")
>>> c = ctypes.c_char.from_buffer(b)
>>> b *= 1000
BufferError: Existing exports of data: object cannot be re-sized

PyObject_AsWriteBuffer() and PyBuffer_Release() did get changed in 3.4, also by 
Issue 22896. Reviewing the history (mainly 
), the only 
behaviour change I see is that it now clears view->obj to NULL, via the new 
PyBuffer_Release() call, before calling DECREF on the object.

--

___
Python tracker 

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



[issue25538] Traceback from __exit__ method is misleading

2015-11-02 Thread R. David Murray

New submission from R. David Murray:

This is at least the second time that I've wasted a bunch of debugging time 
being mislead by the traceback from __exit__.  Perhaps I will remember from now 
on, but...I wonder if it would be possible/practical to improve the situation.  
The problem is that in the traceback printed when __exit__ throws an error, the 
source line printed before the source line from inside the __exit__ is the last 
line of the 'with' block.  I kept staring at that line trying to figure out how 
the exception could possibly be getting raised from that line...which of course 
it wasn't really, it was the "line" in between that one and the next one, a 
psuedo-line representing the exit from the block.

I don't know if it would be worth the effort that would be required to somehow 
clarify this in the traceback (I'm not even sure what that would *look* 
like...maybe the first line of the with block instead?), but I thought I'd 
raise the issue to see if anyone had any clever ideas.

(Hopefully I haven't done this before...I tried searching for similar issues 
and didn't find anything.)

--
messages: 253949
nosy: r.david.murray
priority: normal
severity: normal
status: open
title: Traceback from __exit__ method is misleading

___
Python tracker 

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



Re: Detection of a specific sound

2015-11-02 Thread Lorenzo Sutton

On 26/10/15 01:17, Montana Burr wrote:

I'm looking for a library that will allow Python to listen for the
shriek of a smoke alarm. Once it detects this shriek, it is to notify
someone. Ideally, specificity can be adjusted for the user's
environment. For example, I expect to need moderate specificity as I
live in a quiet neighborhood, but an apartment dweller might need more.

I'm thinking of recording a smoke alarm and having the program try to
find the recorded sound in the stream from the microphone.

Any help is greatly appreciated!



It would really be helpful if you could explain the (hardware) setting 
in more detail.
When you say "Python to listen" I assume you mean a microphone connected 
to a computer where your python programme will be running.


How many smoke allarms and in what radius should be detected? Or is it 
only a specific one?


This could range from a simple programme triggered by an amplitude 
change (e.g. a piezo attached to the single alarm in question) to a 
complex audio fingerprinting one...


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


[issue25535] collections.Counter methods return Counter objects instead of subclass objects

2015-11-02 Thread Raymond Hettinger

Raymond Hettinger added the comment:

The decision was deliberate and matches what we've done elsewhere in Python.   
The nearest kin to Counters are sets/frozensets which also behave the same way:

>>> class S(set):
pass
>>> type(S('abc') | S('cdef'))


Mark Dickinson articulated the reasons clearly.   Python has been consistent 
about this decision from the outset (see array.array or fractions.Fraction for 
example).

Marking this as "not a bug" and closing.

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



[issue25537] Call `isinstance` instead of `issubclass` during exception handling

2015-11-02 Thread R. David Murray

R. David Murray added the comment:

This does not sound like the kind of change we would accept for python 2.7.  (I 
also don't understand what the difference is between calling issubclass on the 
type and isinstance on the instance in this case.  But, then, I haven't looked 
at the code in question.)

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



Re: Unbuffered stderr in Python 3

2015-11-02 Thread Wolfgang Maier

On 02.11.2015 11:48, Wolfgang Maier wrote:


Since Python3.3, the print function has a flush keyword argument that
accepts a boolean and lets you do just this. Rewrite your example as:

import sys, time

def test():
# Simulate a slow calculation that prints status and/or error
# messages to stderr.
for i in range(10):
_print(i, file=sys.stderr, end="", flush=True)
time.sleep(2)
print("", file=sys.stderr)

and it should do what you want.


sorry for this mess (copy pasted from the wrong source).
The code should be:

def test():
# Simulate a slow calculation that prints status and/or error
# messages to stderr.
for i in range(10):
print(i, file=sys.stderr, end="", flush=True)
time.sleep(2)
print("", file=sys.stderr)


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


Re: Unbuffered stderr in Python 3

2015-11-02 Thread Wolfgang Maier

On 02.11.2015 08:52, Steven D'Aprano wrote:

In Python 2, stderr is unbuffered.

In most other environments (the shell, C...) stderr is unbuffered.

It is usually considered a bad, bad thing for stderr to be buffered. What
happens if your application is killed before the buffer fills up? The errors
in the buffer will be lost.

So how come Python 3 has line buffered stderr? And more importantly, how can
I turn buffering off?



I cannot comment on your first question, but unbuffered writing to 
sys.stderr is possible just like for any other buffered file object. You 
just call its flush method after writing.


Since Python3.3, the print function has a flush keyword argument that 
accepts a boolean and lets you do just this. Rewrite your example as:


import sys, time

def test():
# Simulate a slow calculation that prints status and/or error
# messages to stderr.
for i in range(10):
_print(i, file=sys.stderr, end="", flush=True)
time.sleep(2)
print("", file=sys.stderr)

and it should do what you want.


Before Python 3.3, if I needed an unbuffered print function, I used a 
wrapper to call flush for me, so instead of:




import sys, time

def test():
 # Simulate a slow calculation that prints status and/or error
 # messages to stderr.
 for i in range(10):
 print(i, file=sys.stderr, end="")
 time.sleep(2)
 print("", file=sys.stderr)



I'd use (and still do this if I need compatibility with 3.2):

import sys, time

def _print (*args, **kwargs):
   file = kwargs.get('file', sys.stdout)
   print(*args, **kwargs)
   file.flush()

def test():
# Simulate a slow calculation that prints status and/or error
# messages to stderr.
for i in range(10):
_print(i, file=sys.stderr, end="")
time.sleep(2)
print("", file=sys.stderr)

Best,
Wolfgang

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


Re: Problem in implementing Romania Map using Paython Script

2015-11-02 Thread Terry Reedy

On 11/2/2015 12:45 AM, Ben Finney wrote:

amn...@gmail.com writes:


I need a help in completing the Class Roaming problem using Euclidean
function , Completing the Class Node .


I think you need to research how to solve this algorithm, and only
*then* think about how to code it in Python.

Is this a homework assignment?


Norquist's AI book uses the Romania map to illustrate search problems. 
Whether this is a class assignment is a different matter, but OP should 
mention it either way.


--
Terry Jan Reedy

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


[issue2466] os.path.ismount doesn't work for mounts the user doesn't have permission to see

2015-11-02 Thread Berker Peksag

Berker Peksag added the comment:

Thanks for the patch, Robin. The patch needs a test case. See 
Lib/test/test_posixpath.py. The test coverage of ismount() is not high, so we 
need more tests. Also, I don't have much time to work on this right now, but 
Antoine's suggestion in msg71294 sounds good to me. Did you try it?

--
nosy: +berker.peksag
stage:  -> patch review
versions:  -Python 2.6, Python 3.0, Python 3.2, Python 3.3

___
Python tracker 

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



[issue25533] Make pkgutil.iter_modules() yield built-in modules

2015-11-02 Thread Martin Panter

New submission from Martin Panter:

When no specific list of paths are given, pkgutil.iter_modules() and 
walk_packages() will list modules found on sys.path. But they don’t list 
built-in modules, which don’t live in a particular directory. So many users of 
these APIs (such as the ModuleScanner class in pydoc) have to separately 
iterate over sys.builtin_module_names.

I think it would be good to change the pkgutil module to also yield the builtin 
modules. Attached is a patch which does this.

However I had second thoughts on blindly changing the existing function to 
yield the extra modules, because this will hurt backward compatibility for 
people already working around the problem. For example, if I didn’t also update 
pydoc in my patch, a module search would list the built-in modules twice. 
Perhaps we could overcome this with an opt-in flag like 
iter_modules(builtins=True)? I’m interested if anyone else has an opinion on 
this.

Adding support for builtins could also help with proposals such as listing the 
entire library (Issue 20506) and autocompletion of module names (Issue 25419).

--
components: Library (Lib)
files: iter-builtin.patch
keywords: patch
messages: 253905
nosy: martin.panter
priority: normal
severity: normal
status: open
title: Make pkgutil.iter_modules() yield built-in modules
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file40926/iter-builtin.patch

___
Python tracker 

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



  1   2   >