[issue26181] argparse can't handle positional argument after list (help message is wrong)

2016-01-23 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +bethard
versions: +Python 3.5, Python 3.6 -Python 3.4

___
Python tracker 

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



Re: import locale and print range on same line

2016-01-23 Thread Ramo
This works also but I thought it was possible to do it easier:

import locale; locale.setlocale(locale.LC_ALL, ""); 
print('\n'.join(locale.format("%2f", i, 1) for i in range(1,20,4)))
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26098] PEP 510: Specialize functions with guards

2016-01-23 Thread STINNER Victor

STINNER Victor added the comment:

Patch version 4:

* Keywords are now supported everywhere and tested by unit tests
* Inline specode_check() into PyFunction_GetSpecializedCode()

--
Added file: http://bugs.python.org/file41702/specialize-4.patch

___
Python tracker 

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



[issue26146] PEP 511: Add ast.Constant to allow AST optimizer to emit constants

2016-01-23 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5de1bd759f3b by Victor Stinner in branch 'default':
Issue #26146: marshal.loads() now uses the empty frozenset singleton
https://hg.python.org/cpython/rev/5de1bd759f3b

--
nosy: +python-dev

___
Python tracker 

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



[issue26149] Suggest PyCharm Community as an editor for Unix platforms

2016-01-23 Thread Ezio Melotti

Ezio Melotti added the comment:

The two links for VIM and Emacs are useful for Unix developers that happen to 
use these editors, but I agree that we should link to the wiki instead of 
having other links to specific editors.
If we want to recommend a few specific ones, we could list their names so that 
people can find them in the wiki.

--
nosy: +ezio.melotti

___
Python tracker 

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



[issue26177] tkinter: Canvas().keys returns empty strings.

2016-01-23 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> Is avoiding splitlist calls when not needed worthwhile?

We can't guarantee that future release of Tk wouldn't return a list of strings. 
Calling splitlist() for a tuple is cheap (but looks cumbersome).

> I am a bit curious why Canvas gives a different return.  Is the special 
> casing in _tkinter or tk itself?

Tk is full of such inconsistencies. A result for one widget can be a list of 
numbers, but for other it is a list of strings or a list of special Tcl 
objects. One method can return empty list, other returns empty string. One 
widgets truncate floating point parameters, others round them up or down.

I'll commit the patch after testing with Tk 8.5 and 8.4.

--

___
Python tracker 

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



locale and for loop on same line

2016-01-23 Thread Ramo
Can someone tell me why this doesn't work?

import locale; locale.setlocale(locale.LC_ALL, ""); for i in range(1,20,4): 
print(locale.format("%2f", i, 1))

It gives an error: SyntaxError: invalid syntax (highlighting the word 'for')

I need this code on one and the same line.
However when I separate them it works fine:

import locale
locale.setlocale(locale.LC_ALL, "")
for i in range(1,20,4): 
   print(locale.format("%2f", i, 1))

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


[issue25907] Documentation i18n: Added trans tags in sphinx templates

2016-01-23 Thread Julien

Julien added the comment:

@haypo: And here is the patch for 2.7, and here is the result of the patch 
applied and new msgids translated: http://www.afpy.org/doc/python/2.7/

--
Added file: http://bugs.python.org/file41699/trans-tags-in-2.7.patch

___
Python tracker 

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



Re: import locale and print range on same line

2016-01-23 Thread Vlastimil Brom
2016-01-23 11:36 GMT+01:00 Marko Rauhamaa :
> rai...@gmail.com:
>
>> Can someone tell me why next code doesn't work?
>>
>> import locale; locale.setlocale(locale.LC_ALL, ""); for i in
>> range(1,20,4): print(locale.format("%2f", i, 1))
>>
>> It gives an error: SyntaxError: invalid syntax --> indicating 'for'
>>
>> However I need to put the code on one single line.
>> When I separate them like below it works fine.
>>
>> import locale
>> locale.setlocale(locale.LC_ALL, "")
>> for i in range(1,20,4):
>>print(locale.format("%2f", i, 1))
>
> The answer is in Python's syntax definition. Not everything is allowed
> on a single line.
>
> See https://docs.python.org/3/reference/grammar.html>
>
> Only small_stmt's can be separated by semicolons.
>
> A for statement is a compound_stmt, which is not a small_stmt.
>
>
> Marko
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
if you realy can't use multiple lines (which is rather essencial for
python), you can circumvent this in some cases, e.g. using list
comprehension and ignoring the created list itself:
import locale; locale.setlocale(locale.LC_ALL, "");
[print(locale.format("%2f", i, 1)) for i in range(1,20,4)]

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


[issue25907] Documentation i18n: Added trans tags in sphinx templates

2016-01-23 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 72edb81e456b by Victor Stinner in branch '2.7':
doc: i18n HTML templates
https://hg.python.org/cpython/rev/72edb81e456b

--

___
Python tracker 

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



Re: one more question on regex

2016-01-23 Thread Vlastimil Brom
2016-01-22 23:47 GMT+01:00 mg :
> Il Fri, 22 Jan 2016 21:10:44 +0100, Vlastimil Brom ha scritto:
>
>> [...]
>
> You explanation of re.findall() results is correct. My point is that the
> documentation states:
>
> re.findall(pattern, string, flags=0)
> Return all non-overlapping matches of pattern in string, as a list of
> strings
>
> and this is not what re.findall does. IMHO it should be more reasonable
> to get back the whole matches, since this seems to me the most useful
> information for the user. In any case I'll go with finditer, that returns
> in match object all the infos that anyone can look for.
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
I don't know the reasoning for this special behaviour of findall, but
it seems to be documented explicitly:
https://docs.python.org/3/library/re.html#re.findall
"... If one or more groups are present in the pattern, return a list
of groups; this will be a list of tuples if the pattern has more than
one group.
finditer is clearly much more robust for general usage.
I only use findall for quick one-line tests (and there one has to
account for this specificities - either by using non capturing groups
or enclosing the whole pattern in a "main" group and use the first
items in the resulting tuples.
vbr
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26146] PEP 511: Add ast.Constant to allow AST optimizer to emit constants

2016-01-23 Thread STINNER Victor

STINNER Victor added the comment:

> New changeset 5de1bd759f3b by Victor Stinner in branch 'default':
> Issue #26146: marshal.loads() now uses the empty frozenset singleton
> https://hg.python.org/cpython/rev/5de1bd759f3b

This change is not directly related to this issue.

It's required by test_singleton_empty_frozenset() of test_set when an AST 
transformer replaces frozenset(), frozenset([]), etc. calls with an empty 
frozenset constant.

--

___
Python tracker 

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



Re: import locale and print range on same line

2016-01-23 Thread Chris Angelico
On Sun, Jan 24, 2016 at 12:07 AM, Steven D'Aprano  wrote:
> On Sat, 23 Jan 2016 09:02 pm, rai...@gmail.com wrote:
>
>> However I need to put the code on one single line.
>
> Why? Is the Enter key on your keyboard broken?

Maybe it's for a python -c invocation.

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


Re: import locale and print range on same line

2016-01-23 Thread Ramo
The reason why I want to have it on onto one line has nothing to do with my 
question, "why doesn't it work on one line" :)

But if you want to know it, I use this python code in the commandline of a 
texteditor :)

Btw.. thank you all for your help. Very happy with it :)
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26149] Suggest PyCharm Community as an editor for Unix platforms

2016-01-23 Thread Georg Brandl

Georg Brandl added the comment:

> The doc section is woefully incomplete and unix-specific.

That might be because the doc section is called "Using Python on Unix 
platforms".

--
nosy: +georg.brandl

___
Python tracker 

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



[issue25907] Documentation i18n: Added trans tags in sphinx templates

2016-01-23 Thread INADA Naoki

INADA Naoki added the comment:

O/T

Hi, Julien.

