I try importing the mp3play module but it says that it doesn't exist. I also don't know how to put mp3 files into the program.
For example:
f = mp3play.load('Sound.mp3'); play = lambda: f.play()
I dont know how to insert the mp3 file into the 'Sound.mp3'.
First of all, here is the mp3play documentation page: https://pypi.org/project/mp3play/ You said that Python returned that the module didn't exist. Are you sure that you installed it correctly on your system. I would run pip install mp3play and verify that it is installed.
I would suggest putting the audio files in the same folder as your code, so that you can keep everything together. If you look at one of the very first example on the docs page I linked above, you can see that the load function takes one paremeter which is the file address. There, you would need to type the full adress of the file, so for example: C:\Documents and Settings\Michael\Desktop\music.mp3, which is the example in the docs page. I think that should solve your problem.
Your code should look something like this:
f = mp3play.load('FULL ADDRESS/Sound.mp3'); play = lambda: f.play()
Related
I've got a task to do that is crushing my head. I have five .py documents and I want to make a menu in another .py so I can run any of them by introducing a string inside an input() but don't really see the way to do that and I don't know if there is somehow I can.
I have tried import every file to the 6th file but I don't even know how to start.
I would like it just to be seen as simple as it can sound, but yet I find it really hard.
If you just want to run them, then try this:-
import os
file_path = input("Enter the path of your file = ")
os.system(file_path)
If the file that you are trying to execute is not in the current
directory, i.e. doesn't exist in the same folder as the currently
executing python file, then you have to provide it's full path.
Path Format:-. C:\Users\lmYoona\OneDrive\Desktop\example.py
If the python file you are trying to execute is in the same directory as
the currently executing python file, then abstract name will also
work
Path Format:- example.py
P.S.:- I would only recommend this method if all you want is just to execute the other python file, rather then importing stuff from it.
I am using libtorrent for python 3.6 . I just want to get any file names that downloaded with a session, e.g. the folder name, the files name etc.
I searched around the web didn't come across anything. I am using the follow example:
https://www.libtorrent.org/python_binding.html
So when the download progress finish, i want to know what files this session downloaded. How can achieve that? Thanks in advance!
Finally found the answer, the code is:
handle = libtorrent.add_magnet_uri(session, magnetLink,params)
session.start_dht()
while not handle.has_metadata():
time.sleep(1)
torinfo = handle.get_torrent_info()
for x in range(torinfo.files().num_files()):
print(torinfo.files().file_path(x))
The code above prints the file names that came with the magnet file.
Well I searched a lot and found different ways to open program in python,
For example:-
import os
os.startfile(path) # I have to give a whole path that is not possible to give a full path for every program/software in my case.
The second one that I'm currently using
import os
os.system(fileName+'.exe')
In second example problem is:-
If I want to open calculator so its .exe file name is calc.exe and this happen for any other programs too (And i dont know about all the .exe file names of every program).
And assume If I wrote every program name hard coded so, what if user installed any new program. (my program wont able to open that program?)
If there is no other way to open programs in python so Is that possible to get the list of all install program in user's computer.
and there .exe file names (like:- calculator is calc.exe you got the point).
If you want to take a look at code
Note: I want generic solution.
There's always:
from subprocess import call
call(["calc.exe"])
This should allow you to use a dict or list or set to hold your program names and call them at will. This is covered also in this answer by David Cournapeau and chobok.
You can try with os.walk :
import os
exe_list=[]
for root, dirs, files in os.walk("."):
#print (dirs)
for j in dirs:
for i in files:
if i.endswith('.exe'):
#p=os.getcwd()+'/'+j+'/'+i
p=root+'/'+j+'/'+i
#print(p)
exe_list.append(p)
for i in exe_list :
print('index : {} file :{}'.format(exe_list.index(i),i.split('/')[-1]))
ip=int(input('Enter index of file :'))
print('executing {}...'.format(exe_list[ip]))
os.system(exe_list[ip])
os.getcwd()+'/'+i prepends the path of file to the exe file starting from root.
exe_list.index(i),i.split('/')[-1] fetches just the filename.exe
exe_list stores the whole path of an exe file at each index
Can be done with winapps
First install winapps by typing:
pip install winapps
After that use the library:
# This will give you list of installed applications along with some information
import winapps
for app in winapps.list_installed():
print(app)
If you want to search for an app you can simple do:
application = 'chrome'
for app in winapps.search_installed(application):
print(app)
I need to read an msi file and make some queries to it. But it looks like despite it is a standard lib for python, it has poor documentation.
To make queries I have to know database schema and I can't find any examples or methods to get it from the file.
Here is my code I'm trying to make work:
import msilib
path = "C:\\Users\\Paul\\Desktop\\my.msi" #I cannot share msi
dbobject = msilib.OpenDatabase(path, msilib.MSIDBOPEN_READONLY)
view = dbobject.OpenView("SELECT FileName FROM File")
rec = view.Execute(None)
r = v.Fetch()
And the rec variable is None. But I can open the MSI file with InstEd tool and see that File is present in the tables list and there are a lot of records there.
What I'm doing wrong?
Your code is suspect, as the last line will throw a NameError in your sample. So let's ignore that line.
The real problem is that view.Execute returns nothing of use. Under the hoods, the MsiViewExecute function only returns success or failure. After you call that, you then need to call view.Fetch, which may be what your last line intended to do.
Downloaded files location from Google Chrome is:
\\WALL-E\RedirectedFolders\myname\My Documents\Downloads
How do I reference this?
I cannot reference this in normal way like you do C: Drive.
path='C:\\...'
I think you are doing this in windows. Assuming that what you can do is:
- Go to the Downloads folder in windows.
-Click the addressbar which will give you something like this:
C:\Users\TomHarris\Documents\ViberDownloads
Append the name of your designated file on the last of above.
C:\Users\TomHarris\Documents\ViberDownloads\MYFILETOOPEN
While I think both back-slash and forward-slash should work fine ( I am not sure though, check it!), File input in python follows convention which something like this:
fname= "/WALL-E/RedirectedFolders/myname/My Documents/Downloads"
path='\\\\WALL-E\\RedirectedFolders\\rmarshall\\My Documents\\Downloads\\'