Python Directory Which Package to Import
IT IS Easy to create a directory in Python if you know the package you need to import. Packages play a vital role in Python. Create and manipulate directories is simplified in Python with the 'OS' package.
![]() |
Python Commands |
Python Directories
You can create and delete directories in Python. These are the best commands you can use quickly in your projects.
1. How to Create a Directory
Import os
os.mkdir('datafiles')
2. How to Change Directory
os.chdir('newdirectory')
3. How to Create a Directory and then Create a file in it
import os
os.mkdir('datafiles/newfiles');
os.chdir('datafiles/newfiles');
fp=open('input.txt', 'w')
fp.write('Hello, Welcome to Programming in Python')
fp.close()
4. How to Know Present Working Directory
os.getcwd()
5. How to delete the directory
os.rmdir('directoryname')
Comments
Post a Comment
Thanks for your message. We will get back you.