Python:time Module & Serialization &md5& generate random Number & reflection

Source: Internet
Author: User

Time module:
>>>Import Time>>>Time.time<built-inchfunction time>>>>time.time ()1473837803.320634>>>time.localtime () time.struct_time (Tm_year= ., tm_mon=9, tm_mday= -, tm_hour= the, tm_min= at, tm_sec= -, tm_wday=2, tm_yday=258, tm_isdst=0)>>>time.ctime ()'Wed Sep 15:25:17'>>> Time.strftime ('%y-%m-%d%h:%m:%s') '2016-09-14 15:35:30'
Serialization and JSON:

Serialization: The process of encrypting an object (list, meta-ancestor, dictionary) in a special binary way that can serialize any data type.

JSON: the memory of the data of the Jason, the principle and serialization of the same

difference:Pickle can only be used in Python; JSON supports all languages, only regular data types can be serialized; Pickle serialized data does not visually reveal data content

>>> name_dict = {'name':'pingy',' Age': -}>>>Import JSON>>>Import Pickle>>>json.dumps (name_dict)'{"Age": +, "name": "Pingy"}'>>>Pickle.dumps (name_dict) b'\x80\x03}q\x00 (x\x03\x00\x00\x00ageq\x01k\x14x\x04\x00\x00\x00nameq\x02x\x05\x00\x00\x00pingyq\x03u.'
MD5:
= hashlib.md5 () ha.update ('admin')   #md5加密print (Ha.hexdigest ())
Generate random Number:
Random : Stochastic random.random (): randomly generates 0-1 decimal random.randint (1,5): Randomly generated 1-  Integers in the range 5 (including 1 and 5) random.randrange (1,3): Integers in a randomly generated 1-3 range (excluding 3)
= [] for in range (6):    if i = = Random.randint (1, 9 ):        code.append (str (random.randint (1,9)))    Else :         = Random.randint (+)   #A-Z        code.append (chr (temp)) print (' . Join (code))
Reflection: Importing a module as a string and executing a function in the form of a string
temp =  'mysqlserverhelper'count'= __import__ (temp)     = GetAttr (module,'count')   #以字符串的形式执行函数print (function)

Python:time Module & Serialization &md5& generate random Number & reflection

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.