Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
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

Re: Is this pythonic?

2016-11-24 Thread 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, causing them to return EINTR. T

Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
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

Re: Is this pythonic?

2016-11-24 Thread Chris Angelico
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

Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
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

Re: Is this pythonic?

2016-11-24 Thread 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); a thread can be killed, but certain non-interruptible op

Re: Is this pythonic?

2016-11-24 Thread Marko Rauhamaa
"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

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"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

Re: Is this pythonic?

2016-11-23 Thread Steven D'Aprano
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

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"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

Re: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
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'

Re: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
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

Re: Is this pythonic?

2016-11-23 Thread Gregory Ewing
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

Re: Is this pythonic?

2016-11-23 Thread Tim Chase
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

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"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

Re: Is this pythonic?

2016-11-23 Thread Chris Angelico
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

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"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

Re: Is this pythonic?

2016-11-23 Thread Peter Otten
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

Re: Is this pythonic?

2016-11-23 Thread Chris Angelico
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

Re: Is this pythonic?

2016-11-23 Thread Steve D'Aprano
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

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"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

Re: Is this pythonic?

2016-11-23 Thread Frank Millman
"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

Re: Is this pythonic?

2016-11-23 Thread Marko Rauhamaa
"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 - >

Is this pythonic?

2016-11-23 Thread Frank Millman
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

Re: Is this pythonic?

2009-01-27 Thread Baby Coder
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

Re: is this pythonic?

2009-01-22 Thread pruebauno
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

Re: is this pythonic?

2009-01-22 Thread pruebauno
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

Re: is this pythonic?

2009-01-22 Thread TP
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

Re: is this pythonic?

2009-01-22 Thread Peter Otten
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

Re: is this pythonic?

2009-01-21 Thread Scott David Daniels
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

Re: is this pythonic?

2009-01-21 Thread pruebauno
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

Re: is this pythonic?

2009-01-21 Thread alex23
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

Re: is this pythonic?

2009-01-21 Thread alex23
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

Re: is this pythonic?

2009-01-21 Thread MRAB
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

Re: is this pythonic?

2009-01-21 Thread alex23
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

Re: is this pythonic?

2009-01-21 Thread TP
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

Re: is this pythonic?

2009-01-21 Thread MRAB
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

Re: is this pythonic?

2009-01-21 Thread alex23
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

Re: is this pythonic?

2009-01-21 Thread Peter Pearson
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

is this pythonic?

2009-01-21 Thread TP
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

Re: Is this pythonic?

2008-12-18 Thread Hendrik van Rooyen
"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

Re: Is this pythonic?

2008-12-18 Thread Russ P.
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

Re: Is this pythonic?

2008-12-18 Thread Jason Scheirer
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

Re: Is this pythonic?

2008-12-18 Thread pruebauno
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

Re: Is this pythonic?

2008-12-18 Thread Laszlo Nagy
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

Re: Is this pythonic?

2008-12-18 Thread Bruno Desthuilliers
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

Is this pythonic?

2008-12-18 Thread ipytest
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

Re: Is this Pythonic?

2005-08-02 Thread Michael Hudson
[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

Re: Is this Pythonic?

2005-08-02 Thread phil hunt
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

Re: Is this Pythonic?

2005-08-02 Thread Michael Hudson
[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

Re: Is this Pythonic?

2005-08-02 Thread Reinhold Birkenfeld
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() ... >

Re: Is this Pythonic?

2005-08-01 Thread Erik Max Francis
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

Re: Is this Pythonic?

2005-08-01 Thread phil hunt
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

Re: Is this Pythonic?

2005-08-01 Thread phil hunt
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

RE: Is this Pythonic?

2005-08-01 Thread Delaney, Timothy (Tim)
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):

Re: Is this Pythonic?

2005-08-01 Thread phil hunt
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

Re: Is this Pythonic?

2005-08-01 Thread Erik Max Francis
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

Re: Is this Pythonic?

2005-08-01 Thread Bruno Desthuilliers
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

Re: Is this Pythonic?

2005-08-01 Thread Caleb Hattingh
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

Re: Is this Pythonic?

2005-08-01 Thread Benji York
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

Re: Is this Pythonic?

2005-08-01 Thread Peter Hansen
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

Is this Pythonic?

2005-08-01 Thread phil hunt
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

Re: is this pythonic?

2005-07-23 Thread Eric Pederson
"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

Re: is this pythonic?

2005-07-22 Thread Chris Lambacher
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

Re: is this pythonic?

2005-07-22 Thread Caleb Hattingh
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

Apology [was: is this pythonic]

2005-07-21 Thread Steven D'Aprano
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

Re: is this pythonic?

2005-07-21 Thread Terry Reedy
"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

Re: is this pythonic?

2005-07-21 Thread Steven D'Aprano
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

Re: is this pythonic?

2005-07-21 Thread Steven D'Aprano
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

Re: is this pythonic?

2005-07-21 Thread Michael Hoffman
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

Re: is this pythonic?

2005-07-21 Thread Bill Mill
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

Re: is this pythonic?

2005-07-21 Thread Steven D'Aprano
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): >> >

Re: is this pythonic?

2005-07-21 Thread Thomas Lotze
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

Re: is this pythonic?

2005-07-20 Thread Peter Hansen
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

Re: is this pythonic?

2005-07-20 Thread Terry Reedy
> 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

Re: is this pythonic?

2005-07-20 Thread Bill Mill
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): > > >

Re: is this pythonic?

2005-07-20 Thread Bill Mill
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

Re: is this pythonic?

2005-07-20 Thread Caleb Hattingh
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

Re: is this pythonic?

2005-07-20 Thread Simon Brunning
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

is this pythonic?

2005-07-20 Thread Mage
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