概述
当我使用下面的代码时,我得到一个格式很差的输出。一个主要的输出问题是/n,/n不会出现在实际的文本文件中,但是从Python脚本中查看它,它都是“未格式化”的。在
代码:def start():
command = raw_input('''
1) Add
2) Look Up
3) See All
4) Delete Entry
''')
if command=="1":
add()
if command=="2":
look_up()
def add():
name = raw_input("What is your name?")
age = str(raw_input("How old are you?"))
salary = raw_input("Enter Salary:")
state = raw_input("State:")
fileObj = open("employees.txt","a")
fileObj.write("Name:"+name+"n")
fileObj.write('--------------------------n')
fileObj.write("Age:"+age+"n")
fileObj.write("Salary:"+salary+"n")
fileObj.write("State:"+state+"n")
fileObj.write("--------------------------n")
fileObj.write("nn")
fileObj.close()
print "The following text has been saved:"
print "Name:"+name
print "Age:"+age
print "Salary:"+salary
print "State:"+state
print "Note: This text was assigned to one line."
start()
def look_up():
fileObj = open("employees.txt")
line = fileObj.readlines()
print line
start()
start()
阅读和印刷的结果是:
['n','姓名:诺亚n','-----------------------------n','年龄:16岁n','工资:20000n','状态:NCn','-----------------------------n','n','n','姓名:丹尼尔·雷尼n','-----------------------------n','年龄:18岁n','工资:20万n','状态:NCn','-----------------------------n','n','n','名称:fdadasn','-----------------------------n','年龄:343n','工资:344433n','状态:NCn','-----------------------------n','n','n']
最后
以上就是鲜艳巨人为你收集整理的python输出格式错误_获取格式错误的输出(Python)的全部内容,希望文章能够帮你解决python输出格式错误_获取格式错误的输出(Python)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复