Time module and OS module, JSON module

Source: Internet
Author: User

Import time# def month (n): # time.local () # struct_time=time.strptime ("%y-%m-1", "%y-%m-%d") # print (struct_time) # Return Time.mktime (struct_time) # # Print (month (2)) # Ret=time.localtime (1500000000) # print (ret) # Print (Time.strftime ( "%Y", ret) # print (struct_time) # ret=time.localtime () # Print (ret) # Print (Time.strftime ("%Y")) # time module: # Print (time.        Time ()) #时间戳 # timestamp Time, GMT, float data type for machine # London, England 1970.1.1 0:0:0 # beijing time 1970.1.1 8:0:0 # 1533693120.3467407     #时间元祖 # ret=time.localtime () # Print (ret) #格式化时间: # Print (Time.strftime ("%y-%m-%d")) #他们之间的转换关系: #     Timestamp converted to structured time in converted to formatted time # ret=time.localtime (1500000000) # print (ret) # Print (Time.strftime ("%y-%m-%d", ret) # Format time converted to timestamp # struct_time=time.strptime ("2018-8-8", "%y-%m-%d") # Print (Time.mktime (struct_time)) # SYS module Import SYS #    Deal with Python interpreter # Sys.path #查看文件路径 # sys.modules #查看模块路径 # Print (sys.platform) #查看系统 # sys.exit () # End Program #os module import OS #os. Module # os.makedirs (' Dir/dir1 ') #生成文件多层目录 # OS.mkdir (' Dir2 ') #创建同级文件 # os.removedirs (' Dir/dir1 ') #删除多级文件, must require that the file is empty, encountered non-empty file will not delete # Os.rmdir (' Dir2 ') #删除单级文件, non-empty files are not deleted, error # ret=os.listdir (' E:\python:project ') #查看该路径下文件, print in list form # print (ret) # Os.system ("02.py") for copy and delete files # Ret=os.popen (" 02.py ") #用于查看某些信息, perform certain operations # print (Ret.read ()) # Os.path Module # print (Os.path.dirname (' e:\python:project\day27\01.py ')) # Returns the __file__ # print (Os.path.isfile (' 01.py ')) #判断是否文件, using the absolute path # print (Os.path.isfile (' e:\python:project\ Day27 ') # Print (Os.path.isdir (' 01.py ')) #判断是否是一个文件夹, with the absolute path # print (Os.path.isdir (' e:\python:project\day27 ')) # ret = Os.path.join (' e:\python:project\day27 ', ' aaa ', ' BBB ') #将多个路径组合后拼接 # Print (Os.path.abspath (ret)) # Ret=os.path.getsize (R ' E:\python:project ') #统计文件夹中所有的总size # print (ret) # Serialization module Import json# can match four usages of other languages # JSON: # dic={"A": 1, "B": 2, "C": 3}# Str_dic=json.dumps (DIC) #json. Dumps can convert some of the other types to string type # print (str_dic) # dic1=json.loads (str_dic) # Json.loads can revert the string type to the original type # print (DIC1) # with open ("file.txt", mode= "W", encoding= "Utf-8") as F: #将部分其他类型的转换为字符串写入文件 #    Json.dump (dic,f) # with open ("file.txt", mode= "R", encoding= "Utf-8") as F: #将转换的类型还原并且读出 # Print (Json.load (f)) 

Time module and OS module, JSON module

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.