簡體   English   中英

如何在python中輸入並將格式更改為txt?

[英]How to take a input in python and change the format into txt?

This is the whole code

#input from the user
Text = input("Enter a String :) : ")

#this portion will create a file
with open(Text, 'w') as f:
    file = f.write("this is a test file")


#loops through

for i in range(1,100):
#this is creating a new file
    a = open(Text, "a")
    b = a.write("\n this will append to the file")
    a.close() 
    # print(i)

#this portion is reading from the file
f = open(Text, "r")
d = f.read()
print(d,end="")
f.close()

I'm trying to take the input in string, but i want it to save the file in text format我是初學者,只是嘗試一下。

我想要的是,它創建一個文件 in.txt

像,

輸入: helloWorld

輸出: helloWorld.txt

將“.txt”附加到用戶輸入的文件名:

#input from the user
Text = input("Enter a String :) : ") + ".txt"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM