Analysis of OS. path usage in Python

Source: Internet
Author: User
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.

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.