python存txt不删之前_我怎样才能保存到一个.txt文件而不覆盖其中已经存在的所有内容?...

我在空闲时间做一个应该是非常基本的操作系统。但是,我试图创建它以便您可以拥有任意多个用户,但是每次我创建一个新用户时,它都会删除旧用户。到目前为止,我有这个:def typer():

print("Start typing to get started. Unfortunately, you cannot currently save your files.")

typerCMD = input(" ")

CMDLine()

def CMDLine():

print("Hello, and welcome to your new operating system. Type 'help' to get started.")

cmd = input("~$: ")

if cmd == ("help"):

print("Use the 'leave' command to shut down the system. Use the 'type' command to start a text editor.")

cmdLvl2 = input("~$: ")

if cmdLvl2 == ("leave"):

quit()

if cmdLvl2 == ("type"):

typer()

def redirect():

signIn()

def mUserRedirect():

makeUser()

def PwordSignIn():

rPword = input("Password: ")

with open('passwords.txt', 'r') as f:

for line in f:

print(line)

if rPword == (line):

CMDLine()

else:

print("Incorrect password.")

signIn()

def signIn():

rUname = input("Username: ")

with open('usernames.txt', 'r') as f:

for line in f:

print(line)

if rUname == (line):

PwordSignIn()

else:

print("Username not found.")

mUserRedirect()

def makeUser():

nUname = input("New username: ")

nPword = input("Create a password for the user: ")

with open('usernames.txt', 'w') as f:

f.write(nUname)

with open('passwords.txt', 'w') as f:

f.write(nPword)

signIn()

print("Create a new user? (Y/N) ")

nUser = input("")

if nUser == ("N"):

signIn()

if nUser == ("n"):

signIn()

if nUser == ("Y"):

makeUser()

if nUser == ("y"):

makeUser()

那么,如何才能在不删除文件中的所有内容的情况下写入文件呢?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值