Chris Angelico :
> On Thu, Nov 24, 2016 at 10:14 PM, Marko Rauhamaa wrote:
>> When you use threads, you call read(2) in the blocking mode. Then the
>> read(2) operation will block "for ever." There's no clean way to
>> cancel the system call.
>
> Signals will usually interrupt system calls, causi
On Thu, Nov 24, 2016 at 10:14 PM, Marko Rauhamaa wrote:
> When you use threads, you call read(2) in the blocking mode. Then the
> read(2) operation will block "for ever." There's no clean way to cancel
> the system call.
Signals will usually interrupt system calls, causing them to return
EINTR. T
Chris Angelico :
> On Thu, Nov 24, 2016 at 9:59 PM, Marko Rauhamaa wrote:
>> Chris Angelico :
>>> A coroutine can be abandoned at an await point, but the
>>> currently-executed call is still going to complete (usually);
>>
>> I don't quite understand. Say you are awaiting on receiving bytes from
On Thu, Nov 24, 2016 at 9:59 PM, Marko Rauhamaa wrote:
> Chris Angelico :
>
>> On Thu, Nov 24, 2016 at 7:39 PM, Marko Rauhamaa wrote:
>>> * Coroutines can be killed, threads cannot.
>>
>> Not strictly true. A coroutine can be abandoned at an await point, but
>> the currently-executed call is sti
Chris Angelico :
> On Thu, Nov 24, 2016 at 7:39 PM, Marko Rauhamaa wrote:
>> * Coroutines can be killed, threads cannot.
>
> Not strictly true. A coroutine can be abandoned at an await point, but
> the currently-executed call is still going to complete (usually);
I don't quite understand. Say y
On Thu, Nov 24, 2016 at 7:39 PM, Marko Rauhamaa wrote:
> * Coroutines can be killed, threads cannot.
>
Not strictly true. A coroutine can be abandoned at an await point, but
the currently-executed call is still going to complete (usually); a
thread can be killed, but certain non-interruptible op
"Frank Millman" :
> "Steven D'Aprano" wrote in message
> news:58368358$0$1513$c3e8da3$54964...@news.astraweb.com...
>> I'm a newbie to asyncio, but if I were doing this using threads, [...]
>
> To me, the beauty of asyncio (or I suppose async in general) is that I
> don't have to worry about any
"Steven D'Aprano" wrote in message
news:58368358$0$1513$c3e8da3$54964...@news.astraweb.com...
On Thursday 24 November 2016 15:55, Frank Millman wrote:
> "Steve D'Aprano" wrote in message
> news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com...
>
>> Even if the computation of the memoised
On Thursday 24 November 2016 15:55, Frank Millman wrote:
> "Steve D'Aprano" wrote in message
> news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com...
>
>> Even if the computation of the memoised value is done asynchronously, you
>> can easily split the computation off to a separate method (a
"Steve D'Aprano" wrote in message
news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com...
Even if the computation of the memoised value is done asynchronously, you
can easily split the computation off to a separate method (as you already
talked about doing!) and make getval() block until it
On Wed, 23 Nov 2016 10:11 pm, Frank Millman wrote:
> Gah! The law of unintended consequences strikes again!
>
> As I mentioned, the class in question represents a database column.
Yes, you mentioned that.
> A
> separate class represents a database row. I have a __str__() method on the
> 'row'
On Wed, 23 Nov 2016 11:27 pm, Frank Millman wrote:
> It is a bit like quantum theory. I have no way of telling whether the
> computation has been carried out without looking at it, but the act of
> looking at it triggers the computation. I can tell, of course, by looking
> at the underlying attrib
Frank Millman wrote:
For the time being I will use 'print(await obj.__str__())', as this is a
good compromise.
It seems more like a very *bad* compromise to me.
I can't see how this gains you anything over just doing
print(await obj.getvalue()), and you lose the ability to
do anything that cal
On 2016-11-23 22:15, Steve D'Aprano wrote:
> On Wed, 23 Nov 2016 08:10 pm, Frank Millman wrote:
> > The class has a getval() method to return the current value.
> >
> > Usually the value is stored in the instance, and can be returned
> > immediately, but sometimes it has to be computed, incurring
"Chris Angelico" wrote in message
news:CAPTjJmqGEwHPVyrR+Ti9bV=S5MsLt3nquF4TvE=xpees188...@mail.gmail.com...
On Wed, Nov 23, 2016 at 11:27 PM, Frank Millman
wrote:
>
> @Chris
>>
>> This strongly suggests that str(x) is the wrong way to get the
>> information. You shouldn't be doing database
On Wed, Nov 23, 2016 at 11:27 PM, Frank Millman wrote:
>
> @Chris
>>
>> This strongly suggests that str(x) is the wrong way to get the
>> information. You shouldn't be doing database requests inside __str__
>> or __repr__.
>
>
> I guess you are right, but still it is a pity. __str__ has been worki
"Frank Millman" wrote in message news:o13meh$p2g$1...@blaine.gmane.org...
3. When instantiating an object, check if it would need computation -
if computation_required:
self.getval = self._getval_with_comp
else:
self.getval = self._getval
4. In _getval_with_comp, perfor
Frank Millman wrote:
> Hi all
>
> Sometimes I write something that I think is quite clever, but later on I
> look at it and ask 'What was I thinking?'.
>
> I have just come up with a 'clever' solution to a problem. Would this
> cause raised eyebrows if you were reviewing this?
>
> I have a clas
On Wed, Nov 23, 2016 at 10:11 PM, Frank Millman wrote:
> Gah! The law of unintended consequences strikes again!
>
> As I mentioned, the class in question represents a database column. A
> separate class represents a database row. I have a __str__() method on the
> 'row' class that prints a nicely
On Wed, 23 Nov 2016 08:10 pm, Frank Millman wrote:
[...]
> The class has a getval() method to return the current value.
>
> Usually the value is stored in the instance, and can be returned
> immediately, but sometimes it has to be computed, incurring further
> database lookups.
This is called me
"Marko Rauhamaa" wrote in message news:87inrer0dl@elektro.pacujo.net...
"Frank Millman" :
> 3. When instantiating an object, check if it would need computation -
>if computation_required:
>self.getval = self._getval_with_comp
>else:
>self.getval = self._getval
>
> 4
"Marko Rauhamaa" wrote in message news:87inrer0dl@elektro.pacujo.net...
"Frank Millman" :
> What is the verdict? -1, 0, or +1?
Perfectly cromulent, run-of-the-mill Python code.
A new word to add to my vocabulary - thanks :-)
Frank
--
https://mail.python.org/mailman/listinfo/pytho
"Frank Millman" :
> 3. When instantiating an object, check if it would need computation -
>if computation_required:
>self.getval = self._getval_with_comp
>else:
>self.getval = self._getval
>
> 4. In _getval_with_comp, perform the computation, then add the following -
>
Hi all
Sometimes I write something that I think is quite clever, but later on I
look at it and ask 'What was I thinking?'.
I have just come up with a 'clever' solution to a problem. Would this cause
raised eyebrows if you were reviewing this?
I have a class that represents a single database
On 18 déc 2008, 13:51, Jason Scheirer
wrote:
> I'd say it's fine but breaking up the statement once or twice is a
> good idea just because if one of the function calls in this nested
> thing throws an exception, a smaller statement with fewer calls makes
> for a far more readable traceback. And I
On Jan 21, 4:23 pm, Scott David Daniels wrote:
> prueba...@latinmail.com wrote:
> > ... If you have duplicates this will not work. You will have to do
> > something like this instead:
>
> o=[]
> i=0
> ln=len(l)
> while i > if l[i]['title']=='ti':
> > o.append(l.po
On Jan 21, 4:23 pm, Scott David Daniels wrote:
> prueba...@latinmail.com wrote:
> > ... If you have duplicates this will not work. You will have to do
> > something like this instead:
>
> o=[]
> i=0
> ln=len(l)
> while i > if l[i]['title']=='ti':
> > o.append(l.po
Peter Otten wrote:
> If you can change the rest of your program to work smoothly with a
> dictionary I would suggest the following:
[snip]
>>> from collections import defaultdict
[snip]
Thanks a lot.
I didn't know defaultdict. It is powerful.
I begin to understand that people prefer using dictio
TP wrote:
> Hi,
>
> Is the following code pythonic:
>
l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}]
dict = [ dict for dict in l if dict['title']=='ti']
l.remove(*dict)
l
> [{'title': 'to', 'value': 2}]
>
> Precision: I have stored data in the list of dictiona
prueba...@latinmail.com wrote:
... If you have duplicates this will not work. You will have to do
something like this instead:
o=[]
i=0
ln=len(l)
while i
if l[i]['title']=='ti':
o.append(l.pop(i))
ln-=1
else:
i+=1
Or the followin
On Jan 21, 12:34 pm, TP wrote:
> alex23 wrote:
> > Try not to use 'dict' or the name of any of the other built-in types
>
> So my list is rather:
> l=[{"title":"to", "color":"blue", "value":2}
> {"title":"ti", "color":"red", "value":"coucou"}]
>
> So, I will rather use your solution:
>
> for index
On Jan 22, 3:56 am, MRAB wrote:
> I was referring to the code:
>
> for index, record in enumerate(l):
> if record['title'] == 'ti':
> l.pop(index)
>
> where you are enumerating and iterating over 'l', but also modifying 'l'
> with 'l.pop(index)'.
Ack, you're absolutely
On Jan 22, 3:34 am, TP wrote:
> > for index, record in enumerate(l):
> > if record['title'] == 'ti':
> > l.pop(index)
>
> Ok, I will use this solution. But it is less pythonic than list
> comprehensions.
Are you asking if it's less pythonic, or asserting? Because you'll
fi
alex23 wrote:
On Jan 22, 3:27 am, MRAB wrote:
FYI, you shouldn't modify a list you're iterating over.
But I'm not. I'm building a new list and binding it to the same name
as the original, which works perfectly fine (unless I'm missing
something):
[snip]
I was referring to the code:
for
On Jan 22, 3:27 am, MRAB wrote:
> FYI, you shouldn't modify a list you're iterating over.
But I'm not. I'm building a new list and binding it to the same name
as the original, which works perfectly fine (unless I'm missing
something):
>>> l = range(100)
>>> l = [d for d in l if not d % 5]
>>> l
alex23 wrote:
> Try not to use 'dict' or the name of any of the other built-in types
> as labels.
Ops... Moreover I know it...
> You're stepping through an entire list just to pass another list to
> l.remove to step through and remove items from...in fact, given that
> list.remove deletes th
alex23 wrote:
On Jan 22, 1:16 am, TP wrote:
Is the following code pythonic:
l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}]
dict = [ dict for dict in l if dict['title']=='ti']
l.remove(*dict)
l
[{'title': 'to', 'value': 2}]
Try not to use 'dict' or the name of any of the other
On Jan 22, 1:16 am, TP wrote:
> Is the following code pythonic:
> >>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}]
> >>> dict = [ dict for dict in l if dict['title']=='ti']
> >>> l.remove(*dict)
> >>> l
> [{'title': 'to', 'value': 2}]
Try not to use 'dict' or the name of any of t
On Wed, 21 Jan 2009 16:16:32 +0100, TP wrote:
>
> Is the following code pythonic:
>
l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}]
dict = [ dict for dict in l if dict['title']=='ti']
l.remove(*dict)
l
> [{'title': 'to', 'value': 2}]
>
> Precision: I have stored da
Hi,
Is the following code pythonic:
>>> l=[{"title":"to", "value":2},{"title":"ti","value":"coucou"}]
>>> dict = [ dict for dict in l if dict['title']=='ti']
>>> l.remove(*dict)
>>> l
[{'title': 'to', 'value': 2}]
Precision: I have stored data in the list of dictionaries l, because in my
applica
"Bruno Desthuilliers" wrote:
>ipyt...@gmail.com a écrit :
>> x.validate_output(x.find_text(x.match_filename
>> (x.determine_filename_pattern(datetime.datetime.now()
>>
>> Is it even good programming form?
>
>functional programming addicts might say yes. But as far as I'm
>concerned, I find it
On Dec 18, 8:08 am, ipyt...@gmail.com wrote:
> x.validate_output(x.find_text(x.match_filename
> (x.determine_filename_pattern(datetime.datetime.now()
>
> Is it even good programming form?
I hope you're kidding.
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 18, 8:45 am, prueba...@latinmail.com wrote:
> On Dec 18, 11:08 am, ipyt...@gmail.com wrote:
>
> > x.validate_output(x.find_text(x.match_filename
> > (x.determine_filename_pattern(datetime.datetime.now()
>
> > Is it even good programming form?
>
> Lisp and Scheme programmers love that sty
On Dec 18, 11:08 am, ipyt...@gmail.com wrote:
> x.validate_output(x.find_text(x.match_filename
> (x.determine_filename_pattern(datetime.datetime.now()
>
> Is it even good programming form?
Lisp and Scheme programmers love that style. You can tell by the
number of parentheses :-). In Python peo
ipyt...@gmail.com wrote:
x.validate_output(x.find_text(x.match_filename
(x.determine_filename_pattern(datetime.datetime.now()
Is it even good programming form?
You should try LISP. :-)
--
http://mail.python.org/mailman/listinfo/python-list
ipyt...@gmail.com a écrit :
x.validate_output(x.find_text(x.match_filename
(x.determine_filename_pattern(datetime.datetime.now()
Is it even good programming form?
functional programming addicts might say yes. But as far as I'm
concerned, I find it a bit too nested...
--
http://mail.pytho
x.validate_output(x.find_text(x.match_filename
(x.determine_filename_pattern(datetime.datetime.now()
Is it even good programming form?
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] (phil hunt) writes:
>>It would (possibly) be more Pythonic to
>>define an interface instead,
>
> Does Python have the concept of an interface? When was that added?
It doesn't have one included, but there are at least two
implementations, zope.interface and PyProtocols (I'm sure
On Tue, 02 Aug 2005 08:31:27 GMT, Michael Hudson <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] (phil hunt) writes:
>
>> Suppose I'm writing an abstract superclass which will have some
>> concrete subclasses. I want to signal in my code that the subclasses
>> will implement certan methods. Is this
[EMAIL PROTECTED] (phil hunt) writes:
> Suppose I'm writing an abstract superclass which will have some
> concrete subclasses. I want to signal in my code that the subclasses
> will implement certan methods. Is this a Pythonic way of doing what
> I have in mind:
>
> class Foo: # abstract superc
Delaney, Timothy (Tim) wrote:
> Peter Hansen wrote:
>
>> Change those to "raise NotImplementedError('blah')" instead and you'll
>> be taking the more idiomatic approach.
>
> One thing I've noticed, which I may raise on python-dev ...
> NotImplementedError does *not* play well with super() ...
>
phil hunt wrote:
> That's a clever trick, but it's obvious from the code that the class
> is intended to be abstract, so if people are stupid enough to shoot
> themselves in the foot by creating an instance, I don't feel like
> adding extra code to protect themselves from their stupidity.
Righ
On Mon, 01 Aug 2005 14:07:46 -0700, Erik Max Francis <[EMAIL PROTECTED]> wrote:
>
>Yes, but raise NotImplementedError instead of Exception. Another trick
>you can use is to prevent people from instantiating the abstract class:
>
> class Foo:
> def __init__(self):
> i
On Mon, 01 Aug 2005 22:01:06 +0200, Caleb Hattingh <[EMAIL PROTECTED]> wrote:
>Peter
>
>To my mind, this kind of setup (interface class, or abstact class) is more
>usually used in static languages to benefit polymorphism - but python is
>dynamically typed, so in which situations would this setu
Peter Hansen wrote:
> Change those to "raise NotImplementedError('blah')" instead and you'll
> be taking the more idiomatic approach.
One thing I've noticed, which I may raise on python-dev ...
NotImplementedError does *not* play well with super() ...
class A (object):
def test (self):
On Mon, 01 Aug 2005 12:52:02 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>phil hunt wrote:
>> Suppose I'm writing an abstract superclass which will have some
>> concrete subclasses. I want to signal in my code that the subclasses
>> will implement certan methods. Is this a Pythonic way of doin
phil hunt wrote:
> Suppose I'm writing an abstract superclass which will have some
> concrete subclasses. I want to signal in my code that the subclasses
> will implement certan methods. Is this a Pythonic way of doing what
> I have in mind:
>
> class Foo: # abstract superclass
>def bar(se
Caleb Hattingh a écrit :
> Peter
>
> To my mind, this kind of setup (interface class, or abstact class
are two different things.
>) is
> more usually used in static languages
True.
>to benefit polymorphism
This is a good reason to use an interface in Java. C++ has no notion of
'interfac
Peter
To my mind, this kind of setup (interface class, or abstact class) is more
usually used in static languages to benefit polymorphism - but python is
dynamically typed, so in which situations would this setup be useful in a
python program? You see, I expected your post to say that it wo
phil hunt wrote:
> Suppose I'm writing an abstract superclass which will have some
> concrete subclasses. I want to signal in my code that the subclasses
> will implement certan methods. Is this a Pythonic way of doing what
See http://docs.python.org/lib/module-exceptions.html#l2h-298
(NotImpl
phil hunt wrote:
> Suppose I'm writing an abstract superclass which will have some
> concrete subclasses. I want to signal in my code that the subclasses
> will implement certan methods. Is this a Pythonic way of doing what
> I have in mind:
>
> class Foo: # abstract superclass
>def bar(sel
Suppose I'm writing an abstract superclass which will have some
concrete subclasses. I want to signal in my code that the subclasses
will implement certan methods. Is this a Pythonic way of doing what
I have in mind:
class Foo: # abstract superclass
def bar(self):
raise Exception, "Im
"Caleb Hattingh" <[EMAIL PROTECTED]> wrote:
>In another
> newsgroup, I could have been flamed for letting Simon know he helped
> more
> than just the OP with his post :)
+1
OP asks, thousands are educated (perhaps).
The group's generosity is greatly appreciated, even if that appreciation
On Thu, Jul 21, 2005 at 10:27:24AM -0400, Bill Mill wrote:
> On 7/21/05, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> > On Wed, 20 Jul 2005 16:30:10 -0400, Bill Mill wrote:
> >
> > > On 7/20/05, Simon Brunning <[EMAIL PROTECTED]> wrote:
> > >> On 7/20/05, Mage <[EMAIL PROTECTED]> wrote:
> > >> > O
Terry
Yes, I must agree with you that it is something I should know. I do try
to keep with things but there are always some things that slip through the
cracks, like enumerate, in this case. That is why I am extremely grateful
the for the activity, generosity and pure knowledge on this new
It has been suggested to me off-list that my
response(s) to Bill Mill in the "is this pythonic"
thread were rude and hostile.
If that is what people saw in my posts, then I
apologise, because that wasn't my intention. In fact,
my comments weren't especially even aimed a
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Thu, 21 Jul 2005 10:27:24 -0400, Bill Mill wrote:
>
> [snip]
>
>> I said the *builtins* section. I think you learn pretty quick that
>> figuring out what functions are builtins is pretty important in every
>> langu
On Thu, 21 Jul 2005 10:27:24 -0400, Bill Mill wrote:
[snip]
> I said the *builtins* section. I think you learn pretty quick that
> figuring out what functions are builtins is pretty important in every
> language. There's a fair number of people out there giving the advice
> to read chapter 2 of t
On Thu, 21 Jul 2005 16:43:00 +0100, Michael Hoffman wrote:
> Personally, I feel my time is better served by answering questions that
> would not be easy to find without assistance. I can't expect everyone to
> know about or expect enumerate() from the beginning, so I don't have any
> objections
Steven D'Aprano wrote:
> The great thing about Usenet and the Internet is that we can pick each
> other's brains for answers, instead of flailing around blindly in manuals
> that don't understand the simplest natural language query. And isn't that
> why we're here?
Personally, I feel my time is b
On 7/21/05, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Wed, 20 Jul 2005 16:30:10 -0400, Bill Mill wrote:
>
> > On 7/20/05, Simon Brunning <[EMAIL PROTECTED]> wrote:
> >> On 7/20/05, Mage <[EMAIL PROTECTED]> wrote:
> >> > Or is there better way?
> >> >
> >> > for (i, url) in [(i,links[i]) for
On Wed, 20 Jul 2005 16:30:10 -0400, Bill Mill wrote:
> On 7/20/05, Simon Brunning <[EMAIL PROTECTED]> wrote:
>> On 7/20/05, Mage <[EMAIL PROTECTED]> wrote:
>> > Or is there better way?
>> >
>> > for (i, url) in [(i,links[i]) for i in range(len(links))]:
>>
>> for i, url in enumerate(links):
>>
>
Mage wrote:
> Or is there better way?
>
> for (i, url) in [(i,links[i]) for i in range(len(links))]:
> ...
>
> "links" is a list.
for i, url in enumerate(links):
--
Thomas
--
http://mail.python.org/mailman/listinfo/python-list
Terry Reedy wrote:
>>Wow, I didn't know about enumerate.
>
> It is listed and explained in Lib Ref Manual, Chapter 2, on builtin
> functions and types and their methods. Everyone should read at least that
> much of the Lib manual.
Or be sure to read the "What's New in Python X.Y" pages that ar
> Wow, I didn't know about enumerate.
It is listed and explained in Lib Ref Manual, Chapter 2, on builtin
functions and types and their methods. Everyone should read at least that
much of the Lib manual.
Terry J. Reedy
--
http://mail.python.org/mailman/listinfo/python-list
On 7/20/05, Bill Mill <[EMAIL PROTECTED]> wrote:
> On 7/20/05, Simon Brunning <[EMAIL PROTECTED]> wrote:
> > On 7/20/05, Mage <[EMAIL PROTECTED]> wrote:
> > > Or is there better way?
> > >
> > > for (i, url) in [(i,links[i]) for i in range(len(links))]:
> >
> > for i, url in enumerate(links):
> >
>
On 7/20/05, Simon Brunning <[EMAIL PROTECTED]> wrote:
> On 7/20/05, Mage <[EMAIL PROTECTED]> wrote:
> > Or is there better way?
> >
> > for (i, url) in [(i,links[i]) for i in range(len(links))]:
>
> for i, url in enumerate(links):
>
+2 for creating seeing a need and crafting a reasonable solutio
Wow, I didn't know about enumerate.
Many thanks
Caleb
On Wed, 20 Jul 2005 15:19:50 +0200, Simon Brunning
<[EMAIL PROTECTED]> wrote:
> On 7/20/05, Mage <[EMAIL PROTECTED]> wrote:
>> Or is there better way?
>>
>> for (i, url) in [(i,links[i]) for i in range(len(links))]:
>
> for i, url in enumer
On 7/20/05, Mage <[EMAIL PROTECTED]> wrote:
> Or is there better way?
>
> for (i, url) in [(i,links[i]) for i in range(len(links))]:
for i, url in enumerate(links):
--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
--
http://mail.python.org/mailman/listinfo/pytho
Or is there better way?
for (i, url) in [(i,links[i]) for i in range(len(links))]:
...
"links" is a list.
Mage
--
http://mail.python.org/mailman/listinfo/python-list
80 matches
Mail list logo