Re: Which curses version should I use under Windows

2019-06-18 Thread MRAB

On 2019-06-18 04:57, jf...@ms4.hinet.net wrote:

Terry Reedy於 2019年6月18日星期二 UTC+8上午11時03分00秒寫道:

On 6/17/2019 10:54 PM, jf...@ms4.hinet.net wrote:

> c:\Works\Python34>pip install windows-curses
> DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the 
last one supporting it. Please upgrade your Python as Python 3.4 w
> on't be maintained after March 2019 (cf PEP 429).
> Collecting windows-curses
>ERROR: Could not find a version that satisfies the requirement 
windows-curses (from versions: none)
> ERROR: No matching distribution found for windows-curses
> 
> What to do?


What is says, use a newer python.

It is quite possible that there is not 3.4 package for windows-curses. 
Look it up on pypi.org.


--
Terry Jan Reedy


You are right, there is no package for Python 3.4.

In the project description:

'''Adds support for the standard Python curses module on Windows. Based on 
https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses. Uses the PDCurses curses 
implementation.'''

Do I have to install the curses package mentioned there before install/use 
windows-curses? How to use this windows-curses? still "import curses"? I am so 
confused!

1. Install a more recent version of Python. Python 3.7 is the current 
version. (Python 3.4 is no longer supported.)


2. Install windows-curses using pip for that version of Python.

That's it!
--
https://mail.python.org/mailman/listinfo/python-list


Re: Which curses version should I use under Windows

2019-06-18 Thread jfong
MRAB於 2019年6月18日星期二 UTC+8下午6時12分50秒寫道:
> On 2019-06-18 04:57, jf...@ms4.hinet.net wrote:
> > Terry Reedy於 2019年6月18日星期二 UTC+8上午11時03分00秒寫道:
> >> On 6/17/2019 10:54 PM, jf...@ms4.hinet.net wrote:
> >> 
> >> > c:\Works\Python34>pip install windows-curses
> >> > DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be 
> >> > the last one supporting it. Please upgrade your Python as Python 3.4 w
> >> > on't be maintained after March 2019 (cf PEP 429).
> >> > Collecting windows-curses
> >> >ERROR: Could not find a version that satisfies the requirement 
> >> > windows-curses (from versions: none)
> >> > ERROR: No matching distribution found for windows-curses
> >> > 
> >> > What to do?
> >> 
> >> What is says, use a newer python.
> >> 
> >> It is quite possible that there is not 3.4 package for windows-curses. 
> >> Look it up on pypi.org.
> >> 
> >> -- 
> >> Terry Jan Reedy
> > 
> > You are right, there is no package for Python 3.4.
> > 
> > In the project description:
> > 
> > '''Adds support for the standard Python curses module on Windows. Based on 
> > https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses. Uses the PDCurses 
> > curses implementation.'''
> > 
> > Do I have to install the curses package mentioned there before install/use 
> > windows-curses? How to use this windows-curses? still "import curses"? I am 
> > so confused!
> > 
> 1. Install a more recent version of Python. Python 3.7 is the current 
> version. (Python 3.4 is no longer supported.)
> 
> 2. Install windows-curses using pip for that version of Python.
> 
> That's it!

It works, thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


python numpy histogram

2019-06-18 Thread Machiel Kolstein

Hi, 

I get the following error: 

ERROR: 
Traceback (most recent call last):
  File "exponential_distr.py", line 32, in 
numpy.histogram(data_array, bins=100, range=2)
  File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line 499, 
in histogram
mn, mx = [mi + 0.0 for mi in range]
TypeError: 'int' object is not iterable

with the code shown below. 
I guess I am using "numpy.histogram" below. Also, is there a way to fill the 
histogram on an event by event base without using the clumsy way of 
constructing an array as I do below?
And - final question - how can I most easily plot the histogram without having 
to define - again - the bins etc...?

CODE: 

import numpy
import numpy.random

rate = float(1e5)
average_dt = 1.0/rate
print "average dt: ", average_dt

calc_average = 0.0
total_num=1000.0
isFirst = True
for index in range(0, int(total_num)): 
time = numpy.random.exponential(average_dt)
#print "time: ", time, " = ", time*1e9, " ns" 
calc_average = calc_average + time

# Idiot python way of constructing an array (God, I hate python...)
if (isFirst == True): 
data_array = time
isFirst = False
else:
data_array = numpy.hstack((data_array, time))

calc_average = calc_average/total_num
print "calculated average: ", calc_average, " = ", calc_average*1e9, " ns"
print "data_array: ", data_array

numpy.histogram(data_array, bins=100, range=2)
#   import matplotlib.pyplot as plt
#   plt.hist(data_array, bins=100, range=2)
#   plt.show()




-- 
Avís -
Aviso - Legal Notice - (LOPD) - http://legal.ifae.es 

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


Re: python numpy histogram

2019-06-18 Thread Peter Otten
Machiel Kolstein wrote:

> 
> Hi,
> 
> I get the following error:
> 
> ERROR:
> Traceback (most recent call last):
>   File "exponential_distr.py", line 32, in 
> numpy.histogram(data_array, bins=100, range=2)
>   File "/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py", line
>   499, in histogram
> mn, mx = [mi + 0.0 for mi in range]
> TypeError: 'int' object is not iterable
> 
> with the code shown below.
> I guess I am using "numpy.histogram" below. Also, is there a way to fill
> the histogram on an event by event base without using the clumsy way of
> constructing an array as I do below? >
 
> CODE:
> 
> import numpy
> import numpy.random
> 
> rate = float(1e5)
> average_dt = 1.0/rate
> print "average dt: ", average_dt
> 
> calc_average = 0.0
> total_num=1000.0
> isFirst = True
> for index in range(0, int(total_num)):
> time = numpy.random.exponential(average_dt)
> #print "time: ", time, " = ", time*1e9, " ns"
> calc_average = calc_average + time
> 
> # Idiot python way of constructing an array (God, I hate python...)

Numpy is not python, its learning curve is a bit steeper.

> if (isFirst == True):
> data_array = time
> isFirst = False
> else:
> data_array = numpy.hstack((data_array, time))

With both, it helps if you read the documentation, or at least the 
docstring:

>>> import numpy
>>> help(numpy.random.exponential)
Help on built-in function exponential:

exponential(...)
exponential(scale=1.0, size=None)

Exponential distribution.

...
Parameters
--
...
size : tuple of ints
Number of samples to draw.  The output is shaped
according to `size`.

So:

data_array = numpy.random.exponential(average_dt, total_num)
calc_average = data_array.mean()

