Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 04:07 pm, Steve D'Aprano wrote:

> [1] Except in the loosest sense that any use of words to refer to a concept
> is a reference, e.g. the words "Queen Elizabeth" is a reference to the
> current monarch of the UK, Elizabeth Windsor.

Oops, ignore this footnote! It belonged to a paragraph I ended up deleting.



-- 
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 del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 02:40 pm, Ben Finney wrote:

> Steve D'Aprano  writes:

>> `del` cannot be a method or a function, because the argument to `del`
>> is the name of the variable, not the contents of the variable.
> 
> Since a Python “variable” does not have contents, this is IMO another
> instance where using the term “variable” is not helpful.
> 
> >>> x = 123
> >>> y = [0, x, 2, x, 4]
> 
> Neither of the names ‘x’ nor ‘y’ have content; 

What I meant by "content" was "value". In hindsight, I don't even know why I
wrote the word "content". It was not a good choice of words. Mea culpa.

Of course the variables "x" and "y" have values: the value of x is 123, and
the value of y is the specific list bound to the name "y" in the appropriate
namespace. If you don't agree with that, then our terminology is so far apart
that I don't believe we can ever agree, or understand each other.

The point is, if del were a function, then calling del(x) would pass the
*value* of x into the function, not the name 'x' -- unless the interpreter
made del a special case, not a regular function.

But if the interpreter did that, why bother with function notation and the
extraneous parentheses? Why not just make it a statement and avoid surprising
the programmer by giving the del function super-powers that no other function
has?

Which, of course, is exactly what Guido did.


> they are references to objects.

You are conflating the implementation details of how the Python VM implements
name binding (a mapping between names and references to objects) and the
high-level semantics of Python code. In CPython, at least, such references
are pointers. They're something analogous in Jython and IronPython.

It is sometimes useful to peer under the hood and talk about the
implementation of the VM, but I don't think this is one of those times. There
are too many inconsistencies in how we need to use the word "reference" to
make this strategy viable -- see below.


[...]
> So when we give an argument to ‘del’, that argument is not always a
> “variable”; it is always a reference.

The argument to del is a comma-separated list of l-values, that is, the kind
of expression which is legal on the left-hand side of an assignment
statement. That includes:

- bare names like `x`

- qualified names like `module.x` or `instance.attribute`

- items in mappings like `mydict[key]`

- items in sequences like `mylist[0]`

- lists and tuples of such l-values, e.g. this is legal:

py> a, b, c, d = 1, 2, 3, 4
py> del a, [b, c], d


as well as more complex examples. But you can't pass an arbitrary "reference"
to del and expect something sensible:

del math.sin(1)

would, if it were legal, evaluate the expression math.sin(1) and return the
float 0.8414... (or, if you prefer to talk about the *implementation*, return
a reference to the float object) and then try to delete it in some sense. But
that's not legal, and you get a syntax error at compile time.

If del accepted references in the usual sense, this would be legal but
pointless: del would receive the reference to the float object, and delete
the reference, leaving the float to possibly be garbage collected. But that's
not what del does.


> We can delete one item from a list, because that item is accessed via a
> reference; we give the same reference as argument to ‘del’::
> 
> >>> del y[1]

In context, I was specifically referring to unqualified names because deleting
list items *can* be done with a method call. In fact, the above line ends up
calling y.__delitem__[1]. In an alternative universe, Guido might have
forgone the `del` statement and required us to call:

list.pop(1)

or similar for dicts and other collections. The OP was already thinking along
those lines when he or she asked the question, so I didn't think I needed to
cover that case.

But the reason del is a statement is that it *also* covers cases where we
cannot use a regular method or function, and the simplest such case is
unbinding a name.

Now, to go back to your comment that 

"we give the same reference as argument to ‘del’"

that's incorrect, or at least, in order for it to be correct we must use *two*
different meanings to the word "reference", depending on the context. If I
write:

y = [None, "Aardvark", None, None]
print(y[1])  # (A)
del y[1]  # (B)

then the same descriptive text:

"the reference y[1]"

needs to be understood in two different ways:

- in line (A) y[1] is a reference to the string object "Aardvark";

- in line (B) y[1] is *not* a reference to the string object, but
  stands for the 1st position in the sequence referred to by `y`.


So it is misleading, or at least surprising, to use the term "reference" in
both situations. It isn't clear whether you mean reference to the value or
reference or not.

In logic and philosophy, we often need to think about the distinction between
*using* a word and *mentioning* the word:

https://en.wikipedia.org/wiki/Use%E2%80%93menti

Re: Searching For Old Posts On Python

2017-10-16 Thread Cai Gengyang
https://duckduckgo.com/html/?q=%22Cai%20Gengyang%22%20python  This
seems to be the only method that works, using DuckDuckGo

On Tue, Oct 17, 2017 at 4:54 AM, Thomas Jollans  wrote:

> On 16/10/17 22:04, Cai Gengyang wrote:
> > I cannot remember where I posted the question  it was a while ago ..
> >
> > On Mon, Oct 16, 2017 at 5:12 PM, Thomas Jollans  > > wrote:
> >
> > On 2017-10-16 11:01, Cai Gengyang wrote:
> > > Does anyone here know a way I can search for and display all my
> > old posts on Python ? Thanks a lot.
> > >
> > > Gengyang
> > >
> >
> > You already asked this recently. You received good answers.
>
>
> It was just over one week ago. On this very list.
>
> Here is the original thread in the archive:
> https://mail.python.org/pipermail/python-list/2017-October/727139.html
>
> And here is this one:
> https://mail.python.org/pipermail/python-list/2017-October/727567.html
>
>
> --
> Thomas Jollans
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logging module stopped working

2017-10-16 Thread Chris Angelico
On Tue, Oct 17, 2017 at 3:06 PM, llanitedave
 wrote:
> I'm building an application that contains some long-running operations in a 
> separate thread from the user interface.  I've been using the logging module 
> writing logging.info() statements to a .log file to keep track of the data 
> interactions while it runs.
>
> In the midst of a recent run, the logging simply stopped working.  The rest 
> of the application continued on as if nothing had happened, but without the 
> log I'm pretty much blind.
>
> I set up the logging code at the very beginning of the app, before any other 
> work is done.  Here's the relevant code:
>
> #!/usr/bin/env python3
>
> import sys
> import os
> #import functions_classes
> from PyQt5 import QtGui, QtCore, QtWidgets
> from PyQt5.QtGui import *
> from PyQt5.QtCore import *
> from PyQt5.QtWidgets import *
> import sqlite3
> import logging
> import inspect
> import threading
> import datetime
>
> #import local modules
> import qt_EnvTabs
> import globalnames
> import evocontrol
> import inputoutput
>
> class MainWindow(QMainWindow):
> def __init__(self):
> super().__init__()
> # set up logging
> logging.basicConfig(format='%(levelname)s:%(message)s', 
> filename="sample.log", level=logging.DEBUG)
> logging.info("Starting system, MainWindow.__init__,  %s", 
> str(datetime.datetime.today()))
> self.createUI()
>
> I also have an earlier draft of the application that I saved into another 
> directory.  Its initial code is identical to what I posted here.  I opened 
> it, saw the first window activate, and then closed it.  I checked for the 
> sample.log file, it existed, and contained the proper message:
> "INFO:Starting system, MainWindow.__init__,  2017-10-16 20:58:40.988035"
>
> I did the same to the current file, and no log file was created at all!
>
> Between the time that the logging was working and the time it quit, the only
>  changes I made were to add a couple of logging.info() statements into a 
> downstream module.  But that seems irrelevant here, as those modules aren't 
> included in the above test.
>
> Is there any behind-the-scenes behavior that I'm missing?  I'm stumped.

I'd be suspecting that something reconfigured the logging module, most
likely changing the logging level. Audit the modules by either
removing some and seeing if it still happens, or by combing through
the code. Perhaps something was supposed to construct its own logger,
but actually reconfigured the entire module?

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


Re: how to read in the newsreader

2017-10-16 Thread Byung-Hee HWANG (황병희, 黃炳熙)
Andrew Z  께서 쓰시길,
 《記事 全文  에서》:

> Gents,
>  how do i get this group in a newsreader? The digest i'm getting is not
> workable for me - i can't reply , can only read the replies from the
> members of the group. Or. maybe, it shouldn't be a news reader
> please advise..
>
> P.S. Oh the comp.lang.python is a nightmare because of spam...

