Fitting cubic spline on 2D array

2018-05-30 Thread Priya Singh
Hello all,

Can anyone tell me how can I get the functional form of the fitted cubic spline
function on to my 2D array? For eg. when we fit the Gaussian on to an array so 
we have the functional form with the parameters best fitted to my data likewise 
how can we do for the cubic spline function? Actually, I want to express my 
array as

A = summation_i,j(C_ij * value_ij)

Where i and j are the array indices of my 2D array and C_ij should be the 
functional form of the cubic spline and value_ij is the value of A at that ij 
index.

Can anyone has an idea, it's very urgent. Any help will be of great use to me.

Thanks in advance!

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


EuroPython 2018: Early Bird Ticket Sales

2018-05-30 Thread M.-A. Lemburg
We are happy to announce that we’ll start early bird tickets on

   Thursday, at around 12:00 CEST.

We have 200 conference tickets available at the Early Bird rate and
they usually sell out within a day or two.

Invoices will be available in a few weeks
-

Since we’re running the conference in the UK this year and conference
tickets are taxed at the location of the conference, we have to charge
and pay 20% UK VAT on the tickets.

In order to do this, we need a UK VAT registration and associated VAT
ID. Unfortunately, this whole process has taken way too long and so
we’re starting ticket sales without issuing invoices at this time,
simply because we would not be able to issue valid VAT invoices.

We will issues these as soon as we have the UK VAT ID, which should be
within the next couple of weeks if all goes well.

We’ll announce this on the blog and you will then be able to download
the invoices in your website account.



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/174396639222/europython-2018-early-bird-ticket-sales

Tweet:

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

Enjoy,
--
EuroPython 2018 Team
https://ep2018.europython.eu/
https://www.europython-society.org/

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


Problem with OrderedDict

2018-05-30 Thread Frank Millman

Hi all

I want to work backwards to solve this problem, so I have to explain it 
forwards to put you in the picture.


I have an Ordered Dictionary. Under certain circumstances I am getting this 
error -


   RuntimeError: OrderedDict mutated during iteration

I can see why this is happening, and I am pretty sure I can fix it by making 
a copy to iterate over.


However, the error seems to be intermittent - there are times when it should 
fail, but does not - so I want to investigate further.


I tried to reduce it to a simple example. I succeeded, but there are two 
problems -


1. It always fails, so I have not reproduced the intermittent nature yet.

2. It gives a different error -

   RuntimeError: dictionary changed size during iteration

So my first question is, what is the difference between the two error 
messages? I am using an OrderedDict for my test as well, so the difference 
is not caused by using a normal dictionary.


I am using Python 3.6.0.

Thanks

Frank Millman


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


Re: Problem with OrderedDict

2018-05-30 Thread Terry Reedy

On 5/30/2018 4:48 AM, Frank Millman wrote:

Hi all

I want to work backwards to solve this problem, so I have to explain it 
forwards to put you in the picture.


I have an Ordered Dictionary. Under certain circumstances I am getting 
this error -


    RuntimeError: OrderedDict mutated during iteration


This should mean that the value associated with a key was sometimes changed.

I can see why this is happening, and I am pretty sure I can fix it by 
making a copy to iterate over.


However, the error seems to be intermittent - there are times when it 
should fail, but does not - so I want to investigate further.


I tried to reduce it to a simple example. I succeeded, but there are two 
problems -


1. It always fails, so I have not reproduced the intermittent nature yet.

2. It gives a different error -

    RuntimeError: dictionary changed size during iteration


This should mean that a new key-value pair was always added or removed.

So my first question is, what is the difference between the two error 
messages? I am using an OrderedDict for my test as well, so the 
difference is not caused by using a normal dictionary.


I am using Python 3.6.0.


--
Terry Jan Reedy


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


Re: Simple question: how do I print output from .get() method

2018-05-30 Thread Rhodri James

On 30/05/18 06:51, Chris Angelico wrote:

On Wed, May 30, 2018 at 3:44 PM, MrMagoo2018  wrote:

Hello folks, imagine I have the code below and I am getting the "error" message 
when attempting to print() the output of 'sw_report'.
Can you suggest which method I should use to retrieve this? Is that a 
dictionary maybe?

