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 character so
they will never match.

To get around this:

#!/usr/bin/python

fname = open("test43.ini")
var = 'tree'

for item in fname:
   print "item: ", item,

   if (item.rstrip("\n") == var):
       print "found tree: ", item,
   else:
       print "No tree found"




David wrote:
Il Fri, 28 Nov 2008 19:47:01 -0800 (PST), [EMAIL PROTECTED] ha
scritto:

  
I dont understand why the following code never finds "tree".
    

New line marker to be stripped?


  
    if item == var:
    
if item.strip() == var:

D.
--
http://mail.python.org/mailman/listinfo/python-announce-list

        Support the Python Software Foundation:
        http://www.python.org/psf/donations.html
  
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to