필자는 프로그램에서 텍스트 파일에 원격으로 쓸 수있는 Python 프로그램을 작성하고 있습니다. 관련 코드 :".txt"가 아닌 파일에 쓰기 Python
namein = input("What do you want the filename to be? Don't include an extension...\n")
extin = input("What would you like the extension to be? This program supports:\nMicrosoft Word Document: '.docx'\nPlain Text File: '.txt'\nRich Text File: '.rtf'\nPages Document: '.pages'\n")
aw = input("Do you want to append your text file, or rewrite the whole thing? (append/write) ")
if aw == 'append':
textin = input("In the line below, write the text you want to put into your text document!\n\n")
outfile = open(namein + extin, 'a')
outfile.write(textin)
outfile.flush()
print("Great! Now your text file has been updated!")
print("Your text file:\n")
outfile.close()
outfile = open(namein + extin, 'r')
print(outfile.read())
누군가가 파일 '이 .txt'가 아닌, 하나의 파일을 열 수없는 선택! 단지 오류라고 말하면 파일을 열 수 없습니다. 이 문제를 해결할 방법이 있습니까?
사람들은 서버의 파일 시스템 어디에서나 임의의 파일을 만들 수 있습니까? – sdolan
예, 올바른 출력 형식으로 파일에 데이터를 작성해야합니다. –
@sdolan : "원격":) 나는 좋아한다. –