from arista import arista
m = arista()
m.authenticate ("user","password")
sw_report = m.np.sw_report.get("swType="EOS",swMajorVersion="5.0")
print (sw_report)



That's not an error message. You asked Python to print it out, and it
printed it out. As it happens, the display isn't particularly useful,
but it's not an error.

What you have is a *generator object*, which is something you can
iterate over. I don't know about the arista library, so I don't know
what you'll get from that, but at its simplest, you could convert that
to a list:

print(list(sw_report))


Be aware that if you do this, you will exhaust the generator and won't 
be able to use it anywhere else.


>>> def foo():
... yield 1
... yield 2
... yield 3
...
>>> l = foo()
>>> print(l)

>>> print(list(l))
[1, 2, 3]
>>> print(list(l))
[]


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 05:03:02 -0400, Terry Reedy wrote:

> On 5/30/2018 4:48 AM, Frank Millman wrote:
>> Hi all
>> 
>> I want to work backwards to solve this problem, so I have to explain it
>> forwards to put you in the picture.
>> 
>> I have an Ordered Dictionary. Under certain circumstances I am getting
>> this error -
>> 
>>     RuntimeError: OrderedDict mutated during iteration
> 
> This should mean that the value associated with a key was sometimes
> changed.

I don't think so. It should be legal to iterate over a dict and change 
the values. At least it works for me:

import random
from collections import OrderedDict
d = OrderedDict(zip(range(1, 10), "abcdefghi"))
for i in range(1):  # just in case of intermittent errors
for value in d.values():
d[random.randrange(1, 10)] = random.random()


I get no errors.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 10:48:06 +0200, Frank Millman wrote:

> So my first question is, what is the difference between the two error
> messages? I am using an OrderedDict for my test as well, so the
> difference is not caused by using a normal dictionary.

>From Object/orderdict.c I find:

/* Check for unsupported changes. */
if (di->di_odict->od_state != di->di_state) {
PyErr_SetString(PyExc_RuntimeError,
"OrderedDict mutated during iteration");
goto done;
}
if (di->di_size != PyODict_SIZE(di->di_odict)) {
PyErr_SetString(PyExc_RuntimeError,
"OrderedDict changed size during iteration");
di->di_size = -1; /* Make this state sticky */
return NULL;
}


but I have no idea what that means :-)



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Problem with OrderedDict

2018-05-30 Thread Chris Angelico
On Wed, May 30, 2018 at 10:55 PM, Steven D'Aprano
 wrote:
> On Wed, 30 May 2018 05:03:02 -0400, Terry Reedy wrote:
>
>> On 5/30/2018 4:48 AM, Frank Millman wrote:
>>> Hi all
>>>
>>> I want to work backwards to solve this problem, so I have to explain it
>>> forwards to put you in the picture.
>>>
>>> I have an Ordered Dictionary. Under certain circumstances I am getting
>>> this error -
>>>
>>> RuntimeError: OrderedDict mutated during iteration
>>
>> This should mean that the value associated with a key was sometimes
>> changed.
>
> I don't think so. It should be legal to iterate over a dict and change
> the values. At least it works for me:
>
> import random
> from collections import OrderedDict
> d = OrderedDict(zip(range(1, 10), "abcdefghi"))
> for i in range(1):  # just in case of intermittent errors
> for value in d.values():
> d[random.randrange(1, 10)] = random.random()
>
>
> I get no errors.
>

You can always change the *values*, but not the *order* of the keys.

>>> from collections import OrderedDict
>>> d = OrderedDict(zip(range(1, 10), "abcdefghi"))
>>> for x in d:
...   if x == 5: d.move_to_end(x)
...
Traceback (most recent call last):
  File "", line 1, in 
RuntimeError: OrderedDict mutated during iteration

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


Re: Problem with OrderedDict

2018-05-30 Thread INADA Naoki
> However, the error seems to be intermittent - there are times when it
should
> fail, but does not - so I want to investigate further.


CPython raise RuntimeError *by chance*.
Detecting all invalid usage will increase runtime cost.
So CPython may and may not raise RuntimeError.

> I tried to reduce it to a simple example. I succeeded, but there are two
> problems -

> 1. It always fails, so I have not reproduced the intermittent nature yet.

> 2. It gives a different error -

>  RuntimeError: dictionary changed size during iteration

> So my first question is, what is the difference between the two error
> messages?

2nd error will happen when internal hash table is rebuilt while iterating.
If you read C source code, you can expect when it happens.

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


Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 23:05:53 +1000, Chris Angelico wrote:

> You can always change the *values*, but not the *order* of the keys.

Okay, so far we have these operations which are allowed:

- changing a value associated with a key

and these operations which all raise RuntimeError with the "mutated" 
error message:

- changing the position of a key;

- deleting a key (using either del or popitem);

- adding a new key;

- deleting a key and adding it back again;

- deleting a key and adding a new key.

This is the only thing I've found so far that gives the "changed size" 
error message:

- clearing the dictionary with d.clear()