(If you follow the docstring you'd write (total_num,).)

> calc_average = calc_average/total_num
> print "calculated average: ", calc_average, " = ", calc_average*1e9, " ns"
> print "data_array: ", data_array
> 
> numpy.histogram(data_array, bins=100, range=2)

>>> help(numpy.histogram)
Help on function histogram in module numpy.lib.function_base:

histogram(a, bins=10, range=None, normed=False, weights=None, density=None)
Compute the histogram of a set of data.

Parameters
--
...
range : (float, float), optional
The lower and upper range of the bins.  If not provided, range
is simply ``(a.min(), a.max())``.  Values outside the range are
ignored.
...

> #import matplotlib.pyplot as plt
> #plt.hist(data_array, bins=100, range=2)
> #plt.show()

> And - final question - how can I most
> easily plot the histogram without having to define - again - the bins
> etc...?

Matplotlib is the way do go for plotting with Python. If matplotlib can do 
what you want you could omit numpy.histogram()...

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


tkinter: on_cancel() method

2019-06-18 Thread Rich Shepard

I have frames for data entry and modification. Each has two buttons: Save
and Cancel. Is there a standard tkinter on_cancel() method responding to a
user clicking on the Cancel button?

My web searches find suggestions for 'after' responses, but no specific code
to close the dialog box without saving any data. Using return and close()
generate errors.

TIA,

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


Re: python numpy histogram

2019-06-18 Thread Machiel Kolstein


Thank you for your fast reply. You're right, I completely missed the fact that 
range should be given with two numbers (which in retrospect should have been 
obvious). 
Best regards, 

Machiel

-- 
Avís -
Aviso - Legal Notice - (LOPD) - http://legal.ifae.es 

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


Re: Is there an archive of this list with permanent URLs to each message?

2019-06-18 Thread jkn
On Monday, June 17, 2019 at 10:28:44 AM UTC+1, Luciano Ramalho wrote:
> Hello! When I wrote Fluent Python a few years ago I provided my
> readers with hundreds of links to my sources, including several links
> to messages in the python-list archive.
> 
> Now as I prepare the 2nd edition I notice all my links to this list
> are broken. Apparently mailman rebuilds the archives and changes the
> ids of the messages.
> 
> Is there an archive of python-list that preserves each message with a
> permanent URL?
> 
> Thanks!
> 
> Luciano
> 
> PS. For the curious, here is an instance of the problem. The message
> currently at:
> 
> https://mail.python.org/pipermail/python-list/2009-February/525280.html
> 
> Used to be at this URL:
> 
> https://mail.python.org/pipermail/python-list/2009-February/538048.html
> 
> 
> 
> -- 
> Luciano Ramalho
> |  Author of Fluent Python (O'Reilly, 2015)
> | http://shop.oreilly.com/product/0636920032519.do
> |  Technical Principal at ThoughtWorks
> |  Twitter: @ramalhoorg

A second edition? Curses, just after I recently bought a copy of the first 
edition ;-o ...

(It's a very good book BTW - thanks!)

J^n
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter: on_cancel() method [RESOLVED]

2019-06-18 Thread Rich Shepard

On Tue, 18 Jun 2019, Rich Shepard wrote:


I have frames for data entry and modification. Each has two buttons: Save
and Cancel. Is there a standard tkinter on_cancel() method responding to a
user clicking on the Cancel button?


Found the solution: self.destroy()

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


Re: Is there an archive of this list with permanent URLs to each message?

2019-06-18 Thread Luciano Ramalho
On Tue, Jun 18, 2019 at 12:27 PM jkn  wrote:
> A second edition? Curses, just after I recently bought a copy of the first 
> edition ;-o ...
>
> (It's a very good book BTW - thanks!)

Thanks, J!

The 2nd edition won't be available until Q1 2020 at the earliest.

Dave Beazley once told me that Fluent Python was very forward looking,
so the 1st edition is still very relevant IMHO.

The examples that broke are the ones using asyncio, which was
provisional at the time and had significant API changes (aiohttp, used
in several examples, had even more breaking changes).

Besides the asyncio breakage, there are a few better ways of doing
things. And I will cover typing.

Cheers,

Luciano


-- 
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
| http://shop.oreilly.com/product/0636920032519.do
|  Technical Principal at ThoughtWorks
|  Twitter: @ramalhoorg
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2019: Inviting European Python Conference Organizers

2019-06-18 Thread M.-A. Lemburg
As you may know, the EuroPython Society (EPS) has extended it’s
mission to not only run the EuroPython conference, but also provide
help for the Python community in Europe in general.

   * https://www.europython-society.org/ *

As part of this, we would like to get to know, and help create closer
ties between organizers of other European Python events.


Organizers’ Lunch
-

We would like to invite representatives of all European Python
conference to EuroPython 2019 to join us for an organizers’
lunch. We’re planing the lunch for Thursday or Friday. Details will be
announced closer to the event.

Our aim is to get to know each other, exchange experience in
organizing events and to find out how we, as EPS, can most effectively
help other conferences going forward.


Free Tickets


To support and facilitate this, we are giving out one free conference
ticket per conference team, so that each team can send a
representative to the organizers’ lunch.

If your team wants to send someone to join, please write to
bo...@europython.eu, mentioning the conference you’re organizing and
some background on your team.


Dates and Venues


EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at
the Congress Center Basel (CCB) for the main conference days (Wed-Fri)
and the FHNW Muttenz for the workshops/trainings/sprints days
(Mon-Tue, Sat-Sun).

Tickets can be purchased on our registration page:

https://ep2019.europython.eu/registration/buy-tickets/

For more details, please have a look at our website and the FAQ:

https://ep2019.europython.eu/faq


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/185683241297/europython-2019-inviting-european-python

Tweet:

https://twitter.com/europython/status/1141044706979274752


Enjoy,
--
EuroPython 2019 Team
https://ep2019.europython.eu/
https://www.europython-society.org/

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


EuroPython 2019: Community Discounts

2019-06-18 Thread M.-A. Lemburg
The EuroPython Society (EPS) does not only run the EuroPython
conference, but also aims to provide help for the Python community in
Europe in general.

   * https://www.europython-society.org/ *


Let’s all meet at EuroPython


In addition to the Python Organizers Lunch (see previous post), which
focuses on conference organizers, we are also establishing a program
to support attendees of Python user groups and conferences in Europe.

We’d like to invite all of you to EuroPython 2019 this year. Of
course, we cannot give out free tickets to everyone, but we can at
least recognize your participation in the Python community by giving
out discounts for the conference.

  * https://ep2019.europython.eu/ *


Discounts for EuroPython Tickets


If you are running a Python event (conference or user group) in
Europe, please reach out to bo...@europython.eu to request a coupon
code for your group, which you can then pass on to your group members
or attendees.

If you are not running a user group or conference, but a regular
attendee of one, please contact your organizers to have them submit a
request. We can only distribute codes at the user group and conference
organizer level.

The coupon codes are valid for conference tickets bought starting
today and will give you a 10% discount on the ticket price (both
regular and late bird prices). The codes are setup for user group
sizes of between 30-50 members, but we are also extending this to
organizers and attendees of larger conferences. If you need a code
valid for larger groups, please mention this in your email.


Dates and Venues


EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at
the Congress Center Basel (CCB) for the main conference days (Wed-Fri)
and the FHNW Muttenz for the workshops/trainings/sprints days
(Mon-Tue, Sat-Sun).

Tickets can be purchased on our registration page:

https://ep2019.europython.eu/registration/buy-tickets/

For more details, please have a look at our website and the FAQ:

https://ep2019.europython.eu/faq


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/185683252247/europython-2019-community-discounts

Tweet:

https://twitter.com/europython/status/1141044869470871553


Enjoy,
--
EuroPython 2019 Team
https://ep2019.europython.eu/
https://www.europython-society.org/

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


Understand workflow about reading and writing files in Python

2019-06-18 Thread Windson Yang
I'm trying to understand the workflow of how Python read/writes data with
buffer. I will be appreciated if someone can review it.

### Read n data
1. If the data already in the buffer, return data
2. If the data not in the buffer:
1. copy all the current data from the buffer
2. create a new buffer object, fill the new buffer with raw read which
read data from disk.
3. concat the data in the old buffer and new buffer.
4. return the data

### Write n data
1. If data small enough to fill into the buffer, write data to the buffer
2. If data can't fill into the buffer
1. flush the data in the buffer
1. If succeed:
1. create a new buffer object.
2. fill the new buffer with data return from raw write
2. If failed:
1. Shifting the buffer to make room for writing data to the
buffer
2. Buffer as much writing data as possible (may raise
BlockingIOError)
2. return the data
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 3.7.4rc1 and 3.6.9rc1 are now available

2019-06-18 Thread Ned Deily
Python 3.7.4rc1 and 3.6.9rc1 are now available. 3.7.4rc1 is the release
preview of the next maintenance release of Python 3.7, the latest feature
release of Python. 3.6.9rc1 is the release preview of the first
security-fix release of Python 3.6. Assuming no critical problems are
found prior to 2019-06-28, no code changes are planned between these
release candidates and the final releases. These release candidates are
intended to give you the opportunity to test the new security and bug
fixes in 3.7.4 and security fixes in 3.6.9. We strongly encourage you to
test your projects and report issues found to bugs.python.org as soon as
possible. Please keep in mind that these are preview releases and, thus,
their use is not recommended for production environments.

You can find the release files, a link to their changelogs, and more
information here:
https://www.python.org/downloads/release/python-374rc1/
https://www.python.org/downloads/release/python-369rc1/

--
  Ned Deily
  n...@python.org -- []

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


Re: Understand workflow about reading and writing files in Python

2019-06-18 Thread DL Neil
I've not gone 'back' to refer to any ComSc theory on buffer-management. 
Perhaps you might benefit from such?


I like your use of the word "shift", so I'll continue to use it.

There are three separate units of data to consider - each of which could 
be called a "buffer". To avoid confusing (myself) I'll only call the 
'middle one' that:

1 the unit of data 'coming' from the data-source
2 the "buffer" you are implementing
3 the unit of data 'going' out to a data-destination.

1 and 3 may be dictated to you, eg hardware or file specifications, code 
requirements, etc.


So, data is shifted into the (2) buffer in a unit-size decided by (1) - 
in most use-cases each incoming unit will be the same size, but remember 
that the last 'unit' may/not be full-size. Similarly, data shifted out 
from the (2) buffer to (3).


The size of (1) is likely not that of (3) - otherwise why use a 
"buffer"? The size of (2) must be larger than (1) and larger than (2) - 
for reasons already illustrated.


I recall learning how to use buffers with a series of hand-drawn block 
diagrams. Recommend you try similarly!



Now, let's add a few critiques, as requested (interposed below):-


On 19/06/19 3:53 PM, Windson Yang wrote:

I'm trying to understand the workflow of how Python read/writes data with
buffer. I will be appreciated if someone can review it.

### Read n data


- may need more than one read operation if the size of (3) "demands" 
more data than the size of (1)/one "read".



1. If the data already in the buffer, return data


- this a data-transfer of size (3)

For extra credit/an unnecessary complication (but probable speed-up!):
* if the data-remaining is less than size (3) consider a read-ahead 
mechanism



2. If the data not in the buffer:


- if buffer's data-len < size (3)


 1. copy all the current data from the buffer


* if "buffer" is my (2), then no-op


 2. create a new buffer object, fill the new buffer with raw read which
read data from disk.


* this becomes: perform read operation and append incoming data (size 
(1)) to "buffer" - hence why "buffer" is larger than (1), by definition.
NB if size (1) is smaller than size (3), multiple read operations may be 
necessary. Thus a read-loop!?




 3. concat the data in the old buffer and new buffer.


= now no-op. Hopefully the description of 'three buffers' removes this 
confusion of/between buffers.




 4. return the data


* make the above steps into a while-loop and there won't be a separate 
step here (it is the existing step 1!)



* build all of the above into a function/method, so that the 'mainline' 
only has to say 'give me data'!




### Write n data
1. If data small enough to fill into the buffer, write data to the buffer


=yes, the data coming from source (1), which in this case is 'your' code 
may/not be sufficient to fill the output size (3). So, load it into the 
"buffer" (2).



2. If data can't fill into the buffer
 1. flush the data in the buffer


=This statement seems to suggest that if there is already some data in 
the buffer, it will be wiped. Not recommended!


=Have replaced the next steps, see below for your consideration:-


 1. If succeed:
 1. create a new buffer object.
 2. fill the new buffer with data return from raw write
 2. If failed:
 1. Shifting the buffer to make room for writing data to the
buffer
 2. Buffer as much writing data as possible (may raise
BlockingIOError)
 2. return the data


After above transfer from data-source (1) to "buffer" (2):

* if len( data in "buffer" ) >= size (3): output
else: keep going

* output:
shift size(3) from "buffer" to output
retain 'the rest' in/as "buffer"

NB if the size (2) of data in "buffer" is/could be multiples of size 
(3), then the "output" function should/could become a loop, ie keep 
emptying the "buffer" until size (2) < size (3).



Finally, don't forget the special cases:
What happens if we reach 'the end' (of 'input' or 'output' phase), and 
there is still data in (1) or (2)?
Presumably, in "Read" we would discard (1), but in the case of "Write" 
we MUST empty "buffer" (2), even if it means the last write is of less 
than size (3).


NB The 'rules' for the latter may vary between use-cases, eg add 
'stuffing' if the output record MUST be x-bytes long.



Hope this helps.
Do you need to hand-code this stuff though, or is there a better way?
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list