Re: for loop without variable

2008-01-11 Thread Tim Chase
>> I recently faced a similar issue doing something like this: >> >> data_out = [] >> for i in range(len(data_in)): >> data_out.append([]) > > Another way to write this is > data_out = [[]] * len(data_in) ...if you're willing to put up with this side-effect: >>> data_in = ran

Re: for loop without variable

2008-01-11 Thread Mike Meyer
On Fri, 11 Jan 2008 22:18:22 GMT Neil Hodgson <[EMAIL PROTECTED]> wrote: > Marty: > > I recently faced a similar issue doing something like this: > > data_out = [] > > for i in range(len(data_in)): > > data_out.append([]) > > Another way to write this is > data_out = [[]] * le

Re: for loop without variable

2008-01-11 Thread Neil Hodgson
Marty: > I recently faced a similar issue doing something like this: > > data_out = [] > for i in range(len(data_in)): > data_out.append([]) Another way to write this is data_out = [[]] * len(data_in) Neil -- http://mail.python.org/mailman/listinfo/python-list

Re: for loop without variable

2008-01-11 Thread Paul Rubin
Fredrik Lundh <[EMAIL PROTECTED]> writes: > (and if you use sane naming conventions, the risk for collisions is > near zero as well). I haven't felt that way, I'm always worried about clobbering something by leaking a variable. Maybe collisions don't really happen much, but it's always seemed cle

Re: for loop without variable

2008-01-11 Thread Fredrik Lundh
Paul Rubin wrote: > it just seems way too obscure though. Python style seems to favor > spewing extra variables around. that's because (local) variables have near-zero cost, and zero overhead. use as many as you want, and reuse them as often as you want to. (and if you use sane naming conven

Re: for loop without variable

2008-01-10 Thread Mike Meyer
On Fri, 11 Jan 2008 01:48:43 -0500 Marty <[EMAIL PROTECTED]> wrote: > Mike Meyer wrote: > >> This caused me to wonder why Python does not have a "foreach" statement > >> (and > >> also why has it not come up in this thread)? I realize the topic has > >> probably > >> been beaten to death in ea

Re: for loop without variable

2008-01-10 Thread Basilisk96
On Jan 10, 10:36 pm, Marty <[EMAIL PROTECTED]> wrote: > Hrvoje Niksic wrote: > > Mike Meyer <[EMAIL PROTECTED]> writes: > > >> It sounds to me like your counter variable actually has meaning, > > > It depends how the code is written. In the example such as: > > > for meaningless_variable in xrange

Re: for loop without variable

2008-01-10 Thread Marty
Mike Meyer wrote: > On Thu, 10 Jan 2008 22:36:56 -0500 Marty <[EMAIL PROTECTED]> wrote: >> I recently faced a similar issue doing something like this: >> >> data_out = [] >> for i in range(len(data_in)): >> data_out.append([]) > > More succinctly: > > data_out = [] > for _

Re: for loop without variable