Phew! I was starting to think Frank was imagining it, and that the 
"changed size" test was dead code :-)



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Problem with OrderedDict

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 10:48:06 +0200, Frank Millman wrote:

> I tried to reduce it to a simple example. I succeeded, but there are two
> problems -
> 
> 1. It always fails, so I have not reproduced the intermittent nature
> yet.
> 
> 2. It gives a different error -
> 
> RuntimeError: dictionary changed size during iteration


Can you share your simple example?



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Problem with OrderedDict

2018-05-30 Thread Frank Millman

"Steven D'Aprano"  wrote in message news:pem8b8$lm6$4...@blaine.gmane.org...


On Wed, 30 May 2018 10:48:06 +0200, Frank Millman wrote:

> I tried to reduce it to a simple example. I succeeded, but there are two
> problems -
>
> 1. It always fails, so I have not reproduced the intermittent nature
> yet.
>
> 2. It gives a different error -
>
> RuntimeError: dictionary changed size during iteration


Can you share your simple example?



I can, but I actually found my error.

I habitually type -
   from collections import OrderedDict as OD
and
   from collections import defaultdict as DD

My fingers typed the second version by mistake (my brain had nothing to do 
with it!).


Now that I am using the correct version, I consistently get the 'OrderedDict 
mutated during iteration' message.


So working backwards, I have solved the first problem. I am no nearer to 
figuring out why it fails intermittently in my live program. The message 
from INADA Naoki suggests that it could be inherent in CPython, but I am not 
ready to accept that as an answer yet. I will keep plugging away and report 
back with any findings.


Frank


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


Re: Problem with OrderedDict

2018-05-30 Thread INADA Naoki
>
> So working backwards, I have solved the first problem. I am no nearer to
> figuring out why it fails intermittently in my live program. The message
> from INADA Naoki suggests that it could be inherent in CPython, but I am
not
> ready to accept that as an answer yet. I will keep plugging away and
report
> back with any findings.
>

C implementation of OrderedDict checks
​all ​
"key change"
​(remove or insert key) ​
while iteration always.
But you can bypass the check by using dict methods
​.

Both of dict and OrdredDict checks size is not changed from start of
iteration.
So dict can't detect "remove + insert".

>>> od = collections.OrderedDict.fromkeys("abc")
>>> for k in od:
... if k == "b":
... del od["a"]
... od["a"] = "new"
...
Traceback (most recent call last):
  File "", line 1, in 
RuntimeError: OrderedDict mutated during iteration
>>> d = dict.fromkeys("abc")
>>> for k in d:
... if k == "b":
... del d["a"]
... d["a"] = "new"
...
>>> d
{'b': None, 'c': None, 'a': 'new'}


BTW, ​y
our original mail said "RuntimeError: dictionary changed size during
iteration".
Since it says "dictionary", the error was raised from dict, not
OrderedDict.​
You won't see "OrderedDict changed size" in normal code, because
OrderedDict checks all mutations.

>>> od = collections.OrderedDict.fromkeys("abc")
>>> for k in od:
... if k == "b":
... dict.__setitem__(od, "d", None)  # bypass OrderedDict checks
...
Traceback (most recent call last):
  File "", line 1, in 
RuntimeError: OrderedDict changed size during iteration



Currently, dict doesn't detect remove + insert.  But the Python language
doesn't permit it.

Learning these implementation detail should be just for a hobby, or for
developing Python interpreter.
When programming in Python, you should avoid these implementation details.

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


MailingLogger 5.0.0 Released!

2018-05-30 Thread Chris Withers

Hi All,

I'm pleased to announce the release of MailingLogger 5.0.0.

Mailinglogger provides two handlers for the standard python
logging framework that enable log entries to be emailed either as the
entries are logged or as a summary at the end of the running process.

The handlers have the following features:

- customisable and dynamic subject lines for emails sent

- emails sent with a configurable headers for easy filtering

- flood protection to ensure the number of emails sent is not excessive

- support for SMTP servers that require authentication

- fully documented and tested

This release primarily adds support for Python 3.

Thanks to Max Shepherd for breaking the back of the Python 3 work.

Full docs can be found here:

http://mailinglogger.readthedocs.io/en/latest/

For more information, please see:

https://github.com/Simplistix/mailinglogger/

cheers,

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


Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Rob Gaddi

On 05/30/2018 09:34 AM, Paul Rubin wrote:

I think Usenet posts are no longer getting forwarded to the mailing
list, but now I wonder if this is getting out at all, even to usenet.

Does anyone see it?



Can't speak for the mailing list, but this came out to Usenet just fine.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Paul
I see it on the mailing list.
Paul C

