I’m looking for a way to find out the duration of a audio file (.wav) in python. So far i had a look at python wave library, mutagen, pymedia, pymad i was not able to get the duration of the wav file. Pymad gave me the duration but its not consistent. Answer The duration is equal to the number of
Tag: python
Is there a way to get a list of column names in sqlite?
I want to get a list of column names from a table in a database. Using pragma I get a list of tuples with a lot of unneeded information. Is there a way to get only the column names? So I might end up with something like this: [Column1, Column2, Column3, Column4] The reason why I absolutely need this list
How to properly escape single and double quotes
I have a lxml etree HTMLParser object that I’m trying to build xpaths with to assert xpaths, attributes of the xpath and text of that tag. I ran into a problem when the text of the tag has either single-quotes(‘) or double-quotes(“) and I’ve exhausted all my options. Here’s a sam…
How can I remove duplicate words in a string with Python?
Following example: How can I remove the second two duplicates “calvin” and “klein”? The result should look like only the second duplicates should be removed and the sequence of the words should not be changed! Answer
How do you install or activate PyUno in LibreOffice?
How do you make Python (any Python) know about PyUno in LibreOffice? When I do: python says that it knows no module “uno”. (This question came up re. this question.) Answer Here’s what I did: inside the LibreOffice directory, there is a “program” directory with a python.exe, if I…
Elegantly changing the color of a plot frame in matplotlib
This is a kind of follow-up question to this post, where the coloring of axes, ticks and labels was discussed. I hope it is alright to open a new, extended question for this. Changing the color of a complete frame (ticks and axes) around a double-plot (via add_subplot) with axes [ax1, ax2] results in a lot of…
Walking/iterating over a nested dictionary of arbitrary depth (the dictionary represents a directory tree)
Python newbie at time of writing. This came up because I want a user to be able to select a group of files from within a directory (and also any subdirectory), and unfortunately Tkinter’s default ability for selecting multiple files in a file dialog is broken on Windows 7 (http://bugs.python.org/issue80…
When do you use ‘self’ in Python? [duplicate]
This question already has answers here: What is the purpose of the `self` parameter? Why is it needed? (26 answers) Closed 6 months ago. Are you supposed to use self when referencing a member function in Python (within the same module)? More generally, I was wondering when it is required to use self, not just…
Calculating arithmetic mean (one type of average) in Python [duplicate]
This question already has answers here: Finding the average of a list (25 answers) Closed 12 months ago. Is there a built-in or standard library method in Python to calculate the arithmetic mean (one type of average) of a list of numbers? Answer I am not aware of anything in the standard library. However, you…
Bad magic number error with ZipFile module in Python
I am using Python 2.7 on Windows 7 (64 bit). When I try to unzip a zip file with ZipFile module I get the following error:- WinRAR could extract the file I am trying to extract just fine. Here is the code I used to extract files from myzip.zip This code is working fine for many other zip files I