This article mainly introduces the operating system in Python. path usage. the instance analyzes the OS. the various common methods of path have some reference value. if you need them, you can refer to the examples in this article to analyze the OS in Python. path usage. Share it with you for your reference. The details are as follows:
The 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.