Reputation: 984
>>> os.getcwd()
'/Users/seungjunlee/test_dir'
>>> p1 = os.path.abspath('sub_1')
>>> p2 = os.path.join('test_dir', 'sub_1')
>>> os.path.isdir(p1)
True
>>> os.path.isdir(p2)
False
So the current working directory is test_dir
, and there is sub directory called sub_1
. p1 stores absolute path of sub_1 and p2 get path using join method of path module.
But thing is os.path.isdir(p1)
and os.path.isdir(p2)
yield different result. How is this possible, what U'm missing here?
Upvotes: 0
Views: 32
Reputation: 31664
You are already under the directory of test_dir
, and os.path.join('test_dir', 'sub_1')
returns test_dir\\sub_1
.
So, in fact what you are checking is /Users/seungjunlee/test_dir/test_dir/sub_1
, surely it's not valid dir.
Upvotes: 1