我正在尝试制作一个程序,您可以输入职位名称、类别和薪酬,并且我正在尝试将输入的职位名称、类别和薪酬写入文件以存储数据,但我在这样做时遇到了问题。
class Job(object):
def __init__(self, jobName = '', jobCategory = '', jobPay = ''):
self.jobName = jobName
self.jobCategory = jobCategory
self.jobPay = jobPay
def getName(self):
self.jobName = input("What is the Job Title: ")
def getCategory(self):
self.jobCategory = input("What is the Job Category: ")
def getPay(self):
self.jobPay = input("What is the Job Pay: ")
def displayJob(self):
print("Job: " + self.jobName)
print("Job Category: " + self.jobCategory)
print("Job Pay: " + self.jobPay)
print()
def Main():
global NewJob
NewJob = Job()
NewJob.getName()
NewJob.getCategory()
NewJob.getPay()
print()
NewJob.displayJob()
myFile = open('newFile.txt', 'w')
myFile.write(NewJob.displayJob())
myFile.close()
Main()