1, reflection
Keywords:
The getattr a string, to find the member subject
hasattr according to a string, it is determined whether there is a subject that member
setattr according to a string, to set a target moving member (RAM)
delattr according to a string, to judge a set target moving member (RAM)
A simple example:
1, defines five functions, and a number in the file handler
def f1(): print("F1") def f2(): print("F2") def f3(): print("F3") def f4(): print("F4") def f5(): print("F5") f0 = 9
2, and then create a run file. The digital input to the transfer function corresponding to
from types Import FunctionType Import Handler the while True: Print ( "" " function the system supports: 1.f1 2.f2 3.f3 4.f4 5.f5 6.f6 " "" ) Val = the INPUT ( " Please enter function to execute: " ) iF the hasattr (Handler, Val): # determines whether or not normal func_or_val = getattr (Handler, Val) # the parameter string, block to find members of the same name iF the isinstance (func_or_val, FunctionType) : func_or_val () the else : Print (func_or_val) the else : Print ( ' attribute name entered does not exist ' ) # summary. The string parameter (second parameter), to the object (the first parameter) to find the members with the same name
When a relatively large amount of data, it is impossible to determine write a bunch of reflection is particularly important at this time.
to sum up:
What is reflected: string parameter (second parameter), to the object (the first parameter) to find members of the same name (the sentence: the form of the operation target character string attributes associated)
2, md5 encryption
In python md5 encryption module depends on hashlib
The usual md5 encryption, easily knocked library crack. This is when you need salt.
A simple example is as follows:
Import hashlib the SALT = B ' asdasd ' DEF MD5 (pwd): obj = hashlib.md5 (the SALT) # salt the SALT obj.update (pwd.encode ( ' UTF-. 8 ' )) # acquires the ciphertext V = obj.hexdigest () return v
# Because md5 is not reversible, so the md5 decryption. Take data is encrypted and plaintext to encrypt, and then to compare, leading to the conclusion.
3, the log.
Has been written once before, do not repeat it.