470,855 Members | 1,149 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

os.isfile() error

Hi

could someone help me to find out whats wrong with this code?

**************** code ****************
import os, sys

if len(sys.argv) < 2:
sys.exit("please enter a suitable directory.")

dpath = sys.argv[1]
for name in os.listdir(dpath):
if os.isfile(dpath+name):
infile = open(os.path.join(dpath,name), 'rb')
print type(infile)
**************** error ****************
Traceback (most recent call last):
File "python/useful/cat2all.py", line 13, in ?
if os.isfile(dpath+name):
AttributeError: 'module' object has no attribute 'isfile'
thank you
May 6 '06 #1
1 5509
Gary Wessle wrote:
Hi

could someone help me to find out whats wrong with this code?

**************** code ****************
import os, sys

if len(sys.argv) < 2:
sys.exit("please enter a suitable directory.")

dpath = sys.argv[1]
for name in os.listdir(dpath):
if os.isfile(dpath+name):
infile = open(os.path.join(dpath,name), 'rb')
print type(infile)
**************** error ****************
Traceback (most recent call last):
File "python/useful/cat2all.py", line 13, in ?
if os.isfile(dpath+name):
AttributeError: 'module' object has no attribute 'isfile'
thank you

Where 'if os.isfile()' it should be 'os.path.isfile()', the isfile
method is not available in the os module, but in os.path. For more
information look at the module index:

http://docs.python.org/modindex.html

Hope this helps.

Adonis
May 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by p | last post: by
7 posts views Thread by C. A. Kelly | last post: by
6 posts views Thread by NickP | last post: by
5 posts views Thread by 7stud | last post: by
10 posts views Thread by ppaterson | last post: by
2 posts views Thread by 7stud | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.