On Wed, May 30, 2018, 10:07 AM Rob Gaddi 
wrote:

> On 05/30/2018 09:34 AM, Paul Rubin wrote:
> > I think Usenet posts are no longer getting forwarded to the mailing
> > list, but now I wonder if this is getting out at all, even to usenet.
> >
> > Does anyone see it?
> >
>
> Can't speak for the mailing list, but this came out to Usenet just fine.
>
> --
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com
> Email address domain is currently out of order.  See above to fix.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Peter Otten
Rob Gaddi wrote:

> On 05/30/2018 09:34 AM, Paul Rubin wrote:
>> I think Usenet posts are no longer getting forwarded to the mailing
>> list, but now I wonder if this is getting out at all, even to usenet.
>> 
>> Does anyone see it?
>> 
> 
> Can't speak for the mailing list, but this came out to Usenet just fine.
> 

The original did not appear on gmane.

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


Re: Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread Paul St George
True, but I wanted to have some control over the image window, 
fullscreen, colour depth, etc. I am also exploring pygame. I will try 
your suggestion as it is so much simpler.


Being a novice, I had been frightened off using shell=True. See 
.


Is this equivalent?
p = subprocess.Popen('display',  + imagepath)

so

p = subprocess.Popen('display',  'test.png')





On 30/05/2018 03:04, Ian Kelly wrote:

On Sat, May 26, 2018 at 9:17 AM, Paul St George  wrote:

Thank you.
You are very right. The show() method is intended for debugging purposes and
is useful for that, but what method should I be using and is PIL the best
imaging library for my purposes? I do not want to manipulate images, I only
want to show images (full screen) on an external display. I want to use
Python to control the timing of the images.

You probably shouldn't be using PIL at all then. Why open the file in
Python just to export it and re-open it in an image viewer? It would
be simpler just to point whichever image viewer you prefer at the
original file directly. Your entire script could just be something
like this:

import subprocess

# Some timing logic

subprocess.call("display " + imagepath, shell=True)



--
Paul St George
http://www.paulstgeorge.com
http://www.devices-of-wonder.com

+44(0)7595 37 1302

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


Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread Paul St George

Ha! No, my question was clumsy.

If I know the name of the viewer that I want to use (say for example: 
‘ImageMagick’), where do I find the argument that should be used in a 
line of code such as this:


ImageShow.register(MyViewer("gwenview"), -1)

I want to replace ‘gwenview’ with the name of my favourite viewer (for 
example: ‘ImageMagick’).




On 30/05/2018 02:31, Steven D'Aprano wrote:

On Tue, 29 May 2018 20:02:22 +0200, Paul St George wrote:


Is there, somewhere, a list of viewers and their names (for the purposes
of this script)?

Do you mean a list of programs capable of viewing graphics? Do you think
there is some sort of central authority that registers the names of all
such programs? *wink*


You can start here:

https://en.wikipedia.org/wiki/Category:Graphics_software

but that's probably the closest you're going to get.





--
Paul St George
http://www.paulstgeorge.com
http://www.devices-of-wonder.com

+44(0)7595 37 1302

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


Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread MRAB

On 2018-05-30 21:01, Paul St George wrote:

True, but I wanted to have some control over the image window,
fullscreen, colour depth, etc. I am also exploring pygame. I will try
your suggestion as it is so much simpler.

Being a novice, I had been frightened off using shell=True. See
.

Is this equivalent?
p = subprocess.Popen('display',  + imagepath)


p = subprocess.Popen(['display',  imagepath])


so

p = subprocess.Popen('display',  'test.png')


p = subprocess.Popen(['display',  'test.png'])

