在文本文件中的单独行上编写 [英] Writing on a separate lines in a text file
问题描述
import random
device = input("What device do you have? Phone or PC(laptop included). If other
please specify ").upper()
make = ("")
model= ("")
verison = ("")
memory = ("")
if device == ("PHONE"):
make = input ("what make of phone do you have? Iphone or Samsung or other").upper()
if make == ("IPHONE"):
model == input("What model is your iPhone 6 or 7. If other plese spectify")
if device != ("PHONE") or ("PHONE") or (""):
make =input("what make is your " + str(device)).upper()
model = input("whats model is your " + str(device)).upper()
verison = input("what verison is your " + str(device)).upper()
memory = int(input("How much memory is in your " + str(device)))
print(make, model, verison, memory,"GB")
print(casenumber)
f = open('technician.txt','a')
f.write("**CASE NUMBER:{}** ** DEVICE: {}** **MAKE OF DEVICE: {}** **MODEL OF DEVICE: {} **".format(casenumber,device,make,model,verison,memory))
f.write("/n")
f.close()
我要做的是在每个单独的行上写一个程序完成的时间。但是/ n不起作用。我运行了两次程序,所有操作都写在文本文件的同一行上:
What I want for this to do is to write a on a separate line each time the program is finished. But /n does not work. I ran the program twice and all it does is write on the same line in the text file:
案例号:574927542749031461928599801595193290973875978 **设备:标签** 设备制造:苹果 设备型号:IPAD ** / n 案例号:207884437699822095837989343019189844675528960 ** **设备:平板电脑** 设备制造:苹果(Apple) **设备型号:2 ** / n
CASE NUMBER:574927542749031461928599801595193290973875978 ** DEVICE: TABEL** MAKE OF DEVICE: APPLE MODEL OF DEVICE: IPAD **/nCASE NUMBER:207884437699822095837989343019189844675528960** ** DEVICE: TABLET** MAKE OF DEVICE: APPLE **MODEL OF DEVICE: 2 **/n
所有这些都在同一行上。请帮助
All this is on the same line. Please help
非常感谢
Rory Eastham
Rory Eastham
推荐答案
换行符为 \n
,而不是 / n
在您的程序中使用。以此更新代码应该可以解决您所描述的问题。
The newline character is \n
, as opposed to the /n
used in your program. Updating your code with this should fix the issue you're describing.
这篇关于在文本文件中的单独行上编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!