Writing on a separate lines in a text file

旧城冷巷雨未停 提交于 2019-12-11 00:26:48

问题


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()

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:

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

Many Thanks,

Rory Eastham


回答1:


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.



来源:https://stackoverflow.com/questions/42842087/writing-on-a-separate-lines-in-a-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!