It would be nice "gmane.comp.python.general" via NNTP, there are no spam. 

-- 
^고맙습니다 _地平天成_ 감사합니다_^))//
-- 
https://mail.python.org/mailman/listinfo/python-list


Logging module stopped working

2017-10-16 Thread llanitedave
I'm building an application that contains some long-running operations in a 
separate thread from the user interface.  I've been using the logging module 
writing logging.info() statements to a .log file to keep track of the data 
interactions while it runs.

In the midst of a recent run, the logging simply stopped working.  The rest of 
the application continued on as if nothing had happened, but without the log 
I'm pretty much blind.

I set up the logging code at the very beginning of the app, before any other 
work is done.  Here's the relevant code:

#!/usr/bin/env python3

import sys
import os
#import functions_classes
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sqlite3
import logging
import inspect
import threading
import datetime

#import local modules
import qt_EnvTabs
import globalnames
import evocontrol
import inputoutput

class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# set up logging
logging.basicConfig(format='%(levelname)s:%(message)s', 
filename="sample.log", level=logging.DEBUG)
logging.info("Starting system, MainWindow.__init__,  %s", 
str(datetime.datetime.today()))
self.createUI()

I also have an earlier draft of the application that I saved into another 
directory.  Its initial code is identical to what I posted here.  I opened it, 
saw the first window activate, and then closed it.  I checked for the 
sample.log file, it existed, and contained the proper message:
"INFO:Starting system, MainWindow.__init__,  2017-10-16 20:58:40.988035"

I did the same to the current file, and no log file was created at all!

Between the time that the logging was working and the time it quit, the only 
 changes I made were to add a couple of logging.info() statements into a 
downstream module.  But that seems irrelevant here, as those modules aren't 
included in the above test.

Is there any behind-the-scenes behavior that I'm missing?  I'm stumped.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why del is not a function or method?

2017-10-16 Thread Ben Finney via Python-list
Steve D'Aprano  writes:

> On Tue, 17 Oct 2017 03:16 am, Oren Ben-Kiki wrote:
>
> > That doesn't explain why `del` isn't a method though.
>
> `del` cannot be a method or a function, because the argument to `del`
> is the name of the variable, not the contents of the variable.

Since a Python “variable” does not have contents, this is IMO another
instance where using the term “variable” is not helpful.

>>> x = 123
>>> y = [0, x, 2, x, 4]

Neither of the names ‘x’ nor ‘y’ have content; they are references to
objects. The list itself also has references, which the Python code can
use to get at the items.

>>> y
[0, 123, 2, 123, 4]
>>> y[1]
123

So when we give an argument to ‘del’, that argument is not always a
“variable”; it is always a reference.

We can delete one item from a list, because that item is accessed via a
reference; we give the same reference as argument to ‘del’::

>>> del y[1]

Both ‘x’ and ‘y’ remain bound. The reference that was at index 1 of the
above list is deleted.

>>> x
123
>>> y
[0, 2, 123, 4]

> then `del` needs to delete the *name* "x", not the value of x, namely
> 123. If del were a function or method, it would only see the value,
> 123, and have no idea what the name is.

Hopefully when one thinks in terms of references – and the use of a
non-name reference, above, may make that distinction clear – the
operation of ‘del’ is easier to understand.