I'm maintainer of Python Document Japanese translation project.  
(http://docs.python.jp/ )
We use Transifex to ease many volunteers working on translating.

https://www.transifex.com/python-doc-ja/python-35/dashboard/

Repository of Python 3.5 Japanese document is here: 
https://github.com/python-doc-ja/cpython-doc-intl

--
nosy: +naoki

___
Python tracker 

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



[issue25907] Documentation i18n: Added trans tags in sphinx templates

2016-01-23 Thread Julien

Julien added the comment:

@naoki Not sure, but with those patches you'll may be able to translate the 
documentation without forking it. Like we're doing here: 
https://github.com/afpy/python_doc_fr

Also did you contacted the upstream to ask them if they want to cross-link your 
versions ? Sphinx don't natively support it, but it still doable and can be a 
nice way to advertise our efforts (I mean, I'm sure a lot of french people 
don't know we're doing it and stuck to the english version).

I heard we used transfiex too like 6 years ago, long before me being on the 
project, I may drop an eye on it, thanks.

It may be a bit out of the scope of this issue, so let's continue elsewhere, 
like by email if you want I'm julien at palard dot fr.

BTW, nice to hear we're not alone to translate the Python doc :-))).

--

___
Python tracker 

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



[issue26185] zipfile.ZipInfo slots can raise unexpected AttributeError

2016-01-23 Thread SilentGhost

Changes by SilentGhost :


--
stage:  -> patch review

___
Python tracker 

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



[issue26185] zipfile.ZipInfo slots can raise unexpected AttributeError

2016-01-23 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +alanmcintyre, serhiy.storchaka, twouters

___
Python tracker 

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



[issue26183] 2.7.11 won't clean install on Windows 10 x64

2016-01-23 Thread SilentGhost

Changes by SilentGhost :


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

___
Python tracker 

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



[issue26146] PEP 511: Add ast.Constant to allow AST optimizer to emit constants

2016-01-23 Thread STINNER Victor

STINNER Victor added the comment:

@Serhiy: Would you mind reviewing constant-2.patch? I reviewed my own patch and 
added some comments, I found a refleak ;-)

--

___
Python tracker 

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



Re: How to simulate C style integer division?

2016-01-23 Thread Grobu

On 22/01/16 04:48, Steven D'Aprano wrote:
[ ... ]


math.trunc( float(a) / b )



That fails for sufficiently big numbers:


py> a = 3**1000 * 2
py> b = 3**1000
py> float(a)/b  # Exact answer should be 2
Traceback (most recent call last):
   File "", line 1, in 
OverflowError: long int too large to convert to float


Note that Python gets the integer division correct:

py> a//b
2L


And even gets true division correct:

py> from __future__ import division
py> a/b
2.0


so it's just the intermediate conversion to float that fails.



Thanks! I did see recommandations to avoid floats throughout the thread, 
but didn't understand why.


Following code should be exempt from such shortcomings :

def intdiv(a, b):
return (a - (a % (-b if a < 0 else b))) / b


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


Re: import locale and print range on same line

2016-01-23 Thread Steven D'Aprano
On Sat, 23 Jan 2016 09:02 pm, rai...@gmail.com wrote:

> However I need to put the code on one single line.

Why? Is the Enter key on your keyboard broken?



-- 
Steven

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


[issue19883] Integer overflow in zipimport.c

2016-01-23 Thread STINNER Victor

STINNER Victor added the comment:

Serhiy Storchaka added the comment:
> Updated patch addresses Victor's comments and adds (mandatory now) 
> parenthesis. Thank you Victor.

Do  you mean braces {...}?

The new patch looks good to me, thanks for taking all my comments in account ;-)

--

___
Python tracker 

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



Re: How to simulate C style integer division?

2016-01-23 Thread Grobu

def intdiv(a, b):
 return (a - (a % (-b if a < 0 else b))) / b




Duh ... Got confused with modulos (again).

