title: AttributeError: 'str' object has no attribute 'filename' in Python
body: <p>I'm new to Python and currently learning, I had a task to do some reading and writing to files with a python script. The reading part of my script seems to work as expected however the write section is throwing an error. It's probably something trivial I have done but here is my code:</p>
  
  <pre><code>class LogMessage():
    def __init__(self, filename):
      self.filename = filename
  
    def read(self):
      inputFile = open(self.filename)
      for line in inputFile:
          print(line, end='')
  
    def write(self):
      outputFile = open(self.filename)
      #writeInput = input('What data do you wish to write?:\n')
      for line in writeInput:
              print(line,file = outputFile, end='')
  
  
  
  
  filename = LogMessage('new.txt')
  filename.read()
  writeInput = input('What data do you wish to write?:\n')
  LogMessage.write(writeInput)
  </code></pre>
  
  <p>The read part works but taking user data and writing it to the file and gives this error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "/home/alex/workspace/Python/Learn Python/labEx9.py", line 22, in &lt;module&gt;
  LogMessage.write(writeInput)
  File "/home/alex/workspace/Python/Learn Python/labEx9.py", line 11, in write
  outputFile = open(self.filename)
  AttributeError: 'str' object has no attribute 'filename'
  </code></pre>
  
  <p>can anyone help me, thanks a lot. </p>
  
  <p>Alex</p>