Remembering to provide the full paths (unless it's/they're on the 
system's search path).




On 30/05/2018 03:04, Ian Kelly wrote:

On Sat, May 26, 2018 at 9:17 AM, Paul St George  wrote:

Thank you.
You are very right. The show() method is intended for debugging purposes and
is useful for that, but what method should I be using and is PIL the best
imaging library for my purposes? I do not want to manipulate images, I only
want to show images (full screen) on an external display. I want to use
Python to control the timing of the images.

You probably shouldn't be using PIL at all then. Why open the file in
Python just to export it and re-open it in an image viewer? It would
be simpler just to point whichever image viewer you prefer at the
original file directly. Your entire script could just be something
like this:

import subprocess

# Some timing logic

subprocess.call("display " + imagepath, shell=True)





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


Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Ben Bacarisse
Rob Gaddi  writes:

> On 05/30/2018 09:34 AM, Paul Rubin wrote:
>> I think Usenet posts are no longer getting forwarded to the mailing
>> list, but now I wonder if this is getting out at all, even to usenet.
>>
>> Does anyone see it?
>
> Can't speak for the mailing list, but this came out to Usenet just
> fine.

Snap.  The original and the reply.

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


Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread Peter J. Holzer
On 2018-05-30 22:08:45 +0200, Paul St George wrote:
> Ha! No, my question was clumsy.
> 
> If I know the name of the viewer that I want to use (say for example:
> ‘ImageMagick’), where do I find the argument that should be used in a line
> of code such as this:
> 
> ImageShow.register(MyViewer("gwenview"), -1)
> 
> I want to replace ‘gwenview’ with the name of my favourite viewer (for
> example: ‘ImageMagick’).

If your favourite viewer is 'ImageMagick’, then the name is
'ImageMagick'. However, I doubt this is the case, since ImageMagick
isn't a viewer, it is a collection of programs for manipulating images.
The viewer included in the ImageMagick package is simply called
'display' (and it is already the default viewer in PIL, so you don't
have to do anything to use it).

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cProfile, timed call tree

2018-05-30 Thread Peter J. Holzer
On 2018-05-30 07:45:07 +0200, dieter wrote:
> "Peter J. Holzer"  writes:
> > On 2018-05-26 07:38:09 +0200, dieter wrote:
> >> But, in general, you are right: you cannot reconstruct complete
> >> call trees. The reason is quite simple: maintaining information
> >> for the complete caller ancestry (rather than just the immediate
> >> caller) is expensive (both in terms of runtime and storage).
> >> Profiling usually is used as a preparation for optimization.
> >> Optimization has the greatest effects if applied to inner loops.
> >> And for the analysis of inner loops, complete call tree information
> >> is not necessary.
> >
> > I disagree. I have used Tim Bunce's excellent perl profiler
> > (Devel::NYTProf, for the two people here who also use Perl and don't
> > already know it), which does record whole call trees, and this is very
> > useful. You not only see that a function is called 1.5 million times,
> > you also see where it is called (not just from which functions, but from
> > which lines) and how much time is spent in calls from each location. 
> > Often this allowed me find ways to avoid calling a function altogether
> > or prevented me from chasing down the wrong rabbit hole.
> 
> If the profile information is sampled for the call location (rather then
> the call function), you still do not get the "complete call tree".
> If you want to get results based on call paths (rather than the immediate
> caller), the sampling must (in general) sample for call paths (and
> not only the immediate caller) -- which means, you must implement
> your own profiler.

I don't dispute that you would have to implement your own profiler.
I do dispute that this information is useless. As I said, I have used
Devel::NYTProf for Perl, and after using that cProfile feels like a huge
step backwards. There are some areas where Python is ahead of Perl, but
the profiler definitely isn't one of them :-(.

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread Karsten Hilbert
On Wed, May 30, 2018 at 11:01:17PM +0200, Peter J. Holzer wrote:

> On 2018-05-30 22:08:45 +0200, Paul St George wrote:
> > Ha! No, my question was clumsy.
> > 
> > If I know the name of the viewer that I want to use (say for example:
> > ‘ImageMagick’), where do I find the argument that should be used in a line
> > of code such as this:
> > 
> > ImageShow.register(MyViewer("gwenview"), -1)

$> man -k ImageMagick
$> man whatever_you_found_with_the_above

Karsten
-- 
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a Python bug report

2018-05-30 Thread Peter J. Holzer
On 2018-05-29 21:34:21 -0400, José María Mateos wrote:
> On Wed, May 30, 2018 at 01:07:38AM +, Ruifeng Guo wrote:
> > We encountered a bug in Python recently, we checked the behavior for Python 
> > version 2.7.12, and 3.1.1, both version show the same behavior. Please see 
> > below the unexpected behavior in "red text".
[...]
> In [3]: 1000 * 1.017
> Out[3]: 1016.9
> 
> So there you have it.

To expand a bit on that, the reason, why 1000 * 1.017 isn't 1017 isn't
that an x86 processor can't multiply, it is that 1017/1000 cannot be exactly
represented in a binary fraction (just like 1/7 cannot be exactly
represented in a decimal fraction).

So when you type 1.017, the computer really stores
1.016904076730672386474907398223876953125 and when you
multiply that by 1000, the result would be
1016.904076730672386474907398223876953125, but that needs a
few bits too much, so it rounded down to
1016.8863131622783839702606201171875.

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Peter J. Holzer
On 2018-05-30 10:02:06 -0700, Rob Gaddi wrote:
> On 05/30/2018 09:34 AM, Paul Rubin wrote:
> > I think Usenet posts are no longer getting forwarded to the mailing
> > list, but now I wonder if this is getting out at all, even to usenet.
> > 
> > Does anyone see it?
> > 
> 
> Can't speak for the mailing list, but this came out to Usenet just fine.

I see your posting on the mailing list, but not Paul Rubin's.
Looking back through my archive, I don't see any posting by Paul (but
quite a few followups to his), so his postings are probably filtered for
some reason.

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-05-30 Thread Peter J. Holzer
On 2018-05-29 16:20:36 +, Steven D'Aprano wrote:
> On Tue, 29 May 2018 14:04:19 +0200, Peter J. Holzer wrote:
> 
> > The OP has one file. 
> 
> We don't know that. All we know is that he had one file which he was 
> unable to read. For all we know, he has a million files, and this was 
> merely the first of many failures.