def intdiv(a, b):
return (a - (a % (-abs(b) if a < 0 else abs(b / b

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


Re: import locale and print range on same line

2016-01-23 Thread Steven D'Aprano
On Sun, 24 Jan 2016 12:19 am, Chris Angelico wrote:

> On Sun, Jan 24, 2016 at 12:07 AM, Steven D'Aprano 
> wrote:
>> On Sat, 23 Jan 2016 09:02 pm, rai...@gmail.com wrote:
>>
>>> However I need to put the code on one single line.
>>
>> Why? Is the Enter key on your keyboard broken?
> 
> Maybe it's for a python -c invocation.


[steve@ando ~]$ python -c "for i in range(5):
> print 'hello world'
> "
hello world
hello world
hello world
hello world
hello world
[steve@ando ~]$




-- 
Steven

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


[issue19883] Integer overflow in zipimport.c

2016-01-23 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Updated patch addresses Victor's comments and adds (mandatory now) parenthesis. 
Thank you Victor.

--
assignee:  -> serhiy.storchaka
Added file: http://bugs.python.org/file41697/zipimport_int_overflow_4.patch

___
Python tracker 

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



[issue26185] zipfile.ZipInfo slots can raise unexpected AttributeError

2016-01-23 Thread Matthew Zipay

New submission from Matthew Zipay:

The zipfile.ZipInfo.__init__ method permits several of ZipInfo's slot 
attributes to go uninitialized unless the object is obtained from 
ZipFile.getinfo() or ZipFile.infolist().

As a result, accessing those attributes (header_offset, CRC, compress_size, or 
file_size) or attempting to repr() a ZipInfo object can fail unexpectedly with 
AttributeError. (I say "unexpectedly" because ZipInfo.__init__ and its 
attributes are public/documented, so the attributes ought to be properly 
initialized regardless of how the object gets created.)

A simple test to illustrate:

>>> import zipfile
>>> zinfo = zipfile.ZipInfo()
>>> repr(zinfo)
Traceback (most recent call last):
  File "", line 1, in 
  File "/cpython/Lib/zipfile.py", line 376, in __repr__
result.append(' file_size=%r' % self.file_size)
AttributeError: file_size

(If you assign zinfo.file_size = None, it next fails on compress_size.)

This problem has been noted before - see issues 3039 and 22217 - but has not 
been resolved.

Patch including tests is attached.

--
components: Library (Lib)
files: zipfile.ZipInfo.patch
keywords: patch
messages: 258859
nosy: Matthew Zipay
priority: normal
severity: normal
status: open
title: zipfile.ZipInfo slots can raise unexpected AttributeError
type: behavior
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file41698/zipfile.ZipInfo.patch

___
Python tracker 

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



Re: import locale and print range on same line

2016-01-23 Thread Marko Rauhamaa
rai...@gmail.com:

> Can someone tell me why next code doesn't work?
>
> import locale; locale.setlocale(locale.LC_ALL, ""); for i in
> range(1,20,4): print(locale.format("%2f", i, 1))
>
> It gives an error: SyntaxError: invalid syntax --> indicating 'for'
>
> However I need to put the code on one single line.
> When I separate them like below it works fine.
>
> import locale
> locale.setlocale(locale.LC_ALL, "")
> for i in range(1,20,4):
>print(locale.format("%2f", i, 1))

The answer is in Python's syntax definition. Not everything is allowed
on a single line.

See https://docs.python.org/3/reference/grammar.html>

Only small_stmt's can be separated by semicolons.

A for statement is a compound_stmt, which is not a small_stmt.


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


[issue25907] Documentation i18n: Added trans tags in sphinx templates

2016-01-23 Thread STINNER Victor

STINNER Victor added the comment:

> @haypo: And here is the patch for 2.7, and here is the result of the patch 
> applied and new msgids translated: http://www.afpy.org/doc/python/2.7/

Thanks. I also pushed this change.

@INADA Naoki, @Julien: Don't hesitate to bug me if you want to push other 
changes to make your work easier.

--

___
Python tracker 

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



import locale and print range on same line

2016-01-23 Thread raiwil
Can someone tell me why next code doesn't work?

import locale; locale.setlocale(locale.LC_ALL, ""); for i in range(1,20,4): 
print(locale.format("%2f", i, 1))

It gives an error: SyntaxError: invalid syntax --> indicating 'for'

However I need to put the code on one single line.
When I separate them like below it works fine.

import locale
locale.setlocale(locale.LC_ALL, "")
for i in range(1,20,4):
   print(locale.format("%2f", i, 1))
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26182] Deprecation warnings for the future async and await keywords

2016-01-23 Thread SilentGhost

Changes by SilentGhost :


--
components: +asyncio
nosy: +giampaolo.rodola, gvanrossum, haypo, pitrou, yselivanov

___
Python tracker 

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



Re: locale and for loop on same line

2016-01-23 Thread Bev in TX
According to the documentation, "...simple statements may occur on a 
single line separated by semicolons."


The "for" statement is a compound, not simple, statement.

Would it be possible to place your statements in a function and then you 
would just need to invoke the function?


Bev in TX

On 1/23/16 4:08 AM, Ramo wrote:

Can someone tell me why this doesn't work?

import locale; locale.setlocale(locale.LC_ALL, ""); for i in range(1,20,4): 
print(locale.format("%2f", i, 1))

It gives an error: SyntaxError: invalid syntax (highlighting the word 'for')

I need this code on one and the same line.
However when I separate them it works fine:

import locale
locale.setlocale(locale.LC_ALL, "")
for i in range(1,20,4):
print(locale.format("%2f", i, 1))


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


Re: import locale and print range on same line

2016-01-23 Thread Chris Angelico
On Sun, Jan 24, 2016 at 12:45 AM, Steven D'Aprano  wrote:
> On Sun, 24 Jan 2016 12:19 am, Chris Angelico wrote:
>
>> On Sun, Jan 24, 2016 at 12:07 AM, Steven D'Aprano 
>> wrote:
>>> On Sat, 23 Jan 2016 09:02 pm, rai...@gmail.com wrote:
>>>
 However I need to put the code on one single line.
>>>
>>> Why? Is the Enter key on your keyboard broken?
>>
>> Maybe it's for a python -c invocation.
>
>
> [steve@ando ~]$ python -c "for i in range(5):
>> print 'hello world'
>> "
> hello world
> hello world
> hello world
> hello world
> hello world
> [steve@ando ~]$

Well, not everyone's shells are as awesome as bash... and not everyone
knows you can do that. That said, though... this is a good reason for
giving full context for the question. "I'm trying to X, but I get this
error because of Y. How would I go about fixing Y?" - response:
"Actually, you can do X in a slightly different way.".

Just sayin', there might be other reasons for wanting to put things
onto one line.

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


[issue26058] PEP 509: Add ma_version to PyDictObject

2016-01-23 Thread STINNER Victor

STINNER Victor added the comment:

Patch version 6: remove now unused function _testcapi.dict_set_version(). I 
also moved tests to test_pep509.py to make it more explicit that the 
implementation of the PEP 509 is not part the Python dictionary type 
specification, other Python implementations can choose to not implement it.

--
Added file: http://bugs.python.org/file41701/dict_version-6.patch

___
Python tracker 

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



[issue26145] PEP 511: Add sys.set_code_transformers()

2016-01-23 Thread STINNER Victor

STINNER Victor added the comment:

> Note: ast.PyCF_TRANSFORMED_AST is not implemented yet.

Additionnal pycf_transformed_ast.patch implements it. The patch should be 
applied on top of transformers-4.patch.

Note: PyCF_TRANSFORMED_AST has the same value (0x1000) than the old constant 
CO_GENERATOR_ALLOWED. This constant was removed in Python 2.5.0 by the 
changeset 6b42920accc9 in 2006. Is it an issue?

--
Added file: http://bugs.python.org/file41700/pycf_transformed_ast.patch

___
Python tracker 

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



Re: How to simulate C style integer division?

2016-01-23 Thread Jussi Piitulainen
Grobu writes:

>> def intdiv(a, b):
>>  return (a - (a % (-b if a < 0 else b))) / b
>>
>>
>
> Duh ... Got confused with modulos (again).
>
> def intdiv(a, b):
> return (a - (a % (-abs(b) if a < 0 else abs(b / b

You should use // here to get an exact integer result.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about asyncio and blocking operations

2016-01-23 Thread Frank Millman

"Frank Millman"  wrote in message news:n8038j$575$1...@ger.gmane.org...

So I thought I would ask here if anyone has been through a similar 
exercise, and if what I am going through sounds normal, or if I am doing 
something fundamentally wrong.



Thanks for any input


Just a quick note of thanks to ChrisA and Ian. Very interesting responses 
and plenty to think about.


I will have to sleep on it and come back with renewed vigour in the morning. 
I may well be back with more questions :-)


Frank


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


[issue26187] sqlite3 trace callback prints duplicate line

2016-01-23 Thread Aviv Palivoda

New submission from Aviv Palivoda:

I am running the following script:

--
>>> import sqlite3
>>> import os
>>> import time
>>> con1 = sqlite3.connect("/tmp/test.db")
>>> con2 = sqlite3.connect("/tmp/test.db")
>>> con1.set_trace_callback(print)
>>> cur = con1.cursor()
>>> cur.execute("create table test(a)")
create table test(a)

>>> con2.execute("create table test2(a)")

>>> cur.execute("insert into test(a) values(1)")
BEGIN 
insert into test(a) values(1)
insert into test(a) values(1)

>>> for a in con1.execute("select * from test"):
... print("result:", a)
... 
select * from test
result: (1,)
---

As you can see i get duplicate traceback print of the "insert into test(a) 
values(1)" line. The duplicate print has no effect on the actual db.

I have tested this both on python 3.4.3 and 3.6.0a0 on ubuntu14.04

--
components: Extension Modules
messages: 258874
nosy: ghaering, palaviv
priority: normal
severity: normal
status: open
title: sqlite3 trace callback prints duplicate line
type: behavior
versions: Python 3.4, Python 3.6

___
Python tracker 

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



Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-23 Thread Chris Angelico
On Sun, Jan 24, 2016 at 6:43 AM, Steve Petrie, P.Eng.
 wrote:
> In case other Windows XP "orphans" want to use mitmdump, here's what I
> learned (via Google):
>
> I changed the bang line (wrapping the pathname in double quotes) in file
> mitmdump-script.py:
>
>   from: #!e:\a p p s\python27\python.exe
>  to: #!"e:\a p p s\python27\python.exe"

Spaces in names are often a pain. I'd raise this upstream as a bug
report - it should be fixed properly rather than depending on manual
editing.

> I haven't yet got mitmdump to actually write anything to the output file,
> but I expect that's just a matter of studying the mitmdump docs.

I'd say you'll do best with a mailing list dedicated to mitmdump; what
you're looking at now is application-specific issues.

> P.S. Be assured -- I will soon be moving away from Windows XP to a new
> computer running Debian Linux.

Good plan! That's what I use on all my systems. So many things are
easier when you move off XP.

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


FW: Bill Sconce memorial, SAT 13 FEB, Boire Field, Nashua, NH

2016-01-23 Thread Ben Scott
:-(

-- Forwarded message --
From: mad...@li.org 
Date: Sat, Jan 16, 2016 at 2:11 PM
Subject: Bill Sconce obituary and memorial date (February 13th at
Boire Field, Nashua, NH)
To: "Linux, Greater" 
Cc: "Hall, Jon" 


Bill (William Joseph) Sconce, age 72, Lyndeborough, NH, died on January 5,
2016 at Lahey Hospital in Burlington, MA. The cause was a cerebral
hemorrhage.  He was a good man.


Bill was born April 19, 1943 in Indianapolis, IN, and came home to the
House on the Hill in Edinburgh, IN. Bill grew up there with his brother
David, who predeceased him. His parents were Eva Mae and Joseph Byce
Sconce.  Bill soon became a proficient Spelunker and surveyor in the caves
of Indiana and Kentucky, and a motorcycle enthusiast. Graduating from
Culver Military Academy, where he earned his Amateur Radio License, he
received a Fulbright scholarship and rode his Norton motorcycle to CalTech
in San Francisco, CA where he studied Physics and worked in a
crystalography laboratory. He was drafted during the Vietnam war protests
at that school and served in Taigu Korea, where he studied IBM Cobol and
the Korean language, and rode a Honda 90 motorcycle in the mountains. He
returned to Louisville, KY and began a long career in computer science and
founded his company Industrial Specialities.  He met the love of his life
in Louisville, Janet Levy, and with her encouragement he completed his
dream of becoming a pilot, holding a Commercial, Instrument, and Instructor
license. He continued studies at University of Louisville in linguistics
and computer science. Bill & Janet moved to NH in 1979 for Bill to graduate
from being Symposium Coordinator for DECUS to assume the position of
Product Manager for the RSTS Group at Digital Equipment Corporation. Bill
worked for and was layed off from DEC, Compaq, and Hewlett Packard, at
which point he revived his corporation, named it In Spec, Inc. and divided
his time between software engineering and flight instruction.  Bill was a
devoted supporter of GPL and "free" Linux software and the Python
programming language. Bill was a member of the Vintage BMW Motorcycle
Owners, Ltd., the BMW MOVer Motorcycle Club of Vermont, the Contoocook
Valley Radio Club,  a life member of the National Speological Society and
the American Radio Relay League. He supported the EAA and was a Regional
Judge for aerobatic competitions for IAC for many years. He loved aviation,
including hot air ballooning and skydiving.  He participated in Young
Eagles at Boire Airport in Nashua, NH and enjoyed teaching young people to
fly. He taught spins in his Cessna Aerobat. And he was a Quiet Birdman.  He
was a member of the Rex Stout Wolfepack Book Club and The Wodehouse
Society.   Bill loved theatre, classical and rock music, and especially
lately, attending Dr. David Landman's Poetry Nights of medieval poetry in
Lexington, MA.


He loved fixing things and if there were no parts available for a project
he promptly made them himself on his metal lathe, or just used his
ingenuity to create something needed.


He loved cigars, scotch, butter, reading, airplanes, old test equipment,
Paris, BMWs, his red convertible Cabriolet with red earmuffs, and his big
black 4 cylinder 4WD truck, bird watching (outwitting squirrels), camping,
hiking on Pitcher Mountain, William Blake, and he suffered not fools. One
of his favorite lead-ins: "As an engineer..."


Bill is survived by his wife, Janet Levy Sconce, his sister-in-law, June
Levy and her family, and many dear friends. Bill was a kind and loving
"daddy" to Virgil Fox and RDB, the cats of his home. Thanks to "The
Committee" and especially Donna Shea, Chris Levin, Ken Hamel, Donna
Giovannini, Tom Steger, Michelle Donovan, Simon Hutchings, John & Cathy
Gubernat and the surgeons, doctors, and nurses at Lahey Hospital. The
family is grateful to all of his many friends who offered support and love.


There will be a memorial for Bill on February 13, 11:00-2:00  at Nashua Jet
Aviation located on Boire Field in Nashua, NH. Call Air Direct Airways,
(603) 882-5606 for more information.
___
gnhlug-discuss mailing list
gnhlug-disc...@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about asyncio and blocking operations

2016-01-23 Thread Chris Angelico
On Sun, Jan 24, 2016 at 1:38 AM, Frank Millman  wrote:
> I find I am bumping my head more that I expected, so I thought I would try
> to get some feedback here to see if I have some flaw in my approach, or if
> it is just in the nature of writing an asynchronous-style application.

I don't have a lot of experience with Python's async/await as such,
but I've written asynchronous apps using a variety of systems (and
also written threaded ones many times). so I'll answer questions on
the basis of design principles that were passed down to me through the
generations.

> I use a cache to store frequently used objects, but I wait for the first
> request before I actually retrieve it from the database. This is how it
> worked -
>
> # cache of database objects for each company
> class DbObject(dict):
>def __missing__(self, company):
>db_object = self[company] = get_db_object _from_database()
>return db_object
> db_objects = DbObjects()
>
> Any function could ask for db_cache.db_objects[company]. The first time it
> would be read from the database, on subsequent requests it would be returned
> from the dictionary.
>
> Now get_db_object_from_database() is a coroutine, so I have to change it to
>db_object = self[company] = await get_db_object _from_database()
>
> But that is not allowed, because __missing__() is not a coroutine.
>
> I fixed it by replacing the cache with a function -
>
> # cache of database objects for each company
> db_objects = {}
> async def get_db_object(company):
>if company not in db_objects:
>db_object = db_objects[company] = await get_db_object
> _from_database()
>return db_objects[company]
>
> Now the calling functions have to call 'await
> db_cache.get_db_object(company)'
>
> Ok, once I had made the change it did not feel so bad.

I would prefer the function call anyway. Subscripting a dictionary is
fine for something that's fairly cheap, but if it's potentially hugely
expensive, I'd rather see it spelled as a function call. There's
plenty of precedent for caching function calls so only the first one
is expensive.

> Now I have another problem. I have some classes which retrieve some data
> from the database during their __init__() method. I find that it is not
> allowed to call a coroutine from __init__(), and it is not allowed to turn
> __init__() into a coroutine.
>
> I imagine that I will have to split __init__() into two parts, put the
> database functionality into a separately-callable method, and then go
> through my app to find all occurrences of instantiating the object and
> follow it with an explicit call to the new method.
>
> Again, I can handle that without too much difficulty. But at this stage I do
> not know what other problems I am going to face, and how easy they will be
> to fix.

The question here is: Until you get that data from the database, what
state would the object be in? There are two basic options:

1) If the object is somewhat usable and meaningful, divide
initialization into two parts - one that sets up the object itself
(__init__) and one that fetches stuff from the database. If you can,
trigger the database fetch in __init__ so it's potentially partly done
when you come to wait for it.

2) If the object would be completely useless, use an awaitable factory
function instead. Rather than constructing an object, you ask an
asynchronous procedure to give you an object. It's a subtle change,
and by carefully managing the naming, you could make it almost
transparent in your code:

# Old way:
class User:
def __init__(self, domain, name):
self.id = blocking_database_call("get user", domain, name)
# And used thus:
me = User("example.com", "rosuav")

# New way:
class User:
def __init__(self, id):
self.id = id
_User = User
async def User(domain, name):
id = await async_database_call("get user", domain, name)
return _User(id)
# And used thus:
me = await User("example.com", "rosuav")

> So I thought I would ask here if anyone has been through a similar exercise,
> and if what I am going through sounds normal, or if I am doing something
> fundamentally wrong.

I think this looks pretty much right. There are some small things you
can do to make it look a bit easier, but it's minor.

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


Re: How to simulate C style integer division?

2016-01-23 Thread Grobu

On 23/01/16 16:07, Jussi Piitulainen wrote:

Grobu writes:


def intdiv(a, b):
  return (a - (a % (-b if a < 0 else b))) / b




Duh ... Got confused with modulos (again).

def intdiv(a, b):
 return (a - (a % (-abs(b) if a < 0 else abs(b / b


You should use // here to get an exact integer result.



You're totally right, thanks! It isn't an issue for Python 2.x's 
"classic division", but it becomes one with Python 3's "True division", 
and '//' allows to play it safe all along.

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


Re: import locale and print range on same line

2016-01-23 Thread Chris Angelico
On Sun, Jan 24, 2016 at 1:03 AM, Ramo  wrote:
> The reason why I want to have it on onto one line has nothing to do with my 
> question, "why doesn't it work on one line" :)
>
> But if you want to know it, I use this python code in the commandline of a 
> texteditor :)

Called it! :)

It actually has a lot to do with your question, because it puts
special restrictions on the answer. By giving context, you prevent
answers like Steven's that are trying to fix what is thought to be a
faulty assumption; instead, we'll attack the problem as an
intellectual challenge - how can we achieve this goal within these
restrictions? Worded that way, the question will definitely get
responses that aren't what we'd normally call "good code", but they
fit the situation. It's not uncommon to have questions like this,
especially from a security point of view; for instance: "Is it
possible to invoke os.system() without using any builtins or imports,
and without having an underscore anywhere in the code?" (answer: yes,
it is).

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


pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-23 Thread Steve Petrie, P.Eng.

Greetings To Python-list,

I'm trying to install Python package:

  mitmproxy (https://mitmproxy.org/)

on Windows XP SP3.

I'm a complete Python newbie. Not planning to do any Python programming 
at this time. Just trying to get package mitmproxy working (or at least 
the mitmdump component, since "There is no interactive user interface on 
Windows." per:


  http://docs.mitmproxy.org/en/stable/install.html

* * *
* * *

I have installed Python that announces itself on the Python command line 
as:


  Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC 
v.1500 32 bit (Intel)] on win32


* * *
* * *

I'm using the following command in a Win XP cmd.exe shell (not the 
Python shell) to install mitmproxy:


  pip install mitmproxy

The first install attempt failed, ending with some diagnostics displayed 
in the Win XP cmd.exe shell window:


  C:\Documents and Settings\SteveP>pip install mitmproxy
  Collecting mitmproxy
Downloading mitmproxy-0.15.tar.gz (1.7MB)
  100% || 1.7MB 4.5kB/s
  ...

Collecting Pillow<3.1,>=3.0.0 (from mitmproxy)
 Downloading Pillow-3.0.0-cp27-none-win32.whl (1.2MB)
   100% || 1.2MB 6.1kB/s
  Collecting pyperclip<1.6,>=1.5.22 (from mitmproxy)
Downloading pyperclip-1.5.26.zip
  Exception:
  Traceback (most recent call last):
File "e:\a p p s\python27\lib\site-packages\pip\basecommand.py", 
line 211, in main

  status = self.run(options, args)
File "e:\a p p 
s\python27\lib\site-packages\pip\commands\install.py", line 294, in run

  requirement_set.prepare_files(finder)
File "e:\a p p s\python27\lib\site-packages\pip\req\req_set.py", 
line 334, in prepare_files

  functools.partial(self._prepare_file, finder))
File "e:\a p p s\python27\lib\site-packages\pip\req\req_set.py", 
line 321, in _walk_req_to_install

  more_reqs = handler(req_to_install)
File "e:\a p p s\python27\lib\site-packages\pip\req\req_set.py", 
line 491, in _prepare_file

  session=self.session)
File "e:\a p p s\python27\lib\site-packages\pip\download.py", line 
825, in unpack_url

  session,
File "e:\a p p s\python27\lib\site-packages\pip\download.py", line 
677, in unpack_http_url

  unpack_file(from_path, location, content_type, link)
File "e:\a p p s\python27\lib\site-packages\pip\utils\__init__.py", 
line 645,in unpack_file

  flatten=not filename.endswith('.whl')
File "e:\a p p s\python27\lib\site-packages\pip\utils\__init__.py", 
line 546,in unzip_file

  fp = open(fn, 'wb')
  IOError: [Errno 13] Permission denied: 
'c:\\docume~1\\stevep\\locals~1\\temp\\pip-buildpnnfyf\\pyperclip\\docs/make.bat'

  You are using pip version 7.1.2, however version 8.0.0 is available.
  You should consider upgrading via the 'python -m pip 
install --upgrade pip' command.


  C:\Documents and Settings\SteveP>

* * *
* * *

I  upgraded pip to version 8.0.0:

  C:\Documents and Settings\SteveP>python -m pip install --upgrade pip
  Collecting pip
Downloading pip-8.0.0-py2.py3-none-any.whl (1.2MB)
  100% || 1.2MB 9.1kB/s
  Installing collected packages: pip
Found existing installation: pip 7.1.2
  Uninstalling pip-7.1.2:
Successfully uninstalled pip-7.1.2
  Successfully installed pip-8.0.0

* * *
* * *

I tried again to install mitmproxy, and the installation got a little 
further, but failed again on a similar error, on a different file 
(watchdog-0.8.3.tar.gz instead of pyperclip-1.5.26.zip):


  C:\Documents and Settings\SteveP>pip install mitmproxy

  C:\Documents and Settings\SteveP>pip install mitmproxy
  e:\a p p s\python27\lib\site-packages\pip\pep425tags.py:89: 
RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may 
be incorrect

warn=(impl == 'cp')):
  e:\a p p s\python27\lib\site-packages\pip\pep425tags.py:93: 
RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag 
may be incorrect

warn=(impl == 'cp')):
  e:\a p p s\python27\lib\site-packages\pip\pep425tags.py:99: 
