vishavjeet

singh.vishavjeet11@gmail.com

OS Module In python

Posted on March 23, 2021



import os

print(os)

#<module 'os' from 'C:\\Users\\1131\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\os.py'>

print(os.path)

#<module 'ntpath' from 'C:\\Users\\1131\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\ntpath.py'>

print(os.name) # nt

#'posix', 'nt', 'java'

print(os.environ)


print(os.environ["HOME"])

# C:\Users\1131

print(os.chdir("D:/py_core_python")) #Change Directory

print(os.getcwd()) #D:\py_core_python

print(os.path.abspath("django")) #D:\py_core_python\nishu\django

print(os.path.dirname(os.path.abspath("django"))) #D:\py_core_python\nishu

print(os.path.dirname(os.path.dirname(os.path.abspath("django"))))

print("...")

print(__file__) # D:/py_core_python/_os_module.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

print(BASE_DIR)

print(os.path.join(BASE_DIR, "django"))

# os.fchdir(fd)

# os.getcwd()

# os.fchmod(fd, mode)

# os.open(path, flags, mode=0o777, *, dir_fd=None)

# import os

#

# # Build paths inside the project like this: os.path.join(BASE_DIR, ...)

# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


Sign In for comment and like the post.