Module is a python file, which module will be used to import which module
1. Calling the module
# import Model #import的本质就是把这个python从头到尾执行一遍
#
# model.run1 () #调用model模块下的run1函数
# model.run2 ()
# Model.run ()
2. Call the function under the module
# from Model Import Run,run1 (Method 1)
# #只导入某个函数的时候, import only the RUN,RUN1 function
# run ()
# RUN1 ()
# from Model Import *
# from MODEL2 Import *
# #这种你不要用, import all the functions from a module
# run ()
# RUN1 ()
# run2 ()
# from model Import name (Method 2)
3. Call in other file directories
# Set1 file from Day4.set1 import hhh in Day4 directory
# HHH ()
4. Environment variable Directory
Environment variables are used to allow you to use this command in any directory
#导入模块的时候, Python first goes to the current directory to find this module, if the current
#目录下没有找到这个文件的话, then go to the directory inside the environment variable to find
# import Sys
# print (Sys.path) #看系统环境变量
#这个是在其他目录下的话
# sys.path.append (R ' E:\byz_code ') #添加环境变量目录
# from DAY4.SET1 import HHH
# HHH ()
5.random Module-Random number
Import Random
# Print (Random.random ()) # Random floating-point number, default 0-1, cannot specify range
# Print (Random.randint (1)) # Random integer
# Print (Random.randrange (1)) # randomly generates a range
# Print (Random.choice ([1,2,3,4,5]) # randomly take an element
# Print (Random.sample ([1,2,3,4, ' 6 '], 3) # Randomly takes a few elements from a sequence and returns a list
# Print (Random.uniform (1, 88888)) # Random floating point number, can specify range
x = [1, 2, 3, 4, 5, 6]
Random.shuffle (x) # Shuffle, scramble order, will change the value of the original list
Import string
# print (string.ascii_letters + string.digits) # All the numbers and letters
Import JSON
#json和python的字典类型, but only double quotes inside the JSON, not single quotes
#json串实际上就是一个字符串
json_str = "" "
{
" username": "Niuhanyang",
"passwd": 123456,
"Flag": True
}
"""
# fr = Open (' users ')
# json_dic = json.loads (json_str)
# #json串 (string) into a dictionary, the loads method is to turn the JSON into a dictionary
# json_dic_file = Json.load (FR)
# #json串 (string) into a dictionary, the load method is to pass in a file object, and the Load method automatically reads the contents of the file and then turns it into a dictionary
# Print (json_dic_file)
# Print (Type (json_dic_file))
d = {
"HHH": {
"Price": "90000",
" password": "123456 "
},
"Admin": {
" password": "123456",
"Money": 8000
}
}
# FW = open (' Users.json ', ' W ')
# dic_str = Json.dumps (d)
# #把字典变成json串 (String)
# json.dump (D,FW)
# Print (DIC_STR)
# Print (Type (DIC_STR))
#json可以用字典和list
#dump和dumps字典转json串的
#load和loads是json串转字典
#带s就和字符串沾边, without s and file objects
Python note 22-common modules