Re: Strange behaviour with a for loop.

2014-01-04 Thread Larry Hudson
On 01/03/2014 10:32 PM, Sean Murphy wrote: Hi everyone. [snip] The 2nd part of my original question still stands. I will expand upon this a bit more to give more context. I want to print from the beginning of the paragraph to the end. Each paragraph ends with "\n\n\n". If I use "\n\n\n" in l

Re: Strange behaviour with a for loop.

2014-01-04 Thread Larry Hudson
On 01/03/2014 08:03 PM, Sean Murphy wrote: Hello all. This is a newly question. But I wish to understand why the below code is providing different results. import os, sys if len(sys.argv) > 2: filenames = sys.argv[1:] else print ("no parameters provided\n") sys.edit() for filename

Re: Strange behaviour with a for loop.

2014-01-04 Thread Chris Angelico
On Sat, Jan 4, 2014 at 8:52 PM, Sean Murphy wrote: > Thanks for the tip on the function. I was not aware of that function, Grin. > Creating the function as you mention makes a lot of sense. > > I am doing a lot of little bits and pieces focusing on things I need to > eventually build a script th

Re: Strange behaviour with a for loop.

2014-01-04 Thread Sean Murphy
Chris, Thanks for the tip on the function. I was not aware of that function, Grin. Creating the function as you mention makes a lot of sense. I am doing a lot of little bits and pieces focusing on things I need to eventually build a script that is going to compile data from a router and config

Re: Strange behaviour with a for loop.

2014-01-03 Thread Cameron Simpson
On 04Jan2014 16:54, Sean Murphy wrote: > Thanks everyone. > > Mark thanks for the correction on the ':'. Since I didn't cut and copy, > rather typed it out. Errors crept in. :-) > > another question in relation to slicing strings. If you want to get a single > character, just using the index p

Re: Strange behaviour with a for loop.

2014-01-03 Thread Chris Angelico
On Sat, Jan 4, 2014 at 5:32 PM, Sean Murphy wrote: > So I suspect the offset number still starts at the beginning of the string > and counts forward or another way to look at it you are slicing from element > x to element y. If element y is less then element x, return nothing. Does > this make

Re: Strange behaviour with a for loop.

2014-01-03 Thread Sean Murphy
Hi everyone. Worked out what I was doing wrong with the string splicing. The offset number was lower then the index number, so it was failing. E.G: On 04/01/2014, at 4:54 PM, Sean Murphy wrote: > Thanks everyone. > > Mark thanks for the correction on the ':'. Since I didn't cut and copy,

Re: Strange behaviour with a for loop.

2014-01-03 Thread Sean Murphy
Thanks everyone. Mark thanks for the correction on the ':'. Since I didn't cut and copy, rather typed it out. Errors crept in. :-) another question in relation to slicing strings. If you want to get a single character, just using the index position will get it. If I use the following, shouldn'

Re: Strange behaviour with a for loop.

2014-01-03 Thread Mark Lawrence
On 04/01/2014 04:03, Sean Murphy wrote: Hello all. This is a newly question. But I wish to understand why the below code is providing different results. import os, sys if len(sys.argv) > 2: filenames = sys.argv[1:] else print ("no parameters provided\n") sys.edit() for filename in

Re: Strange behaviour with a for loop.

2014-01-03 Thread Chris Angelico
On Sat, Jan 4, 2014 at 3:03 PM, Sean Murphy wrote: > filenames = sys.argv[1:] > > for filename in filenames: > print ("filename is: %s\n" %filename) versus > filenames = sys.argv[1] > > for filename in filenames: > print ("filename is: %s\n" % filename) The first one is slicing sys.arg

Re: Strange behaviour with a for loop.

2014-01-03 Thread Larry Martell
On Fri, Jan 3, 2014 at 11:03 PM, Sean Murphy wrote: > Hello all. > > This is a newly question. But I wish to understand why the below code is > providing different results. > > import os, sys > > > if len(sys.argv) > 2: > filenames = sys.argv[1:] > else > print ("no parameters provided\n") >