Re: How to extend a tuple of tuples?

2016-09-13 Thread Antoon Pardon
Op 12-09-16 om 23:29 schreef Chris Angelico:
> On Tue, Sep 13, 2016 at 7:19 AM, BartC  wrote:
>> By the same argument, then strings and ints are also mutable.
>>
>> Here, the original tuple that a refers to has been /replaced/ by a new one.
>> The original is unchanged. (Unless, by some optimisation that recognises
>> that there are no other references to it, the original is actually appended
>> to. But in general, new objects are constructed when implementing +=.)
> And by definition, that optimization cannot be detected. At best, all
> you could do is something like:
>
> old_id = id(a)
> a += something
> if id(a) == old_id:
> print("We may have an optimization, folks!")
>
> But that can have false positives. If two objects do not concurrently
> exist, they're allowed to have the same ID number.

You could do the following:

old_a = a
a += something
if old_a is a:
print("We have an optimization, folks!")

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


Re: [Python-ideas] Inconsistencies

2016-09-13 Thread Marko Rauhamaa
Rustom Mody :

> And in the same vein, a non-messianic interpretation of the core
> Christian teaching:
> http://themindunleashed.org/2015/11/you-are-god-the-true-teachings-of-jesus.html

The link's message ("You are God") comes close to theosis (https://en.wikipedia.org/wiki/Theosis_(Eastern_Orthodox_theology)>) and
divinization (https://en.wikipedia.org/wiki/Divinization_(Christian)>) but mostly
looks like somebody's ad hoc private theology.

My own take on Jesus's message (apart from establishing a theocratic
state in Palestine) is: the only valid way to worship God is by serving
your fellow human beings.

ObTopic:

Now the serpent was more crafty than any of the wild animals the
Lord God had made. [Gen 3:1]


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


Re: How to extend a tuple of tuples?

2016-09-13 Thread Chris Angelico
On Tue, Sep 13, 2016 at 5:25 PM, Antoon Pardon
 wrote:
> Op 12-09-16 om 23:29 schreef Chris Angelico:
>> On Tue, Sep 13, 2016 at 7:19 AM, BartC  wrote:
>>> By the same argument, then strings and ints are also mutable.
>>>
>>> Here, the original tuple that a refers to has been /replaced/ by a new one.
>>> The original is unchanged. (Unless, by some optimisation that recognises
>>> that there are no other references to it, the original is actually appended
>>> to. But in general, new objects are constructed when implementing +=.)
>> And by definition, that optimization cannot be detected. At best, all
>> you could do is something like:
>>
>> old_id = id(a)
>> a += something
>> if id(a) == old_id:
>> print("We may have an optimization, folks!")
>>
>> But that can have false positives. If two objects do not concurrently
>> exist, they're allowed to have the same ID number.
>
> You could do the following:
>
> old_a = a
> a += something
> if old_a is a:
> print("We have an optimization, folks!")
>

Uhm... that defeats the whole point of it being an optimization. See
above, "there are no other references to it". :)

If this condition is ever true, Python's language spec has been violated.

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


Re: How to extend a tuple of tuples?

2016-09-13 Thread Antoon Pardon
Op 13-09-16 om 11:27 schreef Chris Angelico:
> On Tue, Sep 13, 2016 at 5:25 PM, Antoon Pardon
>  wrote:
>> Op 12-09-16 om 23:29 schreef Chris Angelico:
>>> On Tue, Sep 13, 2016 at 7:19 AM, BartC  wrote:
 By the same argument, then strings and ints are also mutable.

 Here, the original tuple that a refers to has been /replaced/ by a new one.
 The original is unchanged. (Unless, by some optimisation that recognises
 that there are no other references to it, the original is actually appended
 to. But in general, new objects are constructed when implementing +=.)
>>> And by definition, that optimization cannot be detected. At best, all
>>> you could do is something like:
>>>
>>> old_id = id(a)
>>> a += something
>>> if id(a) == old_id:
>>> print("We may have an optimization, folks!")
>>>
>>> But that can have false positives. If two objects do not concurrently
>>> exist, they're allowed to have the same ID number.
>> You could do the following:
>>
>> old_a = a
>> a += something
>> if old_a is a:
>> print("We have an optimization, folks!")
>>
> Uhm... that defeats the whole point of it being an optimization. See
> above, "there are no other references to it". :)

What do you mean? If it is an optimization, then the object a refers to
will be mutated, whether or not there are other references. These other
reference will all still refer to the same object that is now mutated.

So how does my example defeats the point of it being an optimization?

> If this condition is ever true, Python's language spec has been violated.
>
Then python seems to be broken:

]]] a = range(3)
]]] old_a = a
]]] a += [8, 13]
]]] id(a), id(old_a)
(140062018784792, 140062018784792)
]]] a, old_a
([0, 1, 2, 8, 13], [0, 1, 2, 8, 13])

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


Re: How to extend a tuple of tuples?

2016-09-13 Thread Chris Angelico
On Tue, Sep 13, 2016 at 8:01 PM, Antoon Pardon
 wrote:
