<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<pre wrap="">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"
</pre>
<br>
<br>
David wrote:
<blockquote cite="mid:1drnn4s80telr$.1ofybdk342gmc$.dlg@40tude.net"
type="cite">
<pre wrap="">Il Fri, 28 Nov 2008 19:47:01 -0800 (PST), <a class="moz-txt-link-abbreviated" href="mailto:joemacbusiness@gmail.com">joemacbusiness@gmail.com</a> ha
scritto:
</pre>
<blockquote type="cite">
<pre wrap="">I dont understand why the following code never finds "tree".
</pre>
</blockquote>
<pre wrap=""><!---->
New line marker to be stripped?
</pre>
<blockquote type="cite">
<pre wrap=""> if item == var:
</pre>
</blockquote>
<pre wrap=""><!---->if item.strip() == var:
D.
--
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/python-announce-list">http://mail.python.org/mailman/listinfo/python-announce-list</a>
Support the Python Software Foundation:
<a class="moz-txt-link-freetext" href="http://www.python.org/psf/donations.html">http://www.python.org/psf/donations.html</a>
</pre>
</blockquote>
</body>
</html>