python每日练习—2020.2.25

python每日练习—磁盘写入

【问题描述】 从键盘输入一些字符,逐个把它们写到磁盘文件上,直到输入一个 # 为止。
【代码实现】:

if __name__ == '__main__':
    from sys import stdout
    filename = input('输入文件名:\n')
    fp = open(filename,"w")
    ch = input('输入字符串:\n')
    while ch != '#':
        fp.write(ch)
        stdout.write(ch)
        ch = input('')
    fp.close()
发布了32 篇原创文章 · 获赞 14 · 访问量 1210

猜你喜欢

转载自blog.csdn.net/qq_45770364/article/details/104502981