python 3.x learning note 7 (module)

1. Definition:
Module: used to logically organize Python code (variable, function, class, logic: implement a function), which is essentially a python file at the end of. py
Package: to organize modules logically, the essence is a directory (must have a "init". Py file)

2. Import method
import module_name1,module_name2

from module import * (not recommended)

from module import m1,m2,m3
from module import m1 as m

3.import essence
The essence of the import module is to explain the python file once
The essence of the import package is to execute the file "init. Py" under the package

4. Import optimization
from module_test import test

5. Module classification
a. standard library
b. open source module
c. custom module

Standard library:
1.time and datetime

strftime("format", struct_time) ---- > formatted string
strptime("formatted string", "format")

6. Module collection

http://blog.51cto.com/egon09/p2

 

7. Examples

import time

print(time.time())                      #Returns the timestamp of the current time
print(time.altzone)                     #Return and utc Time difference of time,In seconds  -32400
print(time.asctime())                   #Return time format"Fri Jan 26 20:38:48 2018",
print(time.gmtime())                     #The gmtime() method is to convert a timestamp to the struct time of the UTC time zone (0 time zone)

print(time.mktime(time.localtime())) #Convert a struct_time to a timestamp
print(time.asctime()) #Put a tuple representing time or struct_time In this form:
'Fri Jan 26 20:38:48 2018'. If there are no parameters, the time.localtime()Passed in as a parameter.

print(time.asctime(time.gmtime())) # Put a tuple representing time or struct_time In this form:
'Fri Jan 26 20:38:48 2018'. If there are no parameters, the time.localtime()Passed in as a parameter.


print(time.ctime()) #Converts a time stamp (a floating-point number in seconds) to the form time. Ascii(). If the parameter is not given or None, time.time() will be the default parameter. Its function is equivalent to time. ASCII (time. Localtime (SECs)).

string_2_struct
= time.strptime("2018-01-26 20:38:48","%Y-%m-%d %H:%M:%S") #Convert date string to struct time object format print(string_2_struct) print(time.gmtime(time.time() - 98546) # Convert utc timestamp to struct_time format print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())) #Convert the utc struct_time format to the specified string format import datetime print(datetime.datetime.now()) print(datetime.date.fromtimestamp(time.time())) # Time stamp directly converted to date format 2018-01-26 print(datetime.datetime.now()+datetime.timedelta(6)) #current time +6 day print(datetime.datetime.now()-datetime.timedelta(6)) #current time -6 day print(datetime.datetime.now()+datetime.timedelta(hours=6)) #current time +6 hour print(datetime.datetime.now()+datetime.timedelta(minutes=30)) #current time +30 branch c_time = datetime.datetime.now() print(c_time.replace(minute=3,hour=2)) #Time replacement

Tags: Python ascii

Posted on Sun, 03 May 2020 21:13:18 -0700 by WellBaffled