Question
UPDATED: I am getting a AttributeError: 'Apartment_db' object has no attribute 'loadapartments ' when i attempt to run the client module below. I believe my
UPDATED: I am getting a AttributeError: 'Apartment_db' object has no attribute 'loadapartments' when i attempt to run the client module below. I believe my code is off for the beginning part under defmoduleConnector or something is wrong in the apartment_db module possibly in the loadApartments attribute I have gotten a lot of errors there too. I have pasted both below. What I am trying to do is load data from a text file(apartmentDB.txt) and then use it with variables "db" and "tdb" so I can use it at several different points in that same module (client module). Any errors please let let me know
apartment_db module below
import apartment
class Apartment(object): def __init__(self, num, bed, bath, rent, status): self.apt_num = num self.apt_bedrm = bed self.apt_bath = bath self.apt_rent = rent self.apt_status = status
def __repr__(self): return "(num:%s bed:%s bath:%s rent:%s status:%s) "%(self.apt_num,self.apt_bedrm,self.apt_bath,self.apt_rent,self.apt_status)
class Apartment_db(object): def __init__(self): self.apartments = []
def searchDB(self, apt_bedrm, apt_baths, apt_rent, apt_status): results = [] for apt in self.apartments: if ( (apt.getApt_bedrm() >= apt_bedrm) & (apt.getApt_baths() >= apt_baths) & (apt.getApt_rent() <= apt_rent) & (apt.getApt_status().strip() == apt_status) ): results.append(apt) return results
def addApartment(self,apartment): self.Apartment_db.append(apartment) print('Apartment added successfully')
def getApartment(self, apt_num): for apartment in self.apartments: if(apartment.apt_num == apt_num): return apartment return none
def getAvailApartments(self): availApartments = [] for apartment in self.apartments: if(apartment.apt_status == 'A'): availApartments.append(apartment) return availApartments
def getRentedApartments(self): rentedApartments = [] for apartment in self.apartments: if(apartment.apt_status == 'R'): rentedApartments.append(apartment) return rentedApartments
def changeApartmentStatus(self,apartmentNumber, status): found = False for apartment in self.apartments: if(apartment.apt_num == apartmentNumber): found = true if (apartment.apt_status == status): print('apartment status not changed') else: apartment.apt_status = status if(found == False): print('apartment number is not valid')
def getTotalApartments(self): return len(self.apartment)
def getTotalAvailable(self): return len(getAvailApartments(self))
def getTotalRented(self): return len(getRentedApartments(self))
def loadApartments(self, aptFile): file = open(aptFile, "r") for line in file.readlines(): line = line.split(" ") a = Apartment(int(line[0]), int(line[1]), int(line[2]), int(line[3]),(line[4])) self.apartments.append (a)
first part of client module below
from apartment import Apartment from apartment_db import Apartment_db from tenant import Tenant from tenant_database import Tenant_db
input_file = 'apartmentDB.txt'
def moduleConnector(aptFile): db = Apartment_db() tdb = Tenant_db() db.loadapartments(aptFile)
moduleConnector(input_file)
def read_file(): with open(input_file) as f: content = f.readlines() full_lines = [x.strip() for x in content] full_lines = [line.split(' ') for line in full_lines] for line in full_lines: line[0] = int(line[0]) line[1] = int(line[1]) line[2] = int(line[2]) line[3] = int(line[3]) return full_lines read_file()
apartment.py module
class Apartment: def __init__(self, apt_num, apt_bedrm, apt_baths, apt_rent, apt_status): self.apt_num = apt_num self.apt_bedrm = apt_bedrm self.apt_baths = apt_baths self.apt_rent = apt_rent self.apt_status = apt_status
def searchDB(self, apt_bedrm, apt_baths, apt_rent, apt_status): results = [] for apt in self.apartments: if ( (apt.getApt_bedrm() >= apt_bedrm) & (apt.getApt_baths() >= apt_baths) & (apt.getApt_rent() <= apt_rent) & (apt.getApt_status().strip() == apt_status) ): results.append(apt) return results def setApt_num(self,aptNum): self.apt_num = aptNum
def getApt_num(self): return self.apt_num
def setApt_bedrm(self,aptBed): self.apt_bedrm = aptBed
def getApt_bedrm(self): return self.apt_bedrm
def setApt_baths(self, aptBath): self.apt_baths = aptBath
def getApt_baths(self): return self.apt_baths def setApt_rent(self,aptRent): self.apt_rent = aptRent
def getApt_rent(self): return self.apt_rent def setApt_status(self,aptStatus): self.apt_status = aptStatus
def getApt_status(self): return self.apt_status
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started