This is of course possible. It is also possible that the file is updated
daily and the person updating the file is always choosing a random
encoding[2], so his program will always fail the next day. 

But that isn't what he has told us. And I don't find it very helpful to
invent some specific scenario and base the answers on that invented
scenario instead of what the OP has told us.


> > He wants to read it. The very fact that he wants to
> > read this particular file makes it very likely that he knows something
> > about the contents of the file. So he has domain knowledge.
> 
> An unjustified assumption. I've wanted to read many files with only the 
> vaguest guess of what they might contain.
> 
> As for his domain knowledge, look again at the OP's post. His solution 
> was to paper over the error, make the error go away, by moving to Python 
> 2 which is more lax about getting the encoding right:

By "domain knowledge" I didn't mean knowledge of Python or encodings. I
meant knowledge about whatever the contents of the file are about.

My users (mostly) have no idea what an "encoding" is. But they know what
their data is about, and can tell me whether an unidentified character
in the "unit" field is a € or a ¥[1] (and also whether the value is
nominal or real or PPP-adjusted and lots of other stuff I don't need to
know to determine the encoding but may (or may not) need to import the
data correctly).


> "i actually got my script to function by running it in python 2.7"
> 
> So he didn't identify the correct encoding,

No, but just because he didn't doesn't mean it is impossible.

hp

[1] I don't know if there are actually two encodings where these two
have the same encoding. This is an invented example.

[2] BTDT (almost).

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Indented multi-line strings (was: "Data blocks" syntax specification draft)

2018-05-30 Thread Peter J. Holzer
On 2018-05-29 07:57:18 -0600, Ian Kelly wrote:
> On Tue, May 29, 2018 at 3:19 AM, Peter J. Holzer  wrote:
> > On 2018-05-23 11:08:48 -0600, Ian Kelly wrote:
> >>

[...]
> > What if I want all lines to start with some white space?
[...]
> 
> Fair points.
[...]

> >> Also, how about using a string prefix character instead of making
> >> quad-quote meaningful? Apart from being hard to visually distinguish
> >> from triple-quote, this would break existing triple-quote strings that
> >> happen to start with the quote character, e.g What?' she asked.'''
> >
> > No confusion here, since in my proposal there is always a newline after
> > the leading delimiter, since otherwise the first line wouldn't line up
> > with the rest. So the parser would notice that this is a triple-quote
> > and not a quad-quote as soon as it sees the "W".
> 
> Then how about a triple-quote string that starts with a quote
> character followed by a newline?

Collateral damage. Seriously, if you write something like this

s = 
A quoted
multline
string


instead of this

s = """'
A quoted
multline
string
'"""

outside of an obfuscation contest, you get what you deserve.

> >> b = i'''
> >> Here is a multi-line string
> >> with indentation, which is
> >> determined from the second
> >> line.'''
> >
> > Visually, that letter doesn't look like a part of the quote, so I would
> > like to pull the contents of the string over to align with the quote:
> >
> > b = i'''
> >  Here is a multi-line string
> >  with indentation, which is
> >  determined from the second
> >  line.'''
> >
> > But that creates an ambiguity: Is the whole string now indented one
> > space or not? Where is the left edge?
> 
> I don't follow. In the first case you have a multi-line string where
> every line is indented four spaces, so four spaces are to be removed
> from every line. In the second case you have a multi-line string where
> every line is indented by five spaces, so five spaces are to be
> removed from every line.

Nope. Remember that I want to be able to have *all* lines start with
white space.

So I can't simply strip all the common whitespace.

This is the reason why I want the quote (leading or trailing, preferably
both) to indicate where the left edge of the string is.

For a quad quote this is IMHO unambiguous:

b = 
   Py-
  thon


The first line starts with 3 spaces, the second one with 2.

But the prefix makes is visually ambiguous: Is the left edge where the
prefix is or where the first quote character is.