RuntimeWarning: Config variable 'Py_UNICODE_SIZE' is unset, Python ABI 
tag may be incorrect

sys.version_info < (3, 3))) \
  Collecting mitmproxy
Using cached mitmproxy-0.15.tar.gz
  Collecting six<1.11,>=1.10.0 (from mitmproxy)
Using cached six-1.10.0-py2.py3-none-any.whl
  ...

  Collecting pyperclip<1.6,>=1.5.22 (from mitmproxy)
Using cached pyperclip-1.5.26.zip
  Collecting pydivert>=0.0.7 (from mitmproxy)
Downloading pydivert-0.0.7.zip
  Collecting watchdog<0.9,>=0.8.3 (from mitmproxy)
Downloading watchdog-0.8.3.tar.gz (83kB)
  100% || 86kB 6.8kB/s
  Exception:
  Traceback (most recent call last):
File "e:\a p p s\python27\lib\site-packages\pip\basecommand.py", 
line 209, in main

  status = self.run(options, args)
File "e:\a p p 
s\python27\lib\site-packages\pip\commands\install.py", line 299, in run

  

Re: Question about asyncio and blocking operations

2016-01-23 Thread Ian Kelly
On Sat, Jan 23, 2016 at 8:44 AM, Ian Kelly  wrote:
> This is where it would make sense to me to use callbacks instead of
> subroutines. You can structure your __init__ method like this:

