Python isdir returns true with string but false with variable
<p>My Python script is trying to open a file of county names, read them one at a time then find a folder with the same name.  I'm using isdir to make sure the directory exists first. The print testpath statement shows me what is being tested. </p>

<p>When I use testpath as the argument in isdir, it returns FALSE.  When I put output of the print testpath as the isdir argument, it evaluates to TRUE.  </p>

<p>Can anyone explain why the testpath variable returns FALSE?
Thanks</p>

<pre><code>import sys, string, os

rootdir = 'y:/data/test'
county_list = "u:/sortedcounties.txt"

# Open county_list file and read first name.
os.path.exists(county_list)
os.path.isfile(county_list)
infile = open(county_list,'r')
line =  infile.readline()
while line:
   testpath = os.path.join(rootdir, line)
   print testpath
   if os.path.isdir(testpath):
        print 'testpath = true = ' + testpath

line = infile.readline()
</code></pre>
