Hello.
I have an object (lyst2) that is created from multiple classes. When I use that returned object in another module and iterate through it, I get the addresses of the object's values and not the values themselves. Without having to display my entire program here, can anyone tell me why addresses might be written to my text file instead of the values?
(Note: Let me know if I need to display my entire code).
Here is the module that is using the returned object lyst2:
Customer Name Movie Title Days Rented Type Movie Cost
[<customer.Customer object at 0x10b7fd0b8>, <rental.Rental object at 0x10b7d6f28>, <rental.Rental object at 0x10b7fd5f8>, <movie.Movie object at 0x10b7cab00>, <movie.Movie object at 0x10b7cac88>]
[0.55]
I have an object (lyst2) that is created from multiple classes. When I use that returned object in another module and iterate through it, I get the addresses of the object's values and not the values themselves. Without having to display my entire program here, can anyone tell me why addresses might be written to my text file instead of the values?
(Note: Let me know if I need to display my entire code).
Here is the module that is using the returned object lyst2:
from movie import Movie from rental import Rental from customer import Customer import enter_data def createTextFile(lyst2): col_format = '\n' + "{:<15}"*5 + '\n' col_format2 = "{:<15}"*1+'\n' text_file = open("RedBox.txt",'a') text_file.write(col_format.format("Customer Name","Movie Title","Days Rented","Type Movie","Cost")) for i in lyst2: i = str(i) text_file.write(col_format2.format(i)) print(i) text_file.close()Here is one of my classes:
class Movie(object): def __init__(self, children, regular, new_release, cost): self.children = children self.regular = regular self.new_release = new_release self.cost = cost def __str__(self): return str(self.children) + str(self.regular) + str(self.new_release + str(self.cost))Here is the module that populates lyst2:
from movie import Movie from rental import Rental from customer import Customer # Import date time module def enterData(): costLyst = [] lyst2 = [] continue_on = 'y' while continue_on == 'y': custName = input("Enter the name of the customer: ") custName = custName.capitalize() custName = Customer(custName) lyst2.append(custName) rentTime = int(input("Enter the number of days rented: ")) movieName = input ("Enter the name of the movie: ") movieName = movieName.capitalize() rentalData1 = Rental(movieName,"") lyst2.append(rentalData1) rentalData2 = Rental("",rentTime) lyst2.append(rentalData2) movieMenu = int(input("Enter the movie type: \n" "Enter 1 for Children's movie.\n" "Enter 2 for Regular movie.\n" "Enter 3 for New Release movie.\n")) if movieMenu == 1: children = "Children's" regular = '' new_release = '' cost = float(.55) movieType1 = Movie("Children",'','','') movieType2 = Movie('','','',.55) lyst2.append(movieType1) c_cost = movieType2.cost lyst2.append(movieType2) costLyst.append(c_cost) if movieMenu == 2: children = "" regular = 'Regular' new_release = '' cost = 22 movieType = Movie(children,regular,new_release,cost) costLyst.append(movieType) if movieMenu == 3: children = "" regular = '' new_release = 'New-Release' movieType = Movie(children,regular,new_release) lyst2.append(movieType) continue_on = input("Would you like to enter more data for "+str(custName)+"? y or n ") if continue_on == 'y': continue else: pass return lyst2,costLystHere is the data written to the text file. They are the addresses instead of the values:
Customer Name Movie Title Days Rented Type Movie Cost
[<customer.Customer object at 0x10b7fd0b8>, <rental.Rental object at 0x10b7d6f28>, <rental.Rental object at 0x10b7fd5f8>, <movie.Movie object at 0x10b7cab00>, <movie.Movie object at 0x10b7cac88>]
[0.55]