Skip to content

Commit b5bb158

Browse files
committed
Remove getter
It's not generally pythonic to have a "getter" like this - you usually want to just access the object's attributes directly. It looks like you're signalling to the end user that the width and height aren't part of the object's public API. I think it's more clean to skip this (and in fact, I'd change the names from _width and _height to width and height). Others may disagree :)
1 parent c5bd76e commit b5bb158

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

ResizeDemo.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
sc = SeamCarverLib.SeamCarver(pic)
1919

2020
print "print vertical seam 1"
21-
print sc.width(), sc.height()
21+
print sc._width, sc._height
2222
#SeamCarverUtilities.printVerticalSeamEnergy(sc)
2323
SeamCarverUtilities.printSeam(sc, direction="vertical")
2424
#SeamCarverUtilities.distToArray(sc)
2525

2626
print "remove vertical seam"
2727
s = sc.findVerticalSeam()
2828
sc.removeVerticalSeam(s)
29-
print sc.width(), sc.height()
29+
print sc._width, sc._height
3030
print "find vertical seam"
3131
SeamCarverUtilities.printSeam(sc, direction="vertical")
3232

@@ -38,7 +38,7 @@
3838
print "remove horizontal seam"
3939
s = sc.findHorizontalSeam()
4040
sc.removeHorizontalSeam(s)
41-
print sc.width(), sc.height()
41+
print sc._width, sc._height
4242
#SeamCarverUtilities.printHorizontalSeamEnergy(sc)
4343
print "find horizontal seam"
4444
SeamCarverUtilities.printSeam(sc, direction="horizontal")
@@ -49,11 +49,11 @@
4949
# sc.removeVerticalSeam(s)
5050

5151
# # print "print vertical seam 2"
52-
# print sc.width(), sc.height()
52+
# print sc._width, sc._height
5353
# SeamCarverUtilities.printVerticalSeam(sc)
5454
# #SeamCarverUtilities.printVerticalSeamEnergy(sc)
5555
# # s = sc.findVerticalSeam()
56-
# # for i in range(sc.height()):
56+
# # for i in range(sc._height):
5757
# # print s[i]
5858
# # # print sc._edgeTo
5959
# # # print sc._distTo
@@ -62,42 +62,42 @@
6262

6363
# s = sc.findVerticalSeam()
6464
# sc.removeVerticalSeam(s)
65-
# print sc.width(), sc.height()
65+
# print sc._width, sc._height
6666

6767
# # print "print vertical seam 3"
68-
# # print sc.width(), sc.height()
68+
# # print sc._width, sc._height
6969
# SeamCarverUtilities.printVerticalSeam(sc)
7070
# SeamCarverUtilities.distToArray(sc)
7171
# #SeamCarverUtilities.printVerticalSeamEnergy(sc)
7272
# # s = sc.findVerticalSeam()
73-
# # for i in range(sc.height()):
73+
# # for i in range(sc._height):
7474
# # print s[i]
7575

7676
# s = sc.findVerticalSeam()
7777
# sc.removeVerticalSeam(s)
78-
# print sc.width(), sc.height()
78+
# print sc._width, sc._height
7979

8080
# # print "print vertical seam 4"
81-
# # print sc.width(), sc.height()
81+
# # print sc._width, sc._height
8282
# SeamCarverUtilities.printVerticalSeam(sc)
8383
#SeamCarverUtilities.printVerticalSeamEnergy(sc)
8484
# s = sc.findVerticalSeam()
85-
# for i in range(sc.height()):
85+
# for i in range(sc._height):
8686
# print s[i]
8787

8888
# print "print vertical seam 2"
8989
# # print sc._edgeTo
9090
# # print sc._distTo
9191
# s = sc.findVerticalSeam()
9292
# sc.removeVerticalSeam(s)
93-
# print sc.height(), sc.width()
93+
# print sc._height, sc._width
9494
#SeamCarverUtilities.printVerticalSeam(sc)
9595
# print
9696

9797
# print "print vertical seam 3"
9898
# s = sc.findVerticalSeam()
9999
# sc.removeVerticalSeam(s)
100-
# print sc.height(), sc.width()
100+
# print sc._height, sc._width
101101
# # print sc._edgeTo
102102
# # print sc._distTo
103103
# #pdb.set_trace()
@@ -107,15 +107,15 @@
107107
# print "remove vertical seam 4"
108108
# s = sc.findVerticalSeam()
109109
# sc.removeVerticalSeam(s)
110-
# print sc.height(), sc.width()
110+
# print sc._height, sc._width
111111
# # print sc._edgeTo
112112
# # print sc._distTo
113113
# SeamCarverUtilities.printVerticalSeam(sc)
114114

115115
# print "remove vertical seam 5"
116116
# s = sc.findVerticalSeam()
117117
# sc.removeVerticalSeam(s)
118-
# print sc.height(), sc.width()
118+
# print sc._height, sc._width
119119
# SeamCarverUtilities.printVerticalSeam(sc)
120120

121121

SeamCarverLib.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ def __init__(self, picture):
2525
self._edgeTo = []
2626
self._distTo = []
2727

28-
29-
def width(self):
30-
return self._width
31-
32-
def height(self):
33-
return self._height
34-
3528
def energy(self, col, row):
3629
"""return energy of pixel in (col, row)"""
3730
if self._isValid(col, row):

SeamCarverUtilities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ def printSeam(sc, direction):
55
else:
66
seam = sc.findHorizontalSeam()
77

8-
for row in range(sc.height()):
9-
for col in range(sc.width()):
8+
for row in range(sc._height):
9+
for col in range(sc._width):
1010
if direction == "vertical":
1111
is_on_seam = col == seam[row]
1212
else:

0 commit comments

Comments
 (0)