>>> You could do the following:
>>>
>>> old_a = a
>>> a += something
>>> if old_a is a:
>>> print("We have an optimization, folks!")
>>>
>> Uhm... that defeats the whole point of it being an optimization. See
>> above, "there are no other references to it". :)
>
> What do you mean? If it is an optimization, then the object a refers to
> will be mutated, whether or not there are other references. These other
> reference will all still refer to the same object that is now mutated.

The language spec says that tuples are immutable. If there's an
optimization, it is pretending that the tuple is immutable if and only
if there are no other references to that object. But old_a is another
reference to that object!

> So how does my example defeats the point of it being an optimization?
>
>> If this condition is ever true, Python's language spec has been violated.
>>
> Then python seems to be broken:
>
> ]]] a = range(3)
> ]]] old_a = a
> ]]] a += [8, 13]
> ]]] id(a), id(old_a)
> (140062018784792, 140062018784792)
> ]]] a, old_a
> ([0, 1, 2, 8, 13], [0, 1, 2, 8, 13])

A range object is not a tuple. Nor (since you were probably running
this in Python 2) is a list.

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


Re: [RELEASE] Python 3.6.0b1 is now available

2016-09-13 Thread Lele Gaifax
Ned Deily  writes:

> On behalf of the Python development community and the Python 3.6 release
> team, I'm happy to announce the availability of Python 3.6.0b1.

Kudos to everybody involved!

> Among the new major new features in Python 3.6 are:
>
> * PEP 468 - Preserving the order of **kwargs in a function

Yay! I wish I could borrow Guido's time machine to go back to my early effort
on PyObjC, and take advantage of this feature to implement a nicer looking
syntax to expose ObjC methods to Python (instead of hardwiring the information
in the function name)!

I recall we had a very brief exchange on this at the time, and I event spent a
few days trying a quick&dirty approach (basically passing also the ordered
list of keywords...).

Anyway, we are in a new millenium now, and two major versions forward! ;-)

Thank you all,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Global variable is undefined at the module level

2016-09-13 Thread Daiyue Weng
Hi, I defined a global variable in some function like this,

def some_function(self):

 global global_var

PyCharm inspection gave me,

Global variable is undefined at the module level

How to fix this?

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


Re: How to extend a tuple of tuples?

2016-09-13 Thread Sibylle Koczian

Am 13.09.2016 um 12:09 schrieb Chris Angelico:

On Tue, Sep 13, 2016 at 8:01 PM, Antoon Pardon
 wrote:



Then python seems to be broken:

]]] a = range(3)
]]] old_a = a
]]] a += [8, 13]
]]] id(a), id(old_a)
(140062018784792, 140062018784792)
]]] a, old_a
([0, 1, 2, 8, 13], [0, 1, 2, 8, 13])


A range object is not a tuple. Nor (since you were probably running
this in Python 2) is a list.



Not probably, certainly (if it wasn't Python 1):

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 
bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.
>>> a = range(3)
>>> a += [8, 13]
Traceback (most recent call last):
  File "", line 1, in 
a += [8, 13]
TypeError: unsupported operand type(s) for +=: 'range' and 'list'
>>>



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


Expected type 'optional[bytes]' got 'str' instead

2016-09-13 Thread Daiyue Weng
Hi, I have the following piece of code,

rootPath = os.path.abspath(__file__)

rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0]


PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit,

Expected type 'optional[bytes]' got 'str' instead


If I changed it to,

rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit(b'\\', 1)[0]

Python game me errors,

TypeError: Can't convert 'bytes' object to str implicitly

How to fix it?


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


Re: Expected type 'optional[bytes]' got 'str' instead

2016-09-13 Thread Chris Angelico
On Tue, Sep 13, 2016 at 9:06 PM, Daiyue Weng  wrote:
> Hi, I have the following piece of code,
>
> rootPath = os.path.abspath(__file__)
>
> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0]
>
>
> PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit,
>
> Expected type 'optional[bytes]' got 'str' instead
>

Well, the first thing I'd do is use os.path.split instead of rsplit :)
Or alternatively, os.path.join using dot-dot. And if that's not
sufficient, I'd reach for pathlib.

Whichever way I do it, I would *not* mix bytes paths and str paths.

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


Re: Expected type 'optional[bytes]' got 'str' instead

2016-09-13 Thread Chris Angelico
On Tue, Sep 13, 2016 at 9:19 PM, Daiyue Weng  wrote:
> Could you give me an example of doing this using os.path.split and
> os.path.join?
>
> thanks

Sure, but I'm keeping this on list.

os.path.split basically does the same thing you do.

# maintaining your non-PEP-8 names
rootPath = os.path.abspath(__file__)
rootPath = os.path.split(os.path.split(rootPath)[0])[0]

os.path.join simply joins pieces together, so you could join a couple
of ".." to your path.

rootPath = os.path.abspath(os.path.join(__file__, "..", ".."))

Advantage: They don't depend on backslashes in file paths, so they'll
work on all platforms.

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


