为什么 python 在我尝试记录列表时生成错误
Why is python generating an error when I attempt to log a list
当我尝试在 class 的成员函数中记录列表时,它会阻止更新日志文件。我尝试了以下方法:
def set_current_array(self, newvalue):
print(f"newvalue={newvalue}") # works, prints newvalue=[10]
logging.info('Weight set_current_array %s', newvalue) # does not write to file, blocks all other logging
logging.info(f'Weight set_current_array {newvalue}') # does not write to file, blocks all other logging
self.current_array = newvalue
我必须在日志文件更新之前删除 logging.info 行(项目中的许多其他日志记录命令)。
上下文:
- Python 版本 3.9.1
- Windows 10
我通过在程序开头设置日志记录解决了我的问题:
import logging
logging.basicConfig(filename='convert_st.log', level=logging.INFO)
logging.info('Started')
import all_other_packages
import...
...
def main:
# main comes here
...
if __name__ == '__main__':
main()
(*.pyc文件我也删了,不知道有没有关系)
当我尝试在 class 的成员函数中记录列表时,它会阻止更新日志文件。我尝试了以下方法:
def set_current_array(self, newvalue):
print(f"newvalue={newvalue}") # works, prints newvalue=[10]
logging.info('Weight set_current_array %s', newvalue) # does not write to file, blocks all other logging
logging.info(f'Weight set_current_array {newvalue}') # does not write to file, blocks all other logging
self.current_array = newvalue
我必须在日志文件更新之前删除 logging.info 行(项目中的许多其他日志记录命令)。
上下文:
- Python 版本 3.9.1
- Windows 10
我通过在程序开头设置日志记录解决了我的问题:
import logging
logging.basicConfig(filename='convert_st.log', level=logging.INFO)
logging.info('Started')
import all_other_packages
import...
...
def main:
# main comes here
...
if __name__ == '__main__':
main()
(*.pyc文件我也删了,不知道有没有关系)