Doh.

s/subroutines/coroutines
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26169] Pasting 900000 chars into a tk Entry widget fails

2016-01-23 Thread Soufiane BOUSSALI

Soufiane BOUSSALI added the comment:

thanks terry reedy For Fixing This Stack Overflow :)

--

___
Python tracker 

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



Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-23 Thread Chris Angelico
On Fri, Jan 22, 2016 at 3:40 AM, Steve Petrie, P.Eng.
 wrote:
> In both failure cases, it looks to me like there is a bug in the pip logic,
> that is using a *nix forward slash "/" instead of a double backslash "\\"
> before the file name "make.bat".

I'm not sure what your exact problem is, but I can say that it isn't
this; the Unix-style forward slash is perfectly legal under Windows
(and it's even legal to mix and match).

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


[issue26186] LazyLoader rejecting use of SourceFileLoader

2016-01-23 Thread Brett Cannon

Brett Cannon added the comment:

One way to possibly improve this is to remove the create_module() check and 
replace it with a warning if create_module() doesn't return None. Another 
option is to use an assert statement. The final option is to just drop the 
check entirely, although that can make debugging difficult.

--

___
Python tracker 

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



[issue26186] LazyLoader rejecting use of SourceFileLoader

2016-01-23 Thread Brett Cannon

Changes by Brett Cannon :


--
nosy: +eric.snow, ncoghlan

___
Python tracker 

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



Re: Question about asyncio and blocking operations

2016-01-23 Thread Ian Kelly
On Sat, Jan 23, 2016 at 7:38 AM, Frank Millman  wrote:
> Here is the difficulty. The recommended way to handle a blocking operation
> is to run it as task in a different thread, using run_in_executor(). This
> method is a coroutine. An implication of this is that any method that calls
> it must also be a coroutine, so I end up with a chain of coroutines
> stretching all the way back to the initial event that triggered it.

This seems to be a common misapprehension about asyncio programming.
While coroutines are the focus of the library, they're based on
futures, and so by working at a slightly lower level you can also
handle them as such. So  while this would be the typical way to use
run_in_executor:

async def my_coroutine(stuff):
value = await get_event_loop().run_in_executor(None,
blocking_function, stuff)
result = await do_something_else_with(value)
return result

This is also a perfectly valid way to use it:

def normal_function(stuff):
loop = get_event_loop()
coro = loop.run_in_executor(None, blocking_function, stuff)
task = loop.create_task(coro)
task.add_done_callback(do_something_else)
return task

> I use a cache to store frequently used objects, but I wait for the first
> request before I actually retrieve it from the database. This is how it
> worked -
>
> # cache of database objects for each company
> class DbObject(dict):
>def __missing__(self, company):
>db_object = self[company] = get_db_object _from_database()
>return db_object
> db_objects = DbObjects()
>
> Any function could ask for db_cache.db_objects[company]. The first time it
> would be read from the database, on subsequent requests it would be returned
> from the dictionary.
>
> Now get_db_object_from_database() is a coroutine, so I have to change it to
>db_object = self[company] = await get_db_object _from_database()
>
> But that is not allowed, because __missing__() is not a coroutine.
>
> I fixed it by replacing the cache with a function -
>
> # cache of database objects for each company
> db_objects = {}
> async def get_db_object(company):
>if company not in db_objects:
>db_object = db_objects[company] = await get_db_object
> _from_database()
>return db_objects[company]
>
> Now the calling functions have to call 'await
> db_cache.get_db_object(company)'
>
> Ok, once I had made the change it did not feel so bad.

This all sounds pretty reasonable to me.

> Now I have another problem. I have some classes which retrieve some data
> from the database during their __init__() method. I find that it is not
> allowed to call a coroutine from __init__(), and it is not allowed to turn
> __init__() into a coroutine.
>
> I imagine that I will have to split __init__() into two parts, put the
> database functionality into a separately-callable method, and then go
> through my app to find all occurrences of instantiating the object and
> follow it with an explicit call to the new method.
>
> Again, I can handle that without too much difficulty. But at this stage I do
> not know what other problems I am going to face, and how easy they will be
> to fix.
>
> So I thought I would ask here if anyone has been through a similar exercise,
> and if what I am going through sounds normal, or if I am doing something
> fundamentally wrong.

This is where it would make sense to me to use callbacks instead of
subroutines. You can structure your __init__ method like this:

def __init__(self, params):
self.params = params
self.db_object_future = get_event_loop().create_task(
get_db_object(params))

async def method_depending_on_db_object():
db_object = await self.db_object_future
result = do_something_with(db_object)
return result

The caveat with this is that while __init__ itself doesn't need to be
a coroutine, any method that depends on the DB lookup does need to be
(or at least needs to return a future).
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26183] 2.7.11 won't clean install on Windows 10 x64