2008-01-10 Thread Carl Banks
On Thu, 10 Jan 2008 22:36:56 -0500, Marty wrote: > I recently faced a similar issue doing something like this: > > data_out = [] > for i in range(len(data_in)): > data_out.append([]) > > This caused me to wonder why Python does not have a "foreach" statement > (and also why has it

Re: for loop without variable

2008-01-10 Thread Paul Rubin
Mike Meyer <[EMAIL PROTECTED]> writes: > data_out = [[] for _ in data_in] > ... > But I'm curious - what's the difference between the "foreach" you have > in mind and the standard python "for"? The "for" loop, like the list comprehension, pollutes the namespace with an index variable that's not us

Re: for loop without variable

2008-01-10 Thread Paul Rubin
erik gartz <[EMAIL PROTECTED]> writes: > The loop performs some actions with web services. The particular > iteration I'm on isn't important to me. It is only important that I > attempt the web services that number of times. If I succeed I > obviously break out of the loop and the containing functi

Re: for loop without variable

2008-01-10 Thread Matimus
On Jan 10, 10:36 pm, Marty <[EMAIL PROTECTED]> wrote: > Hrvoje Niksic wrote: > > Mike Meyer <[EMAIL PROTECTED]> writes: > > >> It sounds to me like your counter variable actually has meaning, > > > It depends how the code is written. In the example such as: > > > for meaningless_variable in xrange

Re: for loop without variable

2008-01-10 Thread Mike Meyer
On Thu, 10 Jan 2008 22:36:56 -0500 Marty <[EMAIL PROTECTED]> wrote: > I recently faced a similar issue doing something like this: > > data_out = [] > for i in range(len(data_in)): > data_out.append([]) More succinctly: data_out = [] for _ in data_in: data_out.append([]) Or, a

RE: for loop without variable

2008-01-10 Thread Ryan Ginstrom
> On Behalf Of Marty > I recently faced a similar issue doing something like this: > > data_out = [] > for i in range(len(data_in)): > data_out.append([]) > > This caused me to wonder why Python does not have a "foreach" > statement (and also why has it not come up in this thread

Re: for loop without variable

2008-01-10 Thread Marty
Hrvoje Niksic wrote: > Mike Meyer <[EMAIL PROTECTED]> writes: > >> It sounds to me like your counter variable actually has meaning, > > It depends how the code is written. In the example such as: > > for meaningless_variable in xrange(number_of_attempts): > ... > > the loop variable really

Re: for loop without variable

2008-01-10 Thread Basilisk96
On Jan 9, 10:55 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > erik gartz <[EMAIL PROTECTED]> writes: > > The loop performs some actions with web services. The particular > > iteration I'm on isn't important to me. It is only important that I > > attempt the web services that number of times. If I suc

Re: for loop without variable

2008-01-10 Thread Mike Meyer
On Thu, 10 Jan 2008 08:42:16 +0100 Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Mike Meyer <[EMAIL PROTECTED]> writes: > > It sounds to me like your counter variable actually has meaning, > It depends how the code is written. In the example such as: > > for meaningless_variable in xrange(number_of_

Re: for loop without variable

2008-01-10 Thread Duncan Booth
erik gartz <[EMAIL PROTECTED]> wrote: > Hi. I'd like to be able to write a loop such as: > for i in range(10): > pass > but without the i variable. The reason for this is I'm using pylint > and it complains about the unused variable i. I can achieve the above > with more lines of code like: >

Re: Conventions for dummy name (was: for loop without variable)

2008-01-10 Thread Jeroen Ruigrok van der Werven
-On [20080110 00:21], Ben Finney ([EMAIL PROTECTED]) wrote: >The problem with the '_' name is that it is already well-known and >long-used existing convention for an entirely unrelated purpose: in >the 'gettext' i18n library, the '_' function to get the >locally-translated version of a text string.

Re: for loop without variable

2008-01-09 Thread Hrvoje Niksic
Mike Meyer <[EMAIL PROTECTED]> writes: > It sounds to me like your counter variable actually has meaning, It depends how the code is written. In the example such as: for meaningless_variable in xrange(number_of_attempts): ... the loop variable really has no meaning. Rewriting this code on

Re: for loop without variable

2008-01-09 Thread Sam
> Unfortunately, I don't *think* I can shut the > warning for that line or function off, only for the entire file. > Pylint gives you a rating of your quality of code which I think is wrong :) # pylint: disable-msg=X will only impact the current line! $ cat -n dummy.py 1 for i in range(2):

Re: for loop without variable

2008-01-09 Thread Mike Meyer
On Wed, 9 Jan 2008 18:49:36 -0800 (PST) erik gartz <[EMAIL PROTECTED]> wrote: > The loop performs some actions with web services. The particular > iteration I'm on isn't important to me. It is only important that I > attempt the web services that number of times. If I succeed I > obviously break ou

Re: for loop without variable

2008-01-09 Thread Ben Finney
erik gartz <[EMAIL PROTECTED]> writes: > The loop performs some actions with web services. The particular > iteration I'm on isn't important to me. It is only important that I > attempt the web services that number of times. If I succeed I > obviously break out of the loop and the containing funct

Re: for loop without variable

2008-01-09 Thread Carl Banks
On Wed, 09 Jan 2008 14:25:36 -0800, erik gartz wrote: > Hi. I'd like to be able to write a loop such as: for i in range(10): > pass > but without the i variable. The reason for this is I'm using pylint and > it complains about the unused variable i. I can achieve the above with > more lines of

Re: for loop without variable

2008-01-09 Thread Basilisk96
On Jan 9, 9:49 pm, erik gartz <[EMAIL PROTECTED]> wrote: > The loop performs some actions with web services. The particular > iteration I'm on isn't important to me. It is only important that I > attempt the web services that number of times. If I succeed I > obviously break out of the loop and the

Re: for loop without variable

2008-01-09 Thread erik gartz
On Jan 9, 8:35 pm, Dan Sommers <[EMAIL PROTECTED]> wrote: > On Wed, 09 Jan 2008 14:25:36 -0800, erik gartz wrote: > > Hi. I'd like to be able to write a loop such as: > > for i in range(10): > > pass > > but without the i variable. The reason for this is I'm using pylint and > > it complains ab

Re: Conventions for dummy name (was: for loop without variable)

2008-01-09 Thread MRAB
On Jan 9, 11:17 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > > > The underscore is used as "discarded" identifier. So maybe > > > for _ in xrange(10): > > ... > > The problem with the '_' name is that it is already well-known and > long-used exist

Re: for loop without variable

2008-01-09 Thread Dan Sommers
On Wed, 09 Jan 2008 14:25:36 -0800, erik gartz wrote: > Hi. I'd like to be able to write a loop such as: > for i in range(10): > pass > but without the i variable. The reason for this is I'm using pylint and > it complains about the unused variable i ... What does that loop do? (Not the loop

Re: for loop without variable

2008-01-09 Thread John Machin
On Jan 10, 10:00 am, Tim Chase <[EMAIL PROTECTED]> wrote: > >> Hi. I'd like to be able to write a loop such as: > >> for i in range(10): > >> pass > >> but without the i variable. The reason for this is I'm using pylint > >> and it complains about the unused variable i. > > > if a computer tell

Conventions for dummy name (was: for loop without variable)

2008-01-09 Thread Ben Finney
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > The underscore is used as "discarded" identifier. So maybe > > for _ in xrange(10): > ... The problem with the '_' name is that it is already well-known and long-used existing convention for an entirely unrelated purpose: in the 'gettext' i18n

Re: for loop without variable

2008-01-09 Thread Thomas Heller
erik gartz schrieb: > Hi. I'd like to be able to write a loop such as: > for i in range(10): > pass > but without the i variable. The reason for this is I'm using pylint > and it complains about the unused variable i. Pychecker won't complain if you rename 'i' to '_', IIRC: for _ in range(10)

Re: for loop without variable

2008-01-09 Thread Tim Chase
>> Hi. I'd like to be able to write a loop such as: >> for i in range(10): >> pass >> but without the i variable. The reason for this is I'm using pylint >> and it complains about the unused variable i. > > if a computer tells you to do something stupid, it's often better to > find a way to t

Re: for loop without variable

2008-01-09 Thread Diez B. Roggisch
erik gartz schrieb: > Hi. I'd like to be able to write a loop such as: > for i in range(10): > pass > but without the i variable. The reason for this is I'm using pylint > and it complains about the unused variable i. I can achieve the above > with more lines of code like: > i = 0 > while (i !=

Re: for loop without variable

2008-01-09 Thread Fredrik Lundh
erik gartz wrote: > Hi. I'd like to be able to write a loop such as: > for i in range(10): > pass > but without the i variable. The reason for this is I'm using pylint > and it complains about the unused variable i. if a computer tells you to do something stupid, it's often better to find a

for loop without variable

2008-01-09 Thread erik gartz
Hi. I'd like to be able to write a loop such as: for i in range(10): pass but without the i variable. The reason for this is I'm using pylint and it complains about the unused variable i. I can achieve the above with more lines of code like: i = 0 while (i != 10): i += 1 Is there a concise