为什么调用 playsound 模块会导致我的脚本崩溃?
Why does invoking the playsound module cause my script to crash?
代码:
import time
import playsound
print('Study period in minutes?')
studyMin = float(input())
print('Break period in minutes?')
breakMin = float(input())
print('How many repetitions?')
repe = int(input())
for i in range(repe):
print('You have ' + str(repe) + ' repetitions left!')
playsound('repetition.wav')
print('Study!')
time.sleep(studyMin * 60)
playsound('repetition.wav')
print('Take a break!')
time.sleep(breakMin * 60)
playsound('finish.wav')
print('Peace out, girl scout!')
错误:
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "/home/tstew/pypj/StudyTimer/pomodoro.py", line 13, in <module>
playsound('repetition.wav')
TypeError: 'module' object is not callable
我为尝试解决此问题所做的工作:
首先,我是初学者。我试图确保我的所有 python 内容都已更新。确保在 Python3 和 Python 上都安装了 playsound 模块。最初我将声音存储在它们自己的文件夹中,现在我已将它们移动到根文件夹中,希望它能正常工作。
相关信息:
OS - Linux 薄荷
Python 版本 - 3.8.10
Shell - 空闲
这是正确的导入:
from playsound import playsound
代码:
import time
import playsound
print('Study period in minutes?')
studyMin = float(input())
print('Break period in minutes?')
breakMin = float(input())
print('How many repetitions?')
repe = int(input())
for i in range(repe):
print('You have ' + str(repe) + ' repetitions left!')
playsound('repetition.wav')
print('Study!')
time.sleep(studyMin * 60)
playsound('repetition.wav')
print('Take a break!')
time.sleep(breakMin * 60)
playsound('finish.wav')
print('Peace out, girl scout!')
错误:
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "/home/tstew/pypj/StudyTimer/pomodoro.py", line 13, in <module>
playsound('repetition.wav')
TypeError: 'module' object is not callable
我为尝试解决此问题所做的工作:
首先,我是初学者。我试图确保我的所有 python 内容都已更新。确保在 Python3 和 Python 上都安装了 playsound 模块。最初我将声音存储在它们自己的文件夹中,现在我已将它们移动到根文件夹中,希望它能正常工作。
相关信息:
OS - Linux 薄荷
Python 版本 - 3.8.10
Shell - 空闲
这是正确的导入:
from playsound import playsound