Guido van Rossum wrote:
Here's a patch that gets rid of unbound methods, as
discussed here before. A function's __get__ method
now returns the function unchanged when called without
an instance, instead of returning an unbound method object.
I thought the main reason for existence of unbound
Tim Peters wrote:
I expect that's because he stopped working on Zope code, so actually
thinks it's odd again to see a gazillion methods like:
class Registerer(my_base):
def register(*args, **kws):
my_base.register(*args, **kws)
I second that! My PyGUI code is *full* of __init__
methods
otherwise. In Python the
value itself knows whether it's signed or not.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc
.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
by strings.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
Josiah Carlson wrote:
if we could change import in such a
way that made standard library imports different from standard library
imports, we could
...go on to prove that black is white and get
ourselves killed by a python on the next
zebra crossing.
--
Greg Ewing, Computer Science Dept
Nick Coghlan wrote:
A suggestion was made on c.l.p a while back to have a specific module
dedicated to reductive operations. That is, just as itertools is
oriented towards manipulating iterables and creating iterators, this
module would be oriented towards consuming iterators in a reductive
Brian Sabbey wrote:
I prefer re-using the 'for' loop for this purpose because it allows the
problem to be solved in a general way by re-using a structure with which
most users are already familiar, and uses generators, which are easier
to use in this case than defining a class with __exit__,
Nick Coghlan wrote:
That 'x in seq' bit still shouts containment to me rather than
iteration, though.
Perhaps repurposing 'from':
(x from seq if f(x))
That rather breaks TOOWTDI though (since it is essentially new syntax
for a for loop). And I have other hopes for the meaning of (x from ()).
,
If there is a mechanism for passing a code block as
a thunk to an arbitrary function, the function is
free to loop or not as it sees fit. I'd just prefer
the spelling of it didn't force you to make it
look like it's looping when it's not.
--
Greg Ewing, Computer Science Dept
think that if an
identity is specified, it should be used even
if the sequence is non-empty. The reason being
that the user might be relying on that to get
the semantics he wants.
Think of the second argument as accumulator
object rather than identity.
--
Greg Ewing, Computer Science Dept
dt = stopwatch():
a()
b()
Whatever keyword is used is bound to not sound right
for some usages, so it would be best if no keyword
were needed at all.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen
by
passing a thunk to a function that calls it repeatedly.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
it has been passed, and most C implementations
don't provide any way at all. That's why the calling interface
to varargs functions invariably includes some way for the caller
to indicate the number of arguments, such as a format string or
a terminating NULL.
--
Greg Ewing, Computer Science Dept
specified explicitly.
In that case I would argue in favour of keeping it the
way it is, since...
currently sum([1,1], 40) equals 42.
...seems quite reasonable to me. Or at least as reasonable
as anything else.
--
Greg Ewing, Computer Science Dept, +--+
University
, it just seems like a completely
unnecessary layer of mental gymnastics...
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA
Eric Nieuwland wrote:
Perhaps the second argument should not be optional to emphasise this.
After all, there's much more to sum() than numbers.
I think practicality beats purity here. Using it on
numbers is surely an extremely common case.
--
Greg Ewing, Computer Science Dept
to .join(x). Although it might be
better to call it str.concat() instead of str.sum().
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary
the function is called.
Not to mention that if the seq is empty, there's no
way of knowing what T to instantiate...
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand
. This means recording that IOError(EAGAIN) is raised for an empty
non-blocking read.
Isn't that unix-specific? The file object is supposed to
provide a more or less platform-independent interface, I
thought.
--
Greg Ewing, Computer Science Dept, +--+
University
significant.
Currently I can leave some space before/after a
docstring without breaking anything. This can
help readability, especially for class docstrings.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp
behave more like os.read/os.write, maybe called
something like readsome() and writesome(). That would eliminate
the need to extract and manipulate the fds, and might make it
possible to do some of this stuff in a more platform-independent
way.
--
Greg Ewing, Computer Science Dept
Donovan Baarda wrote:
On Mon, 2005-03-21 at 17:32 +1200, Greg Ewing wrote:
I don't agree with that. There's no need to use non-blocking
I/O when using select(), and in fact things are less confusing
if you don't.
Because staller.py outputs and flushes a fragment of data smaller than
selector.py
Travis Oliphant wrote:
I'm proposing to pickle the buffer object so that it unpickles as a
string.
Wouldn't this mean you're only solving half the problem?
Unpickling a Numeric array this way would still use an
intermediate string.
--
Greg Ewing, Computer Science Dept
the point of view of the user of withfile, the name 'thefile'
magically appears in the namespace without it being obvious
where it comes from.
(but
assignments within the block should still affect its _surrounding_
namespace, it seems to me...).
I agree with that much.
--
Greg Ewing, Computer Science
that people want to do on a regular basis.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
rely on a function's signature alone to tell
you much in any case. A distressingly large number of
functions found in third-party extension modules have
a help() string that just says something like
fooble(arg,...)
There's really no substitute for a good docstring!
--
Greg Ewing, Computer Science
don't see a great need for blocks
to be able to return values.
How do blocks work with control flow statements like
break, continue, yield, and return? Perhaps
break and continue raise exceptions similar to StopIteration in this
case?
Something like that, yes.
--
Greg Ewing, Computer Science Dept
func
Usage example:
with_file(foo.txt, w) as f:
f.write(My hovercraft is full of parrots.)
Does that help?
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand
be added
later, without disturbing anything. But I think it's best left
out of an initial specification.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand
. IMO, that's the
WISHBDITFP. :-)
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
-of-this-function. I'd feel uncomfortable
if this were no longer true.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc
they're being used for a purpose
very different from generating and iterating.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary
it by means of a generator, you don't
need a class at all -- just make the whole thing a generator
function.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand
switched on all the time,
and the operator being used for comparison.
2) The first case is syntactically different from subsequent ones,
even though semantically all the cases are equivalent.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury
permit creating a new dialect. Or something.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
in summary, I don't think you necessarily *need*
macros to get nice-looking user-defined control structures.
It depends on other features of the language.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp
Brett C. wrote:
It executes the body, calling next() on the argument
name on each time through until the iteration stops.
But that's no good, because (1) it mentions next(),
which should be an implementation detail, and (2)
it talks about iteration, when most of the time
the high-level intent has
Guido van Rossum wrote:
[Greg Ewing]
* It seems to me that this same exception-handling mechanism
would be just as useful in a regular for-loop, and that, once
it becomes possible to put 'yield' in a try-statement, people
are going to *expect* it to work in for-loops as well.
(You can already put
atexit() hander to invoke it. I don't think
there's any need to mess with the way atexit()
currently works.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand
where they
*do* feel so compelled, they might not if lambda weren't
such a long word.
I was just trying to understand why Smalltalkers seem to
get on fine without macros, whereas Lispers feel they are
needed. I think Smalltalk's lightweight block-passing
syntax has a lot to do with it.
--
Greg
is loaded, its source code
has long since been compiled into code objects.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc
information about both scopes
available.
Although it might be better to have some sort of
outer declaration for rebinding in the enclosing
scope, instead of doing it on a whole-function basis.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury
that it's important for them to
know that mutable objects are never in danger of being
shared, so you should at least tell them that much.
Otherwise they may end up worrying unnecessarily that
two of their lists might get shared somehow behind
their back.
--
Greg Ewing, Computer Science Dept
the source directory
from the host system as a file share, and it turns out
that reading a unix symlink from the Windows end just
returns the contents of the link. Aaarrghh! Braindamage!
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury
Guido van Rossum wrote:
And surely you exaggerate. How about this then:
The with-statement is similar to the for-loop. Until you've
learned about the differences in detail, the only time you should
write a with-statement is when the documentation for the function
you are calling
Elegant as the idea behind PEP 340 is, I can't shake
the feeling that it's an abuse of generators. It seems
to go to a lot of trouble and complication so you
can write a generator and pretend it's a function
taking a block argument.
I'd like to reconsider a thunk implementation. It
would be a lot
variables.
True, but is the difference all that great? It's
just one more C-level indirection, isn't it?
we'll want variables
*assigned to* by the thunk also to be shared with the containing
function,
Agreed. We'd need to add a STORE_CELL bytecode or
something for this.
--
Greg Ewing, Computer
Nick Coghlan wrote:
With an appropriate utility block manager
I've just thought of another potential name for them:
Block Utilization and Management Function (BUMF) :-)
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen
Neil Schemenauer wrote:
A variation on this with somewhat different semantics swaps the keywords:
in EXPR for VAR:
BLOCK
Looks weird to my eyes.
Probably makes perfect sense if you're Dutch, though. :-)
--
Greg Ewing, Computer Science Dept
the meanings
of those particular uses, and leave the full general
explanation as an advanced topic.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned
) as f:
...
Then we could confuse both C *and* Ruby programmers at
the same time! :-)
[No, I don't really mean this. I actually prefer block
to this.]
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp
due to an exception, a break statement or a return
statement)
I've always thought that was a particularly unintuitive use
of the word 'else', and I'm not sure I'd like it to be
extended to any new statements.
--
Greg Ewing, Computer Science Dept
exercise typing redundant
keywords, I'd program in COBOL. :-)
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL
Frobbing:
def __neg__(self):
begin_frobbing()
try:
yield
finally:
end_frobbing()
frobbing = Frobbing()
...
-frobbing:
do_something()
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury
there which
take function arguments could *already* be used with
a thunk-based block statement, without needing to be
re-written at all.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch
propagates the Break exception back out,
the block statement should break any enclosing loop.
If the iterator wants to behave like a loop, it can
catch the Break exception and raise StopIteration
instead.
--
Greg Ewing, Computer Science Dept, +--+
University
syntax and semantics.
If new syntax and tricky new interactions with iterators
are needed to support it, it doesn't seem so elegant
any more.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp
Nick Coghlan wrote:
Something relatively nonsensical, but usefully mnemonic
(like 'stmt') may be a good way to go.
How about 'do'?
do opening(filename) as f:
...
do locking(obj):
...
do carefully(): # :-)
...
--
Greg Ewing, Computer Science Dept
, having break depend
on something defined somewhere completely else seems like
an obstacle to easy understanding. IMHO, of course.
//Simon
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp
existing PEP 340 semantics if uncaught,
i.e. break an enclosing loop rather than just terminate
the block statement.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand
might find it useful for indenting a block
of code for cosmetic reasons, although that could easily
be seen as an abuse...
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New
by generators.
This makes a lot more sense to me than trying to
warp the iterator protocol to make it into a block
protocol as well. Let's keep the two things orthogonal.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen
Ron Adam wrote:
There seems to be some confusion as to weather or
not 'for's will do finalizing. So I was trying to stress I think
regular 'for' loops should not finalize. They should probably give an
error if an object with an try-finally in them or an __exit__ method.
But if the
.
But I don't have a big crowd of people looking
over my shoulder while I work, all trying to figure
out why I chose one particular screwdriver over
another, and decide which would be the best
screwdriver to use on their screws.
--
Greg Ewing, Computer Science Dept
,
it could be as simple as testing whether a slot of a
type object is populated during processing of the
bytecode which causes exit from the loop.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp
Guido van Rossum wrote:
Now it would make more sense to change the syntax to
with EXPR as VAR:
BLOCK
and we have Phillip Eby's proposal.
Change the 'with' to 'do' and I'd be +1 on this.
--
Greg Ewing, Computer Science Dept
an __exit__ method if and only
if they have a yield inside a try/finally? Old generators
won't be doing that, because it's currently illegal.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp
and continue) should
be disallowed in a finally?
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
modules.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
).
Instead of an 'args' attribute, I'd suggest that
the constructor take keyword arguments and store
them in corresponding attributes. Then interested
parties could retrieve them by name instead of
having to remember their positions in the args
tuple of the exception class concerned.
--
Greg Ewing
Guido van Rossum wrote:
- Greg Ewing (I believe) wants 'do' instead of 'with' for the
keyword. I think I like 'with' better, especially combining it with
Benji's proposal. IMO this reads better with 'with' than with 'do':
with open(/etc/passwd) as f:
for line in f
, that
looks like nothing more than a local variable
binding.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL
Here's my vote on things at the moment:
+1 on
do EXPR as VAR:
...
+1 on keeping the EXPR and VAR distinct.
+1 on keeping the do and generator protocols distinct.
+1 on not going out of our way to let the controller
catch exceptions or alter control flow. Let's keep it
as simple as we
Guido van Rossum wrote:
Also, one question: will the do protocol be added to built-in resource
types? That is, locks, files, sockets, and so on?
One person proposed that and it was shot down by Greg Ewing. I think
it's better to require a separate wrapper.
It depends on whether the resource
.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
was that, with it, the semantics
of a block statement would be almost, but not quite,
exactly like those of a for-loop, which seems to be
flying in the face of TOOWTDI. And if it weren't for
the can't-finalise-generators-in-a-for-loop backward
compatibility problem, the difference would be even
smaller.
--
Greg
Ron Adam wrote:
He should also be able to put try excepts before the yield, and after
the yield, or in the block. (But not surrounding the yield, I think.)
I was given to understand that yield is currently
allowed in try-except, just not try-finally. So
this would require a
Nick Coghlan wrote:
the_stmt = EXPR1
stmt_enter = getattr(the_stmt, __enter__, None)
stmt_exit = getattr(the_stmt, __exit__, None)
if stmt_enter is None:
VAR1 = the_stmt
else:
VAR1 = stmt_enter()
If we're doing this, it might be better if VAR were simply
Guido van Rossum wrote:
Unfortunately I can't quite decide whether either rule applies in the
case of exceptions.
I think you'd at least be justified in using the magic rule,
since they're set by the exception machinery.
Greg
___
Python-Dev mailing
Nick Coghlan wrote:
Paul Moore wrote:
On 5/17/05, Nick Coghlan [EMAIL PROTECTED] wrote:
Previously Belaboured Point? (Just guessing from context here, but if I'm
right,
that's one acronym I'm going to have to remember. . .)
Practicality Beats Purity, surely...?
D'oh! *slaps forehead*
to put the same frame in the
traceback twice, which can't work since it's a linked
list.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned
that, all this looks good.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
precision. It just seems to be
asking for trouble.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
Raymond Hettinger wrote:
From the mists of Argentina, a Palidan set things right. The literal
1.1 became representable and throughout the land the monster was
believed to have been slain.
I don't understand. Isn't the monster going to pop
right back up again as soon as anyone does any
to what we are meaning by decimal value
(i.e. an instance of Decimal). In other words, this
principle only applies *after* we have constructed a
Decimal instance.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen
Raymond Hettinger wrote:
Did you see Mike Cowlishaw's posting where he described why he took our
current position (wysiwig input) in the spec, in Java's BigDecimal, and
in Rexx's numeric model?
Yes, it appears that you have channeled him correctly
on that point, and Tim hasn't. :-)
But I also
Guido van Rossum wrote:
So (a) would have my preference.
Mine, too.
the PEP would have to be amended to state that
VAR must be a single variable or a list of variables IN PARENTHESES.
+1
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury
)
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
Phillip J. Eby wrote:
At 11:48 PM 7/3/2005 -0400, Raymond Hettinger wrote:
with context_expression as variable:
# perform actions within a context
The with statement establishes a context in which some operations are to
be performed.
I like this.
The object produced by
*
for beginners.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
into memory until requested?
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
to lead to some awkward circumlocutions
in the documentation and confusion in discussions.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned
.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL PROTECTED
. But decorators in a class body
are executed before the surrounding class even exists.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary
A more descriptive name than 'partition' would be 'split_at'.
--
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
JustFillBug wrote:
trisplit()
And then for when you need to record the result
somewhere, tricord(). :-)
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand
' seems
rather too long-winded for such a useful little function.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc
Charles Cazabon wrote:
Perhaps py3k could have a py2compat module. Importing it could have the
effect of (for instance) putting compile, id, and intern into the global
namespace, making print an alias for writeln,
There's no way importing a module could add something that
works like the old
Josiah Carlson wrote:
A bit of free thought brings me to the (half-baked) idea that if string
methods accepted any object which conformed to the buffer interface;
mmap, buffer, array, ... instances could gain all of the really
convenient methods that make strings the objects to use in many
1 - 100 of 2277 matches
Mail list logo