2016-01-23 Thread Steve Dower

Steve Dower added the comment:

This is trying to remove 2.7.10, so I guess it's not as clean as you think.

You'll need to repair the 2.7.10 install (not just reinstall it - it has to be 
the right version so you can choose repair) and then try again.

--

___
Python tracker 

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



Re: Same function but different names with different set of default arguments

2016-01-23 Thread Paulo da Silva
Às 07:30 de 21-01-2016, Paulo da Silva escreveu:
> Hi all.
> 
> What is the fastest implementation of the following code?
> 
> def g(p):
>   ...
>   return something
> 
> def f1(p="p1"):
>   return g(p)
> 
> def f2(p="p2"):
>   return g(p)
> 

Thanks to all who responded.

I'll try "partial" in my case.
It seems good and simple.

Paulo


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


Question about asyncio and blocking operations

2016-01-23 Thread Frank Millman

Hi all

I am developing a typical accounting/business application which involves a 
front-end allowing clients to access the system, a back-end connecting to a 
database, and a middle layer that glues it all together.


Some time ago I converted the front-end from a multi-threaded approach to an 
asyncio approach. It was surprisingly easy, and did not require me to delve 
into asyncio too deeply.


There was one aspect that I deliberately ignored at that stage. I did not 
change the database access to an asyncio approach, so all reading 
from/writing to the database involved a blocking operation. I am now ready 
to tackle that.


I find I am bumping my head more that I expected, so I thought I would try 
to get some feedback here to see if I have some flaw in my approach, or if 
it is just in the nature of writing an asynchronous-style application.


Here is the difficulty. The recommended way to handle a blocking operation 
is to run it as task in a different thread, using run_in_executor(). This 
method is a coroutine. An implication of this is that any method that calls 
it must also be a coroutine, so I end up with a chain of coroutines 
stretching all the way back to the initial event that triggered it. I can 
understand why this is necessary, but it does lead to some awkward 
programming.


I use a cache to store frequently used objects, but I wait for the first 
request before I actually retrieve it from the database. This is how it 
worked -


# cache of database objects for each company
class DbObject(dict):
   def __missing__(self, company):
   db_object = self[company] = get_db_object _from_database()
   return db_object
db_objects = DbObjects()

Any function could ask for db_cache.db_objects[company]. The first time it 
would be read from the database, on subsequent requests it would be returned 
from the dictionary.


Now get_db_object_from_database() is a coroutine, so I have to change it to
   db_object = self[company] = await get_db_object _from_database()

But that is not allowed, because __missing__() is not a coroutine.

I fixed it by replacing the cache with a function -

# cache of database objects for each company
db_objects = {}
async def get_db_object(company):
   if company not in db_objects:
   db_object = db_objects[company] = await get_db_object 
_from_database()

   return db_objects[company]

Now the calling functions have to call 'await 
db_cache.get_db_object(company)'


Ok, once I had made the change it did not feel so bad.

Now I have another problem. I have some classes which retrieve some data 
from the database during their __init__() method. I find that it is not 
allowed to call a coroutine from __init__(), and it is not allowed to turn 
__init__() into a coroutine.


I imagine that I will have to split __init__() into two parts, put the 
database functionality into a separately-callable method, and then go 
through my app to find all occurrences of instantiating the object and 
follow it with an explicit call to the new method.


Again, I can handle that without too much difficulty. But at this stage I do 
not know what other problems I am going to face, and how easy they will be 
to fix.


So I thought I would ask here if anyone has been through a similar exercise, 
and if what I am going through sounds normal, or if I am doing something 
fundamentally wrong.


Thanks for any input

Frank Millman


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


Release of PyGreSQL version 4.2

2016-01-23 Thread D'Arcy J.M. Cain
The PyGreSQL team is please to announce release 4.2 of PyGreSQL.  It is
available at: http://pygresql.org/files/PyGreSQL-4.2.tgz.

If you are running NetBSD, look in the packages directory under
databases for py-postgresql. There should also be a package in the
FreeBSD ports collection.

Please refer to the changelog for things that have changed in this
version.  The changelog and other information can be found at the web
site http://www.pygresql.org/.

This version has been built and unit tested on:
 - NetBSD
 - FreeBSD
 - openSUSE
 - Ubuntu
 - Windows 7 with both MinGW and Visual Studio
 - PostgreSQL 8.4 and 9.3 64bit
 - Python 2.4, 2.5, 2.6 and 2.7 32 and 64bit

This is the last major release before 5.0 which will include support
for Python 3.x.  Only bug fixes will be applied to this branch.  A beta
of 5.0 is available at http://pygresql.org/files/PyGreSQL-beta.tar.gz.

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org IM:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Deprecation warning for async and await

2016-01-23 Thread Marco Buttu
I enabled the deprecation warning in Python 3.5.1 and Python 3.6 dev, 
but I did not get any warning when assigning to async or await:


$ python -Wd -c "import sys; print(sys.version); async = 33"
3.5.1 (default, Jan 21 2016, 19:59:28)
[GCC 4.8.4]

Is it normal?

--
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbu...@oa-cagliari.inaf.it

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


[issue26186] LazyLoader rejecting use of SourceFileLoader

2016-01-23 Thread Brett Cannon

New submission from Brett Cannon:

It was privately reported to me that importlib.util.LazyLoader rejects using 
importlib.machinery.SourceFileLoader (or at least 
_frozen_importlib.SourceFileLoader). At least a test should be added for 
LazyLoader to make sure it will happily accept 
importlib.machinery.SourceFileLoader, and if it rejects the one from 
_frozen_importlib, tweak the test to accept loaders from there as well.

--
assignee: brett.cannon
components: Library (Lib)
messages: 258873
nosy: brett.cannon
priority: normal
severity: normal
stage: test needed
status: open
title: LazyLoader rejecting use of SourceFileLoader
type: behavior
versions: 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



Install Numba on Debian

2016-01-23 Thread Dave Farrance
I'd like to install Numba on Debian Jessie to work with the system
Python 2.7.9 (rather than installing Anaconda).

When I follow the instructions at
https://github.com/numba/numba#custom-python-environments

