Import Time
Import datetime
Print (time.altzone/3600) returns the UTC time in seconds
Print (Time.asctime ()) Return date
T=time.localtime () returns the time object
Print (T.tm_year,t.tm_mday)
T.tm_year: Return year
t.tm_mday: Number of days from the beginning of the month to the day
print (Time.time () +3600*3) plus 3 hours in seconds from 1970
print (Time.time ())
Print (Time.strptime ("2017-1-5 15:35","%y-%m-%d%h:%m"))#转换成时间对象
t2=time.strptime ("2017-1-5 15:35","%y-%m-%d%h:%m")
print (Time.mktime (T2)) converts a time object to a timestamp
t3=time.localtime (Time.mktime (T2)) converts a timestamp to a time object
t3_str=time.strftime ("%y-%m-%d-%h-%m.log", T3) converts a Time object to a string
print (T3_STR)
print (Datetime.datetime.now ()) returns the current time
Print (Datetime.datetime.fromtimestamp (time.time ()-3600)) Subtract the current time by one hours
print (Datetime.datetime.now () +datetime.timedelta (days=3)) Current time plus 3 days
Random Module
Print (Random.random ())
randomly print a few 0-point decimals
Print (Random.randint)
randomly take 1 to 2 integers, including 1 and 2
Print (Random.randrange (1,5))
randomly take 1 to 5, not including 5
Random.sample (range (100), 5)
randomly take 5 numbers in each of the integers to form a list
Random.sample (' ABCDE ', 2)
randomly take 2 characters
String module
Print (string.ascii_letters+string.digits) will ASCII code character case and 0 to 9 numbers are grouped together
Print (Random.sample (str_source,6)) randomly takes a list of 6 characters in the above characters
Print (", Join (Random.sample (string.ascii_letters+string.digits,6))
randomly take 6 characters, and remove the connector combinations together
randomly generate 4 -bit random numbers
Checkcode="
for I in range (4):
Current=random.randrange (0,4)
if current! = I:
TEMP=CHR (Random.randint (65,90))
Else:
Temp=random.randint (0,9)
CHECKCODE+=STR (temp)
Print (Checkcode)
Shutil Module
Shutil.copyfileobj (F1,F2) Copy the contents of the F1 file to the f2 file
Shutil.copy (R "E:\workspace\s14\day1\sys.py","test")
Copy the sys.py file to the current path and change the name to test
Shutil.copytree (R "E:\workspace\s14\day1","Day1_new")
Copy the source directory to the current directory
Shutil.make_archive (R "C;\day1", format="Zip", root_dir=R "E:\workspace\s14\day1")
compress the directory into C- disk, named day1, zip -format compressed package
Import ZipFile
Zip_obj=zipfile. ZipFile (R "C;\day1_new","W")
Zip_obj.write ("Test1")
Zip_obj.close ()
The above is to day1_new This compressed package open, overwrite mode, add test1 file in
Import Tarfile
Tar=tarfile.open (R ' c;\day1_new ',' W ')
Tar.add (R "C;\day1.zip")
Tar.close ()
The above is to add the Day1.zip compressed package to the day1_new Compression Package
Python Time module