-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
toolkit.py
54 lines (48 loc) · 1.23 KB
/
toolkit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*-coding=utf-8-*-
#常用的工具集合
__author__ = 'Rocky'
'''
http://30daydo.com
Contact: [email protected]
'''
import codecs
class Toolkit():
@staticmethod
def save2file( filename, content):
# 保存为文件
filename = filename + ".txt"
f = open(filename, 'a')
f.write(content)
f.close()
@staticmethod
def save2filecn( filename, content):
# 保存为文件
#filename = filename + ".txt"
f = codecs.open(filename, 'a',encoding='utf-8')
f.write(content)
f.close()
@staticmethod
def getUserData(cfg_file):
f=open(cfg_file,'r')
account={}
for i in f.readlines():
ctype,passwd=i.split('=')
#print(ctype)
#print(passwd)
account[ctype.strip()]=passwd.strip()
return account
@staticmethod
def read_stock(cfg_file):
result=[]
try:
f=open(cfg_file,'r').readlines()
for i in f:
i=i.strip()
if len(i)!=6:
continue
result.append(i)
#print(i)
except Exception as e:
print(e)
return None
return result