Re: [Tutor] For Loop Question

2012-12-24 Thread Alan Gauld
On 24/12/12 16:31, bob gailer wrote: On 12/23/2012 9:02 PM, Alan Gauld wrote: You do realize that self is only defined inside a method? Perhaps. self is just another name - it could be "just" a variable, outside any method. True enough, but given the usage "self.A" it looks pretty certain

Re: [Tutor] For Loop Question

2012-12-24 Thread bob gailer
On 12/23/2012 9:02 PM, Alan Gauld wrote: You do realize that self is only defined inside a method? Perhaps. self is just another name - it could be "just" a variable, outside any method. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor mailli

Re: [Tutor] For Loop Question

2012-12-23 Thread Dave Angel
On 12/23/2012 09:02 PM, Alan Gauld wrote: > On 24/12/12 01:16, Mitya Sirenef wrote: >> On 12/23/2012 08:03 PM, Tom Tucker wrote: >>> >>> >>> Python Gurus, >>> I got a question for ya. Below I have three instance variables >>> (self.A, self.B, etc). How can I use the below >>> for loop for A, B, C

Re: [Tutor] For Loop Question

2012-12-23 Thread Alan Gauld
On 24/12/12 01:16, Mitya Sirenef wrote: On 12/23/2012 08:03 PM, Tom Tucker wrote: Python Gurus, I got a question for ya. Below I have three instance variables (self.A, self.B, etc). How can I use the below for loop for A, B, C to also call those instance variables? Your example is not ent

Re: [Tutor] For Loop Question

2012-12-23 Thread Mitya Sirenef
On 12/23/2012 08:03 PM, Tom Tucker wrote: Python Gurus, I got a question for ya. Below I have three instance variables (self.A, self.B, etc). How can I use the below for loop for A, B, C to also call those instance variables? Example ### . . self.A = 1 self.

[Tutor] For Loop Question

2012-12-23 Thread Tom Tucker
Python Gurus, I got a question for ya. Below I have three instance variables (self.A, self.B, etc). How can I use the below for loop for A, B, C to also call those instance variables? Example ### . . self.A = 1 self.B= 2 self.C= 3 myDict = {'A': 1, 'B':

Re: [Tutor] for loop question

2012-07-04 Thread Emile van Sebille
On 7/1/2012 2:50 PM Jim said... Hello Friends, I apologize for being such a bother. This problem has been evading me all day. Can you please give me a hint as to why I cannot put the variable UpperCaseSentence outside of the for loop? I can do it in other instances but not in this one. Thank you

Re: [Tutor] for loop question

2012-07-04 Thread Hugo Arts
On Sun, Jul 1, 2012 at 11:50 PM, Jim wrote: > Hello Friends, > I apologize for being such a bother. This problem has been evading me all > day. Can you please give me a hint as to why I cannot put the variable > UpperCaseSentence outside of the for loop? > I can do it in other instances but not i

[Tutor] for loop question

2012-07-04 Thread Jim
Hello Friends, I apologize for being such a bother. This problem has been evading me all day. Can you please give me a hint as to why I cannot put the variable UpperCaseSentence outside of the for loop? I can do it in other instances but not in this one. Thank you so much, Jim #Main function.

Re: [Tutor] For Loop question

2008-06-27 Thread Kent Johnson
On Fri, Jun 27, 2008 at 2:45 AM, Mark Tolonen <[EMAIL PROTECTED]> wrote: > The above solutions create new lists. If a functional requirement is to > modify the list in place, then the original is fine (on Python 2.6 and > later) or should use xrange instead of range (on Python 2.5 or earlier, > e

Re: [Tutor] For Loop question

2008-06-26 Thread Mark Tolonen
"Lie Ryan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Thu, Jun 26, 2008 at 3:18 AM, Dick Moores <[EMAIL PROTECTED]> wrote:  Hi I'm learning FOR loop now, very easy too learn. But I get confused to understand this code : myList = [1,2,3,4] for index in range(len(myList)):

Re: [Tutor] For Loop question

2008-06-26 Thread Lie Ryan
On Thu, Jun 26, 2008 at 3:18 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > Hi I'm learning FOR loop now, very easy too learn. But I get confused > to understand this code : > > myList = [1,2,3,4] > for index in range(len(myList)): > myList[index] += 1 > print myList > > And the response is: >

Re: [Tutor] For Loop question

2008-06-26 Thread Cédric Lucantis
Le Thursday 26 June 2008 15:27:05 Danny Laya, vous avez écrit : > Hi I'm learning FOR loop now, very easy too learn. But I get confused to > understand this code : myList = [1,2,3,4] > for index in range(len(myList)): > myList[index] += 1 > print myList > > And the response is: > [2, 3, 4, 5] >

Re: [Tutor] For Loop question

2008-06-26 Thread bhaaluu
On Thu, Jun 26, 2008 at 9:27 AM, Danny Laya <[EMAIL PROTECTED]> wrote: > Hi I'm learning FOR loop now, very easy too learn. But I get confused to > understand this code : > > myList = [1,2,3,4] > for index in range(len(myList)): > myList[index] += 1 > print myList > > And the response is: > [2,

[Tutor] For Loop question

2008-06-26 Thread Danny Laya
Hi I'm learning FOR loop now, very easy too learn. But I get confused to understand this code : myList = [1,2,3,4] for index in range(len(myList)): myList[index] += 1 print myList And the response is: [2, 3, 4, 5] Can you explain me as a newbie, how that code works ?? _

Re: [Tutor] For loop question

2006-05-10 Thread STREET Gideon (SPARQ)
e typed something incorrectly previously :\ Thanks again Gideon (aka Fatfingers) -Original Message- From: w chun [mailto:[EMAIL PROTECTED] Sent: Thursday, 11 May 2006 1:11 PM To: STREET Gideon (SPARQ) Cc: tutor@python.org Subject: Re: [Tutor] For loop question > Thanks all, appears it is

Re: [Tutor] For loop question

2006-05-10 Thread w chun
> Thanks all, appears it is the newline character which was causing me > grief. For some reason I still have to do a readlines on the open file > at this stage, but I can muck about with that to figure it out. that is surprising... i would be interested in hearing what problems you are encounter

Re: [Tutor] For loop question

2006-05-10 Thread STREET Gideon (SPARQ)
Behalf Of Kent Johnson Sent: Thursday, 11 May 2006 1:03 AM Cc: tutor@python.org Subject: Re: [Tutor] For loop question w chun wrote: > Kent Johnson wrote: >> For short Python scripts I usually allow the runtime to close the file. >> For longer programs and anything written in Jy

Re: [Tutor] For loop question

2006-05-10 Thread w chun
> >> For short Python scripts I usually allow the runtime to close the file. > >> For longer programs and anything written in Jython (which has different > >> garbage collection behaviour) I usually use an explicit close(). > > > > i'm still not comfortable without doing my own explicit close(), es

Re: [Tutor] For loop question

2006-05-10 Thread Kent Johnson
w chun wrote: > Kent Johnson wrote: >> For short Python scripts I usually allow the runtime to close the file. >> For longer programs and anything written in Jython (which has different >> garbage collection behaviour) I usually use an explicit close(). > > i'm still not comfortable without doing

Re: [Tutor] For loop question

2006-05-10 Thread w chun
>> HostFile = open("hosts.txt", 'r') >> for item in [x.strip() for x in HostFile]: >> : >> >>Why is this better when the file is large? It still creates a list with all lines in it. yup, that's why i mention this fact below while giving the genex solution. > > Why not simply: > > > > for

Re: [Tutor] For loop question

2006-05-10 Thread Smith, Jeff
CTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Wednesday, May 10, 2006 5:52 AM Cc: tutor@python.org Subject: Re: [Tutor] For loop question w chun wrote: > another thing is that if the host file is large, you may wish to > iterate through the file one line at a time with a l

Re: [Tutor] For loop question

2006-05-10 Thread Kent Johnson
Behalf Of Kent Johnson > Sent: Wednesday, May 10, 2006 5:52 AM > Cc: tutor@python.org > Subject: Re: [Tutor] For loop question > > > w chun wrote: >> another thing is that if the host file is large, you may wish to >> iterate through the file one line at a time with

Re: [Tutor] For loop question

2006-05-10 Thread w chun
> Been trying to understand why the following doesn't work: > > HostFile = open("hosts.txt", 'r') > host = HostFile.readlines() > > for item in host: > print "Connecting to device",item > tn = telnetlib.Telnet(item) >: > File "c:\gideon\python24\lib\telnetlib.py", line 225, in ope

[Tutor] For loop question

2006-05-10 Thread STREET Gideon (SPARQ)
Hi all, Been trying to understand why the following doesn't work: HostFile = open("hosts.txt", 'r') host = HostFile.readlines() for item in host: print "Connecting to device",item tn = telnetlib.Telnet(item) ... Do some other stuff here ... I get the following error: Traceback (most r

Re: [Tutor] For loop question

2006-05-10 Thread Kent Johnson
w chun wrote: > another thing is that if the host file is large, you may wish to > iterate through the file one line at a time with a list comprehension > to do the stripping for you: > > HostFile = open("hosts.txt", 'r') > for item in [x.strip() for x in HostFile]: > : Why is this better