Reputation: 2487
Working with this code, and my output is not the list of strings, but instances. Do I re-write my LineCount class to allow such behavior?
line_count =[]
class LineCount:
def __init__(self, x):
self.x = x
def set_x(self, x):
self.x = x
def get_x(self):
return self.x
# add a value
line_count.append(LineCount(1))
# print list - does not print our string values
print line_count
# [<__main__.LineCount instance at 0x1031d53f8>]
Upvotes: 1
Views: 463
Reputation: 6030
You can change your print statement to call the get_x
function for each element in the list using a list comprehesion.
print [y.get_x() for y in line_count]
Upvotes: 1