I am getting a "AttributeError: 'int' object has no attribute 'splitlines'" when I go to save the users input to a file.
def testfunction():
global names, type, length
while True:
name = input("Name: ")
type = input("Type: ")
if type == "Length":
length = input("Length: ")
output_file = open("Test.txt", "w")
output_file.write(f"""
{length}
""").splitlines()
output_file.close()
return name, type
testfunction()
output_file.write
returns the number of characters written in the file, so you're calling .splitlines()
on a int. You should probably remove the .splitlines()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.