Re: loops

2012-12-02 Thread Rhodri James
On Sun, 02 Dec 2012 22:28:48 -, Verde Denim wrote: Nicely done! That fixed it! Is that a version feature or should I take what I find in these books with a grain of salt? It's a difference between Python 2 and Python 3 (which is almost certainly what your book told you to). The other f

Re: loops

2012-12-02 Thread MRAB
On 2012-12-02 22:28, Verde Denim wrote: On 12/02/2012 04:43 PM, Mitya Sirenef wrote: On 12/02/2012 04:39 PM, Verde Denim wrote: I'm just getting into py coding, and have come across an oddity in a py book - while loops that don't work as expected... [snip] This same loop structure appears i

Re: loops

2012-12-02 Thread Verde Denim
On 12/02/2012 04:43 PM, Mitya Sirenef wrote: > On 12/02/2012 04:39 PM, Verde Denim wrote: >> I'm just getting into py coding, and have come across an oddity in a py >> book - while loops that don't work as expected... >> >> import random >> >> MIN = 1 >> MAX = 6 >> >> def main(): >> again = 'y

Re: loops

2012-12-02 Thread Steven D'Aprano
On Sun, 02 Dec 2012 16:39:07 -0500, Verde Denim wrote: > I'm just getting into py coding, and have come across an oddity in a py > book - while loops that don't work as expected... This error has nothing to do with the while loop. Read the error message that Python gives you: > Traceback (most

Re: loops

2012-12-02 Thread Chris Angelico
On Mon, Dec 3, 2012 at 8:39 AM, Verde Denim wrote: > again = input('Roll again? (y = yes): ') > > Roll again? (y = yes): y > Traceback (most recent call last): > File "dice_roll.py", line 17, in > main() > File "dice_roll.py", line 15, in main > again = input('Roll again? (y =

Re: loops

2012-12-02 Thread Mitya Sirenef
On 12/02/2012 04:39 PM, Verde Denim wrote: I'm just getting into py coding, and have come across an oddity in a py book - while loops that don't work as expected... import random MIN = 1 MAX = 6 def main(): again = 'y' while again == 'y': print('Rolling...') print(

Re: loops for ffmpeg CLI in python

2009-08-13 Thread Albert Hopkins
On Wed, 2009-08-12 at 11:29 +0200, fakhar Gillani wrote: > > Hi, > > I am a begineer in Python. Actually I am encoding video files with > different bitrates using ffmpeg CLI. I wanted to ask you that how can > I make loops so that I can vary the bitrates in the CLI of ffmpeg?? > > I want to b

Re: loops

2008-10-19 Thread Steven D'Aprano
On Sun, 19 Oct 2008 03:17:51 -0700, John Machin wrote: > Steven D'Aprano wrote: > >> On Sat, 18 Oct 2008 20:45:47 -0700, John Machin wrote: >> >> > On Oct 19, 2:30 pm, Steven D'Aprano <[EMAIL PROTECTED] >> > cybersource.com.au> wrote: >> > [snip] >> >> making your code easy to read and easy to ma

Re: loops

2008-10-19 Thread John Machin
Steven D'Aprano wrote: > On Sat, 18 Oct 2008 20:45:47 -0700, John Machin wrote: > > > On Oct 19, 2:30 pm, Steven D'Aprano <[EMAIL PROTECTED] > > cybersource.com.au> wrote: > > [snip] > >> making your code easy to read and easy to maintain is far more > >> important. > >> > >> for x in (2**i for

Re: loops

2008-10-19 Thread Steven D'Aprano
On Sat, 18 Oct 2008 20:45:47 -0700, John Machin wrote: > On Oct 19, 2:30 pm, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> wrote: > [snip] >> making your code easy to read and easy to maintain is far more >> important. >> >> for x in (2**i for i in xrange(10)): >>     print x >> >> will

Re: loops

2008-10-18 Thread Paul Rubin
"James Mills" <[EMAIL PROTECTED]> writes: > > for x in (2**i for i in xrange(10)): > >print x > This is by far the most concise solution I've seen so far. print '\n'.join(str(2**i) for i in xrange(10)) -- http://mail.python.org/mailman/listinfo/python-list

Re: loops

2008-10-18 Thread John Machin
On Oct 19, 2:30 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: [snip] > making your code easy to read and easy to maintain is far more important. > > for x in (2**i for i in xrange(10)): >     print x > > will also print 1, 2, 4, 8, ... up to 1000. I would say up to 512; perhaps

Re: loops

2008-10-18 Thread James Mills
On Sun, Oct 19, 2008 at 1:44 PM, James Mills <[EMAIL PROTECTED]> wrote: > On Sun, Oct 19, 2008 at 1:30 PM, Steven D'Aprano > <[EMAIL PROTECTED]> wrote: >> for x in (2**i for i in xrange(10)): >>print x > > This is by far the most concise solution I've seen so far. > And it should never be about

Re: loops

2008-10-18 Thread James Mills
On Sun, Oct 19, 2008 at 1:30 PM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > for x in (2**i for i in xrange(10)): >print x This is by far the most concise solution I've seen so far. And it should never be about conserving code. Also, Python IS NOT C (to be more specific: Python is not a C-cla

Re: loops

2008-10-18 Thread Steven D'Aprano
On Sat, 18 Oct 2008 03:52:51 -0700, Gandalf wrote: > I was hopping to describe it with only one command. most of the > languages I know use this. > It seems weird to me their is no such thing in python. it's not that I > can't fined a solution it's all about saving code It shouldn't be about savi

Re: loops

2008-10-18 Thread Terry Reedy
MRAB wrote: On Oct 18, 7:31 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: Python provide while loops for more fine-grain control, and a protocol so *reuseable* iterators can plug into for loops. Duncan showed you both. If you *need* a doubling loop variable once, you probably need one more than

Re: loops

2008-10-18 Thread MRAB
On Oct 18, 7:31 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Gandalf wrote: > > On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> > > wrote: > >> Gandalf <[EMAIL PROTECTED]> wrote: > >>> how can I do width python a normal for loop width tree conditions like > >>> for example : > >>> for x=1;x<=

Re: loops

2008-10-18 Thread robert
Aaron Brady wrote: Gandalf wrote: On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: Gandalf <[EMAIL PROTECTED]> wrote: how can I do width python a normal for loop width tree conditions like for example : for x=1;x<=100;x+x: print x What you wrote would appear to be an infinite

Re: loops

2008-10-18 Thread Duncan Booth
wbowers <[EMAIL PROTECTED]> wrote: > I agree that using range() for simple iterations is the way to go. except that as Terry said, "The large majority of use cases for iteration are iterating though sequences" I very rarely use range() in iterations. > Here are some examples of python expressi

Re: loops

2008-10-18 Thread wbowers
On Oct 18, 11:31 am, Terry Reedy <[EMAIL PROTECTED]> wrote: > Gandalf wrote: > > On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> > > wrote: > >> Gandalf <[EMAIL PROTECTED]> wrote: > >>> how can I do width python a normal for loop width tree conditions like > >>> for example : > >>> for x=1;x<

Re: loops

2008-10-18 Thread Terry Reedy
Gandalf wrote: On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: Gandalf <[EMAIL PROTECTED]> wrote: how can I do width python a normal for loop width tree conditions like for example : for x=1;x<=100;x+x: print x What you wrote would appear to be an infinite loop so I'll assume

Re: loops

2008-10-18 Thread Aaron Brady
Gandalf wrote: > On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> > wrote: >> Gandalf <[EMAIL PROTECTED]> wrote: >> > how can I do width python a normal for loop width tree conditions like >> > for example : >> >> > for x=1;x<=100;x+x: >> >     print x >> >> What you wrote would appear to be

Re: loops

2008-10-18 Thread robert
Gandalf wrote: On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: Gandalf <[EMAIL PROTECTED]> wrote: how can I do width python a normal for loop width tree conditions like for example : for x=1;x<=100;x+x: print x What you wrote would appear to be an infinite loop so I'll assume

Re: loops

2008-10-18 Thread Gandalf
On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > Gandalf <[EMAIL PROTECTED]> wrote: > > how can I do width python a normal for loop width tree conditions like > > for example : > > > for x=1;x<=100;x+x: > >     print x > > What you wrote would appear to be an infinite loop so I'll ass

Re: loops

2008-10-18 Thread Gandalf
On Oct 18, 12:39 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > Gandalf <[EMAIL PROTECTED]> wrote: > > how can I do width python a normal for loop width tree conditions like > > for example : > > > for x=1;x<=100;x+x: > >     print x > > What you wrote would appear to be an infinite loop so I'll ass

Re: loops

2008-10-18 Thread Duncan Booth
Gandalf <[EMAIL PROTECTED]> wrote: > how can I do width python a normal for loop width tree conditions like > for example : > > for x=1;x<=100;x+x: > print x > What you wrote would appear to be an infinite loop so I'll assume you meant to assign something to x each time round the loop as w

Re: Loops and things

2007-12-15 Thread ZeD
Jair Trejo wrote: > I was wondering how and if it's possible to write a > loop in python > which updates two or more variables at a time. For > instance, something > like this in C: > > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { > printf("i = %d, j = %d\n", i, j); > } >>> for i,j in z

Re: Loops and things

2007-12-14 Thread Jair Trejo
I was wondering how and if it's possible to write a loop in python which updates two or more variables at a time. For instance, something like this in C: for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { printf("i = %d, j = %d\n", i, j); } So that I would get: i = 0, j = 0 i = 1, j = 1 i = 2

Re: Loops and things

2007-12-14 Thread i . pantusa
On Dec 14, 5:01 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > I was wondering how and if it's possible to write a loop in python > > which updates two or more variables at a time. For instance, something > > like this in C: > > >

Re: Loops and things

2007-12-14 Thread Neil Cerutti
On 2007-12-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I was wondering how and if it's possible to write a loop in python > which updates two or more variables at a time. For instance, something > like this in C: > > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { > printf("i = %d, j =

Re: Loops and things

2007-12-14 Thread Tim Chase
> I was wondering how and if it's possible to write a loop in python > which updates two or more variables at a time. For instance, something > like this in C: > > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { > printf("i = %d, j = %d\n", i, j); > } Well, yes it can be done, but depending

Re: Loops and things

2007-12-14 Thread Gary Herron
[EMAIL PROTECTED] wrote: > I was wondering how and if it's possible to write a loop in python > which updates two or more variables at a time. For instance, something > like this in C: > > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { > printf("i = %d, j = %d\n", i, j); > } > > So that I wo

Re: Loops and things

2007-12-14 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I was wondering how and if it's possible to write a loop in python > which updates two or more variables at a time. For instance, something > like this in C: > > for (i = 0, j = 10; i < 10 && j < 20; i++, j++) { > printf("i = %d, j = %d\n", i, j); > } > > So that

Re: Loops Control with Python

2006-10-13 Thread Steven Bethard
hg wrote: > How about a thread on GOTOs ? ;-) A thread? No need! There's a module: http://entrian.com/goto/ ;-) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Loops Control with Python

2006-10-13 Thread Paddy
hg wrote: > Paddy wrote: > > P.S. Welcome to Python! > > > How about a thread on GOTOs ? ;-) I'm trying to be nice on c.l.p. - Mind you, I do have that rant as part of my blog: http://paddy3118.blogspot.com/2006/03/whats-wrong-with-perl.html ;-) - Paddy. -- http://mail.python.org/mailman/li

Re: Loops Control with Python

2006-10-13 Thread hg
Paddy wrote: > Wijaya Edward wrote: >> Can we make loops control in Python? >> What I mean is that whether we can control >> which loops to exit/skip at the given scope. >> >> For example in Perl we can do something like: >> >> OUT: >> foreach my $s1 ( 0 ...100) { >> >> IN: >> foreach my $s

Re: Loops Control with Python

2006-10-13 Thread Paddy
Wijaya Edward wrote: > Can we make loops control in Python? > What I mean is that whether we can control > which loops to exit/skip at the given scope. > > For example in Perl we can do something like: > > OUT: > foreach my $s1 ( 0 ...100) { > > IN: > foreach my $s2 (@array) { > >

Re: Loops Control with Python

2006-10-13 Thread Scott David Daniels
Wijaya Edward wrote: > Can we make loops control in Python? What I mean is that whether > we can control which loops to exit/skip at the given scope. > For example in Perl we can do something like: > OUT: > foreach my $s1 ( 0 ...100) { > IN: > foreach my $s2 (@array) { >

Re: Loops Control with Python

2006-10-13 Thread Jon Clements
Wijaya Edward wrote: > Can we make loops control in Python? > What I mean is that whether we can control > which loops to exit/skip at the given scope. > > For example in Perl we can do something like: > > OUT: > foreach my $s1 ( 0 ...100) { > > IN: > foreach my $s2 (@array) { > >

Re: loops breaks and returns

2006-01-01 Thread Sam Pointon
rbt wrote: > Is it more appropriate to do this: > > while 1: > if x: > return x > > Or this: > > while 1: > if x: > break > return x > > Or, does it matter? I would pick the first form if that's the only place where x would be returned from the function. However, if the

Re: loops breaks and returns

2006-01-01 Thread Peter Hansen
rbt wrote: > Is it more appropriate to do this: > > while 1: > if x: > return x > > Or this: > > while 1: > if x: > break > return x The former would be considered bad style by some people. Others would consider it perfectly acceptable in a small function (say, no

Re: loops -> list/generator comprehensions

2005-02-07 Thread Steven Bethard
Caleb Hattingh wrote: Would filenames = [os.path.join(dirpath, filename) for dirpath, dirnames, filenames in os.walk('.') for filename in filenames] have been clearer for you? Then all you have to do is remember the order of the for-loop execution: Bizarr

Re: loops -> list/generator comprehensions

2005-02-07 Thread Caleb Hattingh
Wow, Steve, thanks, you went to some effort here. I prefer to give names to the values produced by os.walk -- I think it makes the usage much clearer. However, since I don't use 'dirnames', I use '_' to indicate this: Actually, I feel silly for not recognising this - I read about the Python3

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
Alex Martelli wrote: Steven Bethard <[EMAIL PROTECTED]> wrote: at the OP's original code, the line: [(x[0], x[2]) for x in os.walk(".")] is the equivalent of: [dirpath, filenames for dirpath, dirnames, filenames in os.walk('.')] Just a nit: you need parentheses in your second LC too, i.e.: [(dir

Re: loops -> list/generator comprehensions

2005-02-06 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote: > at the OP's original code, the line: > > [(x[0], x[2]) for x in os.walk(".")] > > is the equivalent of: > > [dirpath, filenames for dirpath, dirnames, filenames in os.walk('.')] Just a nit: you need parentheses in your second LC too, i.e.: [(dirp

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
Caleb Hattingh wrote: filenames = [os.path.join(dirpath, filename) # This is cool for dirpath, _, filenames in os.walk('.') # This is getting tricky, whats the '_' for? Nothing to do with the list comprehension really. '_' is a commonly used variable name

Re: loops -> list/generator comprehensions

2005-02-06 Thread Caleb Hattingh
Sure Steve Lemme see ... (indentation changed so comments associate with correct bits) Out of curiosity, do you find: filenames = [os.path.join(dirpath, filename) # This is cool for dirpath, _, filenames in os.walk('.') # This is getting tricky, whats

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
On 6 Feb 2005 11:28:37 -0800, <[EMAIL PROTECTED]> wrote: > > walkList = [(x[0], x[2]) for x in os.walk(".")] > filenames = [] > for dir, files in walkList: > filenames.extend(["/".join([dir, f]) for f in files]) Caleb Hattingh top-posted: I would be interested to see an example

Re: loops -> list/generator comprehensions

2005-02-06 Thread jamesthiele . usenet
> HTH, It does. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: loops -> list/generator comprehensions

2005-02-06 Thread Caleb Hattingh
I would be interested to see an example of code that is more concise but yet as *clear* as the one you already have. I can actually read and understand what you've got there. That's cool :) On 6 Feb 2005 11:28:37 -0800, <[EMAIL PROTECTED]> wrote: I wrote this little piece of code to get a l

Re: loops -> list/generator comprehensions

2005-02-06 Thread Steven Bethard
[EMAIL PROTECTED] wrote: I wrote this little piece of code to get a list of relative paths of all files in or below the current directory (*NIX): walkList = [(x[0], x[2]) for x in os.walk(".")] filenames = [] for dir, files in walkList: filenames.extend(["/".join([dir, f]) for