Re: tkinter MP working like a charm

2017-12-31 Thread Terry Reedy

On 12/30/2017 7:57 PM, Wu Xi wrote:

from tkinter import *#I cant see 
anything wrong with this , it works like a charm


This imports about 200 names.  A reader may not know which names are 
builtins and which are imports.  There may also be accidental name 
conflicts.



from tkinter import messagebox   #is there a 
serious concern doing things his way ?


This is the normal way to import tkinter subpackages.


import asyncio , threading ,  random #goal is multi 
tasking with the GUI not freezing before loop completed
 #which is being 
achieved here !


I verified that this works in 3.7.0a3 as I believe you intend.  So it is 
possible to create and run a tk loop in the main thread and run async 
loop (created in the main thread) in a subthread.  I don't think anyone 
knows when this will and will not work.


What you show below is that asyncio.sleep and asyncio.wait work under 
this circumstance.  Actually fetching even one url and making it 
readable from the main thread, so it can be displayed in a tk Text 
widget, would be even more impressive, and useful.



def _asyncio_thread(async_loop):
 async_loop.run_until_complete(do_urls())

def do_work(async_loop):
 """ Button-Event-Handler starting stuff """
 threading.Thread(target=_asyncio_thread, args=(async_loop,)).start()

async def one_url(url):
 """ One task. """
 sec = random.randint(1, 8)
 await asyncio.sleep(sec  )
 return 'url: {}  ---  sec: {}'.format(url, sec)

async def do_urls():
 """ Creating and starting 10 tasks. """
 tasks   = [one_url(url)  for url  in range(10)]
 completed, pending =  await asyncio.wait(tasks)
 results = [task.result() for task in completed]
 print('\n'.join(results))

def do_nofreeze():
 messagebox.showinfo(message='see, Tkinter is still responsive')

def submain(async_loop):
 root = Tk()
 b1 = Button(master=root, text='do work',   command= lambda:do_work( 
async_loop)).pack()
 b2 = Button(master=root, text='Frozen?',   command=do_nofreeze 
).pack()


.pack() returns None, and binding None to b1 and b2 is useless.  Either 
skip the assignment or call .pack after the assignment.


Button(master=root, text='do work',
   command= lambda:do_work( async_loop)).pack()

b1 = Button(master=root, text='do work',
command= lambda:do_work( async_loop))
b1.pack()

Since b1 and b2 here are local variables not accessible output submain, 
do the former.  If submain were a method, 'self.b1 = Button...' would 
make it easy to access the button from elsewhere, as for testing.  (It 
is also possible to introspect root for its contents.)



 root.mainloop()

if __name__ == '__main__':
 async_loop = asyncio.get_event_loop()#  all in this loop
 submain(async_loop)


To do everything in the main thread, one can replace 'root.mainloop' 
with loop.run_forever (in the main thread) and repeated root.update calls.


--
Terry Jan Reedy

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


Re: PyWin32 installer question

2017-12-29 Thread Terry Reedy

On 12/29/2017 11:38 AM, Paul Moore wrote:

On 29 December 2017 at 16:04, Skip Montanaro  wrote:

Thanks. I'll shoot Thomas Heller an email...



Actually, make that Christopher Toth. Seems he's the current maintainer.


If you get no joy there, then in a week or two, when I next get access
to a system with a Python 2.x build environment on it, I can see if I
can do a 64-bit build for you. Ping me if that would be a help.


I have not followed this thread, but there may be no need to.
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Christopher Gohlke, at UC Irvine, provides Windows cpxx wheels for about 
300 packages, for 2.7, 3.4, 3.5, 3.6, 3.7, in win32 and win_amd64 
versions (as applicable).   PyWin32-221 is included, with all combinations.


--
Terry Jan Reedy

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


Re: Using the variable type annotation syntax as a placeholder in a nonlocal scope?

2017-12-22 Thread Terry Reedy

On 12/22/2017 8:53 AM, Kirill Balunov wrote:

On Dec 20, 2017 22:43, "Kirill Balunov"  wrote:



Since PEP 526 -- Syntax for Variable Annotations
  was approved, in Python 3.6+
it is possible to provide type hint information in the form *x: int*,
also the PEP says "However, annotating a local variable will cause the
interpreter to always make it local to the scope and leaves the variable
uninitialized".


It is unitialized only if you do not initialize it.


Therefore in Python 3.6+ it is syntactically legal to
write:

def outer():
 x: int
 def inner():
 nonlocal x
 x = 10
 inner()
 print(x)


Why would you write the above instead of

>>> def f():
x:int = 10
print(x)

>>> f()
10


while the above snippet is semantically more equivalent to:


More equivalent than what?


def outer():
 #x
 def inner():
 nonlocal x
 x = 10
 inner()
 print(x)