...I get errors when trying to install Numba either with the git clone
method or installing it with pip.

I'll put the error log on Pastebin since its so large:
http://pastebin.com/gbrj0iHw

I've Googled for recipes for installing numba on Debian, installed every
Debian package suggested as a possible dependency, and still no luck.

Anybody know a working method for installing Numba on Debian Jessie
without Anaconda?
-- 
https://mail.python.org/mailman/listinfo/python-list


How do I add 18 seconds ISO-8301 String in Python?

2016-01-23 Thread Robert James Liguori
How do I add 18 seconds to this string in Python?

2000-01-01T16:36:25.000Z
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26189] Interpreter returns control to cmd.exe early

2016-01-23 Thread Zachary Ware

Zachary Ware added the comment:

What version of Python are you using, where did you get it from, and what 
version of Windows are you using?

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

___
Python tracker 

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



Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-23 Thread Robert James Liguori
Is there a python library to calculate longitudinal acceleration, lateral 
acceleration and normal acceleration?

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


Re: How do I add 18 seconds to an ISO-8601 String in Python?

2016-01-23 Thread Robert James Liguori
Thank you so much!  Btw, how do I convert back to ISO-8301?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import locale and print range on same line

2016-01-23 Thread Chris Angelico
On Sun, Jan 24, 2016 at 1:45 PM, Terry Reedy  wrote:
> C:\Users\Terry>python -c "for i in range(5):\n\tprint('hello world')"
>   File "", line 1
> for i in range(5):\n  print('hello world')
>  ^
> SyntaxError: unexpected character after line continuation character
>
> -c does not preprocess the code string before executing.  I may propose that
> it do so.

As an alternative, maybe multiple -c parameters could result in
multiple lines? Something like:

python3 -c "for i in range(5):" -c " print('Hello, world')"

Currently, a second -c is unparsed (it ends up in sys.argv), so this
would technically be a behavioural change (but then, so would
preprocessing).

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


[issue26189] Interpreter returns control to cmd.exe early

2016-01-23 Thread Ivan Pozdeev

Ivan Pozdeev added the comment:

This also happens when running interactively - so the interactive interpreter 
has to be run from a non-console program to be usable.

This doesn't happen with other programs (e.g. Cygwin bash) or IPython console.

--
title: Non-interactive interpreter returns control to cmd.exe early -> 
Interpreter returns control to cmd.exe early

___
Python tracker 

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



[issue26160] Tutorial incorrectly claims that (explicit) relative imports don't work in the main module

2016-01-23 Thread Kevin Norris

Kevin Norris added the comment:

>It could be misleading saying “the name of the current package”, because the 
>import could be relative to the a higher level parent package if more than one 
>dot is specified.

While this is correct, Python still uses __package__ to determine what to 
import in that case.  I simply replaced "__package__" with "the name of the 
current package" to make it easier to read, much as the original text replaces 
"__name__" with "the name of the current module."

>Then point out that relative imports won’t work with ``python file.py`` or 
>interactive mode, but don’t mention “-m” (or the other ways to run scripts and 
>modules).

SGTM if you can find a reasonable way of phrasing that.

--

___
Python tracker 

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



Re: How do I add 18 seconds to an ISO-8601 String in Python?

2016-01-23 Thread Ben Finney
Robert James Liguori  writes:

(I've corrected the Subject field. The standard you're referring to is
ISO 8601, I believe.)

> How do I add 18 seconds to this string in Python?
>
> 2000-01-01T16:36:25.000Z

Two separate parts:

* How do I get a timestamp object from a text representation in ISO 8601
  format?

* How do I add 18 seconds to a timestamp object?

Parsing a text representation of a timestamp to get a timestamp object
is done with ‘datetime.strptime’ from the Python standard library
::

>>> import datetime
>>> foo_timestamp_text = "2000-01-01T16:36:25.000Z"
>>> iso8601_format = "%Y-%m-%dT%H:%M:%S.%fZ"
>>> foo_timestamp = datetime.datetime.strptime(foo_timestamp_text, 
iso8601_format)
>>> foo_timestamp
datetime.datetime(2000, 1, 1, 16, 36, 25)

Arithmetic on timestamps is done using the ‘datetime.timedelta’ type
::

>>> increment = datetime.timedelta(seconds=18)
>>> increment
datetime.timedelta(0, 18)
>>> foo_timestamp + increment
datetime.datetime(2000, 1, 1, 16, 36, 43)

-- 
 \“You don't change the world by placidly finding your bliss — |
  `\you do it by focusing your discontent in productive ways.” |
_o__)   —Paul Z. Myers, 2011-08-31 |
Ben Finney

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


[issue23076] list(pathlib.Path().glob("")) fails with IndexError

2016-01-23 Thread Thomas Nyberg

Thomas Nyberg added the comment:

I added a patch which causes glob to raise a ValueError exception if it is 
called with an empty string. I also added a test verifying the change and have 
run all the tests and they pass.

Though I've been reading the developer guide, I'm a bit unfamiliar with the 
process here so I'm not totally sure I'm doing this right. I created the patch 
relative to the current default branch (even though the discussion here seems 
to indicate it should maybe be applied going back a few versions).

--
hgrepos: +331
keywords: +patch
nosy: +thomas.nyberg
Added file: http://bugs.python.org/file41703/pathlib_glob.patch

___
Python tracker 

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



[issue26186] LazyLoader rejecting use of SourceFileLoader

2016-01-23 Thread Keith Dart

Changes by Keith Dart :


--
nosy: +kdart

___
Python tracker 

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



Re: Question about how to do something in BeautifulSoup?

2016-01-23 Thread Cody Piersall
On Fri, Jan 22, 2016 at 8:01 AM, inhahe  wrote:
> Say I have the following HTML (I hope this shows up as plain text here
> rather than formatting):
>
> "Is
> today the day?"
>
> And I want to extract the "Is today the day?" part. There are other places
> in the document with  and , but this is the only place that
> uses color #00, so I want to extract anything that's within a color
> #00 style, even if it's nested multiple levels deep within that.
>
> - Sometimes the color is defined as RGB(0, 0, 0) and sometimes it's
defined
> as #00
> - Sometimes the  is within the  and sometimes the  is
> within the .
> - There may be other discrepancies I haven't noticed yet
>
> How can I do this in BeautifulSoup (or is this better done in lxml.html)?

I hope this helps you get started:

This may help you get started:

from bs4 import BeautifulSoup
from itertools import chain
soup = BeautifulSoup('''\
"Is
today the day?"
"Is
tomorrow the day?"''')

# We're going to get all the tags that specify the color, either using hex
or RGB.
# If you only want to get the span tags, just give the positional argument
'span' to
# find_all:
# for tag in chain(soup.find_all('span', style='color: #00;'),
#  soup.find_all('span', style='color: RGB(0, 0, 0);')):

for tag in chain(soup.find_all(style='color: #00;'),
 soup.find_all(style='color: RGB(0, 0, 0);')):
try:
print(tag.em.strong.text)
except AttributeError:
try:
print(tag.strong.em.text)
except AttributeError:
print('ooh no no text')

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


Re: Install Numba on Debian

2016-01-23 Thread Dave Farrance
Dave Farrance  wrote:

>I'd like to install Numba on Debian Jessie to work with the system
>Python 2.7.9 (rather than installing Anaconda).

OK, never mind. Fixed.

By Googling the first error code, finding a suggested fix for that,
running again, Googling the new error, and several repeats of that, and
I've now got a working solution.

This recipe that somebody put on Github overcomes the main hurdle:
https://gist.github.com/sshillo/62955e46cb05e2b47ad3

The main issue seems to be that contrary to the instructions on the
Numba website, it's now a requirement to have  LLVM 3.6 installed, not
LLVM 3.5 which is in the Debian repository, and not LLVM 3.7 which is
the latest release at llvm.org.  Fortunately, a prebuilt LLVM 3.6 is
available at llvm.org.

Also I needed to install this lot from the Debian repository:

python-pip python-setuptools build-essential
python-enum34 libedit-dev python-dev
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26188] Provide more helpful error message when `await` is called inside non-`async` method

2016-01-23 Thread Nicholas Chammas

New submission from Nicholas Chammas:

Here is the user interaction:

```python
$ python3
Python 3.5.1 (default, Dec  7 2015, 21:59:10) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def oh_hai():
... await something()
  File "", line 2
