Re: Can math.atan2 return INF?

2016-06-30 Thread Paul Rubin
> Every time somebody tries to point to an example of a “topic that is
> beyond the reach of science”, it seems to get knocked over eventually.

Generate a sequence of "random" bits from your favorite physical source
(radioactive decay, quantum entanglement, or whatever).  Is the sequence
really algorithmically random (like in Kolmogorov randomness)?  This is
scientifically unknowable.  To check the randomness you have to solve
the halting problem.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Errors in installation of matplotlib and pandas on Macbook

2016-06-30 Thread Chris Angelico
On Thu, Jun 30, 2016 at 4:21 PM, Madhavan Bomidi  wrote:
> How should I modify the profile/configuration of locale permanently? Is it 
> possible to do this on terminal other than using 'export' command always and 
> including the commands in .bash_profile?
>
> How does this locale configuration affect other processes or software on the 
> Macbook?
>
> I also get another problem with selfupdate of Mac port. Below is the error 
> message. Is this a problem of configuration in the locale?

These are all Mac-specific questions (and not, incidentally,
Python-specific). You'll probably find you can learn a lot from
Googling your problems. (Or DuckDuckGoing them, but that doesn't roll
off the tongue so easily.)

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 03:33, Lawrence D’Oliveiro wrote:


So you see, like it or not, we are drawn to the conclusion that there *was* 
indeed something before our particular Big Bang.


That's linear like the Big Bang theorie. What about assuming something 
beyond our notion of time and space, unknown still?

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Lawrence D’Oliveiro
On Thursday, June 30, 2016 at 6:57:41 PM UTC+12, Paul Rubin wrote:

>> Every time somebody tries to point to an example of a “topic that is
>> beyond the reach of science”, it seems to get knocked over eventually.
> 
> Generate a sequence of "random" bits from your favorite physical source
> (radioactive decay, quantum entanglement, or whatever).  Is the sequence
> really algorithmically random (like in Kolmogorov randomness)?  This is
> scientifically unknowable.

The definition of “random” is “unknowable”. So all you are stating is a 
tautology.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can math.atan2 return INF?

2016-06-30 Thread Lawrence D’Oliveiro
On Thursday, June 30, 2016 at 7:13:36 PM UTC+12, Andreas Röhler wrote:
> On 30.06.2016 03:33, Lawrence D’Oliveiro wrote:
> 
>> So you see, like it or not, we are drawn to the conclusion that there
>> *was* indeed something before our particular Big Bang.
> 
> That's linear like the Big Bang theorie. What about assuming something 
> beyond our notion of time and space, unknown still?

M-theory? Branes? Multiverse? All part of the current scientific intellectual 
landscape.
-- 
https://mail.python.org/mailman/listinfo/python-list


Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Peter Otten
Lawrence D’Oliveiro wrote:

> On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote:
> 
>> I would like to see a more Pythonic, more explicit and expressive
>> replacement with its component parts easily understood.
> 
> I don’t know why this fear and suspicion of lambdas is so widespread among
> Python users ... former Java/C# programmers, perhaps?

If there is "fear" I don't share it. However, for

foo = lambda : 

there is syntactic sugar in Python that allows you to write it as

def foo():
return 

with the nice side effects that it improves the readability of tracebacks 
and allows you to provide a docstring.

So yes, assigning a lambda to a name raises my "suspicion".

If a lambda is provided as an argument or as part of an expression I wonder 
how it is tested, and if even if it is trivial like

def reduce(items, func=lambda x, y: x + y): ...

the alternative

def reduce(items, func=add): ...

looks more readable in my eyes even though somewhere -- under the rug or in 
the operator module -- you need

def add(x, y):
   """
   >>> add(3, 4)
   7
   """
   return x + y

>> decorator_with_args = lambda decorator: lambda *args, **kwargs: 
lambda func: decorator(func, *args, **kwargs)
> 
> Ah, I see why there are 3 lambdas, instead of 2. It’s so that you can 
write

I have a suspicion that there would not have been a correction "I see why 
there are three functions instead of two" ;)

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Paul Rubin
Lawrence D’Oliveiro  writes:
> The definition of “random” is “unknowable”. So all you are stating is
> a tautology.

