Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Python's isfile(path) isdir(path) not working for me.


  • Please log in to reply
4 replies to this topic

#1 Ray Parrish

Ray Parrish

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:11:52 PM

Posted 10 March 2010 - 04:26 AM

Hello,

I am using Python Release 2.5.2, 21st February, 2008, and lookng at the
corresponding document, it says -

isfile(path)
Return True if path is an existing regular file. This follows
symbolic links, so both islink() and isfile() can be true for the same
path.

isdir(path)
Return True if path is an existing directory. This follows symbolic
links, so both islink() and isdir() can be true for the same path.


And I am getting -

>>> import os
 >>> isdir("/home/ray/links")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'isdir' is not defined
 >>> os.isdir("/home/ray/links")
 >>> os.isdir("/home/ray/links")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'isdir'
 >>> os.isfile("/home/ray/links")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'isfile'
 >>> import os.path
 >>> os.isfile("/home/ray/links")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'isfile'

Could someone please explain to me why?

Thanks, Ray Parrish

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:52 AM

Posted 10 March 2010 - 01:27 PM

I'm no Python guy, but I believe you need to import os.path rather than just os. Otherwise you should be able to do path.isfile and path.isdir instead.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:11:52 PM

Posted 11 March 2010 - 12:33 PM

Thanks for the info! I had already gotten an answer from the Ubuntu User's group which told me the same thing, so I'm good to go now.

Later, Ray Parrish

#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:12:52 AM

Posted 11 March 2010 - 01:53 PM

OK then -- just an FYI -- it's generally considered rude to post to multiple forums at the same time, because you end up wasting people's time researching your questions. I don't care, but there are several here who might be disinclined to answer if you've posted elsewhere.

Just thought you'd like to know :thumbsup:

Have a nice day,
Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 Ray Parrish

Ray Parrish
  • Topic Starter

  • Members
  • 91 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottage Grove, Oregon
  • Local time:11:52 PM

Posted 13 March 2010 - 05:29 AM

OK then -- just an FYI -- it's generally considered rude to post to multiple forums at the same time, because you end up wasting people's time researching your questions. I don't care, but there are several here who might be disinclined to answer if you've posted elsewhere.

Just thought you'd like to know :thumbsup:

Have a nice day,
Billy3


Yeah, I usually wouldn't do that, especially since the Ubuntu User's group isn't a programming group, but I was kind of in a hurry for the answer that time.

Later, Ray Parrish




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users