I'm writing part of a program that involves writing user generated information to a text file.
class MonsterStats:
def __init__(self, name):
self.__monName = name
def setName(self, name):
self.__monName = name
def fileWrite(self):
monFile = open('MonsterFile.txt', 'w')
monFile.write(self.__monName)
monFile.close()
I wrote this to test it out:
import MonsterClass
name = raw_input('enter name: ')
monStats = MonsterClass.MonsterStats(name)
monStats.fileWrite()
The prompt comes up as it should but I get an error:
Traceback (most recent call last):
File "D:/Python/MonsterMaker/testClass.py", line 7, in <module>
monStats.fileWrite()
File "D:/Python/MonsterMaker\MonsterClass.py", line 13, in fileWrite
monFile.write(self.__monName)
AttributeError: 'tuple' object has no attribute 'write'
What is a 'tuple' object and how do I fix this?