-- 
 \  “The shortest distance between two points is under |
  `\  construction.” —Noelie Alito |
_o__)  |
Ben Finney

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


Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 01:12 pm, Ned Batchelder wrote:

> On 10/16/17 9:06 PM, bartc wrote:
>> On 17/10/2017 01:53, Steve D'Aprano wrote:
[...]
>>> `del` is kind of like an "anti-assignment" in that the argument to
>>> `del` must
>>> be exactly the same sort of expression that can appear on the left
>>> hand side
>>> of assignment:
>>>
>>>
>>> 123 = 1+1  # illegal
>>> del 123  # also illegal
>>
>> Yet in Stefan Ram's example with del applied to a local 'x', it raised
>> an error on:
>>
>> del x    # x not yet assigned to
>>
>> but an assignment to x would have been fine.
> 
> Steve meant that syntactically it had to be valid on the left-hand
> side.  "x" is a syntactically valid LHS, "1+1" is not.


Right.

I didn't say that "del x is a compiler declaration that has no runtime
effect", because that would have been silly. Of course del x tries to delete
the local variable x, and since x doesn't exist yet, it fails with
UnboundLocalError.



-- 
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 del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 03:55 am, Oren Ben-Kiki wrote:

> True... technically, "Deletion of a name removes the binding of that name
> from the local or global namespace". Using `x.del()` can't do that.

Indeed -- not without introducing magic special syntax into the parser, and
effectively treating ".del()" as a special postfix operator that takes the
name x given before it.

In other words, Python would have had introduce special parsing rules. Instead
of always using:

 DOT  

and perform an attribute access, Python would first have to check for the
special case:

 DOT "del()"

and treat it differently. What if you wrote:

x.method().del()

or

x.del().method()

for example? Should that be treated as a syntax error? Special syntactic cases
make for difficult to understand parsers, and surprising syntax.


> That said, I would hazard to guess that `del x` is pretty rare (I have
> never felt the need for it myself).

Indeed. `del` is pretty rare. The main reason I use it is to delete temporary
variables in repetitious code. For example, in one of my modules I have
something close to this snippet to validate a post-condition on two global
dictionaries:


for d in (dict1, dict2):
for x in d.values():
assert x.code == x._calculate_code()
del d, x


d and x are temporary variables that exist only for the validation, and I
don't want them hanging around polluting the module namespace once I'm done
with them.


> Ruby doesn't even have an equivalent 
> operation, and doesn't seem to suffer as a result. If Python used methods
> instead of global functions for `len` and `del`, 

The case of `len` is irrelevant.


> and provided a `delete_local_variable('x')` for these rare cases, 

Don't forget delete_nonlocal_variable, delete_global_variable,
delete_class_variable, and delete_builtin_variable. And if Python ever added
any other scopes (say, a "process global" scope) then you'd need a new delete
function to delete from it.

In fact, deleting *local* variables is probably the least useful use of del
imaginable. Its a local variable -- nothing outside of the current function
can access it, so who cares about deleting it?

In fairness, you could possibly get away with a single function if, either,
you passed the namespace to delete from:

delete_variable('foo', globals())

or if it introduced some sort of implementation-specific magic to work out
which namespace the variable name was defined in. But that would require the
function to know the namespaces of the *caller*, not its own namespaces, and
there is no generally supported way to do that.

So in other words, it would require significant compiler magic. In general,
Python prefers to put the compiler magic in statements, not functions.



> that could have been a viable solution.

True. It would have been an ugly, inelegant solution, but it would be a
solution.



-- 
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: Cooperative class tree filtering

2017-10-16 Thread Ian Kelly
On Mon, Oct 16, 2017 at 8:20 PM, Ian Kelly  wrote:
> On Thu, Oct 12, 2017 at 5:07 PM, Alberto Berti  
> wrote:
>> I would really like to find a way to do this that doesn't involve
>> decorating the methods in A subclasses to free the final developer to
>> remember to import the decorator and apply it, just like I don't want
>> him (probably me six months from now) to have to remember to add an
>> `else: super()...` to its computation...
>>
>> Has anyone done this before and has any suggestion about a better way to
>> do it? Am I getting it wrong?
>
>
> If you don't want an explicit super() call and you don't want the
> decorator to be explicit either then most likely what you need is a
> metaclass that will automatically wrap specific methods with your
> decorator. Metaclasses are inherited, so all you have to do is set it
> for A and it will automatically apply itselt to B and C as well.


Assuming Python 3.6+ (I see you're already using __set_name__) you
could probably use __init_subclass__ for this as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cooperative class tree filtering

2017-10-16 Thread Ian Kelly
On Thu, Oct 12, 2017 at 5:07 PM, Alberto Berti  wrote:
> Now, what i ideally want is to get rid of that super() call at the end of
> the methods in classes B and c and to code that "fallback to what my
> superclass says" coded into A's implementation, where it kicks in if the
> method in the target instance returns None. So to write it in code, I
> would like some like:
>
>
> [SNIP]
>
>
> I've tried some variants of the 'super()' trick, that sometimes seems to
> change behavior if it's written like that or like super(type(self),
> self) in no clear (to me, and I failed to find extensive doc on
> super()'s behavior) way, with things that stop working if mixins are
> involved (even if the mixins do not reimplement the methods involved
> here). Eventually i ended implementing a decorator:
>
>   from functools import partial, wraps
>
>
>   class delegate_super:
>   """A method decorator that delegates part of the computation to the same
>   method on the ancestor class."""
>
>   _name = None
>   _owner = None
>
>   def __init__(self, meth):
>   self._meth = meth
>   @wraps(meth)
>   def wrapper(*args, **kwargs):
>   return self.delegator(*args, **kwargs)
>   self.wrapper = wrapper
>
>   def __get__(self, instance, owner):
>   return partial(self.wrapper, instance)
>
>   def __set_name__(self, owner, name):
>   self._owner = owner
>   self._name = name
>
>   def delegator(self, instance, *args, **kwargs):
>   result = self._meth(instance, *args, **kwargs)
>   if result is None:
>   result = getattr(super(self._owner, instance), self._name)(
>   *args, **kwargs)
>   return result
>
>   class A:
>   def filter(self, element):
>   # the default implementation always returns True
>   return True
>
>
>   class B(A):
>   @delegate_super
>   def filter(self, element):
>   if element == 'foo':
>   return True
>   elif element == 'bar':
>   return False
>
>
>   class C(B):
>   @delegate_super
>   def filter(self, element):
>   if element == 'bar':
>   return True
>   else:
>   return super().filter(element)
>
>
>   def collect_elements(instance):
>   "A semplified element collect function"
>   all_elts = {'foo', 'bar', 'baz', 'zoo'}
>   filtered_elts = set(el for el in all_elts if instance.filter(el))
>   return filtered_elts


My initial reaction is: is this really worth it? This seems like an
awful lot of code and added complexity in order to do away with two
lines. It's a lot easier to reason about "return
super().filter(element)" and verify that it does the right thing than
for the complicated descriptor above.


> I would really like to find a way to do this that doesn't involve
> decorating the methods in A subclasses to free the final developer to
> remember to import the decorator and apply it, just like I don't want
> him (probably me six months from now) to have to remember to add an
> `else: super()...` to its computation...
>
> Has anyone done this before and has any suggestion about a better way to
> do it? Am I getting it wrong?


If you don't want an explicit super() call and you don't want the
decorator to be explicit either then most likely what you need is a
metaclass that will automatically wrap specific methods with your
decorator. Metaclasses are inherited, so all you have to do is set it
for A and it will automatically apply itselt to B and C as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why del is not a function or method?

2017-10-16 Thread Ned Batchelder

On 10/16/17 9:06 PM, bartc wrote:

On 17/10/2017 01:53, Steve D'Aprano wrote:

On Tue, 17 Oct 2017 03:16 am, Oren Ben-Kiki wrote:


That doesn't explain why `del` isn't a method though.



`del` cannot be a method or a function, because the argument to `del` 
is the

name of the variable, not the contents of the variable.

If we write:

 x = 123
 del x

then `del` needs to delete the *name* "x", not the value of x, namely 
123. If
del were a function or method, it would only see the value, 123, and 
have no

idea what the name is.

`del` is kind of like an "anti-assignment" in that the argument to 
`del` must
be exactly the same sort of expression that can appear on the left 
hand side

of assignment:


 123 = 1+1  # illegal
 del 123  # also illegal


Yet in Stefan Ram's example with del applied to a local 'x', it raised 
an error on:


    del x    # x not yet assigned to

but an assignment to x would have been fine.


Steve meant that syntactically it had to be valid on the left-hand 
side.  "x" is a syntactically valid LHS, "1+1" is not.


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


Re: how to read in the newsreader

2017-10-16 Thread Cameron Simpson

On 15Oct2017 22:50, Andrew Z  wrote:

how do i get this group in a newsreader? The digest i'm getting is not
workable for me - i can't reply , can only read the replies from the
members of the group. Or. maybe, it shouldn't be a news reader
please advise..

P.S. Oh the comp.lang.python is a nightmare because of spam...


Well comp.langpython _is_ the newsgroup.

I recommend using the mailing list in individual message mode. It is far 
better. Many mail readers have good interfaces, and you get to keep all the 
messages, making it easy to find things later or to read in a nice threaded 
way.


Digests have many problems, some of which you're well aware of. I wish they 
weren't even an option.


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


Re: why del is not a function or method?

2017-10-16 Thread bartc

On 17/10/2017 01:53, Steve D'Aprano wrote:

On Tue, 17 Oct 2017 03:16 am, Oren Ben-Kiki wrote:


That doesn't explain why `del` isn't a method though.



`del` cannot be a method or a function, because the argument to `del` is the
name of the variable, not the contents of the variable.

If we write:

 x = 123
 del x

then `del` needs to delete the *name* "x", not the value of x, namely 123. If
del were a function or method, it would only see the value, 123, and have no
idea what the name is.

`del` is kind of like an "anti-assignment" in that the argument to `del` must
be exactly the same sort of expression that can appear on the left hand side
of assignment:


 123 = 1+1  # illegal
 del 123  # also illegal


Yet in Stefan Ram's example with del applied to a local 'x', it raised 
an error on:


del x# x not yet assigned to

but an assignment to x would have been fine.
--
https://mail.python.org/mailman/listinfo/python-list


Re: why del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 08:57 am, Thomas Jollans wrote:

> On 16/10/17 21:12, Stefan Ram wrote:
>> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>>> »x = None« observably has not the same effect as »del x«:
>> 
>>   Paradoxically, /deleting/ a local variable which did not
>>   ever exist, has the effect of creating a ghost of that
>>   local variable which then will hide a global variable:

[...]
>>   . Case 2: The »del x« creates a ghost »local variable 'x'«
>>   which now will hide the global variable »x«:
>> 
>> |>>> x = 9
>> |>>> def f():
>> |... del x
>> |... print( x )
>> |...
>> |>>> f()
>> |UnboundLocalError: local variable 'x' referenced before assignment
>> 
>>   .
> 
> That's not what happens. The UnboundLocalError is in the del statement,
> not the print call:

That's exactly what happens! Stefan merely explains it poorly. There's no
mysterious "ghost", it is just that x is treated as a local variable instead
of a global, and you can't delete the local before it is bound to.

`del x` is treated as a form of assignment, just like `x = 123`, and makes `x`
a local variable. So in this code:

def f():
print(x)

there is no assignment to x, so it is treated as a global. But if we write:

def f():
x = 123
print(x)

the Python compiler sees the assignment to x and makes x a local variable.
Note that the rules for this are deliberately very, very simple, so this will
make x a local:

def f():
print(x)  # x is local
x = 123

and even this will too:

def f():
if False:
x = 123  # dead code
print(x)  # but enough to make x a local


You can replace the line "x = 123" with "del x" in any of those functions, and
you will get the same effect: x will be treated as a local.



-- 
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: right list for SIGABRT python binary question ?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 07:32 am, Karsten Hilbert wrote:

> Hi all,
> 
> is this the right list to ask for help in debugging a
> SIGABORT (?) happening on shutdown of a Python 2.7 script ?
> 
> If not, which one is ?
> 
> Karsten

You should try here first.

Please ensure you read and follow this first:

http://sscce.org/


and post a *minimum* example of your code. (Sorry for the redundant
instructions if you already know this, but you would be surprised how many
people don't.)


-- 
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 del is not a function or method?

2017-10-16 Thread Steve D'Aprano
On Tue, 17 Oct 2017 03:16 am, Oren Ben-Kiki wrote:

> That doesn't explain why `del` isn't a method though.


`del` cannot be a method or a function, because the argument to `del` is the
name of the variable, not the contents of the variable.

If we write:

x = 123
del x

then `del` needs to delete the *name* "x", not the value of x, namely 123. If
del were a function or method, it would only see the value, 123, and have no
idea what the name is.

`del` is kind of like an "anti-assignment" in that the argument to `del` must
be exactly the same sort of expression that can appear on the left hand side
of assignment:


123 = 1+1  # illegal
del 123  # also illegal



-- 
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: Strange behavior in string interpolation of constants

2017-10-16 Thread Ned Batchelder

On 10/16/17 7:39 PM, מיקי מונין wrote:

Hello, I am working on an article on python string formatting. As a part of
the article I am researching the different forms of python string
formatting.

While researching string interpolation(i.e. the % operator) I noticed
something weird with string lengths.

Given two following two functions:

def simple_interpolation_constant_short_string():
 return "Hello %s" % "World!"

def simple_interpolation_constant_long_string():
 return "Hello %s. I am a very long string used for research" % "World!"


Lets look at the bytecode generated by them using the dis module

The first example produces the following bytecode:
   9   0 LOAD_CONST   3 ('Hello World!')
   2 RETURN_VALUE

It seems very normal, it appears that the python compiler optimizes the
constant and removes the need for the string interpolation

However the output of the second function caught my eye:

  12  0 LOAD_CONST   1 ('Hello %s. I am a very long
string used for research')
   2 LOAD_CONST2 ('World!')
   4 BINARY_MODULO
   6 RETURN_VALUE

This was not optimized by the compiler! Normal string interpolation was
used!

Based on some more testing it appears that for strings that would result in
more than 20 characters no optimization is done, as evident by these
examples:

def expected_result():
 return "abcdefghijklmnopqrs%s" % "t"

Bytecode:
  15  0 LOAD_CONST   3 ('abcdefghijklmnopqrst')
   2 RETURN_VALUE

def abnormal_result():
 return "abcdefghijklmnopqrst%s" % "u"

Bytecode:

  18  0 LOAD_CONST   1 ('abcdefghijklmnopqrst%s')
   2 LOAD_CONST 2 ('u')
   4 BINARY_MODULO
   6 RETURN_VALUE

I am using Python 3.6.3
I am curios as to why this happens. Can anyone shed further light on this
behaviour?


Optimizers have plenty of heuristics.  This one seems to avoid the 
constant folding if the string is larger than 20.  The code seems to 
bear this out 
(https://github.com/python/cpython/blob/master/Python/peephole.c#L305):


    } else if (size > 20) {
    Py_DECREF(newconst);
    return -1;
    }

As to why they chose 20?  There's no clue in the code, and I don't know.

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


Strange behavior in string interpolation of constants

2017-10-16 Thread מיקי מונין
Hello, I am working on an article on python string formatting. As a part of
the article I am researching the different forms of python string
formatting.

While researching string interpolation(i.e. the % operator) I noticed
something weird with string lengths.

Given two following two functions:

def simple_interpolation_constant_short_string():
return "Hello %s" % "World!"

def simple_interpolation_constant_long_string():
return "Hello %s. I am a very long string used for research" % "World!"


Lets look at the bytecode generated by them using the dis module

The first example produces the following bytecode:
  9   0 LOAD_CONST   3 ('Hello World!')
  2 RETURN_VALUE

It seems very normal, it appears that the python compiler optimizes the
constant and removes the need for the string interpolation

However the output of the second function caught my eye:

 12  0 LOAD_CONST   1 ('Hello %s. I am a very long
string used for research')
  2 LOAD_CONST2 ('World!')
  4 BINARY_MODULO
  6 RETURN_VALUE

This was not optimized by the compiler! Normal string interpolation was
used!

Based on some more testing it appears that for strings that would result in
more than 20 characters no optimization is done, as evident by these
examples:

def expected_result():
return "abcdefghijklmnopqrs%s" % "t"

Bytecode:
 15  0 LOAD_CONST   3 ('abcdefghijklmnopqrst')
  2 RETURN_VALUE

def abnormal_result():
return "abcdefghijklmnopqrst%s" % "u"

Bytecode:

 18  0 LOAD_CONST   1 ('abcdefghijklmnopqrst%s')
  2 LOAD_CONST 2 ('u')
  4 BINARY_MODULO
  6 RETURN_VALUE

I am using Python 3.6.3
I am curios as to why this happens. Can anyone shed further light on this
behaviour?
-- 
https://mail.python.org/mailman/listinfo/python-list


right list for SIGABRT python binary question ?

2017-10-16 Thread Karsten Hilbert
Hi all,

is this the right list to ask for help in debugging a
SIGABORT (?) happening on shutdown of a Python 2.7 script ?

If not, which one is ?

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


[Python] [JOB] Python developer at JRC

2017-10-16 Thread Alfredo Branco
Hello everyone,

I writing just to let you know that European Commission Joint Research
Center [1] is looking for a developer to work in Ispra (Varese -
Italy)

The profile required is as follow:

 Very good knowledge of Python and R

Good English language knowledge

A knowledge of one or more of the following would be a plus :

UML, agile development, design patterns;
OOP: C#, JAVA, C++;ASP.NET ;
SQL, ORACLE, SQL Server;
Experience in working with large meteorological / climate datasets;
Experience in visualization of large spatio-temporal datasets;

For more information and to send a resume please contact Roberto Boca:
rboca a arcadiasit.it 

[1] https://ec.europa.eu/jrc/


--

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


Re: Searching For Old Posts On Python

2017-10-16 Thread MRAB

On 2017-10-16 21:04, Cai Gengyang wrote:

I cannot remember where I posted the question  it was a while ago ..


You posted on Sat, 07 Oct 2017 23:42:10 UTC.


On Mon, Oct 16, 2017 at 5:12 PM, Thomas Jollans  wrote:


On 2017-10-16 11:01, Cai Gengyang wrote:
> Does anyone here know a way I can search for and display all my old
posts on Python ? Thanks a lot.
>
> Gengyang
>

You already asked this recently. You received good answers.


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


Re: how to read in the newsreader

2017-10-16 Thread Mikhail V
Thomas wrote:
>
> On 16/10/17 20:02, Pete Forman wrote:
> > Thomas Jollans  writes:
> > ...
> >>> If you do stick with a digest then check your newsreader for a feature
> >>> to expand it. Then you can read and reply as if you were getting
> >>> individual posts.
> >>>
> >> That exists? How does it work?
> >
> > The Gnus newsreader in Emacs allows you to type C-d on a digest to run
> > gnus-summary-enter-digest-group. That then behaves the same as if you
> > opened any other summary such as a regular Usenet group.
> >
>
> Does it set the References header correctly when replying?

Hi Thomas, regarding the issue with my reply-to header you told me recently -
Does this message looks ok in your threaded view now?

Now I reply by the href of the message I looked up in pipermail archive,
just curious if it looks now correctly.


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


Re: how to read in the newsreader

2017-10-16 Thread Thomas Jollans
On 16/10/17 20:02, Pete Forman wrote:
> Thomas Jollans  writes:
> 
>> On 2017-10-16 08:48, Pete Forman wrote:
>>> Andrew Z  writes:
>>>
 hmm. i did do that.  maybe just a delay.
 I'll see how it will go tomorrow then. Thank you gents.

 On Mon, Oct 16, 2017 at 12:30 AM, Chris Angelico  wrote:

> On Mon, Oct 16, 2017 at 3:19 PM, Andrew Z  wrote:
>> Michael, that's what i use too - gmail. But i get the digest only
>> and can't really reply that way. i was hoping to get the
>> mail.python.org list
>
> Turn off digests then. Easy!
>>>
>>> If you do stick with a digest then check your newsreader for a feature
>>> to expand it. Then you can read and reply as if you were getting
>>> individual posts.
>>>
>> That exists? How does it work?
> 
> The Gnus newsreader in Emacs allows you to type C-d on a digest to run
> gnus-summary-enter-digest-group. That then behaves the same as if you
> opened any other summary such as a regular Usenet group.
> 

Does it set the References header correctly when replying?

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


Re: why del is not a function or method?

2017-10-16 Thread Thomas Jollans
On 16/10/17 21:12, Stefan Ram wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> »x = None« observably has not the same effect as »del x«:
> 
>   Paradoxically, /deleting/ a local variable which did not
>   ever exist, has the effect of creating a ghost of that
>   local variable which then will hide a global variable:
> 
>   Case 1: The global variable »x« can be used in »f« just
>   fine:
> 
> |>>> x = 9
> |>>> def f():
> |... print( x )
> |...
> |>>> f()
> |9
> 
>   . Case 2: The »del x« creates a ghost »local variable 'x'«
>   which now will hide the global variable »x«:
> 
> |>>> x = 9
> |>>> def f():
> |... del x
> |... print( x )
> |...
> |>>> f()
> |UnboundLocalError: local variable 'x' referenced before assignment
> 
>   .

That's not what happens. The UnboundLocalError is in the del statement,
not the print call:

 >>> x = None
 >>> def f():
 ... del x
 ...
 >>> f()
 Traceback (most recent call last):
   File "", line 1, in 
   File "", line 2, in f
 UnboundLocalError: local variable 'x' referenced before assignment
 >>>

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


Re: Searching For Old Posts On Python

2017-10-16 Thread Thomas Jollans
On 16/10/17 22:04, Cai Gengyang wrote:
> I cannot remember where I posted the question  it was a while ago ..
> 
> On Mon, Oct 16, 2017 at 5:12 PM, Thomas Jollans  > wrote:
> 
> On 2017-10-16 11:01, Cai Gengyang wrote:
> > Does anyone here know a way I can search for and display all my
> old posts on Python ? Thanks a lot.
> >
> > Gengyang
> >
> 
> You already asked this recently. You received good answers.


It was just over one week ago. On this very list.

Here is the original thread in the archive:
https://mail.python.org/pipermail/python-list/2017-October/727139.html

And here is this one:
https://mail.python.org/pipermail/python-list/2017-October/727567.html


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


Re: Searching For Old Posts On Python

2017-10-16 Thread Cai Gengyang
On Tuesday, October 17, 2017 at 4:05:16 AM UTC+8, Cai Gengyang wrote:
> I cannot remember where I posted the question  it was a while ago ..
> 
> On Mon, Oct 16, 2017 at 5:12 PM, Thomas Jollans  wrote:
> 
> > On 2017-10-16 11:01, Cai Gengyang wrote:
> > > Does anyone here know a way I can search for and display all my old
> > posts on Python ? Thanks a lot.
> > >
> > > Gengyang
> > >
> >
> > You already asked this recently. You received good answers.
> >
> >
> >

Oh Ok. The DuckDuckGo thing works ... I can find my old posts now. Cool ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Searching For Old Posts On Python

2017-10-16 Thread Cai Gengyang
I cannot remember where I posted the question  it was a while ago ..

On Mon, Oct 16, 2017 at 5:12 PM, Thomas Jollans  wrote:

> On 2017-10-16 11:01, Cai Gengyang wrote:
> > Does anyone here know a way I can search for and display all my old
> posts on Python ? Thanks a lot.
> >
> > Gengyang
> >
>
> You already asked this recently. You received good answers.
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why del is not a function or method?

2017-10-16 Thread bartc

On 16/10/2017 18:46, Michael Torrie wrote:

On 10/16/2017 11:21 AM, bartc wrote:

del x effectively removes it from the namespace so trying to use it on
line 4 generates the same 'undefined' error.

However, the byte-code still needs to be aware of x: at the time when
line 1 is executed, the byte-code for line 3 already exists and it will
need to contain a reference to x.


I'm not sure why you'd think this, as we all know that code referring to
a name involves a dictionary lookup at runtime.  So the byte code for
line does exist before x is defined, but it does not contain a
"reference" to x in the manner you are thinking. Instead, all line three
knows is that it must lookup the key "x" (as in string) in the
dictionary of local or global objects.


Yes, the reference can be a string. So the string "x" will always exist 
in the byte-code even before the program is run, and even if the bit 
that uses x is never executed.


So if you look a file of Python code and count 288 different global 
variables, then somehow those 288 have to be identified by name in the 
binary code.


The symbol tables for them are filled in as it goes along.

I'm just saying it can be done differently. I think it already is for 
local variables, otherwise 'STORE_FAST' would require a lookup each 
time. As it is, accessing a local 'x' after 'del x' says 'referenced 
before assignment'.


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


Re: An endless loop

2017-10-16 Thread bartc

On 16/10/2017 18:53, Stefan Ram wrote:

Ian Kelly  writes:

I honestly can't remember the last time I programmed an endless loop,
and I also can't remember the last time I used a while loop.
Those two things are probably related.


   My Python installation has a "Lib" directory.

   »^ +\bwhile\b.*:$« has 1348 hits in this directory,
   »^ +\bfor\b.*:$« has 8713. That's a ratio of 6.46.

   In other words, while-loops are only 13 % of all loops
   (while or for). That's a clear minority. But it does
   not indicate that while loops are used almost ever.


It's presumably a characteristic of the language. And it depends on what 
the language offers, so if there was no 'while' at all, I guess it would 
be 100% 'for'.


(I just looked through my non-Python language at a couple of projects 
and got these figures:


  forall   29%(Equivalent to Python 'for')
  for  36%(Simple iteration)
  while14%(about the same as your figure)
  repeat-until  3%
  N-times  11%
  endless loop  6%

11% N-times loops doesn't sound a lot but it's one in every 9 loops. 
What the figures don't show is that the N-times and endless loops are 
probably used more with short test programs than in final applications, 
so having a very quick way to express them is convenient.)



--
bartc

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


Re: how to read in the newsreader

2017-10-16 Thread Pete Forman
Thomas Jollans  writes:

> On 2017-10-16 08:48, Pete Forman wrote:
>> Andrew Z  writes:
>>
>>> hmm. i did do that.  maybe just a delay.
>>> I'll see how it will go tomorrow then. Thank you gents.
>>>
>>> On Mon, Oct 16, 2017 at 12:30 AM, Chris Angelico  wrote:
>>>
 On Mon, Oct 16, 2017 at 3:19 PM, Andrew Z  wrote:
> Michael, that's what i use too - gmail. But i get the digest only
> and can't really reply that way. i was hoping to get the
> mail.python.org list

 Turn off digests then. Easy!
>>
>> If you do stick with a digest then check your newsreader for a feature
>> to expand it. Then you can read and reply as if you were getting
>> individual posts.
>>
> That exists? How does it work?

The Gnus newsreader in Emacs allows you to type C-d on a digest to run
gnus-summary-enter-digest-group. That then behaves the same as if you
opened any other summary such as a regular Usenet group.

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


Re: why del is not a function or method?

2017-10-16 Thread Peter Otten
Stefan Ram wrote:

> Peter Otten <__pete...@web.de> writes:
>>team.pop(2)
>>Stefan's explanation may work for
>>del x
>>if you discard
>>x = None  # get rid of the huge object that x was bound to before
>>as a hack
> 
>   »x = None« observably has not the same effect as »del x«:
> 
> |>>> x = 2; x = None; x
> |>>> x = 2; del x; x
> |NameError: name 'x' is not defined

That's a minor technical detail.

I understood the original question as one regarding language design, and I 
don't think merely stating what a statement does counts as a reason for its 
inclusion in the language.

x = None

covers the memory-micromanaging aspect of

del x

which makes some marginal sense. 

I expect to see the NameError (control flow aspect, if you will) only when 
there's a bug in the program.


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


Re: why del is not a function or method?

2017-10-16 Thread Michael Torrie
On 10/16/2017 11:21 AM, bartc wrote:
> del x effectively removes it from the namespace so trying to use it on 
> line 4 generates the same 'undefined' error.
> 
> However, the byte-code still needs to be aware of x: at the time when 
> line 1 is executed, the byte-code for line 3 already exists and it will 
> need to contain a reference to x.

I'm not sure why you'd think this, as we all know that code referring to
a name involves a dictionary lookup at runtime.  So the byte code for
line does exist before x is defined, but it does not contain a
"reference" to x in the manner you are thinking. Instead, all line three
knows is that it must lookup the key "x" (as in string) in the
dictionary of local or global objects.  If it exists, great, if not, an
exception is thrown. So no, there is no reference to x in the byte code
before x is assigned.


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


Re: why del is not a function or method?

2017-10-16 Thread Oren Ben-Kiki
The first line says "The major reason is history." :-) But it also gives an
explanation: providing functionality for types that, at the time, didn't
have methods.

On Mon, Oct 16, 2017 at 8:33 PM, Lele Gaifax  wrote:

> Oren Ben-Kiki  writes:
>
> > So I still think it was a matter of preference rather than a pure
> technical
> > consideration. But that's all second-guessing, anyway. You'd have to ask
> > Guido what his reasoning was...
>
> A rationale is briefly stated in the design FAQs, see
> https://docs.python.org/3/faq/design.html#why-does-python-
> use-methods-for-some-functionality-e-g-list-index-
> but-functions-for-other-e-g-len-list
> and the next one.
>
> 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
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why del is not a function or method?

2017-10-16 Thread Lele Gaifax
Oren Ben-Kiki  writes:

> So I still think it was a matter of preference rather than a pure technical
> consideration. But that's all second-guessing, anyway. You'd have to ask
> Guido what his reasoning was...

A rationale is briefly stated in the design FAQs, see
https://docs.python.org/3/faq/design.html#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list
and the next one.

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


Re: why del is not a function or method?

2017-10-16 Thread bartc

On 16/10/2017 17:55, Oren Ben-Kiki wrote:

True... technically, "Deletion of a name removes the binding of that name
from the local or global namespace". Using `x.del()` can't do that.

That said, I would hazard to guess that `del x` is pretty rare (I have
never felt the need for it myself). Ruby doesn't even have an equivalent
operation, and doesn't seem to suffer as a result.


It just seems the peculiar way that Python works:

   pass  # 1
   pass  # 2
   x = 10# 3
   del x # 4
   pass  # 4

In the above code, x doesn't actually exist in the namespace until line 
3. Trying to use x on lines 1 or 2 would cause an 'undefined' error.


del x effectively removes it from the namespace so trying to use it on 
line 4 generates the same 'undefined' error.


However, the byte-code still needs to be aware of x: at the time when 
line 1 is executed, the byte-code for line 3 already exists and it will 
need to contain a reference to x.


This could have been done in other ways by simply having 'x' always in 
the namespace, but not bound to anything ('undefined). But then the 
equivalent of del x would still have needed something special, for example:


   x = anything# any other undefined name

which is currently not allowed.

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


Re: An endless loop

2017-10-16 Thread Ian Kelly
On Sat, Oct 14, 2017 at 8:10 PM, Stefan Ram  wrote:
>   I made an error I made a thousand times before.
>
>   I had programmed an endless loop.
>
>   But never did I see before so clear why it's called
>   an endless loop. (Tested in IDLE.)
>
> from turtle import *
>
> reset(); reset(); shape( 'turtle' ); showturtle()
>
> def poly( n, length ):
> i = 0
> while i < n:
> forward( length )
> left( 360/n )
>
> poly( 5, 100 )
> done()

I honestly can't remember the last time I programmed an endless loop,
and I also can't remember the last time I used a while loop.

Those two things are probably related.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why del is not a function or method?

2017-10-16 Thread Oren Ben-Kiki
True... technically, "Deletion of a name removes the binding of that name
from the local or global namespace". Using `x.del()` can't do that.

That said, I would hazard to guess that `del x` is pretty rare (I have
never felt the need for it myself). Ruby doesn't even have an equivalent
operation, and doesn't seem to suffer as a result. If Python used methods
instead of global functions for `len` and `del`, and provided a
`delete_local_variable('x')` for these rare cases, that could have been a
viable solution.

So I still think it was a matter of preference rather than a pure technical
consideration. But that's all second-guessing, anyway. You'd have to ask
Guido what his reasoning was...


On Mon, Oct 16, 2017 at 7:36 PM, Ned Batchelder 
wrote:

> On 10/16/17 12:16 PM, Oren Ben-Kiki wrote:
>
>> That doesn't explain why `del` isn't a method though. Intuitively,
>> `my_dict.delete(some_key)` makes sense as a method. Of course, you could
>> also make the same case for `len` being a method... and personally I think
>> it would have been cleaner that way in both cases. But it is a minor
>> issue,
>> if at all.
>>
>> I guess the answer is a combination of "historical reasons" and "Guido's
>> preferences"?
>>
>
> It would still need to be a statement to allow for:
>
> del x
>
> since "x.del()" wouldn't affect the name x, it would affect the value x
> refers to.
>
> --Ned.
>
>
>>
>> On Mon, Oct 16, 2017 at 6:58 PM, Stefan Ram 
>> wrote:
>>
>> Xue Feng  writes:
>>>
 I wonder why 'del' is not a function or method.

>>>Assume,
>>>
>>> x = 2.
>>>
>>>When a function »f« is called with the argument »x«,
>>>this is written as
>>>
>>> f( x )
>>>
>>>. The function never gets to see the name »x«, just
>>>its boundee (value) »2«. So, it cannot delete the
>>>name »x«.
>>>
>>>Also, the function has no access to the scope of »x«,
>>>and even more so, it cannot make any changes in it.
>>>
>>>Therefore, even a call such as
>>>
>>> f( 'x' )
>>>
>>>will not help much.
>>>
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why del is not a function or method?

2017-10-16 Thread Ned Batchelder

On 10/16/17 12:16 PM, Oren Ben-Kiki wrote:

That doesn't explain why `del` isn't a method though. Intuitively,
`my_dict.delete(some_key)` makes sense as a method. Of course, you could
also make the same case for `len` being a method... and personally I think
it would have been cleaner that way in both cases. But it is a minor issue,
if at all.

I guess the answer is a combination of "historical reasons" and "Guido's
preferences"?


It would still need to be a statement to allow for:

    del x

since "x.del()" wouldn't affect the name x, it would affect the value x 
refers to.


--Ned.




On Mon, Oct 16, 2017 at 6:58 PM, Stefan Ram  wrote:


Xue Feng  writes:

I wonder why 'del' is not a function or method.

   Assume,

x = 2.

   When a function »f« is called with the argument »x«,
   this is written as

f( x )

   . The function never gets to see the name »x«, just
   its boundee (value) »2«. So, it cannot delete the
   name »x«.

   Also, the function has no access to the scope of »x«,
   and even more so, it cannot make any changes in it.

   Therefore, even a call such as

f( 'x' )

   will not help much.

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



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


Re: why del is not a function or method?

2017-10-16 Thread Skip Montanaro
> What about del team[2]?
>
> There is no name involved here, and even a reference to team[2] won't help.

(I'm not sure quite what question is asking. Apologies if my
assumption was incorrect.)

That is precisely why del is a statement. At byte-compile time, both
"team" and "2" are available. The easiest way to see this is to define
a simple function:

def f(team):
del team[2]

Now, import the dis module and call

dis.dis(f)

then check out the byte code assembler statements.

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


Re: why del is not a function or method?

2017-10-16 Thread Peter Otten
bartc wrote:

> On 16/10/2017 16:58, Stefan Ram wrote:
>> Xue Feng  writes:
>>> I wonder why 'del' is not a function or method.
>> 
>>Assume,
>> 
>> x = 2.
>> 
>>When a function »f« is called with the argument »x«,
>>this is written as
>> 
>> f( x )
>> 
>>. The function never gets to see the name »x«, just
>>its boundee (value) »2«. So, it cannot delete the
>>name »x«.
>> 
>>Also, the function has no access to the scope of »x«,
>>and even more so, it cannot make any changes in it.
>> 
>>Therefore, even a call such as
>> 
>> f( 'x' )
>> 
>>will not help much.
> 
> What about del team[2]?
> 
> There is no name involved here, and even a reference to team[2] won't
> help.
> 
> Presumably there is no other way to do an in-place deletion of an
> element of a list. (Inserting an element is different.)

There is another way:

team.pop(2)

Stefan's explanation may work for

del x

if you discard

x = None  # get rid of the huge object that x was bound to before

as a hack, but not for

del x[y]

or

del x.y


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


Re: why del is not a function or method?

2017-10-16 Thread Chris Angelico
On Tue, Oct 17, 2017 at 3:18 AM, Stefan Ram  wrote:
> bartc  writes:
>>What about del team[2]?
>
>   All arguments of a call are evaluated before the callable
>   called then is incarnated with the values obtained. Assume,
>   »team[ 2 ]« is bound to »8«. Then, the call
>
> f( team[ 2 ])«
>
>   is equivalent to
>
> f( 8 )
>
>   , and so »f« doesn't stand a chance of deleting »team[ 2 ]«.
>
>   The evaluation rules for calls do not apply to the del-
>   statement, however. Therefore,
>
> del team[ 2 ]
>
>   is /not/ equivalent to
>
> del 8
>
>   , and »del« can delete »team[ 2 ]« just fine. (Because the
>   implementation can use whatever means available to it,
>   since it is not bound to follow the evaluation rules for
>   callables.)

Right, but you *could* implement a function that takes the two parts
and does the assignment or deletion:

def f(lst, idx):
del lst[idx]

f(team, 2)

The reason that 'del' absolutely has to be a statement is that it can
work on simple names, too:

del team

There's no way to do THAT part with a function call (it's basically
the opposite of assignment), so 'del' has to be a statement. Since
it's a statement, it may as well be able to do more than just simple
names, which means we have a consistent way to delete items from
arbitrary objects:

del globals()["foo"] # dicts
del sys.argv[1] # lists
etc

(Although you can't do this with sets. Sets are manipulated
exclusively through methods and operators.)

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


Re: why del is not a function or method?

2017-10-16 Thread Chris Angelico
On Tue, Oct 17, 2017 at 3:07 AM, bartc  wrote:
> On 16/10/2017 16:58, Stefan Ram wrote:
>>
>> Xue Feng  writes:
>>>
>>> I wonder why 'del' is not a function or method.
>>
>>
>>Assume,
>>
>> x = 2.
>>
>>When a function »f« is called with the argument »x«,
>>this is written as
>>
>> f( x )
>>
>>. The function never gets to see the name »x«, just
>>its boundee (value) »2«. So, it cannot delete the
>>name »x«.
>>
>>Also, the function has no access to the scope of »x«,
>>and even more so, it cannot make any changes in it.
>>
>>Therefore, even a call such as
>>
>> f( 'x' )
>>
>>will not help much.
>
>
> What about del team[2]?
>
> There is no name involved here, and even a reference to team[2] won't help.
>
> Presumably there is no other way to do an in-place deletion of an element of
> a list. (Inserting an element is different.)

team.pop(2) will in-place delete one element. So you have both options.

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


Re: why del is not a function or method?

2017-10-16 Thread Oren Ben-Kiki
That doesn't explain why `del` isn't a method though. Intuitively,
`my_dict.delete(some_key)` makes sense as a method. Of course, you could
also make the same case for `len` being a method... and personally I think
it would have been cleaner that way in both cases. But it is a minor issue,
if at all.

I guess the answer is a combination of "historical reasons" and "Guido's
preferences"?


On Mon, Oct 16, 2017 at 6:58 PM, Stefan Ram  wrote:

> Xue Feng  writes:
> >I wonder why 'del' is not a function or method.
>
>   Assume,
>
> x = 2.
>
>   When a function »f« is called with the argument »x«,
>   this is written as
>
> f( x )
>
>   . The function never gets to see the name »x«, just
>   its boundee (value) »2«. So, it cannot delete the
>   name »x«.
>
>   Also, the function has no access to the scope of »x«,
>   and even more so, it cannot make any changes in it.
>
>   Therefore, even a call such as
>
> f( 'x' )
>
>   will not help much.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read in the newsreader

2017-10-16 Thread Chris Green
Marko Rauhamaa  wrote:
> Chris Green :
> 
> > I read newsgroups using tin, a text-mode/command line newsreader. I
> > always run tin on my home desktop machine, even if I'm away from home
> > by using ssh. So I maintain my settings that way. By the way tin *is*
> > mouse away even though it's a text mode program.
> >
> > For reading mailing lists (and all my mail for that matter) I use mutt
> > which is also a text mode program. It makes reading mailing lists easy
> > because it provides threading etc. I use like I use tin, alway on my
> > desktop machine using ssh where necessary.
> 
> Same thing, except that I do all of my typing on emacs (GNUS in the case
> of news and mail).
> 
That's the other advantage of working this way, one always uses the
same text editor for composing messages, I use a vi clone (let's not
start a vi/emacs war!).

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


Re: why del is not a function or method?

2017-10-16 Thread bartc

On 16/10/2017 16:58, Stefan Ram wrote:

Xue Feng  writes:

I wonder why 'del' is not a function or method.


   Assume,

x = 2.

   When a function »f« is called with the argument »x«,
   this is written as

f( x )

   . The function never gets to see the name »x«, just
   its boundee (value) »2«. So, it cannot delete the
   name »x«.

   Also, the function has no access to the scope of »x«,
   and even more so, it cannot make any changes in it.

   Therefore, even a call such as

f( 'x' )

   will not help much.


What about del team[2]?

There is no name involved here, and even a reference to team[2] won't help.

Presumably there is no other way to do an in-place deletion of an 
element of a list. (Inserting an element is different.)


--
Bartc


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


Re: how to read in the newsreader

2017-10-16 Thread Marko Rauhamaa
Chris Green :

> I read newsgroups using tin, a text-mode/command line newsreader. I
> always run tin on my home desktop machine, even if I'm away from home
> by using ssh. So I maintain my settings that way. By the way tin *is*
> mouse away even though it's a text mode program.
>
> For reading mailing lists (and all my mail for that matter) I use mutt
> which is also a text mode program. It makes reading mailing lists easy
> because it provides threading etc. I use like I use tin, alway on my
> desktop machine using ssh where necessary.

Same thing, except that I do all of my typing on emacs (GNUS in the case
of news and mail).


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


Re: how to read in the newsreader

2017-10-16 Thread Chris Green
Paul Moore  wrote:
> On 16 October 2017 at 15:41, Grant Edwards  wrote:
> > On 2017-10-16, Terry Reedy  wrote:
> >> On 10/15/2017 10:50 PM, Andrew Z wrote:
> >>> Gents,
> >>>   how do i get this group in a newsreader?
> >>
> >> Point your newsreader to news.gmane.org,
> >
> > That, IMO, is the only sane way to read mailing lists.  If a mailing
> > list isn't carried on gmane, I don't bother with it.
> 
> Unless you work regularly on multiple PCs, as there's no newsreader I
> know of that maintains your settings (what articles you have read, in
> particular) across multiple installations. And gmane's UI sucks.
> 
> For that situation, reading mailing lists as mails in gmail is the
> best option I've been able to find (not ideal, but adequate).

I read newsgroups using tin, a text-mode/command line newsreader.  I
always run tin on my home desktop machine, even if I'm away from home
by using ssh.  So I maintain my settings that way.  By the way tin
*is* mouse away even though it's a text mode program.

For reading mailing lists (and all my mail for that matter) I use mutt
which is also a text mode program.  It makes reading mailing lists
easy because it provides threading etc.  I use like I use tin, alway
on my desktop machine using ssh where necessary.

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


why del is not a function or method?

2017-10-16 Thread Xue Feng via Python-list

Hi,
   I wonder why 'del' is not a function or method. Most operations can 
be used as follows

len(team)
or
team.append("tom")
But, I think
del team[2]
is somewhat uncommon. Why does not it take a syntax we are famillar with?
--
https://mail.python.org/mailman/listinfo/python-list


Re: how to read in the newsreader

2017-10-16 Thread Rhodri James

On 16/10/17 16:07, Grant Edwards wrote:

Ah yes.  I solved problem that by writing a wrapper around slrn so
that my .newsrc and .score files reside "in the could".

  ^

Now there's a typo someone should run with :-)

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


Re: how to read in the newsreader

2017-10-16 Thread Michael Torrie
On 10/16/2017 08:52 AM, Paul Moore wrote:
> For that situation, reading mailing lists as mails in gmail is the
> best option I've been able to find (not ideal, but adequate).
> Paul

Gmail's web interface is completely broken as far as mailing lists are
concerned.  Conversation view in no way is adequate for the more
complex, multi-person threads that are common.  Gmail does not preserve
the flow and context of such emails.

However Gmail over IMAP is adequate.  There is the issue of in IMAP
gmail will silently through away your replies to messages when they come
through the mailing list server, which is a pretty serious and
long-standing brokenness.  But if you send messages via a different smtp
server than gmail's, it doesn't do that.

If reading the list from anywhere is important, one can always use a
web-based mail client like RoundCube against Gmail's IMAP server.

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


Re: how to read in the newsreader

2017-10-16 Thread Paul Moore
On 16 October 2017 at 16:07, Grant Edwards  wrote:
> On 2017-10-16, Paul Moore  wrote:
>> Unless you work regularly on multiple PCs, as there's no newsreader I
>> know of that maintains your settings (what articles you have read, in
>> particular) across multiple installations.
>
> Ah yes.  I solved problem that by writing a wrapper around slrn so
> that my .newsrc and .score files reside "in the could".  [They're
> actually just sitting in my home directory on a Unix server which I
> can scp them to/from.

Something like that would be great, but not practical for me to write
myself. I'm on Windows machines, and Windows newsreaders from what I
recall aren't as hackable as Unix ones (I'm able to write the code,
but not if the data isn't accessible...). Also, on at least one of my
PCs I'm behind a firewall that blocks access to pretty much all
"personal cloud storage" sites, so a DIY solution isn't possible.
Something like Chrome's "sync my settings" would be ideal, but I've
never found anything like that in a newsreader.

> You mean the gmail web UI?  I don't even use that e-mail (and I use
> gmail for all my e-mail).

Yep. Same reason, it's the only globally accessible option. (I could
use a mail client on the systems that don't block IMAP, but I'd still
need the web UI for the others, and for "borrowed" PCs that I have no
software on).

The cloud is great, but the app UIs are still a lot worse than a
dedicated client app, sadly...
Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read in the newsreader

2017-10-16 Thread Grant Edwards
On 2017-10-16, Paul Moore  wrote:
> On 16 October 2017 at 15:41, Grant Edwards  wrote:
>> On 2017-10-16, Terry Reedy  wrote:
>>> On 10/15/2017 10:50 PM, Andrew Z wrote:
 Gents,
   how do i get this group in a newsreader?
>>>
>>> Point your newsreader to news.gmane.org,
>>
>> That, IMO, is the only sane way to read mailing lists.  If a mailing
>> list isn't carried on gmane, I don't bother with it.
>
> Unless you work regularly on multiple PCs, as there's no newsreader I
> know of that maintains your settings (what articles you have read, in
> particular) across multiple installations.

Ah yes.  I solved problem that by writing a wrapper around slrn so
that my .newsrc and .score files reside "in the could".  [They're
actually just sitting in my home directory on a Unix server which I
can scp them to/from.

> And gmane's UI sucks.

AFIAK, it has no UI.  The web interface has been completely broken for
a couple years now.  It was always mediocre at best (the built-in
search was useless), but it did provide something that you could
search with Google, and it was sometimes handy when you wanted to
provide somebody with a link to a particular posting from years gone
by.

> For that situation, reading mailing lists as mails in gmail is the
> best option I've been able to find (not ideal, but adequate).

You mean the gmail web UI?  I don't even use that e-mail (and I use
gmail for all my e-mail).

-- 
Grant Edwards   grant.b.edwardsYow! I'm encased in the
  at   lining of a pure pork
  gmail.comsausage!!

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


Re: how to read in the newsreader

2017-10-16 Thread Paul Moore
On 16 October 2017 at 15:41, Grant Edwards  wrote:
> On 2017-10-16, Terry Reedy  wrote:
>> On 10/15/2017 10:50 PM, Andrew Z wrote:
>>> Gents,
>>>   how do i get this group in a newsreader?
>>
>> Point your newsreader to news.gmane.org,
>
> That, IMO, is the only sane way to read mailing lists.  If a mailing
> list isn't carried on gmane, I don't bother with it.

Unless you work regularly on multiple PCs, as there's no newsreader I
know of that maintains your settings (what articles you have read, in
particular) across multiple installations. And gmane's UI sucks.

For that situation, reading mailing lists as mails in gmail is the
best option I've been able to find (not ideal, but adequate).
Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read in the newsreader

2017-10-16 Thread Grant Edwards
On 2017-10-16, Terry Reedy  wrote:
> On 10/15/2017 10:50 PM, Andrew Z wrote:
>> Gents,
>>   how do i get this group in a newsreader?
>
> Point your newsreader to news.gmane.org,

That, IMO, is the only sane way to read mailing lists.  If a mailing
list isn't carried on gmane, I don't bother with it.

-- 
Grant Edwards   grant.b.edwardsYow! Were these parsnips
  at   CORRECTLY MARINATED in
  gmail.comTACO SAUCE?

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


Re: how to read in the newsreader

2017-10-16 Thread Ned Batchelder

On 10/16/17 12:31 AM, Andrew Z wrote:

i'm typing without thinking. Sorry. Let me try again.

I subscribed to python-list@python.org. That has 0 spam ( as far as i can
see), but i can only get a digest.


You can choose to get individual messages from Python-List.

--Ned.

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


Re: Searching For Old Posts On Python

2017-10-16 Thread Steve D'Aprano
On Mon, 16 Oct 2017 08:01 pm, Cai Gengyang wrote:

> Does anyone here know a way I can search for and display all my old posts on
> Python ? Thanks a lot.
> 
> Gengyang



Repeating the answers you already got:


Make a site specific search for your name here
https://mail.python.org/pipermail/python-list/

Or download the archives onto your computer and search them locally.

https://mail.python.org/pipermail/python-list/


(download the Gzipped archives).


Or try googling:

https://duckduckgo.com/html/?q=%22Cai%20Gengyang%22%20python




-- 
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: Searching For Old Posts On Python

2017-10-16 Thread Steve D'Aprano
On Mon, 16 Oct 2017 08:12 pm, Thomas Jollans wrote:

> On 2017-10-16 11:01, Cai Gengyang wrote:
>> Does anyone here know a way I can search for and display all my old posts
>> on Python ? Thanks a lot.
>> 
>> Gengyang
>> 
> 
> You already asked this recently. You received good answers.

Yes, but he can't find the answers because he can't search for his old
posts :-)




-- 
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: how to read in the newsreader

2017-10-16 Thread Terry Reedy

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

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


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


--
Terry Jan Reedy

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


Re: how to read in the newsreader

2017-10-16 Thread alister via Python-list
On Mon, 16 Oct 2017 08:57:18 +0100, Chris Green wrote:

> Michael Torrie  wrote:
>> On 10/15/2017 08:50 PM, Andrew Z wrote:
>> > Gents,
>> >  how do i get this group in a newsreader? The digest i'm getting is
>> >  not
>> > workable for me - i can't reply , can only read the replies from the
>> > members of the group. Or. maybe, it shouldn't be a news reader
>> > please advise..
>> > 
>> > P.S. Oh the comp.lang.python is a nightmare because of spam...
>> 
>> Regardless of what usenet reader you use, com.lang.python will have the
>> same spam everywhere.  So maybe reading via usenet isn't that useful
>> anyway.
>> 
> The mostly very silly spam is trivial to filter with some very simple
> rules, most newsreaders have easy ways to specify subjects and/or
> senders to ignore.  I have (I think) just three or four rules that
> eliminate just about all the junk.

Although that is the case I ma finding that because of the amount of junk 
in this newsgroup I am rapidly running out of space in /dev/null !



-- 
In Oz, never say "krizzle kroo" to a Woozy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Searching For Old Posts On Python

2017-10-16 Thread Thomas Jollans
On 2017-10-16 11:01, Cai Gengyang wrote:
> Does anyone here know a way I can search for and display all my old posts on 
> Python ? Thanks a lot.
> 
> Gengyang
> 

You already asked this recently. You received good answers.


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


Re: Searching For Old Posts On Python

2017-10-16 Thread Louis Krupp
On Mon, 16 Oct 2017 02:01:37 -0700 (PDT), Cai Gengyang
 wrote:

>Does anyone here know a way I can search for and display all my old posts on 
>Python ? Thanks a lot.

This might be what you're looking for:

https://groups.google.com/forum/#!search/cai$20gengyang$20python

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


Searching For Old Posts On Python

2017-10-16 Thread Cai Gengyang
Does anyone here know a way I can search for and display all my old posts on 
Python ? Thanks a lot.

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


Re: how to read in the newsreader

2017-10-16 Thread Thomas Jollans
On 2017-10-16 08:48, Pete Forman wrote:
> Andrew Z  writes:
> 
>> hmm. i did do that.  maybe just a delay.
>> I'll see how it will go tomorrow then. Thank you gents.
>>
>> On Mon, Oct 16, 2017 at 12:30 AM, Chris Angelico  wrote:
>>
>>> On Mon, Oct 16, 2017 at 3:19 PM, Andrew Z  wrote:
 Michael, that's what i use too - gmail. But i get the digest only
 and can't really reply that way. i was hoping to get the
 mail.python.org list
>>>
>>> Turn off digests then. Easy!
> 
> If you do stick with a digest then check your newsreader for a feature
> to expand it. Then you can read and reply as if you were getting
> individual posts.
> 
That exists? How does it work?

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


Re: how to read in the newsreader

2017-10-16 Thread Chris Green
Michael Torrie  wrote:
> On 10/15/2017 08:50 PM, Andrew Z wrote:
> > Gents,
> >  how do i get this group in a newsreader? The digest i'm getting is not
> > workable for me - i can't reply , can only read the replies from the
> > members of the group. Or. maybe, it shouldn't be a news reader
> > please advise..
> > 
> > P.S. Oh the comp.lang.python is a nightmare because of spam...
> 
> Regardless of what usenet reader you use, com.lang.python will have the
> same spam everywhere.  So maybe reading via usenet isn't that useful anyway.
> 
The mostly very silly spam is trivial to filter with some very simple
rules, most newsreaders have easy ways to specify subjects and/or
senders to ignore.  I have (I think) just three or four rules that
eliminate just about all the junk.

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