Python Learning-the standard library OS example (3)

Source: Internet
Author: User

#!/usr/bin/env Python3#-*-coding:utf-8-*-#lists the file size and creation date and file name of the current directory, equivalent to the ls-l command fromDatetimeImportdatetimeImportospwd= Os.path.abspath ('.')Print('Size last Modified Name')Print('------------------------------------------------------------') forFinchOs.listdir (PWD): F_size=os.path.getsize (f)ifF_size > 1024: K_size= Round (f_size/1024, 1) F_size= str (k_size) +'K'        ifK_size > 1024: M_size= Round (k_size/1024, 1) F_size= str (m_size) +'M'            ifM_size > 1024: G_size= Round (m_size/1024, 1) F_size= str (g_size) +'G'    Else: F_size= str (f_size) +'B'Mtime= Datetime.fromtimestamp (Os.path.getmtime (f)). Strftime ('%y-%m-%d%h:%m') Flag='/' ifOs.path.isdir (f)Else "'    " "if Os.path.isdir (f): t = '/' Else:t = """ "    #print ('%10d%s%s%s '% (fsize, mtime, F, flag))    Print("{: >10}{:^20}{}{}". Format (f_size, Mtime, F, flag))

Python Learning-the standard library OS example (3)

Related Article

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.