I am not able to run a audio file automatically when the program started i saw playsound module but it is giving me error
Traceback (most recent call last):
File "main.py", line 7, in <module>
playsound('Music/videoplayback(2).mp3')
TypeError: 'module' object is not callable
my code
import random
import playsound
#Creating a KBC Special Quiz!
print("'\033[1m'"+"Welcome To Kaun Banega Crorepati!")
print()
print()
playsound('Music/videoplayback(2).mp3')
i am using repl, even i am finding difficulties in pathing
You are using the playsound module instead of the playsound.playsound function.
The docs show you how to import it so it works like you expected, see below.
>>> from playsound import playsound
>>> playsound('/path/to/a/sound/file/you/want/to/play.mp3')
Related
I am using VS code for my python and I am getting an error saying
'Traceback (most recent call last):
File "c:\Users\thecodeadd\OneDrive\Documents\Program\Python\Pyton programs\Fidget spinner.py", line 1, in <module>
import tkinter
File "c:\Users\thecodeadd\OneDrive\Documents\Program\Python\Pyton programs\tkinter.py", line 2, in <module>
win= Tk()
NameError: name 'Tk' is not defined'
I have repaired my python file and searched on the internet but I have not been able to find any solutions for this.
You didn't import the Tk class. Intead, you imported the tkinter module. To use the Tk class from the module you need to use win = tkinter.Tk().
It also looks like you named your file tkinter.py, which means that even if you do the above it won't work because your tkinter.py will get imported instead of the tkinter module. You should rename your file to something else besides tkinter.py.
I'm just doing some testing with windows-curses (2.3.0) and I was using this code and it gave me an error. The code and error are below.
Code:
import curses
from curses import wrapper
def main(stdscr):
stdscr.clear()
stdscr.addstr("Hello World")
stdscr.refresh()
stdscr.getch()
wrapper(main)
Error:
Traceback (most recent call last):
File "C:\Users\norbe\OneDrive\Desktop\Projects\Testing\Curses\curses.py", line 1, in <module>
import curses
File "C:\Users\norbe\OneDrive\Desktop\Projects\Testing\Curses\curses.py", line 2, in <module>
from curses import wrapper
ImportError: cannot import name 'wrapper' from partially initialized module 'curses' (most likely due to a circular import)
The code already imported curses and its context (methods and variables) binded to it.
It means that wrapper is already identified by python.
Try this :
import curses
wrapper = curses.wrapper
When I start boa-constructor(boa-constructor-0.6.1.src.win32.exe) from the command line by starting the script "Boa.py", I got the message says
My python version is "python-2.7.7.msi" and I download wxPyton "wxPython3.0-win32-3.0.0.0-py27.exe"
O searched for files that contains the string "NO_3D " but I didn't get any can you help me pleaze and thanks
Actually you will require wxPython 2.8.12.1 to not get this error.
>>> import wx
>>> wx.__version__
'2.8.12.1'
>>> wx.NO_3D
0
This is a pity, because the operation …|wx.NO_3D is actually a No-Op. So you could fix this particular issue by defining wx.NO_3D somewhere.
On 2.9.5:
>>> import wx
>>> wx.__version__
'2.9.5.0'
>>> wx.NO_3D
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'NO_3D'
I'm new to python programming and I have a problem. I've been looking for the solution to it problem all day and nothing I've found so far has helped me. I'm writing a time delay program in Python, but once it hits the input for the delay it gives me an error. I've tried running it in the same program and it works, but I want the two programs to be separate.
This is the delay function in delay.py
def delayA(ina):
ina=float(ina)
print("okay!")
time.sleep(ina)
print("done!")
This is the call for it in my main
import delay.py
ina = input("Enter delay in seconds: ")
delayA(ina)
And this is the error message that I've been getting all day
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Python/inputcall.py", line 1, in <module>
import delay.py
ImportError: No module named 'delay.py'; 'delay' is not a package
Thank you in advance for any help!
You were almost there bar a few minor mistakes:
delay.py:
from time import sleep
def delayA(ina):
ina = float(ina)
print("okay!")
sleep(ina)
print("done!")
main.py:
#!/usr/bin/env python
from delay import delayA
ina = input("Enter delay in seconds: ")
delayA(ina)
Your only three mistakes I found were:
Lack of indentation in your delayA function.
from delay import delayA -- Not: import delay.py
Actually importing the delayA function. i.e: from foo import bar
How do you print doc strings in python 3.1.x?
I tried with the re and sys modules as a test and I keep getting errors. Thanks
import re
print(re._doc_)
Traceback (most recent call last):
File "<pyshell#91>", line 1, in <module>
print(re._doc_)
AttributeError: 'module' object has no attribute '_doc_'
It's called __doc__, not _doc_.
import re
print(re.__doc__)
Works just fine.