我想覆盖文件名称student_information.txt。我曾尝试:用Python编写文件
attribute_name = ["student_id", "name", "department", "sex", "age", "nationality", "grade"]
attribute_type = ["INT", "CHAR(20)", "CHAR(50)", "CHAR(1)", "INT", "CHAR(3)", "FLOAT"]
student_list = [("student_id", "name", "department", "sex", "age", "nationality", "grade"), ("student_id", "name", "department", "sex", "age", "nationality", "grade")]
f = open("student_information.txt", "w")
f.write('\n'.join('%s %s %s %s %s %s %s' % x for x in attribute_name))
f.write('\n'.join('%s %s %s %s %s %s %s' % x for x in attribute_type))
for i in range(len(student_list)):
f.write('\n'.join('%s %s %s %s %s %s %s' % x for x in student_list[i]))
f.close()
它给出错误说:
TypeError: not enough arguments for format string.
任何人有,为什么它不工作的任何想法? 谢谢。
错误在哪一行? – Hussain
自此行发生错误f.write('\ n')。加入('%s%s%s%s%s%s%s'%x for attribute_name)) – MakaraPr