Re: [Tutor] for loops when there is only one row in the result - is there an alternative?

2010-11-25 Thread Steven D'Aprano
Rance Hall wrote: Generally you have something like this: clientlist = get_clients() # where get_clients is a prepared sql statement. normally you would get the individual rows like this: for row in clientlist: do stuff which is great for a long list of results. But I'm running into is

[Tutor] for loops when there is only one row in the result - is there an alternative?

2010-11-25 Thread Rance Hall
Im using the py-postgresql module (docs here: http://python.projects.postgresql.org/docs/1.0/) in a python 3.1 environment to connect to my database. so far everything is working, but I'm having trouble understanding the structure of the variable returned by a select statement Generally you have

Re: [Tutor] 'for' loops

2008-12-07 Thread Lie Ryan
On Tue, 02 Dec 2008 01:17:41 +, Alan Gauld wrote: > while loops are used much less in Python than in other languages because > for loops are so powerful. Actually, I think python's for-loop is so powerful that while loop could be removed from the language and no power would be lost (although

Re: [Tutor] 'for' loops

2008-12-01 Thread Kent Johnson
On Mon, Dec 1, 2008 at 7:56 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > [1] Technically, it iterates over an iterator, which you can think of > as an object that behaves like a list when you throw it at a for loop. The object of the 'in' must be an iterable, which is an object that can produce an

Re: [Tutor] 'for' loops

2008-12-01 Thread Alan Gauld
"WM." <[EMAIL PROTECTED]> wrote I recently asked a question about 'for' loops, expecting them to be similar to 'for-next' loops. I have looked at several on-line tutors but am still in the dark about what 'for' loops do. Python for loops are like foreach loops in other languages. A Python fo

Re: [Tutor] 'for' loops

2008-12-01 Thread John Fouhy
On 02/12/2008, WM. <[EMAIL PROTECTED]> wrote: > I recently asked a question about 'for' loops, expecting them to be similar > to 'for-next' loops. I have looked at several on-line tutors but am still > in the dark about what 'for' loops do. > Does anyone have a plain English about the use of 'for

Re: [Tutor] 'for' loops

2008-12-01 Thread W W
On Mon, Dec 1, 2008 at 6:44 PM, WM. <[EMAIL PROTECTED]> wrote: > I recently asked a question about 'for' loops, expecting them to be similar > to 'for-next' loops. I have looked at several on-line tutors but am still > in the dark about what 'for' loops do. > Does anyone have a plain English abou

Re: [Tutor] 'for' loops

2008-12-01 Thread Steve Willoughby
On Mon, Dec 01, 2008 at 04:44:02PM -0800, WM. wrote: > I recently asked a question about 'for' loops, expecting them to be > similar to 'for-next' loops. I have looked at several on-line tutors but > am still in the dark about what 'for' loops do. > Does anyone have a plain English about the use

[Tutor] 'for' loops

2008-12-01 Thread WM.
I recently asked a question about 'for' loops, expecting them to be similar to 'for-next' loops. I have looked at several on-line tutors but am still in the dark about what 'for' loops do. Does anyone have a plain English about the use of 'for' loops? Are 'while' loops the only way Python runs

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread bob gailer
PLEASE REPLY TO THE GROUP NOT JUST ME. Did you miss my request for that (reply-all)? Umesh Singhal wrote: Hi Bob, unfortunately when i pasted in the code it seems to have gone wrong this is how it is at the moment with the correct indentation for the nested loop: code: a=raw_input('please

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread Lie Ryan
On Sat, 2008-08-16 at 18:07 +0200, [EMAIL PROTECTED] wrote: > Message: 1 > Date: Sat, 16 Aug 2008 06:33:42 +0100 > From: Umesh Singhal <[EMAIL PROTECTED]> > Subject: [Tutor] For Loops and nested loops > To: > Message-ID: <[EMAIL PROTECTED]> > Content-Type:

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread Steve Willoughby
On Sat, Aug 16, 2008 at 06:33:42AM +0100, Umesh Singhal wrote: > Hi im still relatively new to python and i am designing a multiplication > table that enables a user to input the size of the times table unfortunately > ive stumbled on the nested loops this is what i have right now: Is this a hom

Re: [Tutor] For Loops and nested loops

2008-08-16 Thread bob gailer
Umesh Singhal wrote: Hi im still relatively new to python and i am designing a multiplication table that enables a user to input the size of the times table unfortunately ive stumbled on the nested loops this is what i have right now: a=raw_input('please enter a number') b=int(a) n=b+1 for ro

[Tutor] For Loops and nested loops

2008-08-16 Thread Umesh Singhal
Hi im still relatively new to python and i am designing a multiplication table that enables a user to input the size of the times table unfortunately ive stumbled on the nested loops this is what i have right now: a=raw_input('please enter a number') b=int(a) n=b+1 for row in range(1, n):

Re: [Tutor] for loops over multiple lists of the same length

2006-06-22 Thread Shantanoo Mahajan
+++ Emily Fortuna [22-06-06 13:22 -0400]: | I feel like there should be a better way to do this process: | Can you please help? | (This is trivial example code I created off the top of my head, but the | same concept that I am trying to do elsewhere.) | | class Person(object): | def __init_

Re: [Tutor] for loops over multiple lists of the same length

2006-06-22 Thread Kent Johnson
Emily Fortuna wrote: > I feel like there should be a better way to do this process: > Can you please help? > (This is trivial example code I created off the top of my head, but the > same concept that I am trying to do elsewhere.) > > class Person(object): > def __init__(self, first_name, a

[Tutor] for loops over multiple lists of the same length

2006-06-22 Thread Emily Fortuna
I feel like there should be a better way to do this process: Can you please help? (This is trivial example code I created off the top of my head, but the same concept that I am trying to do elsewhere.) class Person(object): def __init__(self, first_name, age, fav_color): s

Re: [Tutor] for loops

2006-04-11 Thread Alan Gauld
>> >>Write a Python program to print out the following shape. >> >>You are expected to use two for loops (these must be nested) to solve >> this problem. >> >> output: >> * * * * * >> * * >> * * >> * * * * * > > That looks a lot like homework. I agree and very poo

Re: [Tutor] for loops

2006-04-11 Thread David Rock
* josip <[EMAIL PROTECTED]> [2006-04-11 09:13]: > I have problem with this question. > Can someone show me the code and than explain it? > > >>Write a Python program to print out the following shape. You are > expected to use two for loops (these must be nested) to solve this problem. >

[Tutor] for loops

2006-04-11 Thread josip
I have problem with this question. Can someone show me the code and than explain it?   >>Write a Python program to print out the following  shape. You are expected to use two for loops (these must be nested) to solve this problem.   output: * * * * * *  * *  * * * * * *

Re: [Tutor] for loops and exceptions

2006-03-30 Thread Kent Johnson
Matthew White wrote: > Hello, > >>From a general style and/or programmatic perspective, which is a "better" > way to write this bit of code? Hmm, neither? > > try: > (dn, attrs) = conn.search_s(search_base, search_scope, search_filter, > search_attrs): > except Exception, e: > warn_

[Tutor] for loops and exceptions

2006-03-29 Thread Matthew White
Hello, >From a general style and/or programmatic perspective, which is a "better" way to write this bit of code? try: (dn, attrs) = conn.search_s(search_base, search_scope, search_filter, search_attrs): except Exception, e: warn_the_user(e) do_something_useful() for (name, d