What?  No.  You read a bunch of bits out of the device and you want to
know whether they are Kolmogorov-random (you can look up what that means
if you're not familiar with it).  Quantum theory says they are, but if
it is true, there is no scientific way to confirm it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can math.atan2 return INF?

2016-06-30 Thread Lawrence D’Oliveiro
On Thursday, June 30, 2016 at 7:32:55 PM UTC+12, Paul Rubin wrote:
> Lawrence D’Oliveiro writes:
>> The definition of “random” is “unknowable”. So all you are stating is
>> a tautology.
> 
> What?  No.  You read a bunch of bits out of the device and you want to
> know whether they are Kolmogorov-random (you can look up what that means
> if you're not familiar with it).  Quantum theory says they are, but if
> it is true, there is no scientific way to confirm it.

Randomness is not something you can ever prove. Which is why it is the weak 
point of all encryption algorithms.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Lawrence D’Oliveiro
On Thursday, June 30, 2016 at 7:26:01 PM UTC+12, Peter Otten wrote:
> foo = lambda : 
> 
> there is syntactic sugar in Python that allows you to write it as
> 
> def foo():
> return 
> 
> with the nice side effects that it improves the readability of tracebacks 
> and allows you to provide a docstring.

True, but then again the original had three lambdas, so one line would have to 
become at least 3×2 = 6 lines, more if you want docstrings.

> def reduce(items, func=lambda x, y: x + y): ...

There was a reason why “reduce” was removed from being a builtin function in 
Python 2.x, to being banished to functools in Python 3.

> the alternative
> 
> def reduce(items, func=add): ...
> 
> looks more readable in my eyes even though somewhere ...

Just use “sum” in this case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Steven D'Aprano
On Thursday 30 June 2016 17:43, Lawrence D’Oliveiro wrote:

> On Thursday, June 30, 2016 at 7:26:01 PM UTC+12, Peter Otten wrote:
>> foo = lambda : 
>> 
>> there is syntactic sugar in Python that allows you to write it as
>> 
>> def foo():
>> return 
>> 
>> with the nice side effects that it improves the readability of tracebacks
>> and allows you to provide a docstring.
> 
> True, but then again the original had three lambdas, so one line would have
> to become at least 3×2 = 6 lines, more if you want docstrings.

I hear that we've passed "Peak Newlines" now, so adding extra lines will get 
more and more expensive. I guess languages like C and Java will soon have to be 
abandoned, and everyone will move to writing minified Javascript and Perl one-
liners.


>> def reduce(items, func=lambda x, y: x + y): ...
> 
> There was a reason why “reduce” was removed from being a builtin function in
> Python 2.x, to being banished to functools in Python 3.

Yes, and that reason is that Guido personally doesn't like reduce.



-- 
Steve

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Steven D'Aprano
On Thursday 30 June 2016 12:13, Rustom Mody wrote:

> OTOH Computer Science HAPPENED because mathematicians kept hotly disputing
> for more than ½ a century as to what is legitimate math and what is
> theology/mysticism/etc:

I really don't think so. Computer science happened because people invented 
computers and wanted to study them.

What people like Turing did wasn't computer science, because the subject didn't 
exist yet. He was too busy creating it to do it.

And as for Kronecker, well, I suspect he objected more to Cantor's infinities 
than to real numbers. After all, even the Pythogoreans managed to prove that 
sqrt(2) was an irrational number more than 3000 years ago, something Kronecker 
must have known.


> In particular the question: "Are real numbers really real?" is where it
> starts off... http://blog.languager.org/2015/03/cs-history-0.html

The pre-history of what later became computer science is very interesting, but 
I fear that you are too focused on questions of "mysticism" and not enough on 
what those people actually did and said.

For example, you state that Turing "believes in souls" and that he "wishes to 
put the soul into the machine" -- what do his religious beliefs have to do with 
his work? What evidence do you have for the second claim? What does it even 
mean to put "the" soul (is there only one?) into "the" machine? 


Besides, the whole point of science is to develop objective, rational reasons 
to believe things. The chemist Friedrich Kekulé was inspired to think of 
benzene's molecular structure as a ring through a dream in which a snake bit 
its own tail, but that's not why we believe benzene is a ring-shaped molecule. 
No chemist says "Kekulé dreamed this, therefore it must be true."

The irrational and emotional psychological forces that inspire mathematicians 
can make interesting reading, but they have no relevance in deciding who is 
write or wrong. No numbers are real. All numbers are abstractions, not concrete 
things. If there is a universe of Platonic forms -- highly unlikely, as the 
concept is intellectually simplistic and implausible -- we don't live in it. 
Since all numbers are abstractions, the Real sqrt(2) is no more, or less, 
"real" than the integer 2.



-- 
Steve

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Steven D'Aprano
On Thursday 30 June 2016 17:16, Lawrence D’Oliveiro wrote:

> The definition of “random” is “unknowable”.


It really isn't.

What Julius Caesar had for breakfast on the day after his 15th birthday is 
unknowable.

To the best of our knowledge, the collapse of a quantum wave function is 
random.


-- 
Steve

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


Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Peter Otten
Lawrence D’Oliveiro wrote:

> On Thursday, June 30, 2016 at 7:26:01 PM UTC+12, Peter Otten wrote:
>> foo = lambda : 
>> 
>> there is syntactic sugar in Python that allows you to write it as
>> 
>> def foo():
>> return 
>> 
>> with the nice side effects that it improves the readability of tracebacks
>> and allows you to provide a docstring.
> 
> True, but then again the original had three lambdas, so one line would
> have to become at least 3×2 = 6 lines, more if you want docstrings.
> 
>> def reduce(items, func=lambda x, y: x + y): ...
> 
> There was a reason why “reduce” was removed from being a builtin function
> in Python 2.x, to being banished to functools in Python 3.

You do understand what an example is?

 
>> the alternative
>> 
>> def reduce(items, func=add): ...
>> 
>> looks more readable in my eyes even though somewhere ...
> 
> Just use “sum” in this case.

Nah, the implementation is of course

def reduce(items, func=lambda x, y: x + y):
"""
>>> list(reduce([1,2,3]))
[1, 3, 6]

>>> list(reduce([42]))
[42]

>>> reduce([])
Traceback (most recent call last):
...
TypeError: reduce() with empty sequence
"""
items = iter(items)
try:
first = next(items)
except StopIteration:
raise TypeError("reduce() with empty sequence")

def _reduce(accu=first):
for item in items:
yield accu
accu = func(accu, item)
yield accu

return _reduce()

Yes, I'm kidding...

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 10:24, Steven D'Aprano wrote:

On Thursday 30 June 2016 12:13, Rustom Mody wrote:

[ ... ]
Besides, the whole point of science is to develop objective, rational reasons
to believe things.


Science is not about believing, but about models.
Believing is important to make the career of a scientist maybe, it's for 
people outside.

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


EuroPython 2016: On-desk rates and day passes

2016-06-30 Thread M.-A. Lemburg
It’s getting really close to the conference now and we will be
switching to the on-desk rates for tickets on July 8.

The prices will increase by about 30%, so if you want to still get
tickets at the normal rate, please register for EuroPython 2016 as
soon as possible:


 *** EuroPython 2016 Registration ***

https://ep2016.europython.eu/en/registration/


Full Conference Tickets
---

These are the on-desk rates for full conference tickets (all 8 days):

 * Student full ticket: EUR 180.00
 * Personal full ticket: EUR 470.00
 * Business full ticket: EUR 750.00

Day Passes
--

As in the past, we will sell day passes at the conference venue.

To make things more affordable especially for students and other
people who want to attend the Beginners’ Day or the sprints, we have
decided to split the day pass prices into ones valid from
Monday-Friday for the main conference days and the weekend days.

Day passes for the main conference (valid for the day when they are
purchased):

 * Student conference day pass: EUR 50.00
 * Personal conference day pass: EUR 140.00
 * Business conference day pass: EUR 225.00

Day passes for the first Sunday (Beginners’ Day) and the sprints
weekend (valid for the day when they are purchased):

 * Student weekend day pass: EUR 25.00
 * Personal weekend day pass: EUR 70.00
 * Business weekend day pass: EUR 110.00

All prices include 10% Spanish VAT. Please see the registration page
for full details of what is included in the ticket price.


With gravitational regards,
--
EuroPython 2016 Team
http://ep2016.europython.eu/
http://www.europython-society.org/


PS: Please forward or retweet to help us reach all interested parties:
https://twitter.com/europython/status/748447674102329345
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can math.atan2 return INF?

2016-06-30 Thread Lawrence D’Oliveiro
On Thursday, June 30, 2016 at 9:31:29 PM UTC+12, Andreas Röhler wrote:

> Science is not about believing, but about models.

The nice thing about science is, it works even if you don’t believe in it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 10:24, Steven D'Aprano wrote:

On Thursday 30 June 2016 12:13, Rustom Mody wrote:


The irrational and emotional psychological forces that inspire mathematicians
can make interesting reading, but they have no relevance in deciding who is
write or wrong.


Hmm, so math is not inspired by solving real world problems, for example 
in physics or big-data?




  No numbers are real.


Numbers express relations, which are represented as symbols. So far they 
are real, as math exists, the human mind exists.


We don't have any natural numbers, assume Kronecker made a joke. 
"Natural numbers" is the most misleading term in the field maybe.


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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 11:42, Lawrence D’Oliveiro wrote:

On Thursday, June 30, 2016 at 9:31:29 PM UTC+12, Andreas Röhler wrote:


Science is not about believing, but about models.

The nice thing about science is, it works even if you don’t believe in it.



Thats it!
--
https://mail.python.org/mailman/listinfo/python-list


Re: Iteration, while loop, and for loop

2016-06-30 Thread Tim Chase
On 2016-06-30 09:59, Steven D'Aprano wrote:
> But there's no need to go to such effort for a mutable iterator.
> This is much simpler:
>   
> py> mi = list('bananas')
> py> for char in mi:
> ... if char == 'a':
> ... mi.extend(' yum')
> ... print(char, end='')
> ... else:  # oh no, the feared for...else!
> ... # needed to prevent the prompt overwriting the output
> ... print()
> ...
> bananas yum yum yum  
> py> 
> 
> 
> This example shows two things:
> 
> (1) There's no need for a MutableIterator, we have list;  

Convenient to know.  I was fairly certain that this had failed for me
in past versions, but I went back to the oldest I have (2.4) and it
still works there.  Might have to revisit some queuing code I have.

That said, it's not consistent across iterable container types.  With

  mi = set('bananas')
  for char in mi:
if char == 'a':
  mi.add('X')
print(char)
  else:
print()

I get

  Traceback (most recent call last):
File "", line 1, in 
  RuntimeError: Set changed size during iteration

If the list() meets your needs, then you're in luck.  But just as
frequently, I want to use a set() or a dict() and have to write my
own wrapper around it.

-tkc

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


Re: Errors in installation of matplotlib and pandas on Macbook

2016-06-30 Thread tommy yama
Hi there,

Why you would not use pip and anaconda for panda installation?
It seems much easier to do the same.




https://www.continuum.io/downloads#_macosx


*Tomomi Yamano *




On Thu, Jun 30, 2016 at 4:03 PM, Chris Angelico  wrote:

> On Thu, Jun 30, 2016 at 4:21 PM, Madhavan Bomidi 
> wrote:
> > How should I modify the profile/configuration of locale permanently? Is
> it possible to do this on terminal other than using 'export' command always
> and including the commands in .bash_profile?
> >
> > How does this locale configuration affect other processes or software on
> the Macbook?
> >
> > I also get another problem with selfupdate of Mac port. Below is the
> error message. Is this a problem of configuration in the locale?
>
> These are all Mac-specific questions (and not, incidentally,
> Python-specific). You'll probably find you can learn a lot from
> Googling your problems. (Or DuckDuckGoing them, but that doesn't roll
> off the tongue so easily.)
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Were is a great place to Share your finished projects?

2016-06-30 Thread Natsu Dragneel
Im asking this because im working on a small project, but i won't say what it 
is because i want to do it completely on myself.

I just say it has something to do with Steam and a Feature they rly need to add 
there... so i write it myself :D and it already is finished it only needs a GUI 
now.

And its not going to be compiled, so everyone can edit it and Fix the errors i 
did as a beginner(with that i mean, im going to do it a bit different than 
someone who knows python better as me), because i don't know if my HTML parser 
is going to be able to do his Function on all sides that may be used.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Iteration, while loop, and for loop

2016-06-30 Thread Ian Kelly
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano  wrote:
> I'm curious what REPL you are using, because in the vanilla Python
> interactive interpreter, the output if over-written by the prompt. That is,
> what I see in Python 3.6 is:
>
> py> nas yum yum yumpy>
>
> unless I take steps to prevent that. See below.

I was just using the CPython 3.4 REPL with the default prompt. It
appended the prompt rather than overwriting, and I simply omitted it
in my message since it wasn't relevant to the example.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Christian Gollwitzer

Am 30.06.16 um 14:48 schrieb Natsu Dragneel:

Im asking this because im working on a small project, but i won't say
what it is because i want to do it completely on myself.

I just say it has something to do with Steam and a Feature they rly
need to add there... so i write it myself :D and it already is
finished it only needs a GUI now.


The best place these days to publish software is on github. And that 
includes actual development, not just the final results. For reasons 
why, see also: http://joshldavis.com/2014/06/13/put-yourself-out-there/


Github makes that extremely easy, just create an account, create a repo, 
"git pull" and start working. Your incremental changes will be updated 
with each "git push".


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


Re: Iteration, while loop, and for loop

2016-06-30 Thread Ian Kelly
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano  wrote:
> But there's no need to go to such effort for a mutable iterator. This is
> much simpler:
>
> py> mi = list('bananas')
> py> for char in mi:
> ... if char == 'a':
> ... mi.extend(' yum')
> ... print(char, end='')
> ... else:  # oh no, the feared for...else!
> ... # needed to prevent the prompt overwriting the output
> ... print()
> ...
> bananas yum yum yum
> py>

One small difference with this approach is that iterators extended
onto the list are iterated over immediately rather than in sequence.
That could have implications in some scenarios.
-- 
https://mail.python.org/mailman/listinfo/python-list


Gramps 3.4 problem in ubuntu 16.04, maybe GTK related

2016-06-30 Thread ennoborg
Hello,

I'm a Gramps user, and developer, and for a couple of reasons, I like to stay 
with GTK+2 based Gramps 3.4. This version works fine on Mint 17.3, and ubuntu 
versions up to 15.10, but not on Mint 18, or ubuntu 16.04.

In the Gramps 3.4 GUI, which uses PyGTK, I have a tree view for persons, 
grouped by surname, and in that tree view, I have two problems that may be 
related to the Python (2.7.11+) and GTK (2.24.30) versions in Mint 18 / ubuntu 
16.04.

In that tree view, a GtkTreeView is used with a custom store, which reads data 
from a BSDDB database. And the 1st problem in that view is, that when I try to 
expand the last surname in that view, I see a Python exception, index out of 
bounds. For example, in a two surname tree, with nodes 0 and 1, print output 
from on_get_iter shows that it is called with a path of value (2,), and that 
path does not exist, hence the index out of bounds when it tries to access the 
node list in our store.

The 2nd problem only shows in a larger tree, like with the 8000+ surnames that 
I have in my database. Then, whenever I try to expand a surname near the end of 
the alphabet, Gramps will freeze for a couple of seconds before it expands the 
node. And the prints in on_get_iter then show that it is not just called with 
the path of the node to be expanded, or rather one node number too high, but 
that calls start at path (0,), walking the whole tree, until the right node is 
found. In other words, I see a sort of linear search. This also happens when I 
change the selected row inside an expanded surname node.

These delays, and the exception, don't show in ubuntu 15.10, where the GTK 
version is 2.24.28, and Python is 2.7.10, and because the error shows in the 
GUI, GTK is the 1st piece to suspect. But alas, code differences between .28 
and .30, don't give any clues to me, so the real cause may also be Python 
itself.

I might be able to test this by installing Python 2.7.11 and GTK 2.24.30 into 
ubuntu 15.10, because that is where things are still OK, and I'm writing here, 
because I hope that someone can direct me to install both packages from the 
latest ubuntu repositories, and see what that brings. An alternative would be 
to build Python 2.7.11 and GTK 2.24.30 from source, and redirect some paths, so 
that I can test Gramps without affecting other system parts.

Is there any place where I may find help for this?

thank you,

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


sample chatting apps in pyqt

2016-06-30 Thread tommy yama
Hi all,

Let me post my question here
Has anyone installed and run any of sample chat apps in pyqt?

Although I've tried to install and run sample scripts in pyqt once, the
error said pyqt must be reinstalled.

Appreciate for your suggestions.

Thanks.

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


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread MRAB

On 2016-06-30 14:09, Christian Gollwitzer wrote:

Am 30.06.16 um 14:48 schrieb Natsu Dragneel:

Im asking this because im working on a small project, but i won't say
what it is because i want to do it completely on myself.

I just say it has something to do with Steam and a Feature they rly
need to add there... so i write it myself :D and it already is
finished it only needs a GUI now.


The best place these days to publish software is on github. And that
includes actual development, not just the final results. For reasons
why, see also: http://joshldavis.com/2014/06/13/put-yourself-out-there/

Github makes that extremely easy, just create an account, create a repo,
"git pull" and start working. Your incremental changes will be updated
with each "git push".


An alternative is Bitbucket.


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


Re: sample chatting apps in pyqt

2016-06-30 Thread Michael Torrie
On 06/30/2016 07:45 AM, tommy yama wrote:
> Hi all,
> 
> Let me post my question here
> Has anyone installed and run any of sample chat apps in pyqt?
> 
> Although I've tried to install and run sample scripts in pyqt once, the
> error said pyqt must be reinstalled.

If you paste the error message here, I'm sure someone can help you
figure out what is going on.

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


Re: Can math.atan2 return INF?

2016-06-30 Thread alister
On Thu, 30 Jun 2016 09:24:43 +0300, Marko Rauhamaa wrote:

> Lawrence D’Oliveiro :
>> Every time somebody tries to point to an example of a “topic that is
>> beyond the reach of science”, it seems to get knocked over eventually.
> 
> Of course, an experiment trumps theory, always.
> 
> 
> Marko

in theory there is no difference between theory and practice
in practice there is 



-- 
Q:  What is purple and commutes?
A:  An Abelian grape.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can math.atan2 return INF?

2016-06-30 Thread Rustom Mody
On Thursday, June 30, 2016 at 1:55:18 PM UTC+5:30, Steven D'Aprano wrote:

> you state that Turing "believes in souls" and that he "wishes to 
> put the soul into the machine" -- what do his religious beliefs have to do 
> with 
> his work?

Bizarre question -- becomes more patently ridiculous when put into general form
"What does what I do have to do with what I believe?"

More specifically the implied suggested equation "soul = religious"
is your own belief. See  particularly "Christian faith" in the quote below.

> What evidence do you have for the second claim? What does it even 
> mean to put "the" soul (is there only one?) into "the" machine? 

Excerpted from https://blog.sciencemuseum.org.uk/the-spirit-of-alan-turing/

===
Morcom was Turing’s first love, a fellow, older pupil at
Sherborne School, Dorset, who shared Turing’s passion for
mathematics (who died in 1930)

He was profoundly affected by the death of his friend...  Turing
admitted that he ‘worshipped the ground he trod on’.

Morcom’s death cast a long shadow. Turing turned away from his
Christian faith towards materialism, and began a lifelong quest
to understand the tragedy. As he struggled to make sense of his
loss, Turing pondered the nature of the human mind and whether
Christopher’s was part of his dead body or somehow lived on.

The October after the loss of his friend, Turing went up to
Cambridge, where he studied mathematics. Our exhibition includes
an essay, entitled “Nature of Spirit” that Turing wrote the next
year, in 1932, in which he talked of his belief in the survival
of the spirit after death, which appealed to the relatively
recent field of quantum mechanics and reflected his yearning for
his dear friend.

Around that time he encountered the Mathematical Foundations of
Quantum Mechanics by the American computer pioneer, John von
Neumann, and the work of Bertrand Russell on mathematical
logic. THESE STREAMS OF THOUGHT WOULD FUSE when Turing imagined a
machine that would be capable of any form of computation. Today
the result – known as a universal Turing machine – still
dominates our conception of computing.
===

> And as for Kronecker, well, I suspect he objected more to Cantor's infinities
> than to real numbers. After all, even the Pythogoreans managed to prove that
> sqrt(2) was an irrational number more than 3000 years ago, something Kronecker
> must have known. 

They -- reals and their cardinality -- are the identical problem
And no, the problem is not with √2 which is algebraic
See http://mathworld.wolfram.com/AlgebraicNumber.html
It is with the transcendentals like e and π

ℕ ⫅ ℤ ⫅ ℚ ⫅ A ⫅ ℝ

is obvious almost by definition

That upto A (algebraic numbers) they are equipotent is somewhat paradoxical but 
still acceptable (to all parties)
See the Cantor pairing function 
https://en.wikipedia.org/wiki/Countable_set#Formal_overview_without_details
parties

However between A and ℝ something strange happens (where?) and the equipotence
is lost.  At least thats the traditional math/platonic view (Cantor/Hilbert etc)


Constructivist view
"Yes real numbers are not enumerable
That means any talk of THE SET ℝ is nonsense
(talk with language, symbols whatever can only be enumerable)
Therefore Equipotence is like angels on a pin"

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


Re: fastest way to read a text file in to a numpy array

2016-06-30 Thread Heli
Dear all, 

After a few tests, I think I will need to correct a bit my question. I will 
give an example here. 

I have file 1 with 250 lines:
X1,Y1,Z1
X2,Y2,Z2


Then I have file 2 with 3M lines:
X1,Y1,Z1,value11,value12, value13,
X2,Y2,Z2,value21,value22, value23,...


I will need to interpolate values for the coordinates on file 1 from file 2. 
(using nearest) 
I am using the scipy.griddata for this.  

scipy.interpolate.griddata(points, values, xi, method='linear', fill_value=nan, 
rescale=False)

When slicing the code, reading files in to numpy is not the culprit, but the 
griddata is. 

time to read file2= 2 min
time to interpolate= 48 min

I need to repeat the griddata above to get interpolation for each of the column 
of values. I was wondering if there are any ways to improve the time spent in 
interpolation. 


Thank you very much in advance for your help, 


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


Re: Operator Precedence/Boolean Logic

2016-06-30 Thread Rustom Mody
On Thursday, June 30, 2016 at 5:10:41 AM UTC+5:30, Steven D'Aprano wrote:
> On Wed, 29 Jun 2016 11:30 pm, Rustom Mody wrote:
> 
> > The other answers -- graphs and automata -- are questionable and/or wrong
> > 
> > You may wish to think about them again?
> 
> You may wish to justify your assertion.

> Rusi wrote
> > Please show me how we would define __bool__ for
> >
> > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a
> > graph..."

> I would make the empty graph (zero nodes) falsey, and non-empty graphs (one
> or more nodes) truthy.


> 2. Automata which in a way are special kinds of graphs

As above. 

From https://en.wikipedia.org/wiki/Finite-state_machine#Mathematical_model

A deterministic finite state machine (acceptor) is a quintuple
(Σ, S, δ, s₀, F), where:

Σ  is the input alphabet (a finite, non-empty set of symbols).
S  is a finite, non-empty set of states.
δ  is the state-transition function: δ : S × Σ → S 
s₀  is an initial state, an element of S.
F  is the set of final states, a (possibly empty) subset of S.


Put in more succinct form:

If we take Σ (alphabet) and S (state-set) as given (ie independent) types
we can specify the dependence of s₀ δ and F as the following type_signature:

dfa(Σ, S) = s₀ : S
δ : S × Σ → S
F : ℘ S

Since s₀ : S is part of the dfa spec, S cant be empty

Can Σ (alphabet) be empty??
I'm not clear on that one...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can math.atan2 return INF?

2016-06-30 Thread Steven D'Aprano
On Thu, 30 Jun 2016 08:11 pm, Andreas Rc3b6hler wrote:

> 
> 
> On 30.06.2016 10:24, Steven D'Aprano wrote:
>> On Thursday 30 June 2016 12:13, Rustom Mody wrote:
>>
>>
>> The irrational and emotional psychological forces that inspire
>> mathematicians can make interesting reading, but they have no relevance
>> in deciding who is write or wrong.

"Write" or wrong? Oh the shame :-(


> Hmm, so math is not inspired by solving real world problems, for example
> in physics or big-data?

I didn't say that.

Of course the work people do is influenced by real world problems, or their
own irrational and subjective tastes. Why does one mathematician choose to
work in algebra while another chooses to work in topology? As interesting
as it may be to learn that (say) Pascal worked on probability theory in
order to help a friend who was a keen gambler, the correctness or
incorrectness of his work is independent of that fact.


>>   No numbers are real.
> 
> Numbers express relations, which are represented as symbols. So far they
> are real, as math exists, the human mind exists.

They are real in the same way that "justice" and "bravery" are real. That
is, they are *abstract concepts*, not *things*. 





-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Operator Precedence/Boolean Logic

2016-06-30 Thread Steven D'Aprano
On Fri, 1 Jul 2016 02:01 am, Rustom Mody wrote:

> On Thursday, June 30, 2016 at 5:10:41 AM UTC+5:30, Steven D'Aprano wrote:
>> On Wed, 29 Jun 2016 11:30 pm, Rustom Mody wrote:
>> 
>> > The other answers -- graphs and automata -- are questionable and/or
>> > wrong
>> > 
>> > You may wish to think about them again?
>> 
>> You may wish to justify your assertion.

[snip]

Okay, if you think that automata cannot be empty, I'll accept that. In that
case, then I'll change my answer and say that __bool__ for automata should
simply return True. All automata should be truthy.




-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Steven D'Aprano
On Fri, 1 Jul 2016 01:28 am, Rustom Mody wrote:

> On Thursday, June 30, 2016 at 1:55:18 PM UTC+5:30, Steven D'Aprano wrote:
> 
>> you state that Turing "believes in souls" and that he "wishes to
>> put the soul into the machine" -- what do his religious beliefs have to
>> do with his work?
> 
> Bizarre question -- becomes more patently ridiculous when put into general
> form "What does what I do have to do with what I believe?"

Lots of people do things that go against their beliefs, or their beliefs (at
least, their professed beliefs) go against what they do. But I'll ask
again: in what way does Turing's supposed beliefs about souls have anything
to do with his mathematical work?

Let's be concrete:

In what way does the Halting Problem depend on the existence (or
non-existence) of the soul?

How was his work on breaking German military codes during World War 2
reliant on these supposed souls? (In the sense of a separate, non-material
spirit, not in the figurative sense that all people are "souls".)


> More specifically the implied suggested equation "soul = religious"
> is your own belief. See  particularly "Christian faith" in the quote
> below.

Of course belief in souls is a religious belief. It certainly isn't a
scientific belief, or a materialistic belief.

Don't make the mistake of thinking that materialism is a religious belief.
It is no more a religious belief than "bald" is a hair colour.


>> What evidence do you have for the second claim? What does it even
>> mean to put "the" soul (is there only one?) into "the" machine?
> 
> Excerpted from
> https://blog.sciencemuseum.org.uk/the-spirit-of-alan-turing/

[snip irrelevancy about the death of Morcom]

> Around that time he encountered the Mathematical Foundations of
> Quantum Mechanics by the American computer pioneer, John von
> Neumann, and the work of Bertrand Russell on mathematical
> logic. THESE STREAMS OF THOUGHT WOULD FUSE when Turing imagined a
> machine that would be capable of any form of computation. Today
> the result – known as a universal Turing machine – still
> dominates our conception of computing.

"These streams of thought" being the work of von Neumann and Russell.

Perhaps, and I'll accept this as a fairly unlikely by theorectically
possible result, Turing was only capable of coming up with the concept of
the Turing Machine *because of* his rejection of Christianity and his hopes
and fears and beliefs about the supposed soul of his deceased friend
Morcom. I'll grant that as a possibility, just as it is a possibility that
had Friedrich Kekulé not eaten a late night snack of cheese[1] before going
to sleep, he never would have dreamt of a snake biting its own tail and
wouldn't have come up with the molecular structure of benzene, leaving it
to somebody else to do so. But the idiosyncratic and subjective reasons
that lead Turing to his discovery are not relevant to the truth or
otherwise of his discoveries.


>> And as for Kronecker, well, I suspect he objected more to Cantor's
>> infinities than to real numbers. After all, even the Pythogoreans managed
>> to prove that sqrt(2) was an irrational number more than 3000 years ago,
>> something Kronecker must have known.
> 
> They -- reals and their cardinality -- are the identical problem
> And no, the problem is not with √2 which is algebraic
> See http://mathworld.wolfram.com/AlgebraicNumber.html

What reason do you have for claiming that Kronecker objected to
non-algebraic numbers? Nothing I have read about him suggests that he was
more accepting of algebraic reals than non-algebraic reals.

(I'm not even sure if mathematicians in Kronecker's day distinguished
between the two.)

I daresay that the famous Kronecker comment about god having created the
integers was not intended to be the thing he is remembered by. It was
probably intended as a smart-arsed quip and put-down of Cantor, not a
serious philosophical position. For is we take it *literally*, Kronecker
didn't even believe in sqrt(2), and that surely cannot be correct.


> It is with the transcendentals like e and π

Both e and π can be written as continued fractions, using nothing but ratios
of integers:

e = (2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, ...)

π = (3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, ...)

so surely if Kronecker accepted square root of two:

√2 = (1; 2, 2, 2, 2, ...)

he has no reason to reject the others.



I'm not entirely convinced that transcendentals deserve to be a separate
category of numbers. "Algebraic numbers" seem quite arbitrary to me: what's
so special about integer polynomials? Just because the Ancient Greeks had
some weird ideas about integers doesn't mean that we have to follow along.

I mean, sure, it's interesting to look at integer polynomials as a special
case, just as we might look at (say) Diophantine equations or Egyptian
Fractions as special cases. There might even be some really important maths
that comes from that. But that doesn't necessarily make algebraic numbers
any more *fund

Controlling the Mac OSX GUI via Python?

2016-06-30 Thread maitlandmontmorency
I'd like to use Python to do some simple OSX GUI manipulations such as 
automatically arranging windows, periodically refreshing applications across 
multiple desktops, etc..  Is this possible and if so, is there a preferred 
package?

I know that Qt, Tkinter, and such are available for heavy-duty custom work but 
I think these are intended to create UIs from the ground up vs. the maintenance 
work I'd like to do.

I have tried to learn Applescript and Automator but they aren't really 
scratching my itch.  I am more comfortable with Python.  Seeking FMs to RT, so 
to speak.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread Terry Reedy

On 6/30/2016 3:22 PM, maitlandmontmore...@gmail.com wrote:

I'd like to use Python to do some simple OSX GUI manipulations such
as automatically arranging windows, periodically refreshing
applications across multiple desktops, etc..  Is this possible and if
so, is there a preferred package?


Cpython comes with about 16 *nix-specifio modules, 4 Window-specific 
modules, and none for Mac.  People doing serious Windows-specific work 
usually download other packages.  Unless you can do everything you want 
by calling system utilities via subprocess, you will have to to the same.



Seeking FMs to RT, so to speak.




--
Terry Jan Reedy

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


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread Chris Angelico
On Fri, Jul 1, 2016 at 6:30 AM, Terry Reedy  wrote:
>> Seeking FMs to RT, so to speak.
>
>
> 

Derivative of the old expression, "RTFM". Normally it means "Go read
the manual that you ought to have already read", but AIUI, the OP is
saying that he'd be happy to be pointed to documentation somewhere.

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


Re: fastest way to read a text file in to a numpy array

2016-06-30 Thread Christian Gollwitzer

Am 30.06.16 um 17:49 schrieb Heli:

Dear all,

After a few tests, I think I will need to correct a bit my question. I will 
give an example here.

I have file 1 with 250 lines:
X1,Y1,Z1
X2,Y2,Z2


Then I have file 2 with 3M lines:
X1,Y1,Z1,value11,value12, value13,
X2,Y2,Z2,value21,value22, value23,...


I will need to interpolate values for the coordinates on file 1 from file 2. 
(using nearest)
I am using the scipy.griddata for this.

scipy.interpolate.griddata(points, values, xi, method='linear', fill_value=nan, 
rescale=False)


This constructs a Delaunay triangulation and no wonder takes some time 
if you run it over 3M datapoints. You can probably save a factor of 
three, because:



I need to repeat the griddata above to get interpolation for each of the column 
of values.


I think this is wrong. It should, according to the docs, happily 
interpolate from a 2D array of values. BTW, you stated you want nearest 
interpolation, but you chose "linear". I think it won't make a big 
difference on runtime, though. (nearest uses a KDtree, Linear uses QHull)



I was wondering if there are any ways to improve the time spent in 
interpolation.


Are you sure you need the full generality of this algorithm? i.e., are 
your values given on a scattered cloud of points in the 3D space, or 
maybe the X,Y,Z in file2 are in fact on a rectangular grid? In the 
former case, there is probably nothing you can really do. In the latter, 
there should be a more efficient algorithm by looking up the nearest 
index from X,Y,Z by index arithmetics. Or maybe even reshaping it into a 
3D-array.


Christian

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


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread hasan . diwan
>On 6/30/2016 3:22 PM, you wrote:
>> I'd like to use Python to do some simple OSX GUI manipulations such
>> as automatically arranging windows, periodically refreshing
>> applications across multiple desktops, etc..  Is this possible and if
>> so, is there a preferred package?

Please see this page https://docs.python.org/2/using/mac.html. The following 
will show a window, entitled "Hello world":


#!/pyobjc/virtualenv/path/bin/python

import sys
import os

from AppKit import *
from PyObjCTools import AppHelper


class Delegate (NSObject):
def applicationDidFinishLaunching_(self, aNotification):
'''Called automatically when the application has launched'''
print "Hello, World!"

def windowWillClose_(self, aNotification):
'''Called automatically when the window is closed'''
print "Window has been closed"
NSApp().terminate_(self)


def main():
a=NSApplication.sharedApplication()
delegate = Delegate.alloc().init()
a.setDelegate_(delegate)
frame = ((200.0, 300.0), (250.0, 100.0))
w = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(frame, 
15, 2, 0)
w.setDelegate_(delegate)
w.setTitle_(u'Hello, World!')
w.orderFrontRegardless()
AppHelper.runEventLoop()

if __name__ == '__main__':
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 7:22:43 AM UTC+12, Maitland Montmorency wrote:
> I'd like to use Python to do some simple OSX GUI manipulations such as
> automatically arranging windows, periodically refreshing applications
> across multiple desktops, etc..
> 
> I have tried to learn Applescript and Automator but they aren't really
> scratching my itch.

GUIs, by their nature, are not designed to be automated.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread Chris Angelico
On Fri, Jul 1, 2016 at 8:27 AM, Lawrence D’Oliveiro
 wrote:
> On Friday, July 1, 2016 at 7:22:43 AM UTC+12, Maitland Montmorency wrote:
>> I'd like to use Python to do some simple OSX GUI manipulations such as
>> automatically arranging windows, periodically refreshing applications
>> across multiple desktops, etc..
>>
>> I have tried to learn Applescript and Automator but they aren't really
>> scratching my itch.
>
> GUIs, by their nature, are not designed to be automated.

Doesn't mean they can't be! Ultimately, GUIs are just code, same as
everything else is, and code can be automated. On my Linux box (Debian
with Xfce), I've automated several aspects of the GUI, including
making certain windows "sticky" (ie visible regardless of which
workspace I'm on), and displaying crucial information in appropriate
places.

That said, though, there aren't always Python bindings for these sorts
of facilities. I end up calling on subprocesses most of the time,
because that's the easiest way to do things.

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


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 1:09:31 AM UTC+12, Christian Gollwitzer wrote:
> Github makes that extremely easy, just create an account, create a repo, 
> "git pull" and start working. Your incremental changes will be updated 
> with each "git push".

I start with “git init” and never pull, only push.

I do use “git fetch && git rebase origin/master master” to copy from upstream 
repos to mine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Chris Angelico
On Fri, Jul 1, 2016 at 9:06 AM, Lawrence D’Oliveiro
 wrote:
> On Friday, July 1, 2016 at 1:09:31 AM UTC+12, Christian Gollwitzer wrote:
>> Github makes that extremely easy, just create an account, create a repo,
>> "git pull" and start working. Your incremental changes will be updated
>> with each "git push".
>
> I start with “git init” and never pull, only push.

Same here, and I recommend it to my students because GitHub, when
looking at a completely empty repo (no commits at all) will give a
handy set of copy/paste-ready commands to add a remote and push. But
ultimately, it comes to the same thing.

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


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 10:35:42 AM UTC+12, Chris Angelico wrote:
>
> On Fri, Jul 1, 2016 at 8:27 AM, Lawrence D’Oliveiro wrote:
>>
>> GUIs, by their nature, are not designed to be automated.
> 
> Doesn't mean they can't be!

It’s more trouble than it’s worth. Different (even minor) versions of the 
program will move UI elements around. Things that look and behave like buttons 
might have underlying code that is not quite the same as that for buttons. 
There will be subtle timing issues, where something doesn’t quite get enabled 
in time for your script to click on it. You will suffer mysterious intermittent 
problems, where a sequence works one time but not another time.

Again: GUIs are for manual operations to be performed by humans. For 
automation, you need a function-based scripting API and a command line.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Random832
On Thu, Jun 30, 2016, at 19:06, Lawrence D’Oliveiro wrote:
> On Friday, July 1, 2016 at 1:09:31 AM UTC+12, Christian Gollwitzer wrote:
> > Github makes that extremely easy, just create an account, create a repo, 
> > "git pull" and start working. Your incremental changes will be updated 
> > with each "git push".
> 
> I start with “git init” and never pull, only push.
> 
> I do use “git fetch && git rebase origin/master master” to copy from
> upstream repos to mine.

In context, I assume that by "pull" he actually meant "clone". But,
yeah, git pull is mostly an attractive nuisance for environments that
have a clear hierarchy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread Maitland Montmorency
On Thursday, June 30, 2016 at 3:35:42 PM UTC-7, Chris Angelico wrote:
> On Fri, Jul 1, 2016 at 8:27 AM, Lawrence D’Oliveiro
>  wrote:
> > On Friday, July 1, 2016 at 7:22:43 AM UTC+12, Maitland Montmorency wrote:
> >> I'd like to use Python to do some simple OSX GUI manipulations such as
> >> automatically arranging windows, periodically refreshing applications
> >> across multiple desktops, etc..
> >...
> > GUIs, by their nature, are not designed to be automated.
> 
> Doesn't mean they can't be! Ultimately, GUIs are just code, ...
> ChrisA


Thanks, everyone!  I'll go read about PyObjC.  I'm not sure if I have the chops 
to take advantage of it but it looks like the bridge into Apple's development 
environment I'm seeking.

GUI automation: Good catch on the wording.  I perhaps should have said GUI 
element manipulation instead.  I like my Mac a great deal but there are some 
aspects of the Windows interface that I miss; e.g. tile or cascade all windows 
with a single click.  So, I thought I would try my hand at doing it through 
Python vs. using canned Applescripts.

>>> Seeking FMs to RT, so to speak. 

Chris A interpreted it perfectly.  Often the hardest part of the problem is 
knowing how to ask for the manual whose name you don't even know...

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


Find a file

2016-06-30 Thread tdsperth
Hi All

I have a web app that allows me to choose a file - the file name is returned 
but I need 
to find the path to the file so I can add it as an attachment to a email.

The files I am returning could be in different folders/directories.

Thanks for any help.

Cheers

Colin

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


Lost in descriptor land

2016-06-30 Thread Ankush Thakur
Hello,

There's something I don't understand about descriptors. On a StackOverflow 
discussion 
(http://stackoverflow.com/questions/12846116/python-descriptor-vs-property) one 
of the answers provides the following descriptors example:

class Celsius( object ):
def __init__( self, value=0.0 ):
self.value= float(value)
def __get__( self, instance, owner ):
return self.value
def __set__( self, instance, value ):
self.value= float(value)

class Temperature( object ):
celsius= Celsius()
farenheit= Farenheit()

... and then gets chided in the comments:

"I believe your descriptor implementation of celsius is not correct. You should 
have set the celsius on instance rather than self; If you create two 
Temperature objects they will share the same celsius value."

Overall, I have two problems:
1) I don't get the idea behind the 'instance' and 'owner' parameters at all. Is 
there some simple tutorial that can explain these?
2) I don't understand the motivation behind the comment. Of course declaring a 
class variable would cause celcius to be the same for all objects. Shouldn't we 
be instead using self.celcius in, say, __init__() and then everything will work 
fine?

I have seen examples 
(http://programeveryday.com/post/an-introduction-to-python-descriptors/) where 
"instance" is used as keys of a dictionary, but given my argument above, isn't 
this approach an overkill?

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


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Steven D'Aprano
On Thu, 30 Jun 2016 11:09 pm, Christian Gollwitzer wrote:

> The best place these days to publish software is on github.


http://nedbatchelder.com/blog/201405/github_monoculture.html





-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Lost in descriptor land

2016-06-30 Thread Ian Kelly
On Thu, Jun 30, 2016 at 7:06 PM, Ankush Thakur
 wrote:
> Hello,
>
> There's something I don't understand about descriptors. On a StackOverflow 
> discussion 
> (http://stackoverflow.com/questions/12846116/python-descriptor-vs-property) 
> one of the answers provides the following descriptors example:
>
> class Celsius( object ):
> def __init__( self, value=0.0 ):
> self.value= float(value)
> def __get__( self, instance, owner ):
> return self.value
> def __set__( self, instance, value ):
> self.value= float(value)
>
> class Temperature( object ):
> celsius= Celsius()
> farenheit= Farenheit()
>
> ... and then gets chided in the comments:
>
> "I believe your descriptor implementation of celsius is not correct. You 
> should have set the celsius on instance rather than self; If you create two 
> Temperature objects they will share the same celsius value."

That criticism is accurate. "self" above refers to the Celsius
instance, and there is only one Celsius instance for the Temperature
class, not one per Temperature instance.

> Overall, I have two problems:
> 1) I don't get the idea behind the 'instance' and 'owner' parameters at all. 
> Is there some simple tutorial that can explain these?

First of all, do you understand what descriptors are? This is a fairly
advanced Python concept. For a general tutorial, I would point you to
https://docs.python.org/3/howto/descriptor.html

Whereas the self argument refers to the Celsius instance, the instance
argument refers to the instance of the object currently being accessed
through the descriptor protocol. That is, the object that the Celsius
descriptor is implementing a property of. Using the above example, if
I were to write:

temp = Temperature()
print(temp.celsius)

The access of temp.celsius will cause Celsius.__get__ to be called,
and the value of instance for that call will be temp

The owner argument is the class that this Celsius instance is a
descriptor of. Normally that is just type(instance); however it is
possible to invoke the __get__ method on the class object itself
rather than on an instance, in which case owner is (still) the class
object but instance is None.

> 2) I don't understand the motivation behind the comment. Of course declaring 
> a class variable would cause celcius to be the same for all objects. 
> Shouldn't we be instead using self.celcius in, say, __init__() and then 
> everything will work fine?

It's not clear to me what alternative you're proposing. The reason
celsius is declared on the class is because it's a descriptor, and
descriptors implement properties of classes. Setting an instance
attribute to a descriptor won't accomplish anything.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Ben Finney
Christian Gollwitzer  writes:

> The best place these days to publish software is on github.

For what value of “best”?

If one wants to avoid vendor lock-in, Github is not best: the workflow
tools (other than Git itself) are completely closed and not available
for implementation on another vendor's servers.

If one wants to communicate equally with Git repositories elsewhere,
GitHub is not best: federation between hosts is actively discouraged by
the lock-in.

If one wants to build a community on tools owned by that community,
GitHub is not best.

If one wants to teach newcomers with tools that will still be working
even when GitHub goes out of business, GitHub is not best.

If one wants to grow software freedom, Github is not best
https://mako.cc/writing/hill-free_tools.html>.

Convenience is not a reliable measure of how good something is, so it is
not the best measure of “best”.

-- 
 \ “For myself, I am an optimist — it does not seem to be much use |
  `\  being anything else.” —Winston Churchill, 1954-11-09 |
_o__)  |
Ben Finney

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


Re: Iteration, while loop, and for loop

2016-06-30 Thread jfong
Steven D'Aprano at 2016/6/30 7:59:40AM wrote:
> py> mi = list('bananas')
> py> for char in mi:
> ... if char == 'a':
> ... mi.extend(' yum')
> ... print(char, end='')
> ... else:  # oh no, the feared for...else!
> ... # needed to prevent the prompt overwriting the output
> ... print()
> ...
> bananas yum yum yum
> py> 
> 
> 
> This example shows two things:
... 
> (2) Anyone who says that for...else without break is useless is wrong.

Haha...you win.

By the way, I never said "else" without "break" is illegal or useless, I said 
it will cause confusion semantically, just like this(it reminds me the IOCCC:-):

import math
pass
import os
pass
import sys 

Think of the "try ...except ...else ..." where the situation is similar but 
luckily it was mandatory.

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


Creating a calculator

2016-06-30 Thread Elizabeth Weiss
while True:
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter 'subtract' to subtract two numbers")
print("Enter 'multiply' to multiply two numbers")
print("Enter 'divide' to divide two numbers")
print("Enter 'quit' to end the program")
user_input=input(":")
if user_input=="quit":
break
elif user_input=="add":
num1=float(input("Enter a number"))
num2=float(input("Enter another number"))
result=str(num1+num2)
print("The answer is"+ result)
elif user_input=="subtract":
num1=float(input("Enter a number"))
num2=float(input("Enter another number"))
result=str(num1-num2)
print("The answer is"+result)

Two questions:
1. Why do I need to put ' ' around the words add, subtract, multiply, quit, 
etc. when it is already in quotes in print()? When the calculator asks me which 
option I would like to choose I do not write 'add'- I only write add. 

2. The program I am using to help me learn python mentions that the output line 
could be put outside the if statements to omit repetition of code. What does 
this mean and how would I write the code differently according to this?

Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lost in descriptor land

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 1:06:12 PM UTC+12, Ankush Thakur wrote:

> There's something I don't understand about descriptors.

There’s a lot to not understand about them. :)

Every time I feel unsure, I go back to the horse’s mouth: here 

 is GvR himself with all the details on “new-style” classes, including the 
clearest explanation I have come across about descriptors.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a calculator

2016-06-30 Thread Michael Torrie
On 06/30/2016 09:08 PM, Elizabeth Weiss wrote:
> while True:
>   print("Options:")
>   print("Enter 'add' to add two numbers")
>   print("Enter 'subtract' to subtract two numbers")
>   print("Enter 'multiply' to multiply two numbers")
>   print("Enter 'divide' to divide two numbers")
>   print("Enter 'quit' to end the program")
>   user_input=input(":")
>   if user_input=="quit":
>   break
>   elif user_input=="add":
>   num1=float(input("Enter a number"))
>   num2=float(input("Enter another number"))
>   result=str(num1+num2)
>   print("The answer is"+ result)
>   elif user_input=="subtract":
>   num1=float(input("Enter a number"))
>   num2=float(input("Enter another number"))
>   result=str(num1-num2)
>   print("The answer is"+result)
> 
> Two questions:
> 1. Why do I need to put ' ' around the words add, subtract, multiply, quit, 
> etc. when it is already in quotes in print()? When the calculator asks me 
> which option I would like to choose I do not write 'add'- I only write add. 

I think those extra quotes are just to make the output stand out when
it's printed to the screen so that the user knows that the word in
quotes is the special word they will need to type in.  It's much like
how things are quoted in literature.

Since the string is already inside of double quotes, the inner single
quotes simply get printed.  And if you wanted to print real double
quotes to the screen, you can surround the string with single quotes.
Either works, depending on which quote character you want to actually
print to the screen.

Here's examples using the interactive python prompt:
>>> print ('He said, "How are you?"')
He said, "How are you?"
>>> print ("In British books one might say, 'How are you?'")
In British books one might say, 'How are you?'

Hope this helps.

> 
> 2. The program I am using to help me learn python mentions that the output 
> line could be put outside the if statements to omit repetition of code. What 
> does this mean and how would I write the code differently according to this?

It means that since each of the elif blocks does something that needs to
be printed out, and if it's being printed out the same way by each, then
you can just stick it at the end of the if processing block so that it
always runs regardless of which elif block did the computation.  Though
in your code example this isn't strictly true, since if the input was
not "add" or "subtract" then there is no result to print.  At least if
the code you posted was complete.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lost in descriptor land

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 1:06:12 PM UTC+12, Ankush Thakur wrote:
> 1) I don't get the idea behind the 'instance' and 'owner' parameters at
> all. Is there some simple tutorial that can explain these?

Read the GvR blog post I referenced separately. Then after that, the relevant 
section of the language reference 
 should make a 
little bit more sense.

Remember, a descriptor has its own class. You can have multiple instances of 
this class attached to the same owner class. The actual values you want each 
descriptor instance to get and set are attached to *instances* of the owner 
class.

> Shouldn't we be instead using self.celcius in, say, __init__() and then
> everything will work fine?

I guess it might. But this way, using descriptors, all the setup is done once 
at class definition, rather then every time in class instantiation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Controlling the Mac OSX GUI via Python?

2016-06-30 Thread Christian Gollwitzer

Am 01.07.16 um 01:12 schrieb Lawrence D’Oliveiro:

On Friday, July 1, 2016 at 10:35:42 AM UTC+12, Chris Angelico wrote:


On Fri, Jul 1, 2016 at 8:27 AM, Lawrence D’Oliveiro wrote:


GUIs, by their nature, are not designed to be automated.


Doesn't mean they can't be!


It’s more trouble than it’s worth. Different (even minor) versions of
the program will move UI elements around. Things that look and behave
like buttons might have underlying code that is not quite the same as
that for buttons. There will be subtle timing issues, where something
doesn’t quite get enabled in time for your script to click on it. You
will suffer mysterious intermittent problems, where a sequence works
one time but not another time.


I think you misunderstood the request. Yes, simulating mouse clicks with 
fixed coordinates etc. is prone to such failure, but there are better 
methods. These mouse clicks and keyboard events usually trigger a method 
call inside the GUI program. If there are any means to call that method 
directly, you are independent from the graphics itself.


These bindings then usually call some higher-level functions. Many 
applications export their internal structure via some general 
communications mechanism. On Windows, COM is such a mechanism, CORBA is 
another one, and on the Mac that are Apple Events. AppleScript is a 
Mac-specific (strange) language which allows you to send arbitrary Apple 
events to applications. This has nothing to do with simulating mouse 
clicks. A deprecated Python package is found here:


http://appscript.sourceforge.net/py-appscript/

If you look at the first example:
app('TextEdit').documents['ReadMe'].paragraphs[1].get()

its immediately clear that this is on a very different level than 
simulating Copy/Paste using the mouse to get the first paragraph. 
According to my Google-Fu, howver, py-appscript stopped working with 
some OSX update. One possibility would be to send the equivalent 
applescript to the "osascript" program via subprocess.



Again: GUIs are for manual operations to be performed by humans. For
automation, you need a function-based scripting API and a command
line.


Yes and no. Sometimes GUIs export an API which is just not obvious to 
the user, sometimes they have an internal structure which can be exploited.


Christian


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


Re: Find a file

2016-06-30 Thread Karim



On 01/07/2016 02:51, tdspe...@gmail.com wrote:

Hi All

I have a web app that allows me to choose a file - the file name is returned 
but I need
to find the path to the file so I can add it as an attachment to a email.

The files I am returning could be in different folders/directories.

Thanks for any help.

Cheers

Colin


Hello,

I did this almost equivalent unix find command in python it is 
documented, it is a generator. If it could help you:


import os
from os.path import join as jp, normpath as np

def find(dirs, filenames=None, exts=None, exclude_dirs=None, 
exclude_filenames=None, followlinks=False):

""" Equivalent to the unix/linux find shell command.

@param dirsthe top directories where to search. 
Could be a simple string.

   Default to current directory '.'.

@param filenames   the searched file names. Could be a 
simple string.


@param extsan additional parameter to search files 
by its extension.

   Could be cumulative with the filenames

@param exclude_dirsa filter to exclude given top 
directories from the search process.

   Coud be a simple string.

@param exclude_filenames   a filter to bypass certain files by its 
name.
   Useful when using a search by file 
extension.

   Could be a simple string.

@param followlinks a boolean to specify whether to follow
   symbolic links to subdirectories. 
Defaulted to False.



@return a generator data which provides the found file one after 
another.

"""
if not filenames and not exts:
raise ValueError('The list of searched files and the list of 
searched file extensions could not be both empty!')


if filenames is None:
filenames = ''
if exts is None:
exts  = ''
if exclude_dirs is None:
exclude_dirs  = ''
if exclude_filenames is None:
exclude_filenames =  ''

# Default value
if not dirs:
dirs = tuple(('.',))

if isinstance(dirs, str):
dirs  = tuple((dirs,))
if isinstance(filenames, str):
filenames = tuple((filenames,))
if isinstance(exts, str):
exts  = tuple((exts,))
if isinstance(exclude_dirs, str):
exclude_dirs  = tuple((exclude_dirs,))
if isinstance(exclude_filenames, str):
exclude_filenames = tuple((exclude_filenames,))

# The search.
for d in dirs:
for dirpath, dirnames, fnames in os.walk(d, 
followlinks=followlinks):

# Filtering unwanted top directories.
for d in exclude_dirs:
if d in dirnames:
dirnames.remove(d)
# Search for file names or extensions
for f in fnames:
file_extension = os.path.splitext(f)[-1][1:] # 
extension without the dot!
if f in filenames or (file_extension in exts and f not 
in exclude_filenames):

yield jp(dirpath, f)


if __name__ == '__main__':
   #print(np('\n'.join(find(dirs='.', exts='li', 
exclude_filenames='cds.li'

   # Test
   l = tuple(find(dirs='.', filenames='cds.lib'))

   print('\n'.join(l))

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


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Christian Gollwitzer

Am 01.07.16 um 03:38 schrieb Ben Finney:

Christian Gollwitzer  writes:


The best place these days to publish software is on github.


For what value of “best”?


The question was about visibility of a project for a single beginner 
developer.



If one wants to avoid vendor lock-in, Github is not best: the workflow
tools (other than Git itself) are completely closed and not available
for implementation on another vendor's servers.


Yes, but that is relevant only if the workflow (i.e. pull requests) are 
an important part of the history. The code history is just git and that 
is independent from github. For projects which rely on a single 
developer, there is no issue. Additionally I wanted to point out that 
"finishing" a project is the wrong idea, at least in open source terms.



If one wants to communicate equally with Git repositories elsewhere,
GitHub is not best: federation between hosts is actively discouraged by
the lock-in.


I don't understand what that means. I can git pull my local repo from 
somewhere else and then git push it to github. What do you mean by 
federation between hosts?



If one wants to teach newcomers with tools that will still be working
even when GitHub goes out of business, GitHub is not best.


? git will not stop working


If one wants to grow software freedom, Github is not best
https://mako.cc/writing/hill-free_tools.html>.

Convenience is not a reliable measure of how good something is, so it is
not the best measure of “best”.


Then please propose an alternative instead of just arguing. Make sure 
you try to understand the OPs objectives and background.


Christian


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


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Christian Gollwitzer

Am 01.07.16 um 01:16 schrieb Random832:

On Thu, Jun 30, 2016, at 19:06, Lawrence D’Oliveiro wrote:

On Friday, July 1, 2016 at 1:09:31 AM UTC+12, Christian Gollwitzer wrote:

Github makes that extremely easy, just create an account, create a repo,
"git pull" and start working. Your incremental changes will be updated
with each "git push".


I start with “git init” and never pull, only push.

I do use “git fetch && git rebase origin/master master” to copy from
upstream repos to mine.


In context, I assume that by "pull" he actually meant "clone".


Yes, sorry, I meant clone.

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


Re: Creating a calculator

2016-06-30 Thread Jussi Piitulainen
DFS writes:

> Here's a related program that doesn't require you to tell it what type
> of operation to perform.  Just enter 'num1 operator num2' and hit
> Enter, and it will parse the entry and do the math.
>
> ---
> ui=raw_input('Enter calculation to perform: ')
> n1=float(ui.split(' ')[0])
> op=ui.split(' ')[1]
> n2=float(ui.split(' ')[2])
> if op=='+':c=n1+n2
> if op=='-':c=n1-n2
> if op=='*':c=n1*n2
> if op=='/':c=n1/n2
> print(ui+' = '+str(c))
> ---

I use multiple assignment a lot, like this:

n1, op, n2 = ui.split()

It's not only compact, it also crashes if there are more elements than
expected, and I want it to crash when that happens. Or rather, I prefer
a crash to silence when input is bad.

For the calculator, it may be better to split on any whitespace and
discard empty strings, which is what ui.split() does. Splitting on a
single space seems unnecessarily strict in a calculator (whereas
splitting on a single tab is what I very much do in my work - the data
formats are such).

I think multiple assignment is good even for a beginner. Perhaps do it a
second time straight away:

n1, op, n2 = ui.split()
n1, n2 = float(n1), float(n2)

But it's only with the split where it really pays.

n1, op, n2 = ui.split()
n1 = float(n1)
n2 = float(n2)

The latter might be even preferable. Hm.

n1, n2 = map(float, (n1, n2))

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


Re: Were is a great place to Share your finished projects?

2016-06-30 Thread Lawrence D’Oliveiro
On Friday, July 1, 2016 at 1:39:04 PM UTC+12, Ben Finney wrote:
> Christian Gollwitzer writes:
> 
>> The best place these days to publish software is on github.
> 
> For what value of “best”?
> 
> If one wants to avoid vendor lock-in, Github is not best: the workflow
> tools (other than Git itself) are completely closed and not available
> for implementation on another vendor's servers.

That’s (mostly) OK. Git is what I mainly want it for anyway.

> If one wants to communicate equally with Git repositories elsewhere,
> GitHub is not best: federation between hosts is actively discouraged by
> the lock-in.

I can add as many remotes to my Git repos as I like, pointing to servers 
wherever I like, so I guess it’s not that bad.
-- 
https://mail.python.org/mailman/listinfo/python-list