Day6 OS module, day6os

Source: Internet
Author: User

Day6 OS module, day6os

OS Module

Provides an interface for calling the operating system.

(1) OS. getcwd () obtains the current working directory, that is, the directory path of the current python script.

>>> OS. getcwd () obtains the directory path of the current Python script.
'/Home/zhuzhu'

(2)os.chdir("dirname") Change the working directory of the current script; equivalent to cd under shell

(3)OS. curdir :('.')

(4)OS. pardir :('..')

(5)os.makedirs('dirname1/dirname2') Multiple levels of recursive directories can be generated.

(6)os.removedirs('dirname1') If the directory is empty, delete it and recursively go to the upper-level directory. If the directory is empty, delete it.

(7)os.mkdir('dirname') Generate a single-level Directory, which is equivalent to mkdir dirname in shell.

(8)os.mkdir('dirname') Generate a single-level Directory, which is equivalent to mkdir dirname in shell.

 

(9)os.rmdir('dirname') Delete a single-stage empty directory. If the directory is not empty, it cannot be deleted and an error is returned. This is equivalent to rmdir dirname in shell.

 

(10)os.listdir('dirname') List all files and subdirectories in the specified directory, including hidden files, and print them in list mode.

 

(11)OS. remove () delete an object

(12)os.rename("oldname","newname") Rename a file/Directory

 

(13)os.stat('path/filename') Get the file/Directory Information

 

(14)OS. sep: Specifies the path delimiter of the output operating system."\", Which is "in Linux"/"

 

(15)OS. linesep: output the row Terminator used by the current platform."\t\n"In Linux"\n"

(16)OS. pathsep output the characters used to split the file pathString

>>> OS. pathsep
':'

(17)OS. name output string indicates the current platform. Win->'nt'; Linux->'posix'

(18)os.system("bash command") Run the shell command, directlyDisplay

(19)OS. environ: Obtain the system environmentVariable

(20)OS. path. abspath (path) returns the absolute value of path normalization.Path

>>> OS. path. abspath ("file_json ")
'/Home/zhuzhu/file_json'

(21)OS. path. split (path) Splits path into two groups: Directory and file name.Return

(22)OS. path. dirname (path) returns the path directory. It is actually the first one of OS. path. split (path ).Element

(23)OS. path. basename (path) returns the final file name of the path. If the path ends with a slash (/) or slash (\), a null value is returned. That is, the second OS. path. split (path)

(24)OS. path. exists (path) If path exists, returnTrue; If path does not exist, returnFalse

(25)OS. path. isabs (path) If path is an absolute path, returnTrue

(26)OS. path. isfile (path) If path is an existing fileTrue. OtherwiseFalse

(27)OS. path. isdir (path) If path is an existing Directory, returnTrue. OtherwiseFalse

(28)OS. path. join (path1 [, path2 [,...]) returns the results after combining multiple paths. The parameters before the first absolute path will beIgnore

(29)OS. path. getatime (path) returns the last access to the file or directory pointed to by path.Time

(30)OS. path. getmtime (path) returns the last modification of the file or directory pointed to by path.Time

1. Obtain the current file name and directory name and add it to the system environment variable.

File = OS. path. abspath (_ file _) # obtain the absolute path of the file

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.