Skip to content

Commit f762fb3

Browse files
author
Spencer.Luo
committed
Refactor DRY principle
1 parent 39e2ece commit f762fb3

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

Test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# import pattern.Composite
1616
# import pattern.Clone
1717
# import pattern.Builder
18-
import pattern.Adapter
18+
# import pattern.Adapter
1919
# import pattern.Strategy
2020
# import pattern.Command
2121
# import pattern.Memento
@@ -31,4 +31,4 @@
3131
# import advanced_pattern.Callback
3232

3333
# import application.ImageProcessing
34-
# import principle.Principle
34+
import principle.Principle

principle/DRY.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/python
2+
# Authoer: Spencer.Luo
3+
# Date: 8/11/2018
4+
5+
import os
6+
# 导入os库,用于文件、路径相关的解析
7+
8+
# def getPath(basePath, fileName):
9+
# extName = os.path.splitext(fileName)[1]
10+
# filePath = basePath
11+
# if(extName.lower() == ".txt"):
12+
# filePath += "/txt/"
13+
# elif(extName.lower() == ".pdf"):
14+
# filePath += "/pdf/"
15+
# else:
16+
# filePath += "/other/"
17+
#
18+
# # 如果目录不存在,则创建新目录
19+
# if (not os.path.exists(filePath)):
20+
# os.makedirs(filePath)
21+
#
22+
# filePath += fileName
23+
# return filePath
24+
25+
def getPath(basePath, fileName):
26+
extName = fileName.split(".")[1]
27+
filePath = basePath + "/" + extName + "/"
28+
29+
# 如果目录不存在,则创建新目录
30+
if (not os.path.exists(filePath)):
31+
os.makedirs(filePath)
32+
33+
filePath += fileName
34+
return filePath
35+
36+
print(getPath("E:/upload", "TestFile.rar"))
37+
print(getPath("E:/upload", "Design Pattern for Python.pdf"))

principle/Principle.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
# from . import SRP
77
# from . import OCP
8-
from . import LSP
8+
# from . import LSP
99
# from . import DIP
1010
# from . import LoD
11-
# from . import ISP
11+
# from . import ISP
12+
from . import DRY

0 commit comments

Comments
 (0)