Which is obviously a *SyntaxError: no binding for nonlocal 'x' found`*,
sorry for the pun. Also there is nothing said about this style in PEP 8 and
Python 3.6 docs. So should I consider this as a bug, or an implementation
detail (side effect), or a wart, or a feature?


I don't understand the question.  Maybe people on SO did not either.

--
Terry Jan Reedy

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


Re: Regarding the error: TypeError: can’t pickle _thread.lock objects

2017-12-21 Thread Terry Reedy

On 12/21/2017 8:11 AM, Winston Manuel Vijay wrote:

Hi,

It would be of immense help, if someone could provide a suitable solution or 
related information that helps to sort out the below stated issue-


Ø  I had installed the Python version 3.6.4

Ø  Then I installed the package: Tensorflow

Ø  Installed g2p.exe by downloading from GitHub

Ø  Then tried running the below command-

g2p-seq2seq --interactive --model  (model_folder_path: is 
the path to an English model 2-layer LSTM with 512 hidden units CMU Sphinx dictionary 
downloaded from the CMU Sphinx website)

Following the above procedure, I encountered the following error: TypeError: 
can’t pickle _thread.lock objects-please find the attached screenshot for your 
reference.


This is a text-only mailing list.  One should copy and paste an entire 
traceback.


That said, if Tensorflow or g2p are trying to pickle something that 
cannot be pickled, you would likely do better directing your inquiry to 
the authors.


If you possible can, omit the following nonsensical garbage.  When you 
submit to a public list like python-list, anyone in the world is an 
intended recipient and you implicitly authorize all of the listed 
activities.  If you do not want that, don't submit.





This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
This email is sent for the intended recipient(s) only. If by an addressing or 
transmission error, this mail has been misdirected to you, you are requested to 
delete this mail immediately. If you are not the intended recipient(s), please 
reply to the sender and destroy all copies of the original message. Any 
unauthorized review, use, disclosure, dissemination, forwarding, printing or 
copying of this email, and/or any action taken in reliance on the contents of 
this e-mail is strictly prohibited and may be unlawful. Where permitted by 
applicable law, this e-mail and other e-mail communications sent to and from 
GSR e-mail addresses may be monitored.




--
Terry Jan Reedy


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


Re: How to edit a function in an interactive python session?

2017-12-21 Thread Terry Reedy

On 12/20/2017 8:42 PM, Peng Yu wrote:


R has the function edit() which allows the editing of the definition
of a function. Does python have something similar so that users can
edit python functions on the fly? Thanks.

https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit


In general, no.  In general, it is not possible since the definition may 
not be in Python.  (The equivalent must be true in R also.)


In a decent Python IDE, like IDLE, that allows one to enter, retrieve, 
and edit complete statements, then yes for function definitions entered 
in the same session.  It is also possible to edit multi-line code 
line-by-line in the standard REPL, but it is more painful and error prone.


One can monkey-patch an edited function into an imported module written 
in Python.  The original code can be copied from an editor and pasted 
into the REPL.


--
Terry Jan Reedy

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


Re: correctness proof for alpha-beta algorithm

2017-12-18 Thread Terry Reedy

On 12/19/2017 1:01 AM, namenobodywa...@gmail.com wrote:


can anybody tell me where to look for a proof of the correctness of a 
minimax/negamax algorithm with alpha-beta pruning? thanks if you can help


Where or how have you looked so far?  How formal do you want?

--
Terry Jan Reedy

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


Re: Python Learning

2017-12-16 Thread Terry Reedy

On 12/16/2017 8:26 AM, Marko Rauhamaa wrote:


Unfortunately, Python's indentation mechanism makes the REPL too
frustrating an environment to type in even the simplest of function
definitions, let alone a whole class.


The fundamental problem is that most REPLs are for 'command lines', and 
Python does not have 'command lines'.  It has statements.  A statement 
may consist of a single line, and if simple, it looks and acts like a 
command line.  But a statement may also be multiple lines.  Even without 
indentation, a single-line editing and history mechanism is a poor fit 
to a multiline statement language.


IDLE has a shell built for Python and Python only.  One enters, edits, 
and retrieves complete statements.  Indentation is automatic.  There is 
currently a glitch in that Shell indents with tabs instead of spaces, 
but I want to change that and know of two ways to do so.


--
Terry Jan Reedy

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


Re: Can't start IDLE on mac os x high sierra can't import Tkinter

2017-12-15 Thread Terry Reedy

On 12/15/2017 6:37 AM, ceiussandi...@gmail.com wrote:

Hi, I've been trying to get python 3.4.3 (needed for programming course) on my 
mac, running High Sierra.
I've installed python and activetcl 8.5.18 as per instructions. When I start 
IDLE from finder it flashes in the dock and disappears. When I start it from 
terminal, I get the following response:
** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **
I've googled for the answer but I can't find anything, the closest I got was to 
this https://github.com/pyinstaller/pyinstaller/issues/2665 but I'm not sure if 
it is this issue or not.
Can someone help me get started using python?


I don't have a Mac, but I know that
https://www.python.org/download/mac/tcltk/
has some fairly exacting instructions at the bottom on how to get Python 
to find the newly installed tcl/tk.  You should probably specify rather 
exactly what you did.  There are multiple issues on bugs.python.org and 
questions on stackoverflow.


--
Terry Jan Reedy

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


Re: Python homework

2017-12-13 Thread Terry Reedy

On 12/13/2017 8:28 AM, bo...@choices.random.py wrote:

nick.martin...@aol.com (nick martinez2) writes:


def rollDie(number):
 rolls = [0] * 6
 for i in range(0, number):
 roll=int(random.randint(1,6))


One could just as well use randint(0, 5) and skip the -1 below.


 rolls[roll - 1] += 1
 return rolls


This returns a list with a count of how many times each of 1 to 6 is 
chosen in *number* rolls.



def rollDie(number):
 from random import choices
 return choices((1,2,3,4,5,6), k=number)


This returns a list with all *number* rolls.  Assuming the the first 
function is the one wanted, one could feed choices into a counter.  (The 
import should be outside of the function.)


def rollDie(number):
rolls = [0] * 6
for i in random.choices((0,1,2,3,4,5), k=number):
rolls[i] += 1
return rolls

--
Terry Jan Reedy

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


Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-12-09 Thread Terry Reedy

On 12/9/2017 5:57 AM, Gilmeh Serda wrote:


And next demands to allow Unicode as keywords in a translated version of
Python


Python's liberal open source license allows people to revise and 
distribute their own python or python-like interpreters.  I believe 
there are already a couple of non-english versions aimed at schoolkids. 
The cpython core developer group has nothing to do with such.


--
Terry Jan Reedy

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


Re: How to use a regexp here

2017-12-08 Thread Terry Reedy
On 12/4/2017 11:14 AM, Ned Batchelder wrote:
> On 12/4/17 9:13 AM, Rick Johnson wrote:
>> Perhaps it's not politically correct for me to say this, but
>> i've never been one who cared much about political
>> correctness, so i'm just going to say it...
>
> Cecil, feel free to ignore the rest of Rick's message.â  His messages are
> famous for their outrageous and/or abrasive tone, something he seems to
> revel in.â  Luckily, it's not typical of the Python community.

Or take Rick's 'rest' as a suggestion to reread Library Reference chapters 2,
3, 4 and in particular 4.7.

As for your idea of an RE, '^' matches the beginning of a line, and '$' the
end, though using .startswith, and .endswith, are easier if no other RE syntax
is needed for matching.

--
Terry Jan Reedy

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


Re: we want python software

2017-12-06 Thread Terry Reedy

On 12/5/2017 4:39 PM, Igor Korot wrote:

Hi, Tony,

On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff  wrote:

On 05/12/17 16:55, Igor Korot wrote:

Hi,

On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy
 wrote:

Sir,
 I am b.tech student I would like to learn python. So please send the 
python software.

Sorry, we don't send anything. You will have to go get it yourself. -)


Well, at least try to be helpful:
https://www.python.org/downloads/


This is LMGIFY.
If they say they are tech students - they should know how to work with Google.

And I even tried to be polite. I should have probably write something like:

1. Open the Web browser.
2. In the "Address Bar" type "www.pyton.org".


Fortunately, this wrong url does not currently lead to a fake site with 
malware binaries.



3. Find the link which reads "Downloads". Click on it.
4. Carefully read what version you need to install for your OS.
5. Apply the acquired knowledge and download the appropriate version.
6. Click on the installer (if on Windows).
7. Follow all the prompts.
8. Enjoy.

but this is too much for the tech student.

Thank you.


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



--
Terry Jan Reedy

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


Re: why won't slicing lists raise IndexError?

2017-12-06 Thread Terry Reedy

On 12/5/2017 9:23 PM, Rick Johnson wrote:

Steve D'Aprano wrote:

[...]


You've already been told that there's no indication or
reason to believe that it is a non-action. You've already
been given at least one possible action. It isn't a non-
action, it is two distinct actions:

- the action you take when the slice is non-empty;

- the action you take when the slice is empty.


When Python follows a logic clause like a train skating
along a set of railroad tracks, and finds itself in a *GHOST
TOWN*, that's not an action -- "Steve-o" -- it's a non-
action.


Rick, cut the crap.  If you do not understand that 'something_else()' != 
'pass', re-read the tutorial.

---

The OP asked: "Why is slicing 'forgiving'?"  The current behavior could 
be interpreted as 'letting errors pass silently'.  It would be if 
slicing meant 'give me exactly the length stop-start subsequence from 
start to stop (or raise)'.  But slicing actually means 'give me whatever 
subsequence exists between start and stop'.


My examples attempted to show why this looser definition of slicing is 
*useful*.  The focus of the third example was entirely on the condition, 
not the alternative actions.  (Reminder: either action can be the 
if-action, and the other the else-action, depending on how the condition 
is written.)


I should have mentioned, and others did, that the OP can write a custom 
__getitem__ method that implements stricter slicing for instances of a 
custom class.


I think we have collectively answered the OP's question quite well.

--
Terry Jan Reedy

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


Re: why won't slicing lists raise IndexError?

2017-12-04 Thread Terry Reedy

On 12/4/2017 1:54 PM, Jason Maldonis wrote:

I was extending a `list` and am wondering why slicing lists will never
raise an IndexError, even if the `slice.stop` value if greater than the
list length.



Is there any background on why that doesn't raise an IndexError?


Slicing is perhaps most commonly used on strings, and clamping is 
probably most useful for strings.


Example 1:  s[0:k] gets the k or fewer initial characters of the string, 
perhaps to put in a fixed-width display or storage field.


Example 2: below are two equivalent (I believe) code snippets.

try:
item = seq[n]
except IndexError
do_without_item()
else:
process(item)

item = seq[n:n+1]
if item:
process(item)
else:
do_without_item()

Many prefer the second.  Note that moving process(item) in the first 
into the try clause makes the two non-equivalent.


Example 3:

'if s[k:k+1] in okset' versus 'if len(s) >= k+1 and s[k] in okset'.

There are many examples like this where is slicing did not clamp, the 
user would have to reproduce some of the logic done by slices.


--
Terry Jan Reedy

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


Re: How to use a regexp here

2017-12-04 Thread Terry Reedy

On 12/4/2017 11:14 AM, Ned Batchelder wrote:

On 12/4/17 9:13 AM, Rick Johnson wrote:

Perhaps it's not politically correct for me to say this, but
i've never been one who cared much about political
correctness, so i'm just going to say it...


Cecil, feel free to ignore the rest of Rick's message.  His messages are 
famous for their outrageous and/or abrasive tone, something he seems to 
revel in.  Luckily, it's not typical of the Python community.


Or take Rick's 'rest' as a suggestion to reread Library Reference 
chapters 2, 3, 4 and in particular 4.7.


As for your idea of an RE, '^' matches the beginning of a line, and '$' 
the end, though using .startswith, and .endswith, are easier if no other 
RE syntax is needed for matching.


--
Terry Jan Reedy


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


Re: asyncio loop.call_soon()

2017-11-28 Thread Terry Reedy

On 11/28/2017 11:02 AM, Ian Kelly wrote:

On Tue, Nov 28, 2017 at 8:30 AM, ast  wrote:

Hello

Python's doc says about loop.call_soon(callback, *arg):

Arrange for a callback to be called as soon as possible. The callback is
called after call_soon() returns, when control returns to the event loop.

But it doesn't seem to be true; see this program:

import asyncio

async def task_func():
print("Entering task_func")

def callback():
print("Entering callback")

async def main():
print("Entering main")
task = loop.create_task(task_func())
loop.call_soon(callback)
await task

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Execution provides following output:

Entering main
Entering task_func
Entering callback

callback is executed AFTER task_func, I expected it
to be executed BEFORE.

When "main()" coroutine reach line "await task", it let the control to the
event loop, and it seems that the loop starts to execute task instead of
callback. Then, when task is over the loop runs callback

This is not what the doc says: callback should be called as soon
as possible when the loop has control, with a priority over other
tasks pending in the loop


You omitted this part of the documentation:

"This operates as a FIFO queue, callbacks are called in the order in
which they are registered. Each callback will be called exactly once."

This documents the ordering of call_soon callbacks. It doesn't say
anything about how the callback will be ordered with respect to tasks
or other events that are also immediately ready to be handled.

Also, if you look at the implementation of create_task, it invokes
call_soon. This is therefore consistent with the doc, as call_soon was
actually called twice: first for task_func(), and then for callback.


I believe that this means that any code in the coroutine *before* the 
first await is run immediately.  This is what I experienced in my 
experiments yesterday.



--
Terry Jan Reedy

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


Re: Compile Python 3 interpreter to force 2-byte unicode

2017-11-26 Thread nospam . nospam . Terry Reedy
On 11/25/2017 5:12 PM, Chris Angelico wrote:
> On Sun, Nov 26, 2017 at 9:05 AM,   wrote:
>> Hi, my goal is to obtain an interpreter that internally
>> uses UCS-2. Such a simple code should print 65535:
>>
>>import sys
>>print sys.maxunicode
>>
>> This is enabled in Windows, but I want the same in Linux.
>> What options have I pass to the configure script?

You must be trying to compile 2.7.  There may be Linux distributions that
compile this way.  If you want to use, or ever encounter, non-BMP chars, using
surrogate pairs is problematical.  By my reading of the official UCS-2 docs,
Python's old 16-bit unicode implementation is not fully compliant.  Others have
 claimed that is it not a UCS-2 implementation.

> Why do you want to? What useful value do you have in creating this
> buggy interpreter?

> Ever since Python 3.3, that has simply not been an
> option. The bug has been solved.

If you want to seriously work with unicode, many recommend using modern Python.

--
Terry Jan Reedy

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


Re: connect four (game)

2017-11-26 Thread nospam . nospam . Terry Reedy
On 11/25/2017 4:57 PM, namenobodywa...@gmail.com wrote:
> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote:
>
>> I did, and it looks buggy to me.  The top and left frame lines are
>> missing.  If I click a square, the bottom square in the column lights
>> up.  But then I have no idea whether those are your intentions or not.
> i hadn't noticed about the frame lines, but it's the same for me; but i'm
hoping you meant to write that the TOP square in a column flashes when you
"drop a token" down that column;

All squares start white.  Only the bottom square turns red or black, after
perhaps a .3 second delay during which there is some jitter in white squares
above, which could be the effect of white flashing white.

> if you really meant the bottom one then i'm totally baffled that it could be
the top one for me and the bottom one for you ... is that something that can
happen because of a bug?

I am running on Windows 10 from IDLE (which should not affect your code) with
3.7.0a2 with tk 8.6.6. The OS and tk version could have an effect, though top
versus bottom is hard to fathom.

--
Terry Jan Reedy

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


Re: connect four (game)

2017-11-26 Thread nospam . Terry Reedy
On 11/25/2017 4:57 PM, namenobodywa...@gmail.com wrote:
> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote:
>
>> I did, and it looks buggy to me.  The top and left frame lines are
>> missing.  If I click a square, the bottom square in the column lights
>> up.  But then I have no idea whether those are your intentions or not.
> i hadn't noticed about the frame lines, but it's the same for me; but i'm
hoping you meant to write that the TOP square in a column flashes when you
"drop a token" down that column;

All squares start white.  Only the bottom square turns red or black, after
perhaps a .3 second delay during which there is some jitter in white squares
above, which could be the effect of white flashing white.

> if you really meant the bottom one then i'm totally baffled that it could be
the top one for me and the bottom one for you ... is that something that can
happen because of a bug?

I am running on Windows 10 from IDLE (which should not affect your code) with
3.7.0a2 with tk 8.6.6. The OS and tk version could have an effect, though top
versus bottom is hard to fathom.

--
Terry Jan Reedy

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


Re: Compile Python 3 interpreter to force 2-byte unicode

2017-11-26 Thread nospam . Terry Reedy
On 11/25/2017 5:12 PM, Chris Angelico wrote:
> On Sun, Nov 26, 2017 at 9:05 AM,   wrote:
>> Hi, my goal is to obtain an interpreter that internally
>> uses UCS-2. Such a simple code should print 65535:
>>
>>import sys
>>print sys.maxunicode
>>
>> This is enabled in Windows, but I want the same in Linux.
>> What options have I pass to the configure script?

You must be trying to compile 2.7.  There may be Linux distributions that
compile this way.  If you want to use, or ever encounter, non-BMP chars, using
surrogate pairs is problematical.  By my reading of the official UCS-2 docs,
Python's old 16-bit unicode implementation is not fully compliant.  Others have
 claimed that is it not a UCS-2 implementation.

> Why do you want to? What useful value do you have in creating this
> buggy interpreter?

> Ever since Python 3.3, that has simply not been an
> option. The bug has been solved.

If you want to seriously work with unicode, many recommend using modern Python.

--
Terry Jan Reedy

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


Re: Compile Python 3 interpreter to force 2-byte unicode

2017-11-25 Thread Terry Reedy

On 11/25/2017 5:12 PM, Chris Angelico wrote:

On Sun, Nov 26, 2017 at 9:05 AM,   wrote:

Hi, my goal is to obtain an interpreter that internally
uses UCS-2. Such a simple code should print 65535:

   import sys
   print sys.maxunicode

This is enabled in Windows, but I want the same in Linux.
What options have I pass to the configure script?


You must be trying to compile 2.7.  There may be Linux distributions 
that compile this way.  If you want to use, or ever encounter, non-BMP 
chars, using surrogate pairs is problematical.  By my reading of the 
official UCS-2 docs, Python's old 16-bit unicode implementation is not 
fully compliant.  Others have claimed that is it not a UCS-2 implementation.



Why do you want to? What useful value do you have in creating this
buggy interpreter?



Ever since Python 3.3, that has simply not been an
option. The bug has been solved.


If you want to seriously work with unicode, many recommend using modern 
Python.


--
Terry Jan Reedy

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


Re: connect four (game)

2017-11-25 Thread Terry Reedy

On 11/25/2017 4:57 PM, namenobodywa...@gmail.com wrote:

On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote:


I did, and it looks buggy to me.  The top and left frame lines are
missing.  If I click a square, the bottom square in the column lights
up.  But then I have no idea whether those are your intentions or not.

i hadn't noticed about the frame lines, but it's the same for me; but i'm hoping you 
meant to write that the TOP square in a column flashes when you "drop a token" 
down that column;


All squares start white.  Only the bottom square turns red or black, 
after perhaps a .3 second delay during which there is some jitter in 
white squares above, which could be the effect of white flashing white.



if you really meant the bottom one then i'm totally baffled that it could be 
the top one for me and the bottom one for you ... is that something that can 
happen because of a bug?


I am running on Windows 10 from IDLE (which should not affect your code) 
with 3.7.0a2 with tk 8.6.6. The OS and tk version could have an effect, 
though top versus bottom is hard to fathom.


--
Terry Jan Reedy

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


Re: connect four (game)

2017-11-25 Thread Terry Reedy

On 11/24/2017 9:05 PM, namenobodywa...@gmail.com wrote:

On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote:


Since you did not start with tests or write tests as you wrote code, ...


that I could tell ...

I agree that I should have stuck in a qualifier, such as 'apparently'.


why on earth would you assume that?


I inferred (not assumed) that because
a) people routinely post code here and on Stackoverflow without 
including or mentioning runnable automated tests;

b) you said 'here it is' without a word about tests;
c) your code has no docstrings or other function by function doc, and 
one can hardly write tests without them.


Was I right or are you exceptional?

instantiate "window" and you'll see it works exactly as i intended; 


I did, and it looks buggy to me.  The top and left frame lines are 
missing.  If I click a square, the bottom square in the column lights 
up.  But then I have no idea whether those are your intentions or not.


nobody's asking you to debug code for free; i'm looking for the kind of 
feedback the other respondent gave.


I read Chris's answer and intentionally did not repeat.  Anyway, I think 
the best advice I could give you, based on experience writing and 
reviewing code, if you do not already have complete coverage, is to 
write (more?) automated tests.


--
Terry Jan Reedy

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


Re: Issues encountered while launching the IDLE of python 3.7 64-bit I downloaded recently.

2017-11-24 Thread Terry Reedy

On 11/24/2017 6:39 PM, STEPHINEXT TUTORIALS wrote:

On Wed, Nov 22, 2017 at 4:29 AM, STEPHINEXT TUTORIALS <
oladejist...@gmail.com> wrote:



I just downloaded the new version 3.7 for my windows operating system
64-bits on your site.


Does Python itself run?


The error I got while launching the IDLE


How did you try to launch IDLE?


is shown in the attached Picture.


Python-list (and hence the gmane newsgroup mirror) is a no-attachment 
list.  So the picture was detached.  Copy and paste the text if you can 
or re-type the contents of a Windows error box.



I installed all the options


I don't know what this means.

--
Terry Jan Reedy

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


Re: Benefits of unicode identifiers

2017-11-24 Thread Terry Reedy

On 11/24/2017 7:12 AM, bartc wrote:

π = 3.141;


That's great. But how do I type it on my keyboard? How do I view someone 
else's code on my crappy ASCII text editor?


Input is a problem, but for reading, Python comes with a half-way decent 
Unicode BMP code editor, IDLE.  No one needs to use a 'crappy ASCII text 
editor' for such code.


--
Terry Jan Reedy


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


Re: connect four (game)

2017-11-24 Thread Terry Reedy

On 11/24/2017 10:33 AM, namenobodywa...@gmail.com wrote:

hi all

i've just finished my first excursion into artificial intelligence with a game 
less trivial than tictactoe, and here it is in case anybody can offer 
criticism/suggestions/etc


Since you did not start with tests or write tests as you wrote code, 
write a test file now.  It will probably be at least as long as your 
current file.  You will learn a lot about your code by doing so.


--
Terry Jan Reedy

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


Re: Should constants be introduced to Python?

2017-11-16 Thread Terry Reedy

On 11/16/2017 4:55 PM, Michael Torrie wrote:

On 11/15/2017 11:16 PM, Saeed Baig wrote:

- Do you guys think it would be a good idea? Why or why not? Do you
think there’s a better way to do it? I’d like to know what others
think about this idea before making any formal submission.


Except for forcing it to be read-only, there's absolutely no difference
between your idea of a constant and a normal module name in Python.
Since Python is a dynamic language, all names have to be looked up at
run time.  So there's really no speed benefit to having a special const
syntax.  In Python, we normally expect developers to act as consenting
adults.  Thus a constant is often denoted by an uppercase name (at least
in the scripts I've seen), similar to C or other languages.  We can just
say to developers, please don't rebind a name that's all capitals.
That's it.


The idea of named constants has been proposed before, and rejected 
pretty much for the reason you give above.



Constants as you propose really only make sense in statically-typed,
compiled languages where the compiler replaces the constant names with
the values in the compiled code.  Doesn't work that way in Python, where
things are interpreted at run time.


CPython, at least, already has anonymous constant objects.  Number and 
string literals are turned into objects when parsed.  I presume that all 
implementations do this.  Some constant expressions are replaced by 
(constant) objects during compiling, instead of when running.  For 
instance "n = 10 + 3' will run as 'n = 13', and "for lang in ('C', 
'Java', 'Python') will have the tuple pre-computed (whereas "for lang in 
['C', 'Java', 'Python] will have to construct the list each time run).


--
Terry Jan Reedy


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


Re: Windows - py363 crashes with "vonLöwis.py"

2017-11-16 Thread Terry Reedy

On 11/16/2017 5:51 AM, breamore...@gmail.com wrote:

On Thursday, November 16, 2017 at 8:43:24 AM UTC, wxjm...@gmail.com wrote:


Mark: Jmf's troll posts to the Google group are not propagated to 
python-list and the gmane mirror except when people, like you here, 
quote him.  Please stop.

Do you remember stringbench.py ? Years later, I still do
not understand how it is possible to write a test module,
which is supposed to test Unicode and does not even
contain a non ascii char...


For the benefit of any unicode newbies who read Mark's post but
have not read
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals 
,
by using \u, \U, and \N{name} escape sequences in string 
literals.


--
Terry Jan Reedy

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


Re: Windows - py363 crashes with "vonLöwis.py"

2017-11-15 Thread Terry Reedy

On 11/15/2017 6:58 AM, breamore...@gmail.com wrote:

On Wednesday, November 15, 2017 at 8:53:44 AM UTC, wxjm...@gmail.com wrote:

Sorry, to have to say it.

Have a nice day.


Do you mean it segfaults or simply provides a traceback?  If the latter is your 
environment set correctly?


Why bother?  Anyway, for the obvious interpretation of the message, 
given f:/python/a/vonLöwis.py containing 'print("works")'"


C:\Users\Terry>py -3.6 f:/python/a/vonLöwis.py
works

--
Terry Jan Reedy


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


Re: How to modify this from Python 2.x to v3.4?

2017-11-11 Thread Terry Reedy

On 11/11/2017 9:06 PM, jf...@ms4.hinet.net wrote:

Ned Batchelder於 2017年11月11日星期六 UTC+8下午8時49分27秒寫道:

This looks like fairly advanced code.  It will be difficult to port to
Python 3 *without* understanding some of the old history.  There seem to
be forks on GitHub, including one with a pull request about Python 3
made in the last few days:
https://github.com/davidjamesca/ctypesgen/pull/58 .  I'd recommend
working with others on this.


Thank you, Ned.

As I remember that I had opened a thread here last year, trying to use "2To3" 
tool to convert the ctypesgen package, but didn't success.
https://groups.google.com/forum/#!topic/comp.lang.python/9G0FJXmtwbA

This time, somehow I find this "ctypesgen-python-3" package and can't wait to 
give it a try, but is disappointed again. I suppose there are many v3.x users who like to 
use ctypesgen to ease the using of ctypes. But obviously, it's not an easy work to do, 
convert 2 to 3:-)

By the way, does anyone know what the following codes does? (in printer.py 
file) and how to convert it to v3.x?

class WrapperPrinter:
 def __init__(self,outpath,options,data):
 ...
 ...
 self.print_header()
 print >>self.file


print(file=self.file)  # print blank line


 self.print_preamble()
 print >>self.file

 self.print_loader()
 print >>self.file
 ...
 ...

--Jach




--
Terry Jan Reedy


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


Re: Python Mailing list moderators

2017-11-05 Thread Terry Reedy

On 11/5/2017 4:14 PM, Cameron Simpson wrote:
On 05Nov2017 13:09, Στέφανος Σωφρονίου  
wrote:

Folks,
More and more nonsense are coming in and I find it really difficult to 
follow any new post that may come and I have to either search for 
specific content or scroll down until I hit it by accident.


Can we do something about it?
It's getting really frustrating :/


It seems from the headers on your message that you're actually using the 
comp.lang.python newsgroup and not the mailing list. The newsgroup is 
completed unmoderated.  The mailing list is far less noisy.


Go here:

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

and subscribe, and see if things seem better than the newsgroup.
Or point your newsreader to news.gmane.org group 
gmane.comp.python.general, which mirrors python-list.


Terry Jan Reedy


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


Re: [TSBOAPOOOWTDI]using names from modules

2017-11-04 Thread Terry Reedy

On 11/4/2017 3:42 PM, Stefan Ram wrote:

   What is better:

...
import math
...
... math.cos ...
...

   or

...
from math import cos
...
... cos ...
...

   ?

   (To me, the first is more readable, because at the site
   where »math.cos« is used, it is made clear that »cos«
   comes from math. But I assume that the second might use
   one less name lookup and therefore is faster. What is the
   one way to do it?)


There is no 'one way', which is why there is more than one way.
The first lets the reader know the source at each use site.
The second lets the reader know what use is made of the source at the 
top.  The advantage depends on how familiar the *reader* is with the 
source module and the functions therein.


Is your question generic to any module and object,  or specific to the 
math module?  If generic, and mode is part of the package you are 
writing, then 'import mod' is less likely to create a circular import 
error.  On the other hand, 'from mod import obj' is better for testing 
because it lets one mock obj in the importing module without touching 
the imported module (where the original may be internally needed in the 
same test).  With idlelib, there are both circular import and testing 
issues.


If importing a module is expensive in some way, then knowing that B only 
needs one or two 'cheap' items from A is needed may suggest a workaround 
or refactoring.  For instance, move items from  A to B and reverse the 
import between them.


Replacing an existing 'from tkinter import *' with 'import tkinter' or 
'import tkinter as tk' requires prefixing every existing reference to a 
tkinter object.  Replacing the same with 'from tkinter import Tk, ...' 
requires list each object.  The latter localizes the patch.  Plus see 
the preceding paragraphs.  In either case, complete enough test coverage 
is needed to make the change.


I initially started with the 'as tk' replacement, but switched to the 
list version.  A tkinter-specific reason was planning to switch from tk 
to ttk versions of widgets.  Moving, for instance, 'Button' from the 
tkinter list to the tkinter.ttk list, instead of changing prefixes, 
would be both easy and make it obvious, at the top, that the change had 
been made, and for all Buttons.


--
Terry Jan Reedy


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


Re: python3 byte decode

2017-11-03 Thread Terry Reedy

On 11/3/2017 5:24 AM, Ali Rıza KELEŞ wrote:

Hi,

Yesterday, while working with redis, i encountered a strange case.

I want to ask why is the following `True`

```
"s" is b"s".decode()
```

while the followings are `False`?

```
"so" is b"so".decode()
"som" is b"som".decode()
"some" is b"some".decode()
```

Or vice versa?

I read that `is` compares same objects, not values. So my question is
why "s" and b"s".decode() are same objects, while the others aren't?


For the same reason as

>>> a = 1
>>> b = 1
>>> a is b
True
>>> a = 1000
>>> b = 1000
>>> a is b
False

For CPython, 'small' ints are cached on startup.  Ditto for 'small' 
strings, which I think includes all 128 ascii chars, and maybe latin1 
chars.  Details depends on the implemention and version.  The main use 
of 'is' for immutable builtins is for developers to test the 
implementation in the test suite.


--
Terry Jan Reedy


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


Re: A use-case for for...else with no break

2017-11-02 Thread Terry Reedy

On 11/2/2017 8:53 PM, Steve D'Aprano wrote:

On Fri, 3 Nov 2017 09:20 am, Terry Reedy wrote:


This seems like a bug in how Python interacts with your console. On
Windows, in Python started from an icon or in Command Prompt:

  >>> for c in 'abc': print(c, end='')
...
abc>>>


That's still unfortunate: the prompt is immediately after the output, rather
than starting on a new line.


I agree.  It is just less bad than backspacing into user output first. 
It is easy for IDLE to detect if the prompt needs a \n prefix.  I am 
guessing that this is harder on consoles, and OS dependent.



IDLE adds \n if needed, so prompts always starts on a fresh line.

  >>> for x in 'abcdefgh':
print(x, end='')

abcdefgh
  >>>


The prompts and the output aren't aligned -- the prompts are indented by an
additional space. Is that intentional?


A copy-paste error (I rechecked) that I should have noticed.


Does IDLE do this only when writing to an actual console?


IDLE does this when Python writes to its Shell via stdout or stderr.


Because if it does
so even when output is redirected to a file, adding an extra, unexpected
newline would be a bug in IDLE.


IDLE compiles and execs your code.  During the exec call, IDLE only sees 
output sent to its stdout/stderr replacements.  If your code sends 
output to a file it opens, IDLE is not involved.


--
Terry Jan Reedy

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


Re: FW: Reading a remove csv file

2017-11-02 Thread Terry Reedy

On 11/2/2017 9:18 AM, ROGER GRAYDON CHRISTMAN wrote:

I have a partial answer to my own question:
This seems to work for me:

---
link = urllib.request.urlopen(urlpath)
data = link.read().decode('utf-8').split('\n')

reader = csv.DictReader(data)
for row in reader:
---

I think here my concern is that now 'data' is now a variable
in my program's memory (all of the data),
instead of streamlike.   I suppose I did read
somewhere about setting a stream option.


csv.reader and csv.DictReader are transformation iterators whose first 
argument must be an iterable of string lines.  Given an iterator of 
bytes lines, you just need to interpose a bytes to string iterator  -- 
something like (untested)


def strgen(bytesource, encoding):
for line in bytesource:
yield line.decode(encoding)

with urllib.request.urlopen(urlpath) as link:
lines = strgen(link, 'utf-8')
reader = csv.DictReader(lines)  # plus any other args
for row in reader:
process(row)

Iterators are intended to be chained together like this.

--
Terry Jan Reedy

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


Re: A use-case for for...else with no break

2017-11-02 Thread Terry Reedy

On 11/2/2017 6:10 AM, Steve D'Aprano wrote:

Occasionally it is useful to loop over a bunch of stuff in the interactive
interpreter, printing them as you go on a single line:

for x in something():
 print(x, end='')

If you do that, the prompt overwrites your output, and you get a mess:


py> for x in "abcdefgh":
... print(x, end='')
...
py> efghpy>


This seems like a bug in how Python interacts with your console.  On 
Windows, in Python started from an icon or in Command Prompt:


>>> for c in 'abc': print(c, end='')
...
abc>>>

IDLE adds \n if needed, so prompts always starts on a fresh line.

>>> for x in 'abcdefgh':
print(x, end='')

abcdefgh
>>>


"For ... else" to the rescue!

py> for char in "abcdefgh":
... print(char, end='')
... else:
... print()
...
abcdefgh
py>


--
Terry Jan Reedy

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


Re: replacing `else` with `then` in `for` and `try`

2017-11-02 Thread Terry Reedy

On 11/1/2017 5:12 PM, Alexey Muranov wrote:

what do you think about the idea of replacing "`else`" with "`then`" in 
the contexts of `for` and `try`?


This idea has been argued to death more than once before.  I am opposed 
on both logical and practical grounds, but will not repeat myself for 
the fourth or fifth time.


--
Terry Jan Reedy

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


Re: IDLE doesn't recognise installed packages

2017-10-26 Thread Terry Reedy

On 10/26/2017 12:37 AM, Daniel Tangemann wrote:

ok, I did that. I noticed that this path: 
'C:\\Users\\Daniel86\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\idlelib' 
is missing when I run the python.exe without IDLE. how do I fix this?


Having idlelib on the path or not should not make any difference for 
anything installed by pip.  It is not even needed by IDLE, since IDLE 
imports its modules via Lib.




also I get a syntax error when I try that:


What you try what?  Post the entire traceback.


"To make sure you are running pip with the same binary
as IDLE, enter path-to-binary -m pip 

Your path-to-binary appears to be

C:\Users\Daniel86\AppData\Local\Programs\Python\Python36\python.exe

You should be able to replace that with

py -3.6

but try

py -3.6 -c "import sys; sys.executable"

to be sure.


Terry Reedy  hat am 24. Oktober 2017 um 08:36 geschrieben:


On 10/23/2017 10:23 AM, Daniel Tangemann wrote:

I've recently downloaded and installed python 3.6. (I had already also 2.7 and 3.2 on my computer) 
Initially pip was looking in the wrong directory to install to, so I changed that. then it had 
trouble installing matplotlib, so I decided to get rid of the older versions of python, which 
srewed things up even more. now scrips that I had written (in 3.6), that were running without 
errors before, aren't working anymore. I tried reinstalling python, and I tried the repair option 
multiple times as well. when I look into the python folder, I can see the modules that I have 
installed (and that I import into those scripts), but the IDLE doesn't see them! what's even more 
weird, is that "pip list" doesn't bring up anything but pip itself, while typing 
"pip install matplotlib" returns a message

  that

it's already installed. how do I fix this?
cheers


Recognition of installed packages is done by the python running IDLE and
executing your import statements, by not IDLE. The only effect IDLE
could have is any manipulation of sys.path.

You can find the executable running IDLE with


import sys; sys.executable

'C:\\Programs\\Python37\\pythonw.exe'

Find the sys.path being used with

sys.path


If you run the same binary (minus the 'w' if present), you can find the
sys.path used without IDLE. You can also test imports without IDLE in use.

It is possible that you have more than one binary around, but I cannot
tell from here. To make sure you are running pip with the same binary
as IDLE, enter path-to-binary -m pip  C:\Programs\Python37\python.exe -m pip list

--
Terry Jan Reedy

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



--
Terry Jan Reedy

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


Re: Let's talk about debuggers!

2017-10-25 Thread Terry Reedy

On 10/25/2017 12:12 PM, Thomas Jollans wrote:

On 2017-10-25 15:57, Rustom Mody wrote:


pdb inside emacs works (to a fashion)
And it shows the arrow for current line so its at least quasi-gui

I believe idle too is much more usable than a few years earlier


I haven't used IDLE in years (if ever), partly because Tkinter is so
incredibly ugly, and feels so out-of-place on a modern PC (maybe it's
tolerable on Windows, I wouldn't know).


On Windows, it uses native widgets when possible, so the look and feel 
of IDLE's editor is the same as some other apps, such as Notepad++.  We 
are in the process of switching to the ttk widget set, which improve the 
look on Linux and even more so on Macs.  The settings dialog was redone, 
in part, for 3.6.3 and 3.7.  Which version are you using?



In any case I just tried it out and good lord that's terrible.


The debugger UI has not gotten its badly needed makeover yet; there is a 
issue and patch to do so.



You can
set breakpoints in the editor (good), it shows locals (excellent), but
it doesn't show you what line you're at when stepping through (seriously?).


Seriously, you either did not look, or you have a broken IDLE 
installation, or you ran into a severe bug I would like to know about. 
Rather than never, the next line is shown 2 or 3 times.


1.The module, line number, and code of the next line is shown 
immediately below the header of buttons and checkboxes.


2. The box below shows the complete stack of Python lines in the process 
of being run, including (again) the one that will be executed next.  For 
each, it shows the module, line number, and text of the line.


Bug: code and line number are reversed on the last line, which is the 
repeat of the next line.  Enhancement: make list more readable with 
module, number, and code in neat columns.  The window will have to be 
much wider, or each line split as in tracebacks, to do this.


3. If one checks the '[X] source' box at the top, the 'next' line is 
highlighted in an IDLE editor window.  This is currently not checked by 
default because the debugger would currently open *every* file stepped 
into.  When opening new windows is made optional, source will be checked 
by default.


In summary, I think debugger should rate at least 'good' rather than 
'fail' when it comes to showing you the next line.



I'll go back to not even touching IDLE with a ten-foot pole now.


Do as you want, but please report accurately.  There are bugs around the 
debugger, but not, that I know of, the one you claim.

--
Terry Jan Reedy

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


Re: IDLE doesn't recognise installed packages

2017-10-23 Thread Terry Reedy

On 10/23/2017 10:23 AM, Daniel Tangemann wrote:

I've recently downloaded and installed python 3.6. (I had already also 2.7 and 3.2 on my computer) 
Initially pip was looking in the wrong directory to install to, so I changed that. then it had 
trouble installing matplotlib, so I decided to get rid of the older versions of python, which 
srewed things up even more. now scrips that I had written (in 3.6), that were running without 
errors before, aren't working anymore. I tried reinstalling python, and I tried the repair option 
multiple times as well. when I look into the python folder, I can see the modules that I have 
installed (and that I import into those scripts), but the IDLE doesn't see them! what's even more 
weird, is that "pip list" doesn't bring up anything but pip itself, while typing 
"pip install matplotlib" returns a message that
   it's already installed. how do I fix this?
cheers


Recognition of installed packages is done by the python running IDLE and 
executing your import statements, by not IDLE.  The only effect IDLE 
could have is any manipulation of sys.path.


You can find the executable running IDLE with

>>> import sys; sys.executable
'C:\\Programs\\Python37\\pythonw.exe'

Find the sys.path being used with
>>> sys.path

If you run the same binary (minus the 'w' if present), you can find the 
sys.path used without IDLE.  You can also test imports without IDLE in use.


It is possible that you have more than one binary around, but I cannot 
tell from here.  To make sure you are running pip with the same binary 
as IDLE, enter path-to-binary  -m pip instance, on windows, given the above


path> C:\Programs\Python37\python.exe -m pip list

--
Terry Jan Reedy

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


Re: How to debug an unfired tkinter event?

2017-10-21 Thread Terry Reedy

On 10/21/2017 1:25 PM, jf...@ms4.hinet.net wrote:

Terry Reedy at 2017-10-20 UTC+8 AM 7:37:59 wrote:

On 10/19/2017 5:07 AM, jf...@ms4.hinet.net wrote:


I got some info below each time when I squeeze the table:
.
.5006
.5006.50712528
.5006.50712496
.5006.50712464
.5006.50712144
.5006.50712528.50712560.50782256
.5006.50712528.50712560.50782256.50783024
.5006.50712528.50712560.50782256
.5006.50712528.50712560.50782256.50783024

How to change these number(is it a widget ID?) to a meaning name?


The number strings as names are the defaults that came from tkinter, not
tcl/tk.  In 3.6, the default names were changed to be versions of the
class name.

  >>> import tkinter as tk
  >>> r = tk.Tk()
  >>> b = tk.Button(r)
  >>> b

  >>> b2 = tk.Button(r)
  >>> b2



I have a question about this change. When there are multiple buttons in the same widget 
hierarchy level and a ".xxx.yyy.!button2" showing up, how to figure out which 
button it means?


There is an issue about one particular situation with a name clash. 
This can always be avoided by providing explicit names at least at the leaf.



By the way, where is the document of this change?


What New in 3.6 should have something.


Now it doesn't fit the description in the "tkinter 8.5 reference manual" 
anymore.


If you mean the one at nmt.edu, it is not maintained and is slowly 
becoming out of date.  tcl/tk is now at 8.6.7 or .8.  'tkinter 8.5' is 
something of a misnomer because the tkinter version is the same as the 
Python version and tries to be somewhat up-to-date with tcl/tk, which 
being compatible with earlier tcl/tk versions.


--
Terry Jan Reedy

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


Re: How to debug an unfired tkinter event?

2017-10-19 Thread Terry Reedy

On 10/19/2017 11:28 PM, jf...@ms4.hinet.net wrote:

Terry Reedy於 2017年10月20日星期五 UTC+8上午7時37分59秒寫道:

On 10/19/2017 5:07 AM, jf...@ms4.hinet.net wrote:


I got some info below each time when I squeeze the table:
.
.5006
.5006.50712528
.5006.50712496
.5006.50712464
.5006.50712144
.5006.50712528.50712560.50782256
.5006.50712528.50712560.50782256.50783024
.5006.50712528.50712560.50782256
.5006.50712528.50712560.50782256.50783024

How to change these number(is it a widget ID?) to a meaning name?


The number strings as names are the defaults that came from tkinter, not
tcl/tk.  In 3.6, the default names were changed to be versions of the
class name.

  >>> import tkinter as tk
  >>> r = tk.Tk()
  >>> b = tk.Button(r)
  >>> b

  >>> b2 = tk.Button(r)
  >>> b2


--
Terry Jan Reedy


It's very nice to have this improvment.

What it will be to the previous number output format, say, .5006.50712528? 
Will it become something like this:

 


I anticipate 


then, that's really great:-)



--
Terry Jan Reedy


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


Re: How to debug an unfired tkinter event?

2017-10-19 Thread Terry Reedy

On 10/19/2017 5:07 AM, jf...@ms4.hinet.net wrote:


I got some info below each time when I squeeze the table:
.
.5006
.5006.50712528
.5006.50712496
.5006.50712464
.5006.50712144
.5006.50712528.50712560.50782256
.5006.50712528.50712560.50782256.50783024
.5006.50712528.50712560.50782256
.5006.50712528.50712560.50782256.50783024

How to change these number(is it a widget ID?) to a meaning name?


The number strings as names are the defaults that came from tkinter, not 
tcl/tk.  In 3.6, the default names were changed to be versions of the 
class name.


>>> import tkinter as tk
>>> r = tk.Tk()
>>> b = tk.Button(r)
>>> b

>>> b2 = tk.Button(r)
>>> b2


--
Terry Jan Reedy

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


Re: Can't find latest version of 3.4.x on download page

2017-10-18 Thread Terry Reedy

On 10/18/2017 2:09 AM, Christopher Reimer wrote:

Greetings,

I'm setting up different test environments for tox. I can't find Windows 
installer for the latest version of Python 3.4 on the download page.

Versions 3.4.5 to 3.4.7 only have the source files available.


Correct.  These are security releases, mainly for servers and people who 
would compile themselves.



Version 3.4.4 is the last version with Windows installers.


Correct.

--
Terry Jan Reedy

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


Re: multiprocessing shows no benefit

2017-10-17 Thread Terry Reedy

On 10/17/2017 10:52 AM, Jason wrote:

I've got problem that I thought would scale well across cores.


What OS?


def f(t):
return t[0]-d[ t[1] ]

d= {k: np.array(k) for k in entries_16k }
e = np.array()



pool.map(f, [(e, k) for k in d]


*Every* multiprocessing example in the doc intentionally protects 
multiprocessing calls with


if __name__ == '__main__':

"Safe importing of main module

Make sure that the main module can be safely imported by a new 
Python interpreter without causing unintended side effects (such a 
starting a new process)."



At the heart of it is a list of ~16k numpy arrays (32 3D points) which are 
stored in a single dict.  Using pool.map() I pass the single item of 32 3D 
Points to  be evaluated again the 16k entries. In theory, this would be a 
speedup proportional to the number of physical cores, but I see all 4 cores 
being maxed out and results in a regular map time.

How can I use pool.map better?


Try following the doc and see what happens.

--
Terry Jan Reedy

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


Re: why del is not a function or method?

2017-10-17 Thread Terry Reedy

On 10/17/2017 1:07 AM, Steve D'Aprano wrote:


The point is, if del were a function, then calling del(x) would pass the



*value* of x into the function, not the name 'x'


So we would have to quote either the entire rest of the statement, or 
each item separately,



-- unless the interpreter

  made del a special case, not a regular function.


This is what Lisp does.  Most functions are 'normal': unquoted argument 
expressions are evaluated.  Some are 'special': at least one of the 
argument expressions is automatically quoted or treated specially is 
some way.  Users have to memorize which functions are special and which 
arguments are automatically quoted.  Learning the exceptions and quoting 
rules was for me a barrier to learning Lisp.


In Python, the 'special functions' of Lisp are statements.  With print 
now a function, I believe every python statement with arguments does 
something special with at least one argument.


In assignments statements, for instance, everything to the right of the 
final '=' is evaluated normally.  Everything to the left of any '=' gets 
special treatment.  The final 'get object' part of expression evaluation 
is replace by 'create association' with the corresponding object on the 
right side.


In CPython left-hand expressions are not merely quoted for runtime 
evaluation and use.  They are parsed at compile time and compiled to 
almost normal bytecode.  The difference is that a load bytecode is 
replace by a store bytecode (that takes a second argument).


>>> dis('a[b] = c[d]')
  1   0 LOAD_NAME0 (c)
  2 LOAD_NAME1 (d)
  4 BINARY_SUBSCR
  6 LOAD_NAME2 (a)
  8 LOAD_NAME3 (b)
 10 STORE_SUBSCR
 12 LOAD_CONST   0 (None)
 14 RETURN_VALUE
>>> dis('a(b).c = d(e).f')
  1   0 LOAD_NAME0 (d)
  2 LOAD_NAME1 (e)
  4 CALL_FUNCTION1
  6 LOAD_ATTR2 (f)
  8 LOAD_NAME3 (a)
 10 LOAD_NAME4 (b)
 12 CALL_FUNCTION1
 14 STORE_ATTR   5 (c)
 16 LOAD_CONST   0 (None)
 18 RETURN_VALUE

For statements executed repeatedly, this is more efficient than quoting 
for runtime evaluation.



But if the interpreter did that, why bother with function notation and the



extraneous parentheses? Why not just make it a statement and avoid surprising



the programmer by giving the del function super-powers that no other function



has?



Tcl does not use parentheses for function calls.  But with only one 
syntax, it still needs arcane quoting rules.


--
Terry Jan Reedy

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


Re: how to read in the newsreader

2017-10-16 Thread Terry Reedy

On 10/15/2017 10:50 PM, Andrew Z wrote:

Gents,
  how do i get this group in a newsreader?


Point your newsreader to news.gmane.org, group 
gmane.comp.python.general, which mirrors python-list, among hundreds or 
thousands of other lists.  If you check the headers of this message, you 
should see that I am posting via gmane.


--
Terry Jan Reedy

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


Re: Unable to run pip in Windows 10

2017-10-11 Thread Terry Reedy

On 10/11/2017 10:46 AM, Michael Cuddehe wrote:

- What exactly did you install?

Latest install: Python 3.5.4 (v3.5.4:3f56838, Aug  8 2017, 02:17:05) [MSC

v.1900 64 bit (AMD64)] on win32

Downloaded from python.org.

  - Can you start the Python interpreter?

Yes...works fine.

* How exactly did you go about this

??

  - How exactly do you try to run pip?

Command prompt: c:\Users\FFC>pip import (module)


Try running instead

...> python -m pip install 

or to specifically ensure that you run 3.5,

...> py -3.5 -m pip install 

and if that fails, copy the entire response.


  - What exactly happens when you try?

Windows error message: "This app can't run on your PC"


--
Terry Jan Reedy

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


Re: Unable to run pip in Windows 10

2017-10-11 Thread Terry Reedy

On 10/11/2017 11:54 AM, Michael Torrie wrote:

On 10/11/2017 08:46 AM, Michael Cuddehe wrote:

- What exactly did you install?

Latest install: Python 3.5.4 (v3.5.4:3f56838, Aug  8 2017, 02:17:05) [MSC

v.1900 64 bit (AMD64)] on win32

  ^^^


This is exactly what I see from 64 bit python installed on 64 bit 
Windows.  'win32' refers to the Windows platform, versus linux, unix, 
darwin, etc.  Yes, it is confusing.



So your OS is 32 bit?


The next line says that this binary runs fine.  So 'No'.  The problem is 
specific to trying to run pip.



This v.1900 was downloaded from python.org?


MSC v.1900 is the latest Microsoft C compiler, which was used to compile 
the binary.  It is not downloaded.


--
Terry Jan Reedy

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


Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread Terry Reedy

On 10/10/2017 10:37 AM, xieyuheng wrote:


2. what kind of functions does not have signature,
so that 'inspect.signature(f)' can be used for them ?


When .signature was added, it may not have been usable with *any* 
C-coded function.  About the same, a mechanism was added to make 
signatures available with C-coded functions.  Using the mechanism 
requires recoding for each file.  By now, many CPython functions have 
been recoded.



section '29.12.3. Introspecting callables with the Signature object'
of the official documentation says :

> Some callables may not be introspectable in certain implementations of 
Python.


So 'some' is a gradually shrinking set.


> For example, in CPython, some built-in functions defined in C
> provide no metadata about their arguments.

this is depends on implementation, so I ask for CPython.


--
Terry Jan Reedy

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


Re: Is there a way to globally set the print function separator?

2017-10-09 Thread Terry Reedy

On 10/9/2017 12:22 PM, John Black wrote:

I want sep="" to be the default without having to specify it every time I
call print.  Is that possible?

John Black


Define a replacement print function that makes this the default. 
Something like (untested, a detail may be wrong):


_print = print
def print(*args, **kwargs):
_print(*args, {'sep':''}.update(kwargs))


--
Terry Jan Reedy

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


Re: IDLE help.

2017-10-08 Thread Terry Reedy

On 10/8/2017 5:24 AM, Joe Wilde wrote:


I am having trouble getting IDLE (Python 3.6 - 64-bit) to open for Windows 10. 
When I try and run IDLE, nothing happens. It works fine for Python 2.7, but 
won't open for Python 3.6.


Give more information.  How did you install Python? Did you select the 
option to install tkinter and IDLE?  How are you trying to run IDLE?  Do 
you know what Command Prompt and a console are?



--
Terry Jan Reedy

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


Re: The "loop and a half"

2017-10-07 Thread Terry Reedy

On 10/7/2017 10:45 AM, Grant Edwards wrote:

On 2017-10-07, bartc  wrote:


Interactive Python requires quit() or exit(), complete with parentheses.


Nonsense.  On Unix you can just press ctrl-D (or whatever you have
configured as eof) at the command prompt. On windows, it's Ctrl-Z
.


IDLE's shell quits on ^D at a prompt on all systems.  (This became true 
before I worked on IDLE.)

Clicking the [X] button should close any window on all systems.

--
Terry Jan Reedy

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


Re: Introducing the "for" loop

2017-10-07 Thread Terry Reedy

On 10/7/2017 5:09 AM, Steve D'Aprano wrote:

On Fri, 6 Oct 2017 11:44 pm, ROGER GRAYDON CHRISTMAN wrote:


Despite the documentation, I would still be tempted to say that range is a
function.
Taking duck-typing to the meta-level, every time I use range, I use its name
followed
by a pair of parentheses enclosing one to three parameters, and I get back
an
immutable sequence object.   It sure looks like a function to me.


I agree -- range() is a function in the (almost) mathematical sense, something
which takes arguments and returns a value. It's also a type (class), in the
OOP sense:


py> type(range)



The term "function" is ambiguous but normally clear from context. Often, the
differences make no difference, but when they are important, we can discuss
them:

- range is a callable (a callable object);

- it is also a type/class, and calling it returns an instance;

- it looks like, and behaves like, a function;

- and is, conceptually, a function;

- but it is *not* an instance of FunctionType:


py> from types import FunctionType
py> def function():
... pass
...
py> isinstance(function, FunctionType)
True
py> isinstance(range, FunctionType)
False


No built-in function is an instance of FunctionType
>>> isinstance(compile, FunctionType)
False
>>> isinstance(print, FunctionType)
False
>>> type(compile)

>>> type(int.bit_length)



FunctionType == function defined by def statement or lambda expression.
These are a subset of functions defined by Python code.


It is this last sense (an instance of FunctionType) which people are thinking
of when they state that range is not a function.


Unless one means 'function defined by def or class', excluding all 
functions defined in the interpreter implementation language, which can 
change as modules are recoded one way or the other, and some functions 
defined in Python, FunctionType is too narrow.  The predecate would have 
to be at least


BuiltinFunction = type(compile)
MethonDescriptor = type(int.bit_length)
isinstance(x, (FunctionType, BuiltinFunction, MethodDescriptor))

but that still excludes bound methods and partial functions.

I have the impression that classes being functions is somewhat peculiar 
to Python but I have not been exposed to enough OOP languages to know.


The other sense in which 'range is not a function' makes some sense is 
when it means 'range is not *just* a function'.  This is akin to when 
'people are not animals' means 'people are not (or should not be) *just* 
animals'.  Do people speaking other than English say subcategory Y of 
category X is special by saying 'Ys are not Xs'?


--
Terry Jan Reedy

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


Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]

2017-10-07 Thread Terry Reedy

On 10/6/2017 8:19 PM, Steve D'Aprano wrote:

On Sat, 7 Oct 2017 05:33 am, Grant Edwards wrote:


On 2017-10-06, Marko Rauhamaa  wrote:


The reason a daemon usually opens dummy file descriptors for the 0, 1
and 2 slots is to avoid accidents. Some library might assume the
existence of those file descriptors. For example, I often see GTK print
out diagnositic messages.


I run a lot of GTK programs from the command line, and I would say 90%
or more of them spew a steady stream of meaningless (to the user)
diagnostic messages.  That's pretty sloppy programming if you ask
me...


Indeed.

If you ever start to doubt that the average quality of software is "crap", try
running GUI applications from the command line and watch the stream of
warnings and errors flow by. They range from relatively trivial warnings that
correctly sized icons are missing, to scary looking warnings about
uninitialised pointers.


IDLE does not do that because tkinter and the other stdlib modules it 
uses does not do that.  There are occasionally extraneous messages from 
tcl when shutting down.



Developers: why do you bother to log warnings if you're never going to fix the
damn things?

They're probably to busy re-doing working programs from scratch every few
versions, with a brand new "improved" UI (almost invariably including a kool
new design that uses light grey text on an ever so slightly lighter grey
background) and deleting any useful functionality that the lead developer
personally doesn't use, because "nobody uses that".

https://www.jwz.org/doc/cadt.html






--
Terry Jan Reedy

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


Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]

2017-10-06 Thread Terry Reedy

On 10/6/2017 1:32 PM, Chris Angelico wrote:

On Sat, Oct 7, 2017 at 4:05 AM, Grant Edwards  wrote:

On 2017-10-06, Thomas Jollans  wrote:


Seriously? sys.stdin can be None? That's terrifying.


Why?

Unix daemons usually run with no stdin, stderr, or stdout.

And yes, people do write Unix daemons in Python.


Hmm, but usually I would expect them still to HAVE those streams,
they're just connected to /dev/null or something. I don't think they
would actually fail to exist, would they?


On Windows, a file run with pythonw.exe (no console) starts with 
sys.[__]std[in|out|err][__] (6 entries) set to None.  The program can 
reset them as it pleases.  In an IDLE user process, the non-dunder names 
are set to objects that communicate with the IDLE GUI process.


>>> import sys; sys.__stdin__, sys.stdin
(None, )

GUI programs interact with the OS and thence users through event streams 
rather than character streams.  (Note that terminal escape sequences are 
character-encoded events.)  That is why automating a GUI usually 
requires a special program than can generate and inject events into the 
event queue read by the GUI program.


--
Terry Jan Reedy

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


Re: Introducing the "for" loop

2017-10-06 Thread Terry Reedy

On 10/6/2017 8:44 AM, ROGER GRAYDON CHRISTMAN wrote:


Despite the documentation, I would still be tempted to say that range is a
function.


It is, *according* to the documentation.  Built-in classes are included 
in Library Reference, Ch. 2, Built-in Functions.  Changing that to 
"Built-in Functions and Classes" has been proposed (perhaps by me) and 
rejected.



Taking duck-typing to the meta-level, every time I use range, I use its name
followed
by a pair of parentheses enclosing one to three parameters, and I get back an
immutable sequence object.   It sure looks like a function to me.


In the standard mathematical sense it is, more so than instances of 
classes  or mainly by side effects.



I would similarly say that map is a function, or an iterator generator
I write myself with yield statements is a function,


Functions with 'yield' are 'generator functions'


both of which also return sequences.


Iterators are mutable representatives of sequences, but cannot be indexed.


It is not clear to me what the difference really is between my conception
and the official definition -- is it a question about whether it returns a
first-class object?


No.  All python callables (functions in the broad sense) return objects.


Or more simply, what is the clear and obvious distinction that I can give to my
non-scientific laypeople about why range isn't a function, if it looks like one?


It is a function, in the usual sense not specific to Python, that is 
specifically a Python class.  It is not just a function.  It is a 
function that returns an instance of itself when called.  This is the 
distinguishing feature of classes as functions (callables).


--
Terry Jan Reedy

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


Re: The "loop and a half"

2017-10-04 Thread Terry Reedy

On 10/4/2017 1:24 PM, Grant Edwards wrote:

On 2017-10-04, Steve D'Aprano  wrote:


It is sometimes called the loop and a half problem. The idea is
that you must attempt to read a line from the file before you know
whether you are at the end of file or not.


Utter nonsense. There's no "must" here. I'll accept the remote
possibility that maybe one time in a million you have to do what he
says, but the other 99 times you just read from the file in a
for-loop:

for line in file:
 process(line)


This can also be done if a boolean variable is introduced to help
with the while loop. This boolean variable is the condition that
gets you out of the while loop and the first time through it must be
set to get your code to execute the while loop at least one."


I've been programming in Python for twenty years, and I don't think I have
ever once read from a file using a while loop.


You're right, that construct isn't used for reading from files in
Python.  It _is_ commonly used for reading from things like socket



mysock.connect(...)
while True:
 data = mysock.recv()
 if not data:
 break
 do_something_with(data)
mysock.close()


I contend that it would be better in this case also to separate data 
access from data processing.


def sockreader(socket, size):
while True:
data = socket.recv(size)
if data:
yield data
else:
break

for data in socketreader(mysock, ):
do_something_with(data)

Perhaps the socket module needs an update to make the boilerplate 
generator function a method, such as 'iterread'.


The separation lets one write source-agnostic processing functions.

def do_something(source):
for data in source:


One can now 'do_something' with data from pipe, file, socket, or list.
--
Terry Jan Reedy


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


Re: The "loop and a half"

2017-10-03 Thread Terry Reedy

On 10/3/2017 2:10 PM, Peter Otten wrote:

Stefan Ram wrote:


   Is this the best way to write a "loop and a half" in Python?


[snip while loop]


Use iter() and a for loop:


def input_int():

... return int(input("Enter number (0 to terminate): "))
...

for x in iter(input_int, 0):

... print(f"Square = { x**2 }")
...
Enter number (0 to terminate): 1
Square = 1
Enter number (0 to terminate): 2
Square = 4
Enter number (0 to terminate): 0


I think this is the best answer.  Using a for loop cleanly separates the 
source of a sequence of objects from processing the objects.  While loop 
 raret in Python as they are only needed for other patterns, such as 
'while mutable object is not in the state we want: modify some more', 
and the number of modifications needed is not necessarity known ahead of 
time.


--
Terry Jan Reedy

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


Re: F5 not working?

2017-10-03 Thread Terry Reedy

On 10/3/2017 2:02 PM, Breta Skinner wrote:

Hello,
I tried looking around the website, but didn't see a question about
function keys.
Somehow, I "turned off" the F5 function in the IDLE. It no longer "run
module", but just does nothing. I have downloaded the newest version, 3.7,
but that did not solve the problem.  I admit to being clumsy, so I'm
guessing I hit an odd key combination which disabled F5 for Python IDLE on
this machine (windows 64 bit HP desk top).
I tried to check the configuration, but it looks like the key is set up:
[image: Inline image 1]


This is text only list; images are discarded.  If you run IDLE, select 
Options => Preferences => Keys and scroll down to 'run-module', it will 
will say  for a built-in keyset until you have changed 
idlelib/config-keys.def and should say  for custom key sets 
until you changed it, in which case, you should be able to change it back.


If it says F5, which is perhaps what you meant above, and F5 does not 
work, then you might have changed your keyboard, outside of IDLE, so 
that it does not generate the expected keycode.


Have you rebooted?


Any suggestions?  It was nice to have the key working.


--
Terry Jan Reedy

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


Re: Textwrap doesn't honour NO-BREAK SPACE

2017-09-29 Thread Terry Reedy

On 9/29/2017 2:35 AM, Steve D'Aprano wrote:

On Fri, 29 Sep 2017 03:55 pm, Terry Reedy wrote:


Expected result:


Lorum ipsum dolor sit amet, consectetur adipiscing elit
ZZZ ZZZ sed do euismod tempor incididunt ut labore et
dolore magna aliqua.


On Windows 10, I get this on 2.7, 3.5, 3.6, 3.7.



Sorry Terry, it isn't clear to me which result (expected, or actual) is "this"
in your comment.


The expected result.  I also should have specified 3.5.4, etc, which 
Wolfgang reported should have the backported fix.  So, you are correct 
that what you saw is/was a bug.


--
Terry Jan Reedy

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


Re: Textwrap doesn't honour NO-BREAK SPACE

2017-09-28 Thread Terry Reedy

On 9/29/2017 1:25 AM, Steve D'Aprano wrote:

I don't have Python 3.6 installed, can somebody check to see whether or not it
shows the same (wrong) behaviour?


import textwrap
text = ('Lorum ipsum dolor sit amet, consectetur adipiscing'
 ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt'
 ' ut labore et dolore magna aliqua.')
print(textwrap.fill(text, 59))



Expected result:


Lorum ipsum dolor sit amet, consectetur adipiscing elit
ZZZ ZZZ sed do euismod tempor incididunt ut labore et
dolore magna aliqua.


On Windows 10, I get this on 2.7, 3.5, 3.6, 3.7.


Actual result in Python 3.5 and older:

Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ
ZZZ sed do euismod tempor incididunt ut labore et dolore
magna aliqua.


I'm pretty sure this is a bug.



--
Terry Jan Reedy

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


Re: EuroPython 2017: Videos for Monday available online

2017-09-28 Thread Terry Reedy

On 9/28/2017 12:33 PM, M.-A. Lemburg wrote:


"""
In the coming weeks, we will release the other videos, in batches of
one conference day per week.
"""


It was not obvious to me that 'private video' meant 'non-existent, not 
yet added video'.  It usually means a video that is present but not public.



Perhaps we ought to remove them from the playlist to not cause
confusion.


This doesn't appear to be easily possible due to changes in the
YT UI. We've now set the playlist order to show the private
videos at the end as work-around.


That would make it easier to see what is available not.  I gave up 
trying to scroll through the list.



--
Terry Jan Reedy

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


Re: EuroPython 2017: Videos for Monday available online

2017-09-28 Thread Terry Reedy

On 9/28/2017 8:15 AM, M.-A. Lemburg wrote:

We are pleased to announce the first batch of cut videos for EuroPython
2017.

To see the videos, please head over to our EuroPython YouTube channel
and select the “EuroPython 2017″ playlist:


  * EuroPython 2017 Videos *

http://europython.tv/


Mark-Andre, I clicked the link, which forwards to
https://www.youtube.com/c/EuroPythonConference
and clicked the EuroPython 2017 playlist, and 90% of the 163 videos are 
unviewable [Private video]s.


--
Terry Jan Reedy


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


Re: TypeError with map with no len()

2017-09-25 Thread Terry Reedy

On 9/25/2017 12:44 PM, john polo wrote:

Python List,

I am trying to make practice data for plotting purposes. I am using 
Python 3.6. The instructions I have are


import matplotlib.pyplot as plt
import math
import numpy as np
t = np.arange(0, 2.5, 0.1)
y1 = map(math.sin, math.pi*t)


Change to
y1 = list(map(math.sin, math.pi*t))
or
y1 = tuple(map(math.sin, math.pi*t))
(Does not make much difference.)


plt.plot(t,y1)


or
plt.plot(t, list(y1))


However, at this point, I get a TypeError that says

object of type 'map' has no len()


In 3.x, map returns an iterator.  plot needs a sequence.


In [6]: t
Out[6]:
array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7, 0.8,  0.9,  1. ,
     1.1,  1.2,  1.3,  1.4,  1.5,  1.6,  1.7,  1.8, 1.9,  2. ,  2.1,
     2.2,  2.3,  2.4])
In [7]: y1
Out[7]: 
In [8]: math.pi*t
Out[8]:
array([ 0.    ,  0.31415927,  0.62831853,  0.9424778 , 1.25663706,
     1.57079633,  1.88495559,  2.19911486,  2.51327412, 2.82743339,
     3.14159265,  3.45575192,  3.76991118,  4.08407045, 4.39822972,
     4.71238898,  5.02654825,  5.34070751,  5.65486678, 5.96902604,
     6.28318531,  6.59734457,  6.91150384,  7.2256631 , 7.53982237])

At the start of creating y1, it appears there is an array to iterate 
through for the math.sin function used in map(), but y1 doesn't appear 
to be saving any values. I expected y1 to hold a math.sin() output for 
each item in math.pi*t, but it appears to be empty. Am I 
misunderstanding map()?


See comment 3 above.

Is there something else I should be doing 
instead to populate y1?


See comment 1 (or 2) above.

--
Terry Jan Reedy


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


Re: Beginners and experts (Batchelder blog post)

2017-09-23 Thread Terry Reedy

On 9/23/2017 2:52 PM, Leam Hall wrote:

On 09/23/2017 02:40 PM, Terry Reedy wrote:

https://nedbatchelder.com//blog/201709/beginners_and_experts.html

Great post.


Yup. Thanks for the link. I often have that "I bet Fred> doesn't get frustrated." thing going. Nice to know Ned bangs his 
head now and again.  :P


As do I ;-).


--
Terry Jan Reedy


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


Beginners and experts (Batchelder blog post)

2017-09-23 Thread Terry Reedy

https://nedbatchelder.com//blog/201709/beginners_and_experts.html

Great post.
--
Terry Jan Reedy

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


Re: Fwd: Issues with python commands in windows powershell

2017-09-20 Thread Terry Reedy

On 9/20/2017 1:09 PM, Joey Steward wrote:

-- Forwarded message --
From: Joey Steward 
Date: Tue, Sep 19, 2017 at 10:30 PM
Subject: Issues with python commands in windows powershell
To: python-list@python.org


Hello,

I've been having issues using basic python commands in windows powershell.
I'm new to programming so just going off of online tutorials.

Earlier I was unable to use pip to install Django (pip install Django), and
came to this forum for help and someone was able to give me the correct
command for windows 10 (py -m pip install django).

I've been trying to run this command django-admin startproject mytests, but
get the same error message as when trying to run the original pip


Try py -m django-admin startproject mytests.  If this does not work, ask 
on django lists.



django-admin : *The term 'django-admin' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included,*
*verify that the path is correct and try again.*
*At line:1 char:1*
+ django-admin startproject mytestsite
+ 
 + CategoryInfo  : ObjectNotFound: (django-admin:String) [],
CommandNotFoundException
 + FullyQualifiedErrorId : CommandNotFoundException


I'm very new so honestly have no idea what the issue may be, but from
previously trying to use python I think it may have something to do with
configuring windows environment variables? Not sure, but just something
I've ran into in the past previous times trying to learn python for more
data analysis purposes.

Any help would be greatly appreciated!

Thanks a lot,

Joey Steward




--
Terry Jan Reedy

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


Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"

2017-09-18 Thread Terry Reedy

On 9/18/2017 5:21 PM, John Ladasky wrote:

On Saturday, September 16, 2017 at 11:01:03 PM UTC-7, Terry Reedy wrote:

On 9/16/2017 7:04 PM, b...@g...com wrote:



The particular crippler for CLBG problems is the non-use of numpy in
numerical calculations, such as the n-body problem.  Numerical python
extensions are over two decades old and give Python code access to
optimized, compiled BLAS, LinPack, FFTPack, and so on.  The current one,
numpy, is the third of the series.  It is both a historical accident and
a continuing administrative convenience that numpy is not part of the
Python stdlib.


OK, I found this statement intriguing.  Honestly, I can't function without 
Numpy, but I have always assumed that many Python programmers do so.


True.  Very few websites need numpy.  Ditto for some other categories.
 >  Meanwhile: most of the time, I have no use for urllib, but that 
module is in the standard library.


Urllib is comparable in scope to, say, BLAS, or even to the math + 
statistics module.  And it is less dependent on particular systems. 
Django and associated modules, which is comparable, in its own way, to 
numpy + scipy, is also not in the stdlib, and should not be.



I noticed the adoption of the @ operation for matrix multiplication.  I have 
yet to use it myself.

So is there a fraction of the Python community that thinks that Numpy should in 
fact become part of the Python stdlib?


Only naive beginners, I should think.


 What is the "administrative convenience" to which you refer?


Numerical analysis is quite different from compiler construction and 
communication protocols.  So numpy needs its own set of developers, 
policies, decision process, release schedule, etc.  It took an expert in 
the field to persuade the numerical and numarray people to join together 
to produce numpy.  PSF provides the infrastructure that makes 'pip 
install numpy' or 'pip install django' possible.  Separate groups 
provide the content.

Does this make sense?

--
Terry Jan Reedy

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


Re: [Tutor] beginning to code

2017-09-17 Thread Terry Reedy

On 9/17/2017 4:39 PM, Rick Johnson wrote:


My point is
that Python source code was meant to be "executable pseudo
code" (Python devs' words not mine!),


The coinage 'Executable pseudocode' was my description of Python on 
comp.lang.python, mirrored to this list, in April 1997, long before
I became a Python (core) dev.  Guido did say things like 'human 
readable' before that.  To the extent that my description implies a 
higher standard, you cannot imput it to Guido ;-).


> and while regular expressions are meant to be cryptic,
> Python source code was not.

That I agree with.

--
Terry Jan Reedy

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


Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"

2017-09-16 Thread Terry Reedy

On 9/17/2017 2:04 AM, Chris Angelico wrote:

On Sun, Sep 17, 2017 at 4:00 PM, Terry Reedy  wrote:

The numerical extensions have been quasi-official in the sense that at least
3 language enhancements have been make for their use.


I know about the matrix multiplication operator. What are the other
two (or more)?


Stride slicing, which later became valid in regular code, and Ellipsis. 
(I could be wrong on the latter.)


--
Terry Jan Reedy

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


Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"

2017-09-16 Thread Terry Reedy

On 9/16/2017 7:04 PM, breamore...@gmail.com wrote:

I thought some might find this 
https://sites.google.com/view/energy-efficiency-languages/ interesting.


By 'energy', they only mean electricity, not food calories. This is the 
email I sent to the authors.

---

As a two-decade user of Python, I was interested to read your paper. 
Unfortunately, it is deeply flawed with respect to Python in the sense 
that your conclusions are inapplicable to real-world usage of Python.


The problem is your use of the Computer Language Benchmark Game.  As the 
name says, it is a *game*.  As a game, it has artificial rules dictated 
by the game masters.  It uses toy problems, and for Python, the rules 
dictate unrealistic toy solutions.  In particular, it appears to 
disallow use of 'import' with 3rd-party modules, whereas real-world 
Python is expected to use them, and nearly always does.


The particular crippler for CLBG problems is the non-use of numpy in 
numerical calculations, such as the n-body problem.  Numerical python 
extensions are over two decades old and give Python code access to 
optimized, compiled BLAS, LinPack, FFTPack, and so on.  The current one, 
numpy, is the third of the series.  It is both a historical accident and 
a continuing administrative convenience that numpy is not part of the 
Python stdlib.  However, it is easily installed from the PSF-maintained 
repository (python -m pip install numpy), and is included with most 
third-party distributions of Python.


The numerical extensions have been quasi-official in the sense that at 
least 3 language enhancements have been make for their use.  Nearly all 
real-world scientific, financial, and neural-network Python programs are 
build on top of numpy.  When a Python program spend 95% of the time in 
the optimized compiled C routines, it is nearly as fast as a 100% C 
solution.  The reason people use Python instead of C for the other 5% is 
to save human time.


Even when it come to executing the pure Python solutions, the CLBG rules 
apparently require the slowest execution possible. Execution would be at 
least 2 to 5 times faster if compilation to machine code were allowed, 
either before or during execution.  But the point of the game is to 
provide a 'level' playing field for competition between Python 
programmers, even if the cost is to cripple comparison with other 
language solution.


Terry Jan Reedy




--
Terry Jan Reedy

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


Re: Standard for dict-contants with duplicate keys?

2017-09-15 Thread Terry Reedy

On 9/15/2017 3:36 PM, Tim Chase wrote:

Looking through docs, I was unable to tease out whether there's a
prescribed behavior for the results of defining a dictionary with the
same keys multiple times

   d = {
  "a": 0,
  "a": 1,
  "a": 2,
   }

In my limited testing, it appears to always take the last one,
resulting in

   {"a": 2}

as if it iterated over the items, adding them to the dict, tromping
atop any previous matching keys in code-order.

Is this guaranteed by the language spec,


https://docs.python.org/3/reference/expressions.html#dictionary-displays
If a comma-separated sequence of key/datum pairs is given, they are 
evaluated from left to right to define the entries of the dictionary: 
each key object is used as a key into the dictionary to store the 
corresponding datum. This means that you can specify the same key 
multiple times in the key/datum list, and the final dictionary’s value 
for that key will be the last one given.


 or do I have a long weekend

of data-cleaning ahead of me?  (this comes from an unwitting coworker
creating such dicts that mung customer data, and I am trying to
determine the extent of the damage...whether it's a consistent issue
or is at the arbitrary whims of the parser)

Thanks,

-tkc







--
Terry Jan Reedy


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


Re: "tkinter"

2017-09-13 Thread Terry Reedy

On 9/13/2017 6:46 PM, Ben Finney wrote:

r...@zedat.fu-berlin.de (Stefan Ram) writes:


   I presume that "tkinter" is intended to be pronounced
   "logically":

T K inter (tee kay inter /ti keI In t%/)


This is how I've always pronounced it.

The toolkit in question is named “tk”, which I have only ever known to
be pronounced “tee kay”.

The rest of the word is an abbreviation of “interface”.

So, to me “Tkinter” is pronounced “tee kay inter”.


   . But it would be faster to pronounce it


Speed at the expense of clarity is a goal difficult to justify in
programming, and is even harder to justify in human speech. So, that
basis doesn't convince me of a useful pronunciation.


I program in tkinter more or less daily and now, at least,I think it 
'tee-kinter'. I believe I have said it that way also, though to a 
somewhat naive listener. Now I know that some would think it strange ;-).


I said the same thing back in 2002 on this list:
https://mail.python.org/pipermail/python-list/2002-December/139508.html
Mike C. Fletcher: mostly t k inter, sometimes t kinter, accent on t.
Dennis Lee Bieber: t kinter, slurred at tick inter.
then thread veered off onto Poles and consonants.

What do haphazerdly selected public Python speakers say?

t k inter Russell Keith-Magee, https://www.youtube.com/watch?v=yI7NYgP54sw

t k inter Jeff Armstrong https://www.youtube.com/watch?v=6isuF_bBiXs

t kinter Zach King https://www.youtube.com/watch?v=N6aEc6Qu2vM

t'kinter 'sentdex', https://www.youtube.com/watch?v=Ccct5D2AyNM

t k inter Bryson Tyrrell, https://www.youtube.com/watch?v=Wb1YFgHqUZ8

t k inter Derek Banas https://www.youtube.com/watch?v=-tbWoZSi3LU

I am perhaps in a minorit

--
Terry Jan Reedy


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


Re: "tkinter"

2017-09-13 Thread Terry Reedy

On 9/13/2017 3:09 PM, Grant Edwards wrote:


I tried to write a small (but non-trivial) Tcl app once[1], and would
happily vote to bury Tcl and then might even dance on its grave.
Tkinter, OTOH, is great for small, simple GUI apps -- with a few
caveats:

  1. You have to grit your teeth because you know there's a Tcl
 interpreter buried in the details.

  2. When you package up a trivial Tkinter application using something
 like py2exe, it balloons up to a ginormous size (way larger than
 the equivalent app written using wxPython).  I assume this is
 caused largely by 1.

  3. No matter how hard you try, Tkinter apps always look a bit
 foreign.  I've just given up trying to them to look like native
 apps: it doesn't work, and it annoys the mule.


Relative to past Windows, Win 10 looks a bit foreign.  On Windows, tk 
pretty much uses native widgets.  The ttk versions are a bit better on 
Windows, definitely better on linux, and apparently even more better on 
Mac.  Did you use them?



[1] After wasting several days fighting with TCL's quoting sematics, I
 gave up and wrote the app in Scheme (and was done in a couple
 hours).




--
Terry Jan Reedy

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


Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-13 Thread Terry Reedy

On 9/13/2017 2:44 AM, Paul Rubin wrote:


Are there actually Py3 codebases?


Let's think a bit.  There is the Python half of the Python3 codebase, 
perhaps 400K.  But we can discount that.


Then there are all the Py compatible modules on PyPI, which is to say, 
most of the major one.  How could not not notice those?


One of them is a little project call Django.  I believe that this is the 
one slated to be 3.x only in its 2.0 version.


I believe at least one linux distribution uses Py 3 for its system python.

A year ago, a producers of a Unicode-based app sold internationallly 
announce that their next version would be Py 3 only.  When 3.3 came out 
with the new Unicode implementation, they developed a 3.3 version of the 
app.  By 3.5, they realized that 3.3+ unicode made things much easier, 
wile maintaining the 2.7 version was painful by comparison.  They asked 
their (non-programmer) customers if they already used the 3.x version or 
could install 3.x to run the 3.x version.  95% said yes to one of these. 
 So they decided that the next version, early this year, would be 3.x only.


Have you ever hear of a little startup called 'Instagram'?  Earlier this 
year, they announce that they had about finished an 18 month process of 
switching most of their Python code to 3.x.  They described in fair 
detail how they did it.  Really impressive.


--
Terry Jan Reedy

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


Re: version of Python to install Windows 7 professional 64 bit, intel core i5

2017-09-11 Thread Terry Reedy

On 9/11/2017 10:49 PM, Zubair Shaikh wrote:

  What version of Python to install Windows 7 professional 64 bit, intel core i5


Whatever version you want.  If you have no idea, goto
https://www.python.org/downloads/release/python-362/
and click Windows-x86-64 executable installer.


--
Terry Jan Reedy

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


IEEE Spectrum ranks Python at top, along with C

2017-09-11 Thread Terry Reedy

https://spectrum.ieee.org/static/interactive-the-top-programming-languages-2017
--
Terry Jan Reedy

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


Re: Simple board game GUI framework

2017-09-11 Thread Terry Reedy

On 9/11/2017 12:56 PM, Paul Moore wrote:


I'm not looking at actually implementing chess. The idea was prompted
by a programming exercise my son was given, that was about programming
a series of classes modelling robots that know their position on a
grid, and when told to move, can do so according to certain rules. One
moves in a straight line till it hits the edge, one moves in a random
direction, some bounce when they hit an obstacle and some just stop,
etc. The idea is to demonstrate classes and inheritance to model
common behaviours and objects holding state that the behaviour acts
on.

The original exercise (which used Java) just had the program print out
the objects' co-ordinates at each step. I thought that visualising the
results by actually showing the objects moving would be better. (And a
quick discussion/demo with the guy I'm training showed me I'm right -
his reaction was "wow, that looks really impressive" :-))


Once you have a tkinter board, it is pretty easy to add an animated 
'sprite'.  The key is understanding root.after loops.  This example has 
multiple animated warp-around robots, moving at different speeds and 
different movement patterns.



import random
import tkinter as tk

def create_board(root):
board = {}
for r in range(8):
for c in range(8):
lbl = tk.Button(bg="white", text="   ", font=("Consolas", 12))
lbl.grid(row=r, column=c)
board[c,r] = lbl
return board

class Robot():
def __init__(self, color, x, y, dt, strategy):
self.color = color
self.x = x
self.y = y
self.dt = dt
self.strategy = strategy
board[x, y]['bg'] = color
root.after(dt, self.move)
def move(self):
dx, dy = self.strategy()
if dx or dy:
x, y = self.x, self.y
board[x, y]['bg'] = 'white'
x, y = (x+dx) % 8, (y+dy) % 8
board[x, y]['bg'] = self.color
self.x, self.y = x, y
root.after(self.dt, self.move)

def ranmove():
return random.choice((-1, 0, 1)), random.choice((-1, 0, 1))

def upperleft():
return -1, -1

def lowerright():
return 1, 1

root = tk.Tk()
board = create_board(root)
yellow = Robot('yellow', 1, 1, 50, ranmove)
red = Robot('red', 3, 5, 100, ranmove)
blue = Robot('blue', 5, 3, 150, ranmove)
green = Robot('green', 2, 7, 300, lowerright)
black= Robot('black', 7, 1, 350, upperleft)

#root.mainloop()  # Uncomment if not run from IDLE editor.
---

If one want a time resolution finer than 50 milliseconds, then one would 
need to active mainloop even in IDLE.


--
Terry Jan Reedy

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


Re: Simple board game GUI framework

2017-09-11 Thread Terry Reedy

On 9/11/2017 10:12 AM, Paul Moore wrote:


Thanks for the information. That's more or less the sort of thing I
was thinking of. In fact, from a bit more browsing, I found another
way of approaching the problem - rather than using pygame, it turns
out to be pretty easy to do this in tkinter.


I was going to suggest tkinter.


The following code is basically the core of what I need:

import tkinter as tk

def create_board(root):
 board = {}
 for r in range(8):
 for c in range(8):
 lbl = tk.Button(bg="white", text="   ", font=("Consolas", 12))
 lbl.grid(row=r, column=c)
 board[r,c] = lbl
 return board

root = tk.Tk()
board = create_board(root)
root.mainloop()


Mainloop is a blocking call, and while it is running, one can only 
interact with the data and gui in ways that one has already programmed. 
If you run the above with python -i, or equivalently, from an IDLE 
editor, you will not see a >>> prompt until you close the tk windows, at 
which point there is nothing left to interact with.



That creates an 8x8 grid of white buttons. With this, I can make a
button red simply by doing

board[3,2]["bg"] = "red"


However, if you run the code above from an IDLE editor, you can omit or 
comment out the mainloop call and still see the board, because IDLE's 
run code calls tk's update in a non-blocking manner about 20 times a 
second.  Without mainloop running, you immediately get a >>> prompt and 
can interact with the gui in a live exploratory fashion.  You can enter 
statements like the color assignment above, and the background updates 
will make them quickly take effect.


(I just opened https://bugs.python.org/issue31421 to document this.)


That's really all I need. With that I can place objects on the grid by
asking them for their colour and x/y co-ordinates. Add a bit of driver
logic, and I have a display system. We can then spend the time working
on how we add business logic to the classes (movement, collision
detection, etc...)

I really need to spend some time looking into tkinter. I very rarely
think of it when developing code, and yet whenever I do it's amazingly
easy to put together a solution quickly and easily.


--
Terry Jan Reedy

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


Re: array.array()'s memory shared with multiprocessing.Process()

2017-09-10 Thread Terry Reedy

On 9/10/2017 5:05 PM, iurly wrote:

Il giorno domenica 10 settembre 2017 18:53:33 UTC+2, MRAB ha scritto:



I've had a quick look at the source code.

When an object is put into the queue, it's actually put into an internal
buffer (a deque), and then the method returns.

An internal thread works through the buffer and pickles the objects.

Therefore, just because the method has returned, it doesn't mean that
it's now safe to modify the object.


I see. So that explains everything. However, I wonder if that's the intended 
behavior and/or that should be documented somehow.


We are still improving the docs.  Reread the docs and if you think 
something is needed, open an issue, preferably the the new wording you 
would like.


--
Terry Jan Reedy

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


Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-09 Thread Terry Reedy

On 9/9/2017 6:31 AM, Pavol Lisy wrote:

Interesting reading:
https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1


So much for Python 3 having killed python ;-)

--
Terry Jan Reedy

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


Re: Using Python 2

2017-09-08 Thread Terry Reedy

On 9/8/2017 12:27 PM, Steve D'Aprano wrote:

On Sat, 9 Sep 2017 12:23 am, Leam Hall wrote:



If Python 3 is not a total re-write then why break
compatibility?


To avoid building up excess cruft in the language.

To fix design mistakes which cannot be fixed without a backwards-incompatible
change.


One of the semi-myths about 3.0 is that is was somehow unique in 
breaking backward compatibility.  Python has always (for last 2 decades, 
anyway) has a procedure of deprecation and removal of old stuff.  What 
happened is that about 2.4, or whenever planning for 3.0 became serious, 
removals were mostly delayed until 3.0.  For instance, the original 
proposal for changing 1/2 from being 0 to being .5 proposed doing it in 
2.5.  Instead it was delayed to 3.0.  Without the prospect of 3.0, it 
would have happened sooner.


One change during 2.x that was not delayed was the removal of string 
exceptions.


So far during 3.x, at least a few modules have been deprecated and 
scheduled to be removed.  But when support for 2.7 was extended another 
5 years, we decided to delay such removals until after 2.7 support ends, 
in order to ease porting.


--
Terry Jan Reedy

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


Re: Using Python 2

2017-09-08 Thread Terry Reedy

On 9/8/2017 6:12 AM, Leam Hall wrote:


I've read comments about Python 3 moving from the Zen of Python.


Comments about Python 3 range from factual to opinionated to fake.


I'm a "plain and simple" person myself.


Many of the changes in Python3 were simplifications -- removing a 
semi-deprecated 'old way' in favor of a new way that was already in 
Python 2 and widely used.  A major example was dropping old-style 
classes.  This had little impact because by 2.6, people were mostly 
using new-style classes or were mostly using old-style classes in a way 
compatible with new-style classes.



Complexity to support what CompSci folks want,


I was part of the Python 3 design discussions.  I don't remember ever 
hearing anything like "we should do it this more complex way because 
that is what CompSci folks want".


which was used to describe some of the Python 3 changes, 


I presume by people trying to persuade you to avoid Python 3. That does 
not make it true.  This claim is nonsensical in that 3.0 introduced very 
little that was new.  Unicode was added in 2.0, a decade before.


--
Terry Jan Reedy

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


Re: No importlib in Python 3 64 bit ?

2017-09-06 Thread Terry Reedy

On 9/6/2017 12:30 PM, Chris Angelico wrote:

On Thu, Sep 7, 2017 at 2:17 AM, MRAB  wrote:

On 2017-09-06 14:00, Chris Angelico wrote:



I'm not 100% sure, but I think that having two different versions of
CPython X.Y isn't supported on Windows.


I have both 64-bit and 32-bit Python 3.6 installed on Windows 10, as well as
older versions. They all work without a problem.


Ah, that's good to know, thanks. (I knew it was fine to have 3.6 and
3.5 installed at once, just the question of two 3.6es.)


The py launcher lets you choose
py -3.6
py -3.6-32

--
Terry Jan Reedy

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


Re: Python console's workspace path

2017-09-05 Thread Terry Reedy

On 9/5/2017 10:26 AM, Andrej Viktorovich wrote:

Hello,

I run Python 3.6 console under windows 10. Where is default console directory?


It depends on how and where you start it.


I run script:

tf = open ("aaa.txt", "w")
tf.write(" %s" % 123)
tf.close()


Where file aaa.txt will be created?


I have compiled 3.7 as F:\\dev\\3x\\PCbuild\\win32\\python_d.exe.  I 
suspect I originally started it from Explorer, so it started in
'F:\\dev\\3x\\PCbuild\\win32'.  I then pinned it to the task bar.  Left 
clicking the icon restarts it in the same directory.  If I right click 
the icon and then right click 'Python', I see Properties, which shows 
"Start in" and a box with the path above.  The Start in value can be edited.


If you start python with a console command, instead of an icon, the 
initial directory is instead the current directory when you issue the 
command.



Can I change default work space location? How?


By editing the icon (Rustom Mody), changing the directory before issuing 
a startup command, or with os.chdir (MRAB).


--
Terry Jan Reedy

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


Re: Run Windows commands from Python console

2017-09-04 Thread Terry Reedy

On 9/4/2017 5:50 PM, Rick Johnson wrote:

Terry Reedy wrote:

[...]


In IDLE, trackbacks *do* include source lines.

  >>> def f():
return 1/0

  >>> f()
Traceback (most recent call last):
File "", line 1, in 
  f()
File "", line 2, in f
  return 1/0
ZeroDivisionError: division by zero


One of the few things that IDLE did better than Python,
which is much more informative than:


Traceback (most recent call last):
File "", line 1, in 
File "", line 2, in f
ZeroDivisionError: division by zero


I think newbies would find IDLE's explicit messaging to be
more intuitive compared to standard Python. Counting lines
is never any fun, and even if you're only dealing with a
few, it's both annoying and inefficient.

When i'm away from an editor (like IDLE, for instance), one
of the features i miss most is the ability to right click
the line of the exception message (you know, the one that
includes the offending line number and offending script
filepath), and choose "open script for editing" from a
contextual menu, which will open the script and
automatically scroll down to the offending line for me.
Ahhh, efficient bliss.


'Goto file/line' also works on the grep/find-in-files Output Window.  I 
must have used this about 30 times in 8 outputs tonight try to track 
down bugs in a proposed IDLE patch.  There were no tracebacks, just 
thinkgs not working.


I plan to make it a bit faster by moving the option to the top of the 
menu.  I have thought about making it even faster by not having to use 
the context menu -- just click, or maybe double click, and the jump 
happens.  What do you think?


--
Terry Jan Reedy

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


Re: Run Windows commands from Python console

2017-09-03 Thread Terry Reedy

On 9/3/2017 11:17 AM, eryk sun wrote:

On Sun, Sep 3, 2017 at 7:56 AM,   wrote:



What means line below:

File "", line 1

I don't have any  file.


Indeed, on Windows you cannot create a file named "". Python
uses this fake name for the code object it compiles when reading from
stdin (i.e. the file stream opened for console input).

It's not exactly smart about this, either, since whenever an exception
is raised in the REPL it will try to open this fake file multiple
times, including trying every entry in sys.path. For example, in a
typical Python 3.6 all-users installation, it will try opening the
following file paths:

 
 
 C:\Program Files\Python36\python36.zip\
 C:\Program Files\Python36\python36.zip\
 C:\Program Files\Python36\DLLs\
 C:\Program Files\Python36\lib\
 C:\Program Files\Python36\
 C:\Program Files\Python36\lib\site-packages\
 ...

Of course, all of these attempts to open "" necessarily fail on
Windows.


The result, after doing all the above, is tracebacks like

>>> def f():
... return 1/0
...
>>> f()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in f
ZeroDivisionError: division by zero

with source lines missing.  Note that 'line 1' is misleading as the 
'f()' call is on line 4.  It is the first line of the 2nd statement.


In IDLE, trackbacks *do* include source lines.

>>> def f():
return 1/0

>>> f()
Traceback (most recent call last):
  File "", line 1, in 
f()
  File "", line 2, in f
return 1/0
ZeroDivisionError: division by zero

Each statement is numbered, and treated as a file, so that line 
numbering starts at 1 for each statement.


The secret to doing this is that traceback printing looks in 
linecache.cache *before* trying to open a file, as described above. 
When the file is read, it is added to the cache.  IDLE stuffs the lines 
for each statement into the cache and replaces linecache.checkcache with 
a wrapper that prevents them from being deleted.



On Unix, however, this can actually succeed, which is kind of
funny:

 >>> open('', 'w').write('What the !@#$%^&*?')
 18

 >>> dit
 Traceback (most recent call last):
   File "", line 1, in 
 What the !@#$%^&*?
 NameError: name 'dit' is not defined


Won't happen with 


--
Terry Jan Reedy

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


Re: Delay a computation in another thread

2017-09-02 Thread Terry Reedy

On 9/2/2017 6:53 AM, Steve D'Aprano wrote:

I want to delay a computation and then print it, in the REPL (interactive
interpreter). I have something like this:


import time
from threading import Timer

def do_work():
 x = 2 + 2
 print("It is", time.asctime(), "and 2+2 is", x)

def schedule_work():
 Timer(60, do_work, ()).start()  # schedule it in one minute


Is this the right way to do it?

If I do that, it works, mostly. For example:

py> schedule_work()
py> dir(45)  # do other stuff, in the interactive interpreter, for one minute
['bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 
'real', 'to_bytes']
py>
py> It is Sat Sep  2 20:37:58 2017 and 2+2 is 4


The problem is that after the message is printed, the REPL's prompt is
disrupted. This is especially annoying when I'm in the middle of typing a line.
This is just a cosmetic flaw, but it would be nice if I could tell Python to
redraw the current line. For example, using _ to indicate the position of the
cursor, this is what happens now:

py> class K:
... attribute =It is Sat Sep  2 20:48:39 2017 and 2+2 is 4
_


This is what I'd prefer:

py> class K:
... attribute =It is Sat Sep  2 20:48:39 2017 and 2+2 is 4
... attribute =_


I loaded your code into IDLE editor, hit F5, then interactively in Shell:

>>> schedule_work()
>>> It is Sat Sep  2 19:13:44 2017 and 2+2 is 4
"thei is kjlkj jjdkj f jkjkd j"
'thei is kjlkj jjdkj f jkjkd j'

With a 10sec delay, I was near the end of typing the statement after the 
prompt.  When the print came, the partial entry was pushed down to a new 
line.  I think that this is even better than what you asked for.  I 
closed the string and hit return and got the normal echo.


If one is entering a multiple line statement, the whole statement is 
pushed down.


>>> go()
>>> It is Sat Sep  2 19:42:10 2017 and 2+2 is 4
a = (
12,

  IDLE usually keeps input blocks, output blocks, and error blocks 
separated, on separate lines.  Response to input(prompt) is an 
exception.  There is also an ocassional bug that I cannot reproduce yet.

I consider not moving the prompt down a minor bug.
bugs.python.org/issue31331


The other problem is that if I exit the REPL while a Timer is still active, it
freezes until the time has run before exiting. I know you can't kill a thread
from the main thread, but is there a way for the Timer to see that the
interpreter is shutting down and shut itself down?


If you kill a process from another process, it should die.  It does with 
your code run from IDLE.


On Windows, the background user-code execution process start at 11.x Mb. 
 In Win 10 task manager, background processes are listed separately 
from app windows.  I restored 60 sec delay and added s = 'a'*1000 
near the top of your code to differentiate a process with your code from 
the default user process.


=== RESTART: F:\Python\mypy\tem.py 
===

>>> schedule_work()
>>>   # Hit Restart Shell
=== RESTART: Shell 
===

>>>

Restart Shell means kill the current user process and start a new one. 
Watching TackManager while doing so, the 20+Mb process is immediately 
replaced by a default 10+Mb process.  Closing Shell justs kills the 
20+Mb process.


--
Terry Jan Reedy

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


Re: Cannot find IDLE

2017-08-31 Thread Terry Reedy

On 8/31/2017 8:46 AM, Yusuf Mohammad wrote:

You must provide much more information to get any help.
Are you installing on a network or an individual machine?
What version of Windows is running, including 32 versus 64 bit?
Do you have admin access to the machine?
What *exact* python installer are you using, including 32 vs 64 bit?
IE, what is the file name of the installer?
Where did you get the installation file?
Note: Python 3.6+ requires Windows Vista or later.  No XP.


Wont work unfortunately


Are you guessing or did something 'not work'?
If the latter, what exactly did you do and what does 'not work' mean?


31. aug. 2017 13:39 skrev "Bear Light" :




How do i install Python in a specific folder with the custom option and be

able to use IDLE?

After you choose customize install, pick the ”Install for all users”
option then you can change the install location.


This works for me and for numerous others.


For some reason when Python is installing it stores in Appdata/Local


The reason is that this is the *standard* Windows location for programs 
installed for a single user.



folder. This is quite weird and when i'm trying to install Python with the
custom option to change the location (to Program files (x86)),


32 bit apps go here, 64 bit apps go in /Program files.  If you install 
for all users, the default location is one of these.



IDLE is not to be found.


IDLE is a collection of Python modules.  Until you can run Python, you 
cannot run IDLE.


I believe the installer has an option to install tcl/tk, tkinter, and 
IDLE -- not.  I don't know what the standard install does.  If you do a 
custom install, make sure the box is checked.


--
Terry Jan Reedy


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


Re: If you are running 32-bit 3.6 on Windows, please test this

2017-08-30 Thread Terry Reedy

On 8/30/2017 1:35 PM, Terry Reedy wrote:
https://stackoverflow.com/questions/45965545/math-sqrt-domain-error-when-square-rooting-a-positive-number 



reports the following:
-
Microsoft Windows [Version 10.0.16251.1002]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\Adam>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit 
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
 >>> import math
 >>> math.sqrt(1.3)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: math domain error
 >>>

I upgraded from version 3.6.1 to 3.6.2 to try to resolve the issue and 
restarted my computer but it is still occurring. Some numbers are 
working (1.2, 1.4) and some others are also not working (1.128).



Neither installed 64 bit 3.6.2 nor my repository 3.6 32-bit debug build 
reproduce this.  If anyone has the python.org 32bit 3.6.1/2 releases 
installed on Windows, please test and report.


Three people have reported that math.sqrt(1.3) works in 32 bit Python on 
64-bit Windows and no one otherwise.  I reported back on SO that the 
problem is likely local.  Thanks for the responses.


--
Terry Jan Reedy


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


If you are running 32-bit 3.6 on Windows, please test this

2017-08-30 Thread Terry Reedy

https://stackoverflow.com/questions/45965545/math-sqrt-domain-error-when-square-rooting-a-positive-number

reports the following:
-
Microsoft Windows [Version 10.0.16251.1002]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\Adam>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit 
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.sqrt(1.3)
Traceback (most recent call last):
 File "", line 1, in 
ValueError: math domain error
>>>

I upgraded from version 3.6.1 to 3.6.2 to try to resolve the issue and 
restarted my computer but it is still occurring. Some numbers are 
working (1.2, 1.4) and some others are also not working (1.128).



Neither installed 64 bit 3.6.2 nor my repository 3.6 32-bit debug build 
reproduce this.  If anyone has the python.org 32bit 3.6.1/2 releases 
installed on Windows, please test and report.


--
Terry Jan Reedy

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


Re: Latency for API call to a Python Function

2017-08-29 Thread Terry Reedy

On 8/29/2017 11:22 AM, shazianu...@gmail.com wrote:


def getvideos(self, listitem):
channelId = ""
returnVideos,dictData = {},{}
mode = 0
channelId = listitem[KEY_CHANNELID]
if KEY_CHANNELMODE in listitem :
mode = int(listitem[KEY_CHANNELMODE])
filteredVideos = []

...

Please make code readable by indenting properly, *with spaces*. 
Guessing at what you meant:


def getvideos(self, listitem):
channelId = ""
returnVideos,dictData = {},{}
mode = 0
channelId = listitem[KEY_CHANNELID]
if KEY_CHANNELMODE in listitem :
mode = int(listitem[KEY_CHANNELMODE])
filteredVideos = [].
...

If you posted with tab indents, they disappeared, as is common with 
news/mail.


--
Terry Jan Reedy

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


Re: tkinter keypress events are a mess for numpad keys

2017-08-28 Thread Terry Reedy

On 8/28/2017 7:20 PM, Irmen de Jong wrote:

Hi,

Using tkinter in python3, I was trying to intercept individual keypresses (and 
releases)
of keys on the numeric keypad. I want to use this as a simple joystick 
simulation.
While you can bind the  event, actually doing something sensible with 
it in a
cross platform way seems utterly impossible.

The distinguishing attribute of the event object is different depending on what 
OS
you're using (keysym, keycode, keysym_num) and on Windows registering some keys 
doesn't
even seem to work (or they're confused with the same keys on the normal 
keyboard area).
The keysym names/values in the documentation are not correct either
(I'm mainly looking at 
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/key-names.html)


*The* documentation (for 8.6) is the tcl.tk/man doc set:
https://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm
For the level of detail you are looking at, they are essential.

The nmt docs for 8.5 are neither complete (intentionally not) nor always 
correct nor always up to date.  The tk docs may also have errors, just 
as our do, but I presume one can file a report somewhere and possibly 
get a fix.



My original question with the details on stackoverflow:
https://stackoverflow.com/questions/45869902/better-way-to-deal-with-tks-keyboard-events-mess-for-numpad-keys-in-pythontkin

Unfortunately there hasn't been a useful response or answer.

A gist with a small example program is here:
https://gist.github.com/irmen/2c9d6bb0afb16b464805410c108a2885

Does anyone here have a clue perhaps?
Or have any idea why this is so messy?



--
Terry Jan Reedy

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


Re: Proposed new syntax

2017-08-21 Thread Terry Reedy

On 8/20/2017 12:28 AM, Rustom Mody wrote:


Lives today in python in the fact that the russel-set gives a straightforward
syntax error and nothing more grandly profound

R = {x if x not in x}



R = {x for x not in x}


Try the actual Python syntax set builder expression and you get 
executable code:


sos = 
R = {x for x in sos if x not in x}

In Python, the expression creates a new set that is not a member of sos, 
so the x in 'x not in x' is never S, and there is no problem, as far as 
S is concerned, in evaluating 'x not in x'.


But, is R is equal to some set z in sos?  If yes, then we could identify 
R and z and say that R is in sos.  But the answer is No. Russell's 
'paradox' comes from separately insisting that the answer is also Yes.


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


Re: Ask for help about a tkinter problem

2017-08-21 Thread Terry Reedy

> On 2017-08-21 01:28, jf...@ms4.hinet.net wrote:
>> Peter Otten at 2017/8/20 UTC+8 PM 5:52:24 wrote:
> [snip]
>
>>> That is just a peculiarity of TCL; a "-" is added to the option by the
>>> Python wrapper before passing it along
>>
>> This extra "-" confuses people when showing up in the Traceback info.
>> Can't figure out why the author want to do this.
>>
> To clarify what Peter said, tkinter is a GUI library written in the Tcl
> programming language.
The Tcl GUI framework is tk, not tkinter.
> The 'tkinter' module in Python's standard library is just a wrapper
> around that library.

tkinter abbreviates tk interface.  In particular, it adds a Python 
class-based interface to tcl and tk functions and structures.


> The "-" is added because the Tcl language requires it.

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


Re: The tragic tale of the deadlocking Python queue

2017-08-17 Thread Terry Reedy

On 8/17/2017 4:31 AM, breamore...@gmail.com wrote:

I found it interesting, possibly some of you may feel the same way so here it 
is https://codewithoutrules.com/2017/08/16/concurrency-python/


The intro ends with "Weep when you read the response of Python’s 
maintainers!", referring to https://bugs.python.org/issue14976.  The 
issue was originally about signals, threads, and Queue's, which Itamar 
admits "don't interact well".  The solution to that was to document 
"Don't do this.".


Followup: When Itamar posted, yesterday, a clear demonstration that 
there is a bug in other, more reasonable code, the response has been to 
reopen the issue, with a plan to rewrite in C using (somewhat 
ironically) the (somewhat hated) GIL as a lock.


--
Terry Jan Reedy


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


Re: Cross-language comparison: function map and similar

2017-08-16 Thread Terry Reedy

On 8/16/2017 10:53 AM, Steve D'Aprano wrote:

Over in another thread, we've been talking about comprehensions and their
similarities and differences from the functional map() operation.
Reminder:
map(chr, [65, 66, 67, 68])
will return ['A', 'B', 'C'].


The comprehension 'while' proposal is for future Python 3.  Asking your 
while question the restricted context of Python 2 encouraged the 
restricted list-based or concrete-collection-based thinking about 
comprehensions that you got in some of the answers.  The above snipper 
is only true for Python-2 . In Python 3,


>>> oracle = map(chr, [65, 66, 67, 68])
>>> oracle

>>> next(oracle)
'A'
>>> next(oracle)
'B'
>>> next(oracle)
'C'

When oracle is asked for the next value, it asks base_oracle = 
iter(iterable) for a value.  If base_oracle gives one, oracle gives 
func(value).  If base_iterable raises StopIteration, so does oracle. 
This process is inherently sequential.  It remains so with multiple 
input iterables.


>>> next(oracle)
'D'
>>> next(oracle)
Traceback (most recent call last):
  File "", line 1, in 
next(oracle)
StopIteration

Even in pre-2.2 Python, map's input was not restricted to being a list, 
but could be any 'sequence'.  From 2.0 doc: "The list arguments may be 
*any kind of sequence*" [emphasis added].


I am rather sure that in this context, a 'sequence' was merely something 
that could be indexed and that a pre-defined length was not required. 
This means that map could use the old iterator protocol.  So 'sequence' 
meant 'iterator' in current terms.  The old spelling of 'next(iterator)' 
was 'iterator[i]' where i is 0 for the first request for an object and 
incremented thereafter. The 'sequence' was free to ignore i when 
generating the return object.  It could also use external input.



My questions for those who know languages apart from Python:

Are there language implementations which evaluate the result of map() (or its
equivalent) in some order other than the obvious left-to-right first-to-last
sequential order?


If map's collection input is unbounded, as with Python, a right-to-left 
or completely parallel order is not possible.  If the input oracle 
creates objects on demand, as Python allows, then doing anything other 
that applying func as objects are made available requires internal 
storage.  Asking an oracle for millions of objects when only the first 
few are needed, is foolish.  Storing millions or billions of objects all 
at once when there are only needed one at a time is also foolish.  Which 
is why map and filter were changed in Python 3.


--
Terry Jan Reedy

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


Re: Proposed new syntax

2017-08-14 Thread Terry Reedy

On 8/14/2017 5:59 AM, Ben Finney wrote:


At what point will you accept the feedback: That the comprehension
syntax *does not* necessarily connote a procedural loop, but instead can
quite reasonably be interpreted as its designer intended, a single
conceptual operation.


In a world where functions have 'side-effects', which is to say, 
implicit inputs and outputs, procedural order is necessary for 
predictable outcomes.  The 'single conception operation' is ambiguious.


Suppose stdin contains "a\nb\nc\nd\ne\nf\ng\n".
What is the meaning of
[input(f"response{i}") for i in range(6)]?
In Python, the predictable result is
['a', 'b', 'c', 'd', 'e', 'f']
It would not be with some of Rustom Mody's 'equivalents'.
Or let L = .
This implementation of list reversal: [L.pop() for i in range(len(L))]

Do not functional languages define comprehensions in terms of recursion, 
equivalent to for loops?


--
Terry Jan Reedy

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


Re: Redirecting input of IDLE window

2017-08-14 Thread Terry Reedy

On 8/14/2017 6:19 AM, Joel Goldstick wrote:


do you know about the utility called pydoc?  Type it at a command line to
learn more.


This only works if a wrapper has been installed in a directory on the 
system path.  'python -m pydoc' should always work.



 It displays information like help does in a python
environment, but you can also redirect it to a file


The other way around: help uses pydoc, but help does not expose all of 
pydoc's options.



--
Terry Jan Reedy

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


<    2   3   4   5   6   7   8   9   10   11   >