在python 3中,当variable=null时如何传递

2024-05-29 05:01:33 发布

您现在位置:Python中文网/ 问答频道 /正文

到目前为止我有这个:

import datetime
f = open("log.txt", "a", encoding='UTF-8')
print ("Log file created")
print ("Enter /close to leave.")
spc = " "
while 1:
    msg = input(">>:")
    now = datetime.datetime.now()
    now1 = str(now)
    if msg == None:
        pass
    if msg == " ":
        pass
    else:
        msg2 = now1+spc+msg+"\n"
        if msg == "/close":
            exit()
        f.write(msg2)
        f.flush()

但是,这一行没有按我的要求运行,它仍然在日志文件中返回一个空行:

if msg == None:
    pass

我希望它不返回任何内容,而只是继续while循环,我该如何解决这个问题?


Tags: importnonelogclosedatetimeifmsgpass

热门问题