OS in Python

                                                OS

OS stand for operating System, os python ka built in module hai to ise hme install nhi krna padega , OS module hame operating system se related operation krne mai madad krta hai jaise ki current working directory dekhna ya fir usay change krna , os module ki madad se hm koi bhi folder kisi bhi drive mai create kr skte hai. Aayiye ise aur clear banate hai example ki madad se 


------------------------
import os 

#os module ko import krne ke liye 
----------------------------------------------------------------
print(os.getcwd())

output:

C:\Users\hp

#cwd stand for current working directory , getcwd function hame hamari current working directory batata hai
-----------------------------------------------------------

print(dir(os))

output:

['DirEntry', 'F_OK', 'MutableMapping', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_NOINHERIT', 'O_RANDOM', 'O_RDONLY', 'O_RDWR', 'O_SEQUENTIAL', 'O_SHORT_LIVED', 'O_TEMPORARY', 'O_TEXT', 'O_TRUNC', 'O_WRONLY', 'P_DETACH', 'P_NOWAIT', 'P_NOWAITO', 'P_OVERLAY', 'P_WAIT', 'PathLike', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET', 'TMP_MAX', 'W_OK', 'X_OK', '_Environ', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_execvpe', '_exists', '_exit', '_fspath', '_get_exports_list', '_putenv', '_unsetenv', '_wrap_close', 'abc', 'abort', 'access', 'altsep', 'chdir', 'chmod', 'close', 'closerange', 'cpu_count', 'curdir', 'defpath', 'device_encoding', 'devnull', 'dup', 'dup2', 'environ', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv', 'execve', 'execvp', 'execvpe', 'extsep', 'fdopen', 'fsdecode', 'fsencode', 'fspath', 'fstat', 'fsync', 'ftruncate', 'get_exec_path', 'get_handle_inheritable', 'get_inheritable', 'get_terminal_size', 'getcwd', 'getcwdb', 'getenv', 'getlogin', 'getpid', 'getppid', 'isatty', 'kill', 'linesep', 'link', 'listdir', 'lseek', 'lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep', 'pipe', 'popen', 'putenv', 'read', 'readlink', 'remove', 'removedirs', 'rename', 'renames', 'replace', 'rmdir', 'scandir', 'sep', 'set_handle_inheritable', 'set_inheritable', 'spawnl', 'spawnle', 'spawnv', 'spawnve', 'st', 'startfile', 'stat', 'stat_result', 'statvfs_result', 'strerror', 'supports_bytes_environ', 'supports_dir_fd', 'supports_effective_ids', 'supports_fd', 'supports_follow_symlinks', 'symlink', 'sys', 'system', 'terminal_size', 'times', 'times_result', 'truncate', 'umask', 'uname_result', 'unlink', 'urandom', 'utime', 'waitpid', 'walk', 'write']


#basically ye wo function hai jise hm os module ke andar use kr skte hai, agar apko kisi bhi module ke andar kitne function hai , agar ye janana hai to ap print(dir(module ka name)) se find kr skte hai.
----------------------------------------------------------------------
os.chdir("c://Users//hp//")

#agar apko apni current working directory change krni hai to ap chdir ka use kr skte hai , chdir stand for change directory , apko apne directory ka path inverted comma mai likhna hai

--------------------------------------------------------------------------
print(os.listdir("C://"))

output:

['$Recycle.Bin', '$WINDOWS.~BT', 'background', 'Bitnami', 'Documents and Settings', 'hiberfil.sys', 'hp', 'Intel', 'IntelOptaneData', 'pagefile.sys', 'PerfLogs', 'Program Files', 'Program Files (x86)', 'ProgramData', 'Recovery', 'swapfile.sys', 'swsetup', 'System Volume Information', 'SYSTEM.SAV', 'Users', 'Windows']

#ye batayega ki apki C drive mai kya kya hai, agar apko aur koi drive mai check krna hai to apko path change krna padega

------------------------------------------------------------------------------
os.mkdir("hey")

#this will create a folder named hey in your current working directory 
--------------------------------------------------------------------------------
os.rename("hey" ,"hello")

#agar apko folder ka name hey se hello mai change krna hai to ap rename function ka use kr skte ho.
--------------------------------------------------------------------------------
os.path.exists("c://")

output:
True

#True mtlb ye path harmare operating system mai exist krta hai
----------------------------------------------------------------------


Comments

Popular posts from this blog

All about Machine learning

Machine Learning