python - python中的日志文件
问题描述
你好有人可以帮助我,我有一个 Python 程序,我想在“日志”中注册输出数字,但我想输入所有数字,因为我在程序中使用了 open 然后我使用了 + = 希望na horade在程序跳过一行的文件中写入下一行,但程序出错,请有人帮忙():
hora = str (datetime.now ()). replace (":", "."). split ()
hour = hour [0] + "," + hour [1]
name = "log" + time
log = open (". txt", "wb")
log + = "," + str (num)
这是日志的一部分
解决方案
你犯了多个错误。
hour = hour [0] + "," + hour [1]
会给你一个错误,因为它应该是hora而不是hour。正确的行:
hour = hora [0] + "," + hora [1]
第二个错误:
log = open (". txt", "wb")
在编写文本而不是二进制(“wb”)时,您应该使用文本模式(“wt”)。
log = open (". txt", "wt")
第三个错误:
写入文件使用file.write()
So
log + = "," + str (num)
应该
log.append("," + str (num))
推荐阅读
- python - 在 SQL 中显示多行项目
- java - Intellij 依赖问题 - java.lang.NoClassDefFoundError
- excel - 输入 0 时重置累计总数
- xml - 使用 powershell 在 bigfix 上创建基线
- node.js - MongoDB Result 可以 console.log() 但不能推送到数组 NodeJS
- node.js - 如何在从节点 js 获取的反应中显示图像
- informatica - Informatica 9.5 中的时间戳未更新
- java - 扩展 log4j2.xml 并在它变得很长时将其拆分
- python - sleep() 在下面的代码中是如何工作的?
- r - 从所有具有事件边的顶点获取图 R igraph