configparser&hashlib

生成配置文件:

import configparser

config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '45',
                     'Compression': 'yes',
                     'CompressionLevel': '9'}

config['bitbucket.org'] = {}
config['bitbucket.org']['User'] = 'hg'
config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = '50022'  # mutates the parser
topsecret['ForwardX11'] = 'no'  # same here
config['DEFAULT']['ForwardX11'] = 'yes'
with open('example.ini', 'w') as f:#写入文件,不同于文件操作
    config.write(f)

example.ini

[DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forwardx11 = yes

[bitbucket.org]
user = hg

[topsecret.server.com]
host port = 50022
forwardx11 = no
 1 import configparser
 2 
 3 config = configparser.ConfigParser()
 4 
 5 #---------------------------------------------查
 6 print(config.sections())   #[]
 7 
 8 config.read('example.ini')
 9 
10 print(config.sections())   #['bitbucket.org', 'topsecret.server.com']
11 
12 print('bytebong.com' in config)# False
13 
14 print(config['bitbucket.org']['User']) # hg
15 
16 print(config['DEFAULT']['Compression']) #yes
17 
18 print(config['topsecret.server.com']['ForwardX11'])  #no
19 
20 
21 for key in config['bitbucket.org']:
22     print(key)
23 
24 
25 # user
26 # serveraliveinterval
27 # compression
28 # compressionlevel
29 # forwardx11
30 
31 
32 print(config.options('bitbucket.org'))#['user', 'serveraliveinterval', 'compression', 'compressionlevel', 'forwardx11']
33 print(config.items('bitbucket.org'))  #[('serveraliveinterval', '45'), ('compression', 'yes'), ('compressionlevel', '9'), ('forwardx11', 'yes'), ('user', 'hg')]
34 
35 print(config.get('bitbucket.org','compression'))#yes
36 
37 
38 #---------------------------------------------删,改,增(config.write(open('i.cfg', "w")))
39 
40 
41 config.add_section('yuan')
42 
43 config.remove_section('topsecret.server.com')
44 config.remove_option('bitbucket.org','user')
45 
46 config.set('bitbucket.org','k1','11111')
47 
48 config.write(open('i.cfg', "w"))
49 
50 增删改查
增删改查


 hashlib

 

1 import hashlib
2 
3 obj = hashlib.md5()#可通过撞库破解
4 # obj = hashlib.md5('sb'.encode('utf-8'))#加盐,即任意增加一段字符串
5 
6 obj.update('admin'.encode('utf-8'))
7     #对admin进行加密,编码方式自定,obj.update固定格式
8 print(obj.hexdigest())

 

posted @ 2018-03-05 17:09  web123  阅读(105)  评论(0编辑  收藏  举报