Re: Expected type 'optional[bytes]' got 'str' instead

2016-09-13 Thread Peter Otten
Daiyue Weng wrote:

> Hi, I have the following piece of code,
> 
> rootPath = os.path.abspath(__file__)
> 
> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit('\\', 1)[0]
> 
> 
> PyCharm inspection gave me warning on argument '\\' of the 2nd rsplit,
> 
> Expected type 'optional[bytes]' got 'str' instead
> 
> 
> If I changed it to,
> 
> rootPath = (rootPath.rsplit('\\', 1)[0]).rsplit(b'\\', 1)[0]
> 
> Python game me errors,
> 
> TypeError: Can't convert 'bytes' object to str implicitly
> 
> How to fix it?

Do you use Python 2 or 3? 

Is your version the one PyCharm expects and supports? If yes, consider 
filing a bug report (for PyCharm, not Python).

You should of course still follow Chris' advice and use os.path to 
manipulate file paths.

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


Re: Global variable is undefined at the module level

2016-09-13 Thread Peter Otten
Daiyue Weng wrote:

> Hi, I defined a global variable in some function like this,
> 
> def some_function(self):
> 
>  global global_var
> 
> PyCharm inspection gave me,
> 
> Global variable is undefined at the module level

There is no single way to silence that complaint and actually improve your 
code; you have to provide some context: Why do you need a global at all, why 
can't you (or don't want to) bind it on the module level etc.

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


Re: Global variable is undefined at the module level

2016-09-13 Thread Ned Batchelder
On Tuesday, September 13, 2016 at 6:42:56 AM UTC-4, Daiyue Weng wrote:
> Hi, I defined a global variable in some function like this,
> 
> def some_function(self):
> 
>  global global_var
> 
> PyCharm inspection gave me,
> 
> Global variable is undefined at the module level
> 
> How to fix this?

It probably wants you to have a line at the top-level of the module (outside of 
any function) defining the variable:

global_var = None   # or some other default value

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


Re: Global variable is undefined at the module level

2016-09-13 Thread dieter
Daiyue Weng  writes:

> Hi, I defined a global variable in some function like this,
>
> def some_function(self):
>
>  global global_var
>
> PyCharm inspection gave me,
>
> Global variable is undefined at the module level
>
> How to fix this?

You define the global variable at the module level.

"global VVV" (in a function) actually does not define "VVV"
as a global variable. Instead, it tells the interpreter that
"VVV" should not be treated as a local variable but be looked up
in the "global" (usually module) namespace.

In order to define "VVV", you must assign a value to it -- either
directly in the "global" (i.e. module) namespace or in your function
(together with a "global VVV" declaration).

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


Re: How to extend a tuple of tuples?

2016-09-13 Thread Random832
On Mon, Sep 12, 2016, at 17:29, Chris Angelico wrote:
> old_id = id(a)
> a += something
> if id(a) == old_id:
> print("We may have an optimization, folks!")
> 
> But that can have false positives. If two objects do not concurrently
> exist, they're allowed to have the same ID number.

But the two objects do concurrently exist, from the time __iadd__ is
evaluated until the time when a is assigned, in the formal semantics of
this code. Allowing them to not concurrently exist is, effectively,
precisely the optimization being discussed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python inner function parameter shadowed

2016-09-13 Thread Daiyue Weng
Hi, I am using inner function like this,

def timeit(func=None, loops=1, verbose=False):
if func is not None:
def inner(*args, **kwargs):

# some code

return inner
else:
def partial_inner(func):
return timeit(func, loops, verbose)

return partial_inner


PyCharm warns about "Shadows name 'func' from outer scope" on

def partial_inner(func):

How to fix it?

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


Re: Python inner function parameter shadowed

2016-09-13 Thread Chris Angelico
On Wed, Sep 14, 2016 at 2:34 AM, Daiyue Weng  wrote:
> Hi, I am using inner function like this,
>
> def timeit(func=None, loops=1, verbose=False):
> if func is not None:
> def inner(*args, **kwargs):
>
> # some code
>
> return inner
> else:
> def partial_inner(func):
> return timeit(func, loops, verbose)
>
> return partial_inner
>
>
> PyCharm warns about "Shadows name 'func' from outer scope" on
>
> def partial_inner(func):
>
> How to fix it?
>
> cheers

Hmm. I think the real solution here is to separate this into two functions:

def timeit(func, loops=1, verbose=False):
def inner(*args, **kwargs):

# some code

return inner

def timeit_nofunc(loops=1, verbose=False):
def partial_inner(func):
return timeit(func, loops, verbose)
return partial_inner

