names for
boolean-valued functions in any context. Including 'true'
in their names smacks of the same kind of redundancy as
if blarg == True:
...
which is widely regarded as a naive-newbie style blunder
in any language.
+1 on 'any' and 'all
altogether for this very
different use case.
-Brian
--
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
pes for the meaning of (x from ()). . .
How about:
(for x in seq if f(x))
It still has the word 'for' in it and avoids mentioning
x more times than necessary.
Although I can't help feeling that it should be some
other word instead, such as
(all x in seq i
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, C
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, C
ke that would be better, yes. Maybe even just
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, +--+
Universit
were implemented 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.
ction to find out how
many parameters 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.
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 of
ntity(y)
Not that it's false, 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
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
def g(...):
...
Of course if the functions then are
allowed to change the surrounding bindings this could be used for
resource release issues etc.
Yes, rebinding in the surrounding scope is the one thing
that style wouldn't give you
--
Greg Ewing, Comput
nt 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-o
ted until 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 |
Christc
scoped.
(7) A __leave__ or __exit__ special method really turns into another
name for __del__.
Not really. A PEP-310-style __exit__ method is explicitly
invoked at well-defined times, not left until the object
is reclaimed. It doesn't suffer from any of the problems
of __del__.
--
Greg Ewing, C
setblocking(True) file (the default, right?) behaves as you described
above, warts and all. (So old code that uses fcntl() continues to
"work" as before.) But files that have had setblocking(False) called
could gain these new semantics that you propose.
Greg
--
Greg Ward <
read,
and EOF. 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, +
lines 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 NewZealandCo
methods which 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
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 t
to try the other detected browser alternatives.
I like it. Short, simple, and obvious. Can you think of a way to
unit-test it? I took a brief look at the code, and it wasn't obvious to
me. Might require factoring out a lazy initializer, and even then it
might not work. And that would cert
rently than OSS, so be
it.)
(But, oh yeah: +1 to Fred's suggestion of making redirection
controllable. Something like this: default should be no redirection,
programmer should be allowed to specify what to do with stdout/stderr of
GUI browsers.)
Greg
--
Greg Ward <[EMAIL
x4019056c>
NewStyleSpam.__add__ <__main__.NewStyleSpam object at 0x4019062c>
<__main__.NewStyleSpam object at 0x4019056c>
Traceback (most recent call last):
File "/home/cosc/staff/research/greg/tmp/foo.py", line 27, in ?
print x1 + x2
TypeError: unsupported operand ty
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, Comput
s that from
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.
--
Gre
There isn't all that
much left 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 su
You can't 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!
--
Gre
ffect, not to compute a value for consumption
by the block function. I 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&qu
se()
return 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 NewZea
sion of the regular assignment statement.
Syntactically, yes, but semantically it's more
complicated than just a "simple extension", to
my mind.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZea
t;readme.txt")
def _(fileobj):
...
(Disclaimer: This post should not be taken as
an endorsement of this abuse! I'd still much
rather have a proper language feature for it.)
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury,
to understand what it was doing. We already
have "return" and "yield"; this would be a third similar-yet-
different thing.
If it were considered important enough, it could easily be added
later, without disturbing anything. But I think it's best left
out of an initial specifi
x27;m +1 on moving towards __next__, BTW. IMO, that's the
WISHBDITFP. :-)
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-own
tercepting break
and continue isn't so bad, since they're already associated
with the loop they're in, but return has always been an
unconditional get-me-out-of-this-function. I'd feel uncomfortable
if this were no longer true.
--
Greg Ewing, Computer Science Dept, +-
and iterators (even though they are)
doesn't seem right, because they're being used for a purpose
very different from generating and iterating.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealand
;help", "copyright", "credits" or "license" for more information.
>>> "foo" is "foo"
True
>>> "foo" is "f" + "oo"
False
>>> "foo" is intern("f" + "oo")
True
you're defining 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 |
being 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 Cante
ning the main
.py file for .pth files? This would make it easier to
have collections of Python programs sharing a common
set of modules, without having to either install them
system-wide or write hairy sys.path-manipulating code
or use platform-dependent symlink or PATH hacks.
--
Greg Ewing, Comp
Jim Jewett wrote:
defmacro myresource(filename):
with myresource("thefile"):
def reader():
...
def writer():
...
def fn():
-1. This is ugly.
--
Greg Ewing, Computer Science Dept, +--+
University of
readable. Or prohibit
anything that would 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 subsidi
sing syntax is
fairly unobtrusive.
So 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 Canterbu
l intent has nothing to do with iteration.
In other words, this is too low a level of explanation.
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/option
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 a
nt, and register a
single 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,
only that, in those cases 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 ha
could
use the normal exec statement to invoke the block whenever needed.
There's no need for all that. They're just callable objects.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZeal
le 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 US
le, when you write
while expr:
...
it gets turned into
expr.__while__(thunk)
etc.
No, I'm not really serious about this -- it was just
a wild thought!
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZeal
statement, for example.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
[EMAIL
l the necessary 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, +--+
uido was saying 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 Ewi
on Windows
running under Virtual PC mounting 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, +--
hink Guido was right in the first place, and __error__
really is just a minor variation on __next__ that shouldn't
have a separate entry point.
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/pyth
lanation can't be found, I strongly suspect
that this doesn't correspond to a cohesive enough concept
to be made into a built-in language feature. If you can't
give a short, understandable explanation of it, then it's
probably a bad idea.
Greg
___
oogle and got "PEP 340: Prevention and Care of
Athletic Injuries"!]
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
. Cells
slow down access somewhat compared to regular local 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
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 citiz
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
xplain 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 | wh
e of a for-loop. This is
going to give people the wrong idea altogether.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA
tement.
struct opening(foo) 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, +--+
Universit
7; (i.e. it is not
> terminated early 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
extende
to get lots of finger 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 s
y!
class Frobbing:
def __neg__(self):
begin_frobbing()
try:
yield
finally:
end_frobbing()
frobbing = Frobbing()
...
-frobbing:
do_something()
--
Greg Ewing, Computer Science Dept, +--+
University o
y out 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 |
C
g these
user-defined statements look even more like the native
ones.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand |
rator 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, +--+
Universi
y extends as far as it *doesn't*
require anything beyond existing 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, +--+
U
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 Ew
gt; trying to understand the source code, 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, +--+
o *not* retain 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 |
Christchurc
some people 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 |
Christ
give you block iterators implemented 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, +--+
Univ
an __exit__ method.
But if the for-loop can tell whether the iterator
needs finalizing or not, why not have it finalize
the ones that need it and not finalize the ones
that don't? That would be backwards compatible,
since old for-loops working on old
know or care whether it
requires finalization -- it should Just Work, whatever
context it is used in.
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
particular screw, and this isn't a problem.
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
If implemented properly,
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 New
the right
statement.
For backwards compatibility, the existing for-loop
would work for partial iteration of old iterators,
but this usage would be deprecated.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen
d" idiom.
I'm inclined to agree. Anything more elaborate than
breaking from a single place in the immediately
enclosing loop tends to be getting into the realm
of spaghetti, in my experience. Giving people named
loops would be tantamount almost to giving them
a go
he's not wrong, and due to the way things are
coded, the reference happens to hang around a little
longer than strictly needed.
If garbage collection were sufficient, we'd be relying
on it to close our files in the first place, and this
whole thread would never have gotten sta
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
ecorator
What about giving them 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,
n this case?
Or do you think return (and break and continue) should
be disallowed in a finally?
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | whol
are in some very old library modules.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc
; attribute set to
> None if not a chained exception).
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 positio
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':
line)
To anyone with a Lisp or funcional background, 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
ing to do with whether
a generator is used or not. Keeping them separate
seems to be a useful thing in its own right.
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.or
lso I don't see that people will be
writing block controllers anywhere near as often as
iterators, so writing classes for them isn't going to
be a big chore. And people can always use a
do-protocol-to-generator adaptor if they really want.
Greg
_
u want
to do 'with' it, e.g. you have a pathname and you want
to open a file. I've already argued against giving file
objects __enter__ and __exit__ methods. And I'm -42 on
giving them to strings. :-)
--
Greg Ewing, Computer Science Dept, +--+
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 requ
ety of possible errors.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA In
method *does*
return a canvas, with __enter__ and __exit__
methods, and the rule that you have to use the
appropriate protocol before you can use it. This
would avoid most of the aforementioned problems.
So I think I may have just talked myself out of
e
> existing "open" builtin would suffice:
>
>with open(filename, "rb") as f:
>for line in f:
>print line
I think I'm starting to agree. Currently about +0.6 in
favour of 'with' now, especially if this is to be
almost
lity constraints.
E.g. it seems we can't make for-loops work the way
they should in the face of generator finalisation
or we break old code.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a
blem, the difference would be even
smaller.
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned
kwards-compatible
change.
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Aahz wrote:
> On Fri, May 13, 2005, Greg Ewing wrote:
>
>>Instead of an 'args' attribute, I'd suggest that the constructor take
>>keyword arguments and store them in corresponding attributes.
>
> Sounds reasonable, but it should be equally easy to ha
t an exception if you try to re-use one.
I still think it's conceptually cleaner if the object
you use to access the resource is created by the
__enter__ method rather than being something pre-
existing, but I'm willing to concede that PBP here.
--
Greg Ewing, Computer Science Dept, +--
1901 - 2000 of 2499 matches
Mail list logo