This is of course not a problem if the *trailing* quote determines the
indentation:

a_multi_line_string = i'''
   Py-
  thon
'''


> What about the second string would make the algorithm think that four
> spaces are to be removed from every line, leaving one?

Because you have to skip 4 spaces to get below the "i" which starts the
quote.

> Why not remove three, leaving two? Or remove one, leaving
> four? And why is the first string safe from this?

Not sure what you mean by "first string". The way you wrote has either
no leading whitespace (if the "i" signals the left edge) or is a syntax
error (if the first "'" signals the left edge, because then
non-whitespace characters would have to be discarded).

> In any case, Chris made a good point that I agree with. This doesn't
> really need to be syntax at all, but could just be implemented as a
> new string method.

Depending on the details, not quite. A method wouldn't get the
horizontal position of the leading quote. It could infer the position of
the trailing quote, though.

So, yes, it would be possible. And the optimizer might call the method
at compile time instead of runtime. There is still the visual noise,
though.

This is a bit of a pet peeve of mine: It is common to indent code in all
languages invented in the 40 years or so (and even older languages like
Fortran have adopted that convention). But *none*[1] of them has syntax
to let the programmer write multiline strings that are  properly aligned
with the rest of the code. Not even Python, where indentation is part of
the syntax.

[1] I exaggerate. SPL is the one exception I know. And there are
probably a few other similarly obscure languages.

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread Cameron Simpson

On 30May2018 21:29, MRAB  wrote:

On 2018-05-30 21:01, Paul St George wrote:

Is this equivalent?
p = subprocess.Popen('display',  + imagepath)


p = subprocess.Popen(['display',  imagepath])


so

p = subprocess.Popen('display',  'test.png')


p = subprocess.Popen(['display',  'test.png'])

Remembering to provide the full paths (unless it's/they're on the system's 
search path).


Personally, I am generally against the "use a full path" advice.

Using a full path to the executable is (a) nonportable because executables may 
be in different places on different systems and (b) obstructive to the user, 
because they may have built or installed  their own version of the app for 
specific purposes, such as the vendor provided version being out of date.


For example, Paul's problem might also be addressable by writing his own 
"display" shell script invoking the tool of his choice. Like Python, the 
executable command name is a dynamic lookup!


IMO it is the programme caller's task to provide the execution environment, and 
the programme should expect $PATH (UNIX execution search path) to be suitable 
already.


Every hardwired path is a maintenance and fragility nightmare.

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


Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Steven D'Aprano
On Wed, 30 May 2018 21:53:05 +0100, Ben Bacarisse wrote:

> Rob Gaddi  writes:
> 
>> On 05/30/2018 09:34 AM, Paul Rubin wrote:
>>> I think Usenet posts are no longer getting forwarded to the mailing
>>> list, but now I wonder if this is getting out at all, even to usenet.
>>>
>>> Does anyone see it?
>>
>> Can't speak for the mailing list, but this came out to Usenet just
>> fine.
> 
> Snap.  The original and the reply.

You shouldn't generalise about Usenet, as individual news servers can and 
do drop messages. In this case, gmane seems to be dropping Paul Rubin's 
posts.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-30 Thread Chris Angelico
On Thu, May 31, 2018 at 9:34 AM, Cameron Simpson  wrote:
> On 30May2018 21:29, MRAB  wrote:
>>
>> On 2018-05-30 21:01, Paul St George wrote:
>>>
>>> Is this equivalent?
>>> p = subprocess.Popen('display',  + imagepath)
>>>
>> p = subprocess.Popen(['display',  imagepath])
>>
>>> so
>>>
>>> p = subprocess.Popen('display',  'test.png')
>>>
>> p = subprocess.Popen(['display',  'test.png'])
>>
>> Remembering to provide the full paths (unless it's/they're on the system's
>> search path).
>
>
> Personally, I am generally against the "use a full path" advice.
>
> Using a full path to the executable is (a) nonportable because executables
> may be in different places on different systems and (b) obstructive to the
> user, because they may have built or installed  their own version of the app
> for specific purposes, such as the vendor provided version being out of
> date.
>
> For example, Paul's problem might also be addressable by writing his own
> "display" shell script invoking the tool of his choice. Like Python, the
> executable command name is a dynamic lookup!
>
> IMO it is the programme caller's task to provide the execution environment,
> and the programme should expect $PATH (UNIX execution search path) to be
> suitable already.
>
> Every hardwired path is a maintenance and fragility nightmare.

Bless you, it all depends! [1]