But without knowing more about what you're accomplishing, I can't
really say. If you just want a quick fix to shut the linter up (note
that this is NOT a Python error, it's just a message from a linter),
you could use a different name for one of the variables.

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


Re: Python inner function parameter shadowed

2016-09-13 Thread Brendan Abel
This looks like a decorator function that optionally accepts arguments to
change the behavior.

You can safely ignore the warning form PyCharm.  the variable won't be
shadowed it's included in the function signature of the inner function.

A lot of times, the outside decorator will just use the *args or **kwargs
parameters and check whether the first arg is callable or not and if any
keywords have been passed in to decide which version of the wrapped
function to return

Here is an example:
http://stackoverflow.com/questions/653368/how-to-create-a-python-decorator-that-can-be-used-either-with-or-without-paramet

On Tue, Sep 13, 2016 at 9:40 AM, Chris Angelico  wrote:

> On Wed, Sep 14, 2016 at 2:34 AM, Daiyue Weng  wrote:
> > Hi, I am using inner function like this,
> >
> > def timeit(func=None, loops=1, verbose=False):
> > if func is not None:
> > def inner(*args, **kwargs):
> >
> > # some code
> >
> > return inner
> > else:
> > def partial_inner(func):
> > return timeit(func, loops, verbose)
> >
> > return partial_inner
> >
> >
> > PyCharm warns about "Shadows name 'func' from outer scope" on
> >
> > def partial_inner(func):
> >
> > How to fix it?
> >
> > cheers
>
> Hmm. I think the real solution here is to separate this into two functions:
>
> def timeit(func, loops=1, verbose=False):
> def inner(*args, **kwargs):
>
> # some code
>
> return inner
>
> def timeit_nofunc(loops=1, verbose=False):
> def partial_inner(func):
> return timeit(func, loops, verbose)
> return partial_inner
>
> But without knowing more about what you're accomplishing, I can't
> really say. If you just want a quick fix to shut the linter up (note
> that this is NOT a Python error, it's just a message from a linter),
> you could use a different name for one of the variables.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python inner function parameter shadowed

2016-09-13 Thread Chris Angelico
On Wed, Sep 14, 2016 at 4:28 AM, Brendan Abel <007bren...@gmail.com> wrote:
> This looks like a decorator function that optionally accepts arguments to
> change the behavior.

Oh, I get it. So, yeah, it is one function doing two jobs -
legitimately. In that case, I'd just rename one of the 'func'
arguments - probably the inner one, since that's never going to be
passed as a keyword.

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


Re: Python inner function parameter shadowed

2016-09-13 Thread Brendan Abel
Yeah, you could change the name, but it shouldn't matter, the "func" in the
inner function will always be the one passed into it, it won't be the
"func" from the outer function, which in this specific case, would always
be None (at least as far as the second inner function is concerned.)

On Tue, Sep 13, 2016 at 11:31 AM, Chris Angelico  wrote:

> On Wed, Sep 14, 2016 at 4:28 AM, Brendan Abel <007bren...@gmail.com>
> wrote:
> > This looks like a decorator function that optionally accepts arguments to
> > change the behavior.
>
> Oh, I get it. So, yeah, it is one function doing two jobs -
> legitimately. In that case, I'd just rename one of the 'func'
> arguments - probably the inner one, since that's never going to be
> passed as a keyword.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Tkinter file dialog screwed

2016-09-13 Thread kerbingamer376
The tkinter file dialog is, for me, unusable. Whenever I try to use it, it 
opens, but all the text is white on a white background (see this 
http://xomf.com/qzhgy) making it unusable. This has happened on 2 linux 
systems, both KDE plasma 5. Any help?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter file dialog screwed

2016-09-13 Thread Christian Gollwitzer

Am 13.09.16 um 22:08 schrieb kerbingamer376:

The tkinter file dialog is, for me, unusable. Whenever I try to use
it, it opens, but all the text is white on a white background (see
this http://xomf.com/qzhgy) making it unusable. This has happened on
2 linux systems, both KDE plasma 5. Any help?


Never seen that. This dialog is implemented in Tcl under X11, so maybe 
somebody from over there can help. I can imagine that it is a strange 
setting for colours in the option database. In your screenshot, I can 
see the file names in a very bright grey colour. bin, probably selected, 
is black. If you use the arrow keys to navigate the files, does it 
"highlight" the current item in black?


Best regards,

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


Re: Tkinter file dialog screwed

2016-09-13 Thread martinjp376
yes, I can make the labels turn black by selecting them with the arrow keys.
-- 
https://mail.python.org/mailman/listinfo/python-list


Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread rgrigonis
It would help newbies and prevent confusion.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread Jerry Hill
On Tue, Sep 13, 2016 at 4:57 PM,   wrote:
> It would help newbies and prevent confusion.

Are you asking why Guido didn't call it foreach back in 1989, or why
the core developers don't change it now, 27 years later?  I can't
speak for the historical perspective, but I'm sure there's basically
no chance that it will be changed now.  It would be a totally
backwards incompatible change, invalidate every tutorial and bit of
python documentation that's been written over the last three decades,
and break pretty much every python program that works today. In
exchange, you get newbies who are a slightly less confused about for
loops.  That tradeoff isn't worth it.

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


Re: Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread Ian Kelly
On Tue, Sep 13, 2016 at 2:57 PM,   wrote:
> It would help newbies and prevent confusion.

Ada uses "for".
C++11 uses "for".
Dart uses "for".
Go uses "for".
Groovy uses "for".
Java uses "for".
JavaScript uses "for".
MATLAB uses "for".
Objective-C uses "for".
Pasceal uses "for".
Perl moved from "foreach" to just "for" in Perl 6.
Ruby uses "for".
Scala uses "for".
Swift uses "for".

Why do you think it's confusing that Python uses the same keyword in
its foreach loops that all the above languages do? What mistake is
this causing newbies to make?
-- 
https://mail.python.org/mailman/listinfo/python-list


DLL Error from a beginner

2016-09-13 Thread srfpala
Running Pyscripter and  Python version 2.7.12 on Win10 Home on a 64bit Laptop
1. A simple Python application runs successfully.
2. WxPython(wxPython3.0-win64-3.0.2.0-py27(1).exe executed  successfully
3. To the simple app above, I add   import wx  and  an Error Dialog occurs:
ImportError: DLL load failed: %1 is not a valid 32 application
If I see win64 in the exe filename I think I have the correct wxPython install.
What have a done wrong ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread Grant Edwards
On 2016-09-13, Ian Kelly  wrote:
> On Tue, Sep 13, 2016 at 2:57 PM,   wrote:
>> It would help newbies and prevent confusion.
>
> Ada uses "for".
[a dozen or so other langages]
> Swift uses "for".
>
> Why do you think it's confusing that Python uses the same keyword in
> its foreach loops that all the above languages do? What mistake is
> this causing newbies to make?

One might guess that the OP is coming from PHP where there are
separate "for" and "foreach" looping constructs, and Python's "for" is
analogous to PHP's "foreach".

That said, I despise PHP so thoroughly that "because PHP does it" is,
to me, a pretty strong argument for _not_ doing something.

Even trying to ignore my bias agains PHP, I can't see that Python's
calling it "for" instead of "foreach" is going to confuse anybody with
a PHP background...

-- 
Grant Edwards   grant.b.edwardsYow! I have accepted
  at   Provolone into my life!
  gmail.com

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


Re: DLL Error from a beginner

2016-09-13 Thread Irmen de Jong
On 13-9-2016 23:59, srfp...@gmail.com wrote:
> Running Pyscripter and  Python version 2.7.12 on Win10 Home on a 64bit Laptop
> 1. A simple Python application runs successfully.
> 2. WxPython(wxPython3.0-win64-3.0.2.0-py27(1).exe executed  successfully
> 3. To the simple app above, I add   import wx  and  an Error Dialog occurs:
> ImportError: DLL load failed: %1 is not a valid 32 application
> If I see win64 in the exe filename I think I have the correct wxPython 
> install.
> What have a done wrong ?
> 



Is your python installation itself of the 64-bit kind?
Otherwise, you have to install the 32 bits wxpython library rather than the 64 
bits one
you showed us above. (Or switch to a 64 bit python implementation)


Irmen

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


Re: How to extend a tuple of tuples?

2016-09-13 Thread Thomas 'PointedEars' Lahn
John Gordon wrote:

> […] Thomas 'PointedEars' Lahn […] writes:

It is supposed to be an attribution *line*, _not_ an attribution novel.

>> >> The obvious way does not work -
>> >>
>> >> a += (5, 6)
>>  ^^
>> > Right, because a tuple is immutable.
> 
>> How did you get that idea?  It has been mutated in the very statement
>> that you are quoting
> 
> No.  An entirely new tuple is created, and 'a' is rebound to it.  The
> existing tuple is not mutated.

Indeed,

| $ python3
| Python 3.4.4 (default, Apr 17 2016, 16:02:33) 
| [GCC 5.3.1 20160409] on linux
| Type "help", "copyright", "credits" or "license" for more information.
| >>> t = ((1, 2), (3, 4))
| >>> t.__repr__
| 
| >>> t += (5, 6),
| >>> t.__repr__
| 

indicates that this is so.  However, this argument is purely academic, as 
that rebinding happens would neither validate Ben’s argument nor invalidate 
mine: The result obtained without the trailing comma is not so “because a 
tuple is immutable”, but because of how the expression RHS is parsed.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread BartC

On 13/09/2016 22:20, Ian Kelly wrote:

On Tue, Sep 13, 2016 at 2:57 PM,   wrote:

It would help newbies and prevent confusion.


Ada uses "for".
C++11 uses "for".
Dart uses "for".
Go uses "for".
Groovy uses "for".
Java uses "for".
JavaScript uses "for".
MATLAB uses "for".
Objective-C uses "for".
Pasceal uses "for".
Perl moved from "foreach" to just "for" in Perl 6.
Ruby uses "for".
Scala uses "for".
Swift uses "for".


And Fortran uses "do".

My own language uses "for", "forall" and "foreach". (Apparently PHP also 
has a choice, according to another post.)


"for" only iterates over an integer sequence. "forall" over the values 
in an object (such as a list), similar to Python. (And "foreach" breaks 
apart certain kinds of object, such as the bits in an integer, and 
iterates over those).


Probably "for", "forall" and "foreach" could be combined (perhaps with a 
conversion to drive the the kind of iteration desired), but I think it's 
useful to see "for" and /know/ it's a basic loop. It also makes it 
easier to optimise, as well as allowing a stripped-down version that 
only counts, or repeats forever).


Value Iterates over:
  For: Forall:   Foreach:
1..3  1,2,31,2,3 --
(10,20,30)1,2,310,20,30  --
"ABC" 1,2,3"A","B","C"   65,66,67   (works with both)
100   0,1,2...63   --0,0,1,0,0,1,1,0,...0

Getting back to Python, it only has one kind of for-loop and it has 
decided to call it "for". It's just one minor thing (among many) that 
has to be learned.


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


Re: Expression can be simplified on list

2016-09-13 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> […] Thomas 'PointedEars' Lahn […] wrote:
>> If I knew that it is always going to be a list or a tuple, I would check
>> its length instead:
>>
>>   if len(errors) == 0:
> 
> I wouldn't. I'd use boolification here too. Only if I had to
> distinguish between None, [], and [1,2,3], would I use a more explicit
> check (and it wouldn't be "== []", it would be probing for None).

Why (not)?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Expression can be simplified on list

2016-09-13 Thread Chris Angelico
On Wed, Sep 14, 2016 at 9:16 AM, Thomas 'PointedEars' Lahn
 wrote:
> Chris Angelico wrote:
>
>> […] Thomas 'PointedEars' Lahn […] wrote:
>>> If I knew that it is always going to be a list or a tuple, I would check
>>> its length instead:
>>>
>>>   if len(errors) == 0:
>>
>> I wouldn't. I'd use boolification here too. Only if I had to
>> distinguish between None, [], and [1,2,3], would I use a more explicit
>> check (and it wouldn't be "== []", it would be probing for None).
>
> Why (not)?

It's more Pythonic and faster. And shorter. What's not to love?

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


Re: Tkinter file dialog screwed

2016-09-13 Thread Steve D'Aprano
On Wed, 14 Sep 2016 06:08 am, kerbingamer376 wrote:

> The tkinter file dialog is, for me, unusable. Whenever I try to use it, it
> opens, but all the text is white on a white background (see this
> http://xomf.com/qzhgy) making it unusable. This has happened on 2 linux
> systems, both KDE plasma 5. Any help?


What happens if you change your KDE theme, or use another desktop
environment?




-- 
Steve
“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: Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread Steve D'Aprano
On Wed, 14 Sep 2016 06:57 am, rgrigo...@gmail.com wrote:

> It would help newbies and prevent confusion.

No it wouldn't.



Claims-which-are-made-without-evidence-can-be-rejected-without-evidence-ly y'rs,


-- 
Steve

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


Re: Expression can be simplified on list

2016-09-13 Thread Lawrence D’Oliveiro
On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote:
> Why do you object to the type conversion to bool?

It would be better if all such conversions were explicit, e.g.

if bool(«non-bool expr») :
if not bool(«non-bool expr») :

instead of

if «non-bool expr» :
if not «non-bool expr» :
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Expression can be simplified on list

2016-09-13 Thread Ben Finney
Lawrence D’Oliveiro  writes:

> On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote:
> > Why do you object to the type conversion to bool?
>
> It would be better if all such conversions were explicit

Why? It's entirely unambiguous: the expression of an ‘if’ statement *can
only be* evaluated in a Boolean context. What else could the reader
reasonably expect?

-- 
 \“When I was a baby I kept a diary. Recently I was re-reading |
  `\   it, it said ‘Day 1: Still tired from the move. Day 2: Everybody |
_o__)  talks to me like I'm an idiot.’” —Steven Wright |
Ben Finney

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


Re: Expression can be simplified on list

2016-09-13 Thread Chris Angelico
On Wed, Sep 14, 2016 at 12:25 PM, Ben Finney  wrote:
> Lawrence D’Oliveiro  writes:
>
>> On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote:
>> > Why do you object to the type conversion to bool?
>>
>> It would be better if all such conversions were explicit
>
> Why? It's entirely unambiguous: the expression of an ‘if’ statement *can
> only be* evaluated in a Boolean context. What else could the reader
> reasonably expect?

Error: Logical value not 0 or 1

That's what REXX would say if you used anything else in a boolean
context. Improvement? You be the judge.

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


Re: Python inner function parameter shadowed

2016-09-13 Thread Lawrence D’Oliveiro
On Wednesday, September 14, 2016 at 4:34:34 AM UTC+12, Daiyue Weng wrote:
> PyCharm warns about "Shadows name 'func' from outer scope"

Typical piece of software trying to be too helpful and just getting in the way.

Can you turn off such warnings?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Expression can be simplified on list

2016-09-13 Thread Lawrence D’Oliveiro
On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote:
> Lawrence D’Oliveiro writes:
> 
> > It would be better if all such conversions were explicit
> 
> Why? It's entirely unambiguous ...


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


Python reverse debugger

2016-09-13 Thread Steven D'Aprano
PyPy has recently released a reverse debugger for Python:

https://mail.python.org/pipermail/pypy-dev/2016-September/014661.html

Armin Rigo wrote:

[quote]
It is my pleasure to announce the first beta release of RevDB: a
"reverse debugger" for Python.

A reverse debugger is a debugger where you can go forward and backward
in time.  RevDB is designed to track down the annoying, hard-to-
reproduce bug in your Python program.






-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


Re: Expression can be simplified on list

2016-09-13 Thread Ben Finney
Lawrence D’Oliveiro  writes:

> On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote:
> > Lawrence D’Oliveiro writes:
> > 
> > > It would be better if all such conversions were explicit
> > 
> > Why? It's entirely unambiguous: the expression of an ‘if’ statement
> > *can only be* evaluated in a Boolean context. What else could the
> > reader reasonably expect?
>
> 

That reference supports my position: The only reasonable interpretation
of the expression specified to ‘if‘, is that it is interpreted in a
Boolean context.

The behaviour described there was a bug. Once recognised, it was fixed.
There isn't any other reasonable interpretation of the expression for
‘if’: it's interpreted as a Boolean value.

-- 
 \  “The best mind-altering drug is truth.” —Jane Wagner, via Lily |
  `\Tomlin |
_o__)  |
Ben Finney

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


Re: Expression can be simplified on list

2016-09-13 Thread Steven D'Aprano
On Wednesday 14 September 2016 12:16, Lawrence D’Oliveiro wrote:

> On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote:
>> Why do you object to the type conversion to bool?
> 
> It would be better if all such conversions were explicit, e.g.
> 
> if bool(«non-bool expr») :
> if not bool(«non-bool expr») :
> 
> instead of
> 
> if «non-bool expr» :
> if not «non-bool expr» :


Better according to what standard?

According to statically-typed languages, it's not just better, but probably 
essential, to explicitly cast or coerce values to bool.

But according to dynamically-typed languages like Python, using the second pair 
of examples is just duck-typing, where all values and objects can "quack like a 
bool". There's no need to explicitly cast an expression to bool, because the 
interpreter can do it for you as part of the truthiness protocol. Needing 
explicit casts, as you do, is as silly as these would be:


for obj in iter(expression):
...


# hypothetical built-in to convert methods to callables
result = callable(myobj.method)(arg)


only *even more so*, since implicit truthiness is expected to always succeed, 
while iter() is not.


You're perfectly entitled to dislike duck-typed truthiness. But that makes the 
majority of dynamically-typed languages (like Python, Javascript, Ruby, Lua and 
more) a bad fit for your way of thinking.



-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


Re: Expression can be simplified on list

2016-09-13 Thread Jussi Piitulainen
Lawrence D’Oliveiro writes:

> On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote:
>> Lawrence D’Oliveiro writes:
>> 
>> > It would be better if all such conversions were explicit
>> 
>> Why? It's entirely unambiguous ...
>
> 

That's the story of a time object t being false around midnight UTC,
because the class defined it to be so.

What would bool(t) be?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Expression can be simplified on list

2016-09-13 Thread Steven D'Aprano
On Wednesday 14 September 2016 13:59, Lawrence D’Oliveiro wrote:

> On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote:
>> Lawrence D’Oliveiro writes:
>> 
>> > It would be better if all such conversions were explicit
>> 
>> Why? It's entirely unambiguous ...
> 
> 


*shrug* 

And if somebody designed an iterator that behaved badly or surprisingly, would 
you conclude that the entire concept of iteration is therefore broken?

The midnight gotcha was (it has now been fixed) a design bug of the class. As 
simple as that.



-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-13 Thread Steven D'Aprano
On Monday 12 September 2016 12:26, Chris Angelico wrote:

> On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D’Oliveiro
>  wrote:
>> On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote:
>>> I have some _extremely_ strong views about absolutes (they come from the
>>> Creator of the Universe) ...
>>
>> By “Universe” do you mean “everything that exists”? So if the Creator
>> exists, then the Creator, too, must be part of the Universe.
>>
>> So whoever created the Universe also created the Creator...
> 
> No, God isn't part of the universe, any more than an author is part of
> his novel.

Tell that to Dante Alighieri.

Some more recent examples include Stephen King and Philip K Dick.

But in any case, a novel is not "everything that exists", unlike the universe. 
The maker of a sandwich is not part of the sandwich, but the universe has the 
boot-strap problem that the maker of the universe has to be part of the 
universe as well.

In any case, even if we *define* the "the universe" in a more limited fashion 
("just this solar system", "just this galaxy", "just the visible part of the 
universe", "the entire multi-verse except for the bit the maker lives in") and 
so exclude the maker, that doesn't imply anything else about the maker. We 
don't even know whether it is necessarily sentient, let alone someone/something 
benevolent that we should be taking moral absolutes from.

Perhaps our universe is a mere side-effect or by-product of some purely 
unconscious action: our universe is the pearl to some interdimensional oyster. 
Maybe we're a simulation in a computer, run by the inter-dimensional equivalent 
of Sheldon from "Big Bang Theory". The idea that the maker of the universe is 
necessarily benevolent AND competent isn't obviously true: if it were, life 
would probably be much easier and more pleasant. On the other hand, the 
evidence doesn't support the idea that the maker of the universe is *actively* 
malevolent either -- unless It, or They, simply haven't noticed us yet. Perhaps 
the gods do slumber in R'lyeh.

But for the sake of the argument, let's agree that the universe needs a maker, 
but the maker doesn't. What follows logically from those (presumably) facts?

We don't know if the maker is necessarily sentient; even if the maker is 
sentient, we don't know if it is aware of us; even if the maker is aware of us, 
we don't know if it is benevolent or malevolent or merely indifferent; even if 
benevolent, we don't know if it is benevolent towards individuals, personally, 
rather than towards creation overall; even if personal, we don't know what it 
is capable of doing (I can create a sandwich, but that doesn't mean I can stop 
it from growing old and stale and eventually rotting); even if capable, we 
don't know if it is motivated to do anything for us; even if motivated, we 
don't know if the maker is comprehensible to the human mind; even if 
comprehensible, we don't know if our ideas of what the maker must be like are 
correct.

There is an awfully long leap from the reality of "the universe exists" to any 
of the of Atum/Ptah/El/Coatlicue/Ranginui/Vishnu/Yahweh/Pangu/Waheguru etc., 
regardless of which one you pick.

(Unlike *our* divine revelation, which is clearly the truth, the whole truth, 
and nothing but the truth, *their* divine revolution is illusion, error and 
lies. All of the gods are myth and superstition, except for the One True God 
that conveniently has revealed himself to us rather than our enemies, who are 
pagans and heretics the lot of them.)




-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


Re: [Python-ideas] Inconsistencies

2016-09-13 Thread Gregory Ewing

Marko Rauhamaa wrote:

It has been prophesied that God will
eventually write a Version 2 of the universe which will have most of the
known glitches in Version 1 fixed.


Well, He did release a Religion 2.0 and sent His son
to install it, but some users resisted the upgrade and
crucified him before it could be fully deployed. There
are still problems to this day due to incompatible
versions in use.

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


Re: [Python-ideas] Inconsistencies

2016-09-13 Thread Lawrence D’Oliveiro
On Monday, September 12, 2016 at 2:26:21 PM UTC+12, Chris Angelico wrote:
> On Mon, Sep 12, 2016 at 12:04 PM, Lawrence D’Oliveiro wrote:
>> On Monday, September 12, 2016 at 1:11:39 PM UTC+12, Chris Angelico wrote:
>>> I have some _extremely_ strong views about absolutes (they come from the
>>> Creator of the Universe) ...
>>
>> By “Universe” do you mean “everything that exists”? So if the Creator
>> exists, then the Creator, too, must be part of the Universe.
>>
>> So whoever created the Universe also created the Creator...
> 
> No, God isn't part of the universe, any more than an author is part of
> his novel.

So if “Universe” does not mean “everything that exists”, then there would be 
things that exist, that God did not create...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-13 Thread Rustom Mody
On Wednesday, September 14, 2016 at 10:52:48 AM UTC+5:30, Steven D'Aprano wrote:
> (Unlike *our* divine revelation, which is clearly the truth, the whole truth, 
> and nothing but the truth, *their* divine revolution is illusion, error and 
> lies. All of the gods are myth and superstition, except for the One True God 
> that conveniently has revealed himself to us rather than our enemies, who are 
> pagans and heretics the lot of them.)

The piquant situation of being human is that 20/20 vision is always available
— at least as hindsight.

The bible more of less describes the world as a few hundred kms east/west
of Eden.
By most modern accounts this is wrong.
So were the authors fools?
Would you or I have done better?

Newton painstakingly calculated the age of the universe to be
about 6000 years BC by counting biblical generations.
Questions similar to the above

Amerigo Vespucci asked if the wondrous animals he saw in the new world
were on Noah's ark.
Was he a religious nut?
Was he even specially religious?
Or just functioning under the pervasive assumptions of his age?


These seem like rhetorical questions.
Yet we remain cocksure of our assumtions inspite of the repeated data
that everything we know will be negated in 5-50-500 years

Lord Kelvin said that physics was a closed project -- everything had been
discovered.. Just a few universal constants needed to be measured to increased
accuracy
This was before relativity, quantum physics, stellar spectroscopy etc etc

And then Max Planck discovered (the precursors to) quantum physics
And he remained a staunch classicist his whole life
Wishing and believing that vile genie he had unwittingly unleashed would somehow
or other be re-bottled

And Knuth wept that the CS that he largely created is historicized
in a different sense than he envisaged:
http://cacm.acm.org/magazines/2015/1/181633-the-tears-of-donald-knuth/abstract

My dear gpa to the end of his life would say:
“You guys can keep believing and worshipping who you like
For me the greatest is Socrates who said: ‘The one thing of which I am
100% certain is that I do not know.’ ”
-- 
https://mail.python.org/mailman/listinfo/python-list