Python: Check whether a file path is a file or a directory
Python Basic: Exercise-85 with Solution
Write a Python program to check whether a file path is a file or a directory.
import os path="abc.txt" if os.path.isdir(path): print("\nIt is a directory") elif os.path.isfile(path): print("\nIt is a normal file") else: print("It is a special file (socket, FIFO, device file)" ) print()
It is a normal file
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Unpack variables from iterable:
# One can unpack all iterables (tuples, list etc) >>> a, b, c = 1, 2, 3 >>> a, b, c (1, 2, 3) >>> a, b, c = [1, 2, 3] >>> a, b, c (1, 2, 3)
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework