os.isfile() error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Wessle

    #1

    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("pleas e enter a suitable directory.")

    dpath = sys.argv[1]
    for name in os.listdir(dpat h):
    if os.isfile(dpath +name):
    infile = open(os.path.jo in(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
  • Adonis

    #2
    Re: os.isfile() error

    Gary Wessle wrote:[color=blue]
    > Hi
    >
    > could someone help me to find out whats wrong with this code?
    >
    > *************** * code *************** *
    > import os, sys
    >
    > if len(sys.argv) < 2:
    > sys.exit("pleas e enter a suitable directory.")
    >
    > dpath = sys.argv[1]
    > for name in os.listdir(dpat h):
    > if os.isfile(dpath +name):
    > infile = open(os.path.jo in(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[/color]


    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:



    Hope this helps.

    Adonis

    Comment

    Working...