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
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
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
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
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 =
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(
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
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
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
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
"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
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
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
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
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
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
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<=
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
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
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<
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
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
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
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
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
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
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
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
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:
>
> >
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 =
> 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
[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
[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
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
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
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
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) {
>
>
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) {
>
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) {
>
>
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
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
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
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
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
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
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
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
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
> HTH,
It does. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
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
[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
51 matches
Mail list logo