Make delicious recipes!

Package OS


Package OS can be used to execute shell commands.
>>> import os
>>> for x in dir (os):
...   print(x)
  1. F_OK
  2. MutableMapping
  3. O_APPEND
  4. O_BINARY
  5. O_CREAT
  6. O_EXCL
  7. O_NOINHERIT
  8. O_RANDOM
  9. O_RDONLY
  10. O_RDWR
  11. O_SEQUENTIAL
  12. O_SHORT_LIVED
  13. O_TEMPORARY
  14. O_TEXT
  15. O_TRUNC
  16. O_WRONLY
  17. P_DETACH
  18. P_NOWAIT
  19. P_NOWAITO
  20. P_OVERLAY
  21. P_WAIT
  22. R_OK
  23. SEEK_CUR
  24. SEEK_END
  25. SEEK_SET
  26. TMP_MAX
  27. W_OK
  28. X_OK
  29. _Environ
  30. __all__
  31. __builtins__
  32. __cached__
  33. __doc__
  34. __file__
  35. __initializing__
  36. __loader__
  37. __name__
  38. __package__
  39. _copyreg
  40. _execvpe
  41. _exists
  42. _exit
  43. _get_exports_list
  44. _get_masked_mode
  45. _make_stat_result
  46. _make_statvfs_result
  47. _pickle_stat_result
  48. _pickle_statvfs_result
  49. _putenv
  50. _unsetenv
  51. _wrap_close
  52. abort
  53. access
  54. altsep
  55. chdir
  56. chmod
  57. close
  58. closerange
  59. curdir
  60. defpath
  61. device_encoding
  62. devnull
  63. dup
  64. dup2
  65. environ
  66. errno
  67. error
  68. execl
  69. execle
  70. execlp
  71. execlpe
  72. execv
  73. execve
  74. execvp
  75. execvpe
  76. extsep
  77. fdopen
  78. fsdecode
  79. fsencode
  80. fstat
  81. fsync
  82. get_exec_path
  83. get_terminal_size
  84. getcwd
  85. getcwdb
  86. getenv
  87. getlogin
  88. getpid
  89. getppid
  90. isatty
  91. kill
  92. linesep
  93. link
  94. listdir
  95. lseek
  96. lstat
  97. makedirs
  98. mkdir
  99. name
  100. open
  101. pardir
  102. path
  103. pathsep
  104. pipe
  105. popen
  106. putenv
  107. read
  108. readlink
  109. remove
  110. removedirs
  111. rename
  112. renames
  113. replace
  114. rmdir
  115. sep
  116. spawnl
  117. spawnle
  118. spawnv
  119. spawnve
  120. st
  121. startfile
  122. stat
  123. stat_float_times
  124. stat_result
  125. statvfs_result
  126. strerror
  127. supports_bytes_environ
  128. supports_dir_fd
  129. supports_effective_ids
  130. supports_fd
  131. supports_follow_symlinks
  132. symlink
  133. sys
  134. system
  135. terminal_size
  136. times
  137. times_result
  138. umask
  139. uname_result
  140. unlink
  141. urandom
  142. utime
  143. waitpid
  144. walk
  145. write

Example:

# A small function to rename all files present in current directory
def removePatternFromFileNames (pat, globPath):
    for x in glob.glob(globPath): # glob lists all files matching a pattern
        if x.find(pat) > -1 :
            os.rename (x, x.replace(pat,""))







Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal