-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDK.py
77 lines (64 loc) · 2.23 KB
/
PDK.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""This is a module for Python Development , it's a Python Development Kit that gives you some shortcut while you are coding"""
def read_file(file_path=None):
"""
To tired copying how to read a file?
:param file_path: The path of the file that you need computer to read(default=None)
:return: result
"""
with open(file_path, 'r', encoding='utf-8') as f:
result = f.read()
return result
def write_file(file_path=None, content=''):
"""
To tired copying how to write a file?
:param file_path: The path of the file that you need computer to write(default=None)
:param content: The content you want to write(default='')
:return: result
"""
with open(file_path, 'w', encoding='utf-8') as f:
result = f.write(content)
return result
def read_binary_file(file_path=None):
"""
To tired copying how to read a binary file?
:param file_path: The path of the file that you need computer to read(default=None)
:return: result
"""
with open(file_path, 'rb') as f:
result = f.read()
return result
def write_binary_file(file_path=None, content=None):
"""
To tired copying how to write a binary file?
:param file_path: The path of the file that you need computer to write(default=None)
:param content: The content you want to write(default=None)
:return: result
"""
with open(file_path, 'wb') as f:
result = f.write(content)
return result
def add_file(file_path=None, content=''):
"""
To tired copying how to add a file?
:param file_path: The path of the file that you need computer to add(default=None)
:param content: The content you want to add(default='')
:return: result
"""
with open(file_path, 'a', encoding='utf-8') as f:
result = f.write(content)
return result
def resize(w, h, newW, newH, pil_image):
"""
:param w:
:param h:
:param newW:
:param newH:
:param pil_image:
:return:
"""
f1 = 1.0 * newW / w
f2 = 1.0 * newH / h
factor = min([f1, f2])
width = int(w * factor)
height = int(h * factor)
return pil_image.resize((width, height), Image.ANTIALIAS)