python,獲取用戶輸入,並且將輸入的內容寫到.txt


該功能缺點是必須保證該文件不存在的情況才會成功

f=open('E:/mywork/保存文件.txt','x')

def userwrite(code):
    if code=='w':
        f.close()
        return False
    else:
        f.writelines(code+'\n')
        return True
isbool = True
count = 0
while isbool:
    code=''
    if count==0:
        code = input("請輸入內容:\n")
    else:
        code = input("")
    isbool = userwrite(code)
    count+=1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM