python - AudioSegment.from_file 由于某种原因被覆盖?
问题描述
我在我的程序中使用了 AudioSegment.from_file 函数:sound = AudioSegment.from_file(audio_path, format="m4a")
我还实现了一个我创建的文件:import GUI_log
在这个文件中,我有下一节课:
class TextHandler(logging.Handler):
"""This class allows you to log to a Tkinter scroll_text or Scrolledscroll_text widget"""
def __init__(self, scroll_text):
# run the regular Handler __init__
logging.Handler.__init__(self)
# Store a reference to the scroll_text it will log to
self.scroll_text = scroll_text
def emit(self, record):
msg = self.format(record)
tag = ""
if record.levelno == ACTION:
tag = "ACTION"
def append():
self.scroll_text.configure(state='normal')
self.scroll_text.insert(Tkinter.END, msg + '\n', tag)
self.scroll_text.configure(state='disabled')
# Autoscroll to the bottom
self.scroll_text.yview(Tkinter.END)
# This is necessary because we can't modify the scroll_text from other threads
self.scroll_text.after(0, append)
出于某种原因,当我执行我提到的第一行(带有 的那一行from_file
)时,类emit
中的函数TextHandler
被执行。
任何人都知道它的原因是什么以及如何解决它?
编辑:我发现我覆盖了这段代码中的某个地方:
# Create Tkinter object and ScrolledText
root =Tkinter.Tk()
st = ScrolledText.ScrolledText(root, state='disabled')
st.configure(font='TkFixedFont')
st.pack()
st.tag_config("ACTION", foreground="dark green")
# Create text handler
text_handler = TextHandler(st)
formatter = logging.Formatter('%(asctime)s IP: %(IP)-15s PORT: %(PORT)-5s MESSAGE: %(message)s', datefmt='%Y-%m-%d,%H:%M:%S') #.%(msecs)03d
text_handler.setFormatter(formatter)
# Add action level
logging.addLevelName(ACTION, "ACTION")
def action(self, message, *args, **kws):
self._log(ACTION, message, args, **kws)
logging.Logger.action = action
# Create logger
logger = logging.getLogger()
logger.addHandler(text_handler)
logger.setLevel(logging.DEBUG)
return (root, logger)
解决方案
在互联网上滚动后,我发现 pydub 使用日志记录,我可能会覆盖记录器。为了解决这个问题,我改变了这一行logger = logging.getLogger()
:logger = logging.getLogger("SOMENAME")
推荐阅读
- sql - 如何将内连接 SQL 查询转换为 Lambda 表达式
- python-3.x - views.py 需要为 googlemap api 附近搜索停止一秒钟吗?
- c - 每个字符串参数的长度
- jquery - HTML/CSS 侧导航栏未按预期工作
- python - 无法使用 PIP 安装 - 帮助修复它?
- python - 熊猫数据框填充模式
- vba - IHTMLElement 事件 OnClick - 如何将事件绑定到 VBA 中的元素(访问)
- laravel-backpack - 在 crud 中更改日期范围过滤器的日期格式
- assembly - 启动时为什么我的 USB 密钥被识别为软盘
- php - 树莓派 3 B 中未安装软件包