A hardwired path is safe against someone externally messing with your
script. But a pathless name allows you to make use of
externally-configured $PATH. Sometimes you want the safety; sometimes
you want the flexibility.

Using just the name is very similar to typing the command at the
shell, but it's not identical to that either; shell aliases can mean
that typing "grep foo bar" is not the same as "`which grep` foo bar".
So it's that bit harder to explain, and you HAVE to want the behaviour
that it gives.

Make an intelligent decision as to whether you want a hard-coded path
or just a name.

ChrisA

[1] I'm on the wrong mailing list to expect everyone to recognize that
line. It's from "The Mikado" by Gilbert & Sullivan.
-- 
https://mail.python.org/mailman/listinfo/python-list


leetv 1.12 released

2018-05-30 Thread Jim Lee

Hello, python-list members!


This is my first post.  I have created 'leetv', a Python application.  
You can find it at:



https://github.com/oregonjim/leetv


There are several 'firsts' here (besides my first post...).  This is my 
first time using Github.  This is my first major Python effort, though I 
have been a C/C++/Asm/Embedded developer for several decades.  As a 
result, I'm sure the code is more C-onic than Pythonic at this point.  
This is a project that I've wanted to do for a long time, as well as 
learn Python, so I combined the two.



Here is a short excerpt from the README:

---

Do you have a large collection of TV shows stored on a hard drive 
somewhere? Have you spent weeks (or months) ripping all your TV and 
movie DVDs to media files? Have you ever wanted a program that could 
take your entire collection and just play it according to a daily 
schedule, all day long, every day (like a real TV station does), without 
requiring you to do anything beyond the initial schedule programming? Do 
you wish you could choose your OWN commercials to play between shows 
(perhaps some memorable favorites from your childhood, or maybe a few of 
those SuperBowl halftime legends) rather than watch the drivel that 
plagues today's television? Want to get rid of Cable because you 
realized that you're paying for 1000 channels worth of stuff that 
doesn't interest you?


That's what LeeTV is for. It's a set-it-and-forget-it application that 
turns an unused computer into an always on, always playing personal TV 
station - one that plays the content YOU want.


My own setup has been running continuously for months now. It requires 
nothing of me. I will occasionally ssh into my LeeTV box to change a 
schedule, or to add a few more commercials that I found on YouTube, but 
that's it. I don't even have to stop or restart anything. It works so 
well that I added a wireless HDMI transmitter so that the signal is 
available on any TV in the house!


---

Thanks for reading,

--Jim Lee


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


Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Ben Bacarisse
Steven D'Aprano  writes:

> On Wed, 30 May 2018 21:53:05 +0100, Ben Bacarisse wrote:
>
>> Rob Gaddi  writes:
>> 
>>> On 05/30/2018 09:34 AM, Paul Rubin wrote:
 I think Usenet posts are no longer getting forwarded to the mailing
 list, but now I wonder if this is getting out at all, even to usenet.

 Does anyone see it?
>>>
>>> Can't speak for the mailing list, but this came out to Usenet just
>>> fine.
>> 
>> Snap.  The original and the reply.
>
> You shouldn't generalise about Usenet, as individual news servers can and 
> do drop messages. In this case, gmane seems to be dropping Paul Rubin's 
> posts.

Was I generalising?  I didn't intend to.  I only meant I saw both on
Usenet.

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


[RELEASE] Python 3.7.0b5 bonus beta!

2018-05-30 Thread Ned Deily
A 3.7 update: Python 3.7.0b5 is now the final beta preview of Python 3.7,
the next feature release of Python. 3.7.0b4 was intended to be the final
beta but, due to some unexpected compatibility issues discovered during
beta testing of third-party packages, we decided to revert some changes
in how Python's 3.7 Abstract Syntax Tree parser deals with docstrings;
3.7.0b5 now behaves like 3.6.x and previous releases (refer to the
3.7.0b5 changelog for more information).

**If your code makes use of the ast module, you are strongly encouraged
to test (or retest) that code with 3.7.0b5, especially if you previously
made changes to work with earlier preview versons of 3.7.0.**

As always, please report issues found to bugs.python.org as soon as
possible. Please keep in mind that this is a preview release and its use
is not recommended for production environments. Attention macOS users:
there is now a new installer variant for macOS 10.9+ that includes a
built-in version of Tcl/Tk 8.6. This variant is expected to become the
default version when 3.7.0 releases. Check it out!

The next (and final, we hope!) preview release will be the release
candidate which is now planned for 2018-06-11, followed by the official
release of 3.7.0, now planned for 2018-06-27. You can find Python 3.7.0b5
and more information here:

https://www.python.org/downloads/release/python-370b5/

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

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