await something()
  ^
SyntaxError: invalid syntax
```

It would be helpful if Python could tell the user something more specific about 
_why_ the syntax is invalid. Is that possible?

For example, in the case above, an error message along the following lines 
would be much more helpful:

```
SyntaxError: Cannot call `await` inside non-`async` method.
```

Without a hint like this, it's too easy to miss the obvious and waste time 
eye-balling the code, like I did. :-)

--
components: Interpreter Core
messages: 258879
nosy: Nicholas Chammas
priority: normal
severity: normal
status: open
title: Provide more helpful error message when `await` is called inside 
non-`async` method
versions: Python 3.5, Python 3.6

___
Python tracker 

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



Re: How do I add 18 seconds to an ISO-8601 String in Python?

2016-01-23 Thread Robert James Liguori
Oh... How do I convert it back to ISO 8301?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I add 18 seconds to an ISO-8601 String in Python?

2016-01-23 Thread Robert James Liguori
I cant thank you enough
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26189] Non-interactive interpreter returns control to cmd.exe early

2016-01-23 Thread Ivan Pozdeev

New submission from Ivan Pozdeev:

When running python.exe from windows console non-interactively, cmd.exe prompt 
appears immediately after starting:

C:\>python -c "import time; time.sleep(2); print 'bla-bla-bla'"

C:\>bla-bla-bla


Not only this prevents from cmd to setting ERRORLEVEL to the return code, this 
makes it impossible to run scripts that expect input from console because 
Python and cmd get input lines in turns (I typed both inputs 2 times in the 
following example):

C:\>python -c "s=raw_input('1st:'); print s; s=raw_input('2nd:'); print s"

C:\>1st:abcdef
'abcdef' is not recognized as an internal or external command,
operable program or batch file.

C:\>abcdef
abcdef
2nd:123456
'123456' is not recognized as an internal or external command,
operable program or batch file.

C:\>123456
123456


--
components: IO
messages: 258880
nosy: Ivan.Pozdeev
priority: normal
severity: normal
status: open
title: Non-interactive interpreter returns control to cmd.exe early
type: behavior
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



[issue26074] Add a method to pip.. pip.require("package_name")

2016-01-23 Thread Blaize Rhodes

Blaize Rhodes added the comment:

Righto.. will talk to the pip dudes.  Thanks for your time.  

(@matrixise The reason I posted this here is because pip is included as part of 
the cpython distribution.  None of the documentation I've seen suggests that 
this isn't a forum for discussing the std python libs, and indeed there seem to 
be many enhancement requests for python libs in this bug db.  It seems that pip 
has some special status as included as part of the std python distribution but 
not part of the std libs.  I would have thought that it was obvious from the 
context that I was unaware of this fact at the time I posted the request.  Does 
that answer your question?  What's with the attitude?  You've never made a 
mistake I take it?).

--

___
Python tracker 

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



Re: import locale and print range on same line

2016-01-23 Thread Terry Reedy

On 1/23/2016 8:58 AM, Chris Angelico wrote:

On Sun, Jan 24, 2016 at 12:45 AM, Steven D'Aprano  wrote:

On Sun, 24 Jan 2016 12:19 am, Chris Angelico wrote:


On Sun, Jan 24, 2016 at 12:07 AM, Steven D'Aprano 
wrote:

On Sat, 23 Jan 2016 09:02 pm, rai...@gmail.com wrote:


However I need to put the code on one single line.


Why? Is the Enter key on your keyboard broken?


Maybe it's for a python -c invocation.



[steve@ando ~]$ python -c "for i in range(5):

 print 'hello world'
"

hello world
hello world
hello world
hello world
hello world
[steve@ando ~]$


Well, not everyone's shells are as awesome as bash...


Like Windows command prompt is not.  I tried:

C:\Users\Terry>python -c "for i in range(5):\n\tprint('hello world')"
  File "", line 1
for i in range(5):\n  print('hello world')
 ^
SyntaxError: unexpected character after line continuation character

-c does not preprocess the code string before executing.  I may propose 
that it do so.  However, Python is still pretty awesome.


C:\Users\Terry>python -c "exec('''for i in range(5):\n  print('hello 
world')''')"

hello world
hello world
hello world
hello world
hello world


and not everyone knows you can do that.


One can even combine -i (interactive) with -c (code).

C:\Users\Terry> python -i -c "exec('''a=[]\nfor i in 
(1,2,3):\n\ta.append(i)''')"

>>> a
[1, 2, 3]
>>>

--
Terry Jan Reedy

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


Re: How do I add 18 seconds to an ISO-8601 String in Python?

2016-01-23 Thread Michael Torrie
On 01/23/2016 07:22 PM, Robert James Liguori wrote:
> Thank you so much!  Btw, how do I convert back to ISO-8301?

Have a look at the documentation for the datetime module.  The docs will
tell you how you can convert to a string, formatted to your
specifications and needs.  As always, the documentation should be the
first place you look, followed by internet searches.

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


Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-23 Thread Bernardo Sulzbach
Showing any bits of input would help us help you.

Your question also seems too vague. Almost a "how to optimize".
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26189] Interpreter returns control to cmd.exe early

2016-01-23 Thread Steve Dower

Steve Dower added the comment:

That'd suggest a change in the link options since 2.7.10, probably SUBSYSTEM. 
Or possibly there's a config option that prevents allocating a console 
correctly on startup.

FWIW, I don't think WinXP 64-bit was ever considered trustworthy, so it may be 
a bug in the OS that never got fixed.

--

___
Python tracker 

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



Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-23 Thread Steven D'Aprano
On Sunday 24 January 2016 11:27, Robert James Liguori wrote:

> Is there a python library to calculate longitudinal acceleration, lateral
> acceleration and normal acceleration?

Calculate acceleration of what?

I think we need some more detail before we can give a sensible answer, but 
you could try numpy and scipy:


http://www.numpy.org/
https://www.scipy.org/

or Sage:

http://www.sagemath.org/


-- 
Steve

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


[issue26189] Interpreter returns control to cmd.exe early

2016-01-23 Thread Ivan Pozdeev

Ivan Pozdeev added the comment:

Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:40:30) [MSC v.1500 64 bit 
(AMD64)] on win32
WinXP x64 SP2

I also tested with PowerShell 1.0. Python opens another window, but the shell's 
prompt also shows up immediately.

--

___
Python tracker 

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



Re: How do I add 18 seconds to an ISO-8601 String in Python?

2016-01-23 Thread Ben Finney
Robert James Liguori  writes:

> Thank you so much!  Btw, how do I convert back to ISO-8301?

You are consistently referring to “ISO 8301”, but I am confident that
you are not intending to talk about:

ISO 8301: Thermal insulation -- Determination of steady-state
thermal resistance and related properties -- Heat flow meter
apparatus


Please take care to refer to the correct standard code for the standard
you're referencing :-)

-- 
 \ “You say I took the name in vain / I don't even know the name / |
  `\But if I did, well, really, what's it to you?” —Leonard Cohen, |
_o__) _Hallelujah_ |
Ben Finney

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


[issue26189] Interpreter returns control to cmd.exe early

2016-01-23 Thread Eryk Sun

Eryk Sun added the comment:

Try forcing cmd to wait using the "start" command:

C:\>start /b /w python -c "raise SystemExit(42)"
C:\>echo %errorlevel%
42

--
nosy: +eryksun

___
Python tracker 

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



Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-23 Thread Steven D'Aprano
Second attempt.


On Sunday 24 January 2016 11:27, Robert James Liguori wrote:

> Is there a python library to calculate longitudinal acceleration, lateral
> acceleration and normal acceleration?

Calculate acceleration of what?

I think we need some more detail before we can give a sensible answer, but 
you could try numpy and scipy:


http://www.numpy.org/
https://www.scipy.org/

or Sage:

http://www.sagemath.org/



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