I have to create and write to a file that’s named by user input.
print("Please enter the name of the file you would like to create (Must include .txt in name):")
bmiFile = input()
bmiFile = open(bmiFile, 'w')
print("Creating", bmiFile)
This seems to work just fine, but when I add information to a list (bmiIndex) and try to write it to the file it doesn’t let me (using a picture to show that .write isn’t highlighted as a function in my VS code) (also not posting the whole code because it’s massive and irrelevant)
I’ve tried changing it to bmiFile = open(bmiFile+’.txt’, ‘w’) like ive seen other people do, but that doesn’t work either.
Stephanie Davi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.