Analysis of OS. path usage and pythonos. path usage in Python
This article analyzes the usage of OS. path in Python. Share it with you for your reference. The details are as follows:
Copy codeThe Code is as follows: # coding = UTF-8
Import OS
Print OS. path. abspath ("d: \ new \ test.txt ")
Print OS. path. basename ("d :\\ new \ test.txt ")
Print OS. path. dirname ("d: \ new \ test.txt ")
Print OS. path. exists ("d: \ new ")
Print OS. path. lexists ("d: \ new ")
Print OS. path. expanduser ("d :\\ new \ text.txt ")
Print OS. path. getatime ("d: \ new") # last access time
Print OS. path. getmtime ("d: \ new") # Last modified path time
Print OS. path. getctime ("d: \ new") # Creation Time
Print OS. path. getsize ("d: \ new \") # The size of the path is in bytes.
Print OS. path. isabs ("d :\\") # whether it is an absolute path
Print OS. path. isfile ("d :\\ new \ hello.txt ")
Print OS. path. isdir ("d: \ new ")
Print OS. path. islink ("d :\\ new \ hello.txt ")
Print OS. path. join ("d: \ new", "hello.txt ")
Print OS. path. normcase ("d: \ new \ hello.txt ")
Print OS. path. relpath ("d: \ new \ hello.txt") # Relative path
Print OS. path. split ("d: \ new \ hello.txt") # separate file names
Print OS. path. splitdrive ("d :\\ new \ hello.txt") # detach a disk drive
Print OS. path. splitext ("d :\\ new \ hello.txt") # separated Extension
Running result:
>>>
D: \ new \ test.txt
Test.txt
D: \ new
True
True
D: \ new \ text.txt
1322235096.47
1322235096.47
1321610018.9
16384
True
True
True
False
D: \ new \ hello.txt
D: \ new \ hello.txt
Hello.txt
('D: \ new', 'hello.txt ')
('D: ',' \ new \ hello.txt ')
('D: \ new \ hello ', '.txt ')
>>>
I hope this article will help you with Python programming.