Re: newbie question: if var1 == var2:

2008-12-12 Thread Ethan Furman
Andrew Robert wrote: Two issues regarding script. You have a typo on the file you are trying to open. It is listed with a file extension of .in when it should be .ini . Pardon? The OPs original post used .in both in the python code and the command line. Doesn't look like a typo to me. Ou

Re: newbie question: if var1 == var2:

2008-12-12 Thread MRAB
Kirk Strauser wrote: At 2008-12-12T15:35:11Z, "J. Cliff Dyer" writes: Python has a version equally good: def chomp(s): return s.rstrip('\r\n') You'll hardly miss Perl at all. ;) I haven't missed Perl in years! I just wish there was a basestring.stripeol method because I seem to end up

Re: newbie question: if var1 == var2:

2008-12-12 Thread Kirk Strauser
At 2008-12-12T15:35:11Z, "J. Cliff Dyer" writes: > Python has a version equally good: > > def chomp(s): > return s.rstrip('\r\n') > > You'll hardly miss Perl at all. ;) I haven't missed Perl in years! I just wish there was a basestring.stripeol method because I seem to end up writing the in

Re: newbie question: if var1 == var2:

2008-12-12 Thread J. Cliff Dyer
On Thu, 2008-12-11 at 13:44 -0600, Kirk Strauser wrote: > At 2008-12-11T17:24:44Z, rdmur...@bitdance.com writes: > > > >>> ' ab c \r\n'.rstrip('\r\n') > > ' ab c ' > > >>> ' ab c \n'.rstrip('\r\n') > > ' ab c ' > > >>> ' ab c '.rstrip('\r\n') > > ' ab c ' > >

Re: newbie question: if var1 == var2:

2008-12-11 Thread John Machin
On Dec 12, 1:11 pm, MRAB wrote: > John Machin wrote: > > On Dec 12, 11:39 am, MRAB wrote: > >> Jason Scheirer wrote: > >>> On Dec 11, 3:49 pm, John Machin wrote: > On Dec 12, 10:31 am, "Rhodri James" > wrote: > > On Thu, 11 Dec 2008 19:49:23 -, Steve Holden   > > wrote: >

Re: newbie question: if var1 == var2:

2008-12-11 Thread MRAB
John Machin wrote: On Dec 12, 11:39 am, MRAB wrote: Jason Scheirer wrote: On Dec 11, 3:49 pm, John Machin wrote: On Dec 12, 10:31 am, "Rhodri James" wrote: On Thu, 11 Dec 2008 19:49:23 -, Steve Holden wrote: Kirk Strauser wrote: At 2008-11-29T04:02:11Z, Mel writes: You could try

Re: newbie question: if var1 == var2:

2008-12-11 Thread John Machin
On Dec 12, 11:39 am, MRAB wrote: > Jason Scheirer wrote: > > On Dec 11, 3:49 pm, John Machin wrote: > >> On Dec 12, 10:31 am, "Rhodri James" > >> wrote: > > >>> On Thu, 11 Dec 2008 19:49:23 -, Steve Holden   > >>> wrote: > Kirk Strauser wrote: > > At 2008-11-29T04:02:11Z, Mel writ

Re: newbie question: if var1 == var2:

2008-12-11 Thread Rhodri James
On Thu, 11 Dec 2008 23:49:10 -, John Machin wrote: On Dec 12, 10:31 am, "Rhodri James" wrote: On Thu, 11 Dec 2008 19:49:23 -, Steve Holden   wrote: > ... and it's so hard to write >      item = item[:-1] Tsk.  That would be "chop".  "chomp" would be      if item[-1] == '\n':    

Re: newbie question: if var1 == var2:

2008-12-11 Thread MRAB
Jason Scheirer wrote: On Dec 11, 3:49 pm, John Machin wrote: On Dec 12, 10:31 am, "Rhodri James" wrote: On Thu, 11 Dec 2008 19:49:23 -, Steve Holden wrote: Kirk Strauser wrote: At 2008-11-29T04:02:11Z, Mel writes: You could try for item in fname: item = item.strip() This is o

Re: newbie question: if var1 == var2:

2008-12-11 Thread Jason Scheirer
On Dec 11, 3:49 pm, John Machin wrote: > On Dec 12, 10:31 am, "Rhodri James" > wrote: > > > > > On Thu, 11 Dec 2008 19:49:23 -, Steve Holden   > > wrote: > > > > Kirk Strauser wrote: > > >> At 2008-11-29T04:02:11Z, Mel writes: > > > >>> You could try > > > >>> for item in fname: > > >>>    

Re: newbie question: if var1 == var2:

2008-12-11 Thread John Machin
On Dec 12, 10:31 am, "Rhodri James" wrote: > On Thu, 11 Dec 2008 19:49:23 -, Steve Holden   > wrote: > > > > > Kirk Strauser wrote: > >> At 2008-11-29T04:02:11Z, Mel writes: > > >>> You could try > > >>> for item in fname: > >>>     item = item.strip() > > >> This is one case where I really

Re: newbie question: if var1 == var2:

2008-12-11 Thread greg
Kirk Strauser wrote: At 2008-12-11T19:49:23Z, Steve Holden writes: item = item[:-1] It's easy - and broken. Bad things happen if you're using something other than '\n' for EOL. Or if the last line of your file doesn't end with a newline. -- Greg -- http://mail.python.org/mailman/lis

Re: newbie question: if var1 == var2:

2008-12-11 Thread Rhodri James
On Thu, 11 Dec 2008 19:49:23 -, Steve Holden wrote: Kirk Strauser wrote: At 2008-11-29T04:02:11Z, Mel writes: You could try for item in fname: item = item.strip() This is one case where I really miss Perl's "chomp" function. It removes a trailing newline and nothing else, so

Re: newbie question: if var1 == var2:

2008-12-11 Thread Kirk Strauser
At 2008-12-11T19:49:23Z, Steve Holden writes: > ... and it's so hard to write > > item = item[:-1] It's easy - and broken. Bad things happen if you're using something other than '\n' for EOL. -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question: if var1 == var2:

2008-12-11 Thread Bruno Desthuilliers
Steve Holden a écrit : Kirk Strauser wrote: At 2008-11-29T04:02:11Z, Mel writes: You could try for item in fname: item = item.strip() This is one case where I really miss Perl's "chomp" function. It removes a trailing newline and nothing else, so you don't have to worry about losing le

Re: newbie question: if var1 == var2:

2008-12-11 Thread Steven D'Aprano
On Thu, 11 Dec 2008 13:44:22 -0600, Kirk Strauser wrote: > At 2008-12-11T17:24:44Z, rdmur...@bitdance.com writes: > >> >>> ' ab c \r\n'.rstrip('\r\n') >> ' ab c ' >> >>> ' ab c \n'.rstrip('\r\n') >> ' ab c ' >> >>> ' ab c '.rstrip('\r\n') >> ' ab c ' > > I did

Re: newbie question: if var1 == var2:

2008-12-11 Thread Kirk Strauser
At 2008-12-11T17:24:44Z, rdmur...@bitdance.com writes: > >>> ' ab c \r\n'.rstrip('\r\n') > ' ab c ' > >>> ' ab c \n'.rstrip('\r\n') > ' ab c ' > >>> ' ab c '.rstrip('\r\n') > ' ab c ' I didn't say it couldn't be done. I just like the Perl version better. -- K

Re: newbie question: if var1 == var2:

2008-12-11 Thread Steve Holden
Kirk Strauser wrote: > At 2008-11-29T04:02:11Z, Mel writes: > >> You could try >> >> for item in fname: >> item = item.strip() > > This is one case where I really miss Perl's "chomp" function. It removes a > trailing newline and nothing else, so you don't have to worry about losing > leadin

Re: newbie question: if var1 == var2:

2008-12-11 Thread rdmurray
On Thu, 11 Dec 2008 at 10:24, Kirk Strauser wrote: At 2008-11-29T04:02:11Z, Mel <[EMAIL PROTECTED]> writes: You could try for item in fname: item = item.strip() This is one case where I really miss Perl's "chomp" function. It removes a trailing newline and nothing else, so you don't hav

Re: newbie question: if var1 == var2:

2008-12-11 Thread Kirk Strauser
At 2008-11-29T04:02:11Z, Mel <[EMAIL PROTECTED]> writes: > You could try > > for item in fname: > item = item.strip() This is one case where I really miss Perl's "chomp" function. It removes a trailing newline and nothing else, so you don't have to worry about losing leading or trailing spac

Re: newbie question: if var1 == var2:

2008-11-29 Thread Andrew Robert
Two issues regarding script. You have a typo on the file you are trying to open. It is listed with a file extension of .in when it should be .ini . The next issue is that you are comparing what was read from the file versus the variable. The item read from file also contains and end-of-line

Re: newbie question: if var1 == var2:

2008-11-29 Thread John Machin
On Nov 29, 2:53 pm, [EMAIL PROTECTED] wrote: > Hi All, > > I dont understand why the following code cannot find the > variable "tree".  It is very simple but I could not find the answer > to this on the Python Tutorials.  Here is the code, input and runtime: > > #!/usr/bin/python > > fname = open("

Re: newbie question: if var1 == var2:

2008-11-29 Thread Massimo Di Pierro
because when you loop over open(...) is the same as looping over open (...).readlines() and readlines() reads everything including newlines. Try replace: if item == var: with if item.strip() == var: Massimo On Nov 28, 2008, at 9:47 PM, [EMAIL PROTECTED] wrote: Hi All, I dont un

Re: newbie question: if var1 == var2:

2008-11-29 Thread Reggie Dugard
On Fri, 2008-11-28 at 19:47 -0800, [EMAIL PROTECTED] wrote: > Hi All, > > I dont understand why the following code never finds "tree". The problem is that the lines you are reading from the file have a newline at the end so 'tree' != 'tree\n'. See below for suggested changes. > I could not find

Re: newbie question: if var1 == var2:

2008-11-29 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: Hi All, I dont understand why the following code never finds "tree". I could not find the answer in the Python tutorials. Here is the code, test43.in, and runtime: #!/usr/bin/python fname = open("test43.in") var = 'tree' for item in fname: print "item: ", item,

Re: newbie question: if var1 == var2:

2008-11-29 Thread kirby urner
It's the newline after each word that's messing you up. var = "tree\n" ... or if item.strip() == var: ... etc. Kirby On Fri, Nov 28, 2008 at 7:47 PM, <[EMAIL PROTECTED]> wrote: > Hi All, > > I dont understand why the following code never finds "tree". > I could not find the answer in the Py

Re: newbie question: if var1 == var2:

2008-11-29 Thread Mike Howard
item = "tree\n" != 'tree' [EMAIL PROTECTED] wrote: Hi All, I dont understand why the following code never finds "tree". I could not find the answer in the Python tutorials. Here is the code, test43.in, and runtime: #!/usr/bin/python fname = open("test43.in") var = 'tree' for item in fname:

Re: newbie question: if var1 == var2:

2008-11-29 Thread filtered
Any reason for posting such an issue to the account list? Pillock! On Sat, Nov 29, 2008 at 4:47 AM, <[EMAIL PROTECTED]> wrote: > Hi All, > > I dont understand why the following code never finds "tree". > I could not find the answer in the Python tutorials. > Here is the code, test43.in, and runti

Re: newbie question: if var1 == var2:

2008-11-28 Thread alex23
On Nov 29, 1:53 pm, [EMAIL PROTECTED] wrote: > I dont understand why the following code cannot find the > variable "tree". > > fname = open("test43.in") > var = 'tree' > > for item in fname: This will include the EOL character for each line. Try adding the following line here: item = item.s

Re: newbie question: if var1 == var2:

2008-11-28 Thread Mel
[EMAIL PROTECTED] wrote: > Hi All, > > I dont understand why the following code cannot find the > variable "tree". It is very simple but I could not find the answer > to this on the Python Tutorials. Here is the code, input and runtime: > > #!/usr/bin/python > > fname = open("test43.in") > va

newbie question: if var1 == var2:

2008-11-28 Thread joemacbusiness
Hi All, I dont understand why the following code cannot find the variable "tree". It is very simple but I could not find the answer to this on the Python Tutorials. Here is the code, input and runtime: #!/usr/bin/python fname = open("test43.in") var = 'tree' for item in fname: print "item