title: Objects of type File must support the iteration protocol, and iterates through the lines of the file
body: <p>So, I have a few tasks for creating class in python:</p>
  
  <ul>
  <li>Can someone give me review of my code.</li>
  <li>I need to use Magic Methods to complete tasks.</li>
  </ul>
  
  <p>Here is my tasks:</p>
  
  <p>1) The class must be initialized in the full path.</p>
  
  <p>such as</p>
  
  <pre><code>obj = File('/tmp/file.txt')
  </code></pre>
  
  <p>2) The class must support the write method.</p>
  
  <p>3) Objects of type File must support adding.</p>
  
  <p>4) Objects of type File must support the iteration protocol, and iterates through the lines of the file.</p>
  
  <pre><code>for line in File('/tmp/file.txt'):
  </code></pre>
  
  <p>And here I have a problem, as a result I heve an infinite loop.</p>
  
  <p>5) When outputting a file using the print function, it should print its full path, passed at initialization.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import os
  
  class File:
  
  def __init__(self, file_path, content = None):
      self.file_path = file_path
      self.content = content
      try:
          with open(file_path) as file_to:
              self.content = file_to.read()
      except FileNotFoundError:
          print("File or directory does not exist!\nEnter existing directory")
  
  
  def write(self, line):
      self.line = line
      with open(self.file_path, 'a+') as file_to:
          file_to.write(self.line)
  
  def __add__(self, obj):
          with open('result.txt', 'a+') as new_file:
              new_file.write(self.content + obj.content)
  
  def __iter__(self):
      return self
  
  def __next__(self):
      self.stop = 0
      with open(self.file_path) as f:
          data = f.readlines()
      if self.stop &gt; len(data):
          raise StopIteration
  
      self.stop += 1
  
      return data 
  
  def __str__(self):
      return f"{self.file_path}"
  </code></pre>