current position:Home>Python notes-day13-system module
Python notes-day13-system module
2022-05-15 06:03:43【Wandering mage 12】
Preface
python Grammar learning , Leave it to those who need it , Understand everything !!
# coding=utf8
# @time:2022/4/21 20:14
# Author Haoyu
# One 、 Time module
# import time,datetime
# 1.python There are two modules related to time :time、datetime
# 2. Time stamp
'''''''''
Timestamp refers to the current time to 1970 year 1 month 1 Japan 0 when 0 branch 0 second ( It refers to Greenwich mean time ) The time difference ( The unit is seconds )
benefits :
1) Saving time with a timestamp takes much less than saving time with a string
2) It's easier to encrypt time with a timestamp
1650544031.5202246 -> Including the year \ month \ Japan \ when \ branch \ second \ millisecond
'''''''''
# One . Time stamp
# 1.time() usage - Get the current time
# t1 = time.time()
# print(t1,type(t1)) # 1650543825.3692148 <class 'float'> ( Time stamp )
# 2.locatime usage
# 1)localtime() - Get local time
# t2 = time.localtime()
# print(t2,type(t2)) # time.struct_time(tm_year=2022, tm_mon=4, tm_mday=21, tm_hour=20, tm_min=40, tm_sec=15, tm_wday=3, tm_yday=111, tm_isdst=0)
# 2)localtime( Time stamp ) - Convert timestamp to local structure time
# t3 = time.localtime(0)
# print(t3)
# 3. Convert structure time to string time
'''''''''
Time format string - Contains the time placeholder string
%Y - year
%m - month
%d - Japan
%H - when
%M - branch
%S - second
%a - week ( Abbreviations of English words )
%A - week ( Complete spelling of English words )
%b - month ( English abbreviation )
%B - month ( Spell it all in English )
'''''''''
# strftime( Time format string , Structure time )
# t5 = time.localtime()
# s_t5 = time.strftime('%Y year -%m month -%d Japan ',t5)
# print(s_t5)
# -----------------------------------------------
# 4.sleep( Time ) - Program pause time ( Unit second )
# time.sleep(2)
# print('================')
# 4.datetime
'''''''''
from datetime import time,date,datetime,timedelta
# time - Minutes and seconds
# date - Specific date
# datetime - Mm / DD / yyyy HHM / S
t1 = date.today()
print(t1,t1.year,t1.month,t1.day) # 2022-04-21 2022 4 21
t2 = datetime.now()
print(t2) # 2022-04-21 22:50:40.328680
'''''''''
# Two .hashlib modular
import hashlib
# hashlib yes python It comes with a special one to provide hash Encrypted module
# 1.hash Features of encryption
'''''''''
1) The result of the same data through the same encryption algorithm is the same ( The encrypted result is called ciphertext or abstract )
2) The encrypted result is irreversible
3) The length of the summary generated by the same algorithm is the same for data of different sizes
'''''''''
# 2. Application scenarios
'''''''''
1) Create data irreversible ciphertext ( encryption )
2) Verify the integrity of the data and whether it has been modified
'''''''''
# 3. How to generate summary
'''''''''
# 1) Create according to the encryption algorithm hash object
hash = hashlib.md5() # common hash Algorithm :md5、sha relevant
# 2) Add encrypted object
# hash object .update( data )
# data - Must be bytes object
hash.update(bytes(' I am the best in the world ',encoding = 'utf--8')) # The added data needs to be converted into binary
# 3) Generate summary ( Generating ciphertext )
# hash object .hexdigest()
result = hash.hexdigest()
print(result) # 1bcbf481b5a6b208c8e3d8b2765f1146
'''''''''
# Generate image summary
'''''''''
hash = hashlib.md5()
with open(' beauty .jpg','rt') as f:
hash.update(f.read())
print(hash.hexdigest())
'''''''''
# Generate a summary of the text file
'''''''''
hash = hashlib.md5()
with open('01- Exception trapping .py','rb') as f:
hash.update(f.read())
print(hash.hexdigest())
'''''''''
# Supplementary content :
'''''''''
# 1) String to binary
# Method 1 :bytes( character string ,encoding=utf-8)
str1='hello world'
b1=bytes(str1,encoding='utf-8')
print(b1,type(b1))
# Method 2 : character string .encode()
b2=str1.encode()
print(b1,type(b1))
# 2) Binary to string
# Method 1 :a.str( Binary system ,encoding='utf-8')
s1=str(b1.encoding='utf-8')
print(s1,type(s1))
# Method 2 : Binary system .decode()
'''''''''
More secure sharing , Please pay attention to 【 Security info】 WeChat official account !
copyright notice
author[Wandering mage 12],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/131/202205110607424233.html
The sidebar is recommended
- Introduction to the differences between Python and Java
- Explain Python CONDA in detail
- The pycham downloaded by MAC reports an error as soon as it is opened. The downloaded Python interpreter is also the latest version
- From entry to mastery, python full stack engineers have personally taught Python core technology and practical combat for ten years
- Python is used to detect some problems of word frequency in English text.
- How to choose between excel, database and pandas (Python third-party library)?
- WxPython download has been reporting errors
- Pyside6 UIC and other tools cannot be found in the higher version of pyside6 (QT for Python 6). How to solve it?
- About Python Crawlers
- Successfully imported pandas, unable to use dataframe
guess what you like
How to extract some keywords in the path with Python
Python encountered a problem reading the file!
When Python is packaged into exe, an error is reported when opening assertionerror: C: \ users \ Acer \ appdata \ local \ temp\_ MEI105682\distutils\core. pyc
Eight practical "no code" features of Python
Python meets SQL, so a useful Python third-party library appears
100 Python algorithm super detailed explanation: a hundred dollars and a hundred chickens
[fundamentals of Python] Python code and so on
When Python uses probit regression, the program statement is deleted by mistake, and then it appears_ raise_ linalgerror_ Unrecognized error of singular
Python testing Nicholas theorem
Accelerating parallel computing based on python (BL) 136
Random recommended
- Python dynamic programming (knapsack problem and longest common substring)
- Django uses queryset filter save, and an 'queryset' object has no attribute 'Save' error occurs. Solution?
- Analysis of built-in functions in Python learning
- Python office automation - 90 - file automation management - cleaning up duplicate files and batch modifying file names
- Python office automation - 91 - word file Automation - word operation and reading word files
- After python, go also runs smoothly on the browser
- Self taught Python 26 method
- Summary of Python Tkinter component function examples (code + effect picture) (RadioButton | button | entry | menu | text)
- Python implementation of official selection sorting of Luogu question list
- Application of Django template
- Get project root path and other paths in Python project
- Get, rename, and delete file names in Python projects
- How to set the width and height of Python operation table
- Python string preceded by 'f' R 'B' U '
- JSON and other types convert to each other in Python
- Key value of key combination in pynput in Python
- Conversion of Python PDF file to word file
- Interface testing uses Python decorators
- Get the current time in Python
- Python course notes -- Python string, detailed explanation of related functions
- Python file and folder operations
- Python file content operation
- Three basic data quality evaluation methods and python implementation
- Python data structure and mathematical algorithm examples (continuously updating)
- GUI interface mail sending program based on SMTP protocol server and python language
- Python application tool development: mail sending GUI program
- Python application tool development: PIP instruction GUI program
- Application development based on Python and MySQL database: student information score management system version 1.0
- [Python] sort and sorted
- [Python] create a two-dimensional array with list, which is easy to step on
- Multiply [email protected]
- About creating in Python project folder__ init__. Understanding of PY
- Python, zsbd
- Smplify introduction and in python2 7 operation in environment
- Boost(2):boost. Python library introduction and simple examples
- Boost (3): encapsulate C + + classes into Python classes
- Boost (5): extract the type of C + + language and extract class from Python object
- Boost(6):Boost. How Python converts C + + parameter and return value types
- Boost(7):Boost. Python encapsulates overloaded functions and passes default parameters
- Boost(8):Boost. Python implements Python objects and various types of built-in operations and methods