title: importing file using class on lines
body: <p>I am importing a class module, and then opening a text file. Maybe I am not understanding classes right, but I was thinking that if I called the <strong>init</strong> constructor it would take the information from the file and put it in that format. I have read a lot of questions asking how to do this on this site, about people having trouble reading a text file and using their constructor on it- but haven't seen any answers that combine the import file and class component. here is my code for the class:</p>
  
  <pre><code>class Apartments:
        def __init__(self,apartNum, rent, rooms, bath):
              self.apartNum=apartNum
              self.rent=rent
              self.rooms=rooms
              self.bath=bath
  </code></pre>
  
  <p>Here is the file I'm importing it to :</p>
  
  <pre><code>import sys
  sys.path.append("/Users/kabe/Desktop/Apartments")
  
  import Apartments
  
  dataFile = open('apartmentData.txt').readlines()
  </code></pre>
  
  <h1>everything after this point is code I tried out but doesn't work.</h1>
  
  <pre><code>apartmentsList = []
  for line in dataFile:
      strippedLine=line.split()
      apartmentsList.append(Apartments)
  
  for apartment in apartmentsList:
      print(apartment.apartNum + ' ' + apartment.rent + ' ' + apartment.rooms + ' ' + apartment.bath)
  openfile()
  </code></pre>
  
  <p>this code gives me the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/lortiz/Desktop/Memes/College/homework/l_kennedy_lab8_wk9.py", line 13, in &lt;module&gt;
      print(apartment.apartNum + ' ' + apartment.rent + ' ' + apartment.rooms + ' ' + apartment.bath)
  AttributeError: module 'Apartments' has no attribute 'apartNum'
  </code></pre>
  
  <p>I'm trying to achieve class objects that look like this from the text file I am importing:</p>
  
  <pre><code>apt_1= Apartments(111,1000,1,1)
  apt_2= Apartments(112,2000,2,1)
  apt_3= Apartments(113,2500,2,2)
  apt_4= Apartments(114,3000,3,2)
  apt_5= Apartments(115,3500,3,3)
  </code></pre>
  
  <p>Thanks!</p>