title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Python: sort the list | 2,059,564 | <p>I want to sort the array c. But I don't get the answer a,b,c,d. Instead I get a,b,d,c. What could I do, for sorting the whole array and not only one row?</p>
<p>EDIT: I want to sort the numbers. And the connected letters, should have the same order like the sorted numbers. sorry my question wasn't clear. Maybe I sh... | 0 | 2010-01-13T19:25:31Z | 2,059,695 | <pre><code>def sort_parallel(a, b):
ba = zip(b, a)
ba.sort()
return [e[1] for e in ba]
a = ['a','b','d','c']
b = [1,2,4,3]
print sort_parallel(a, b)
</code></pre>
<p>prints</p>
<pre><code>['a', 'b', 'c', 'd']
</code></pre>
| 1 | 2010-01-13T19:44:45Z | [
"python",
"list",
"sorting"
] |
Python: sort the list | 2,059,564 | <p>I want to sort the array c. But I don't get the answer a,b,c,d. Instead I get a,b,d,c. What could I do, for sorting the whole array and not only one row?</p>
<p>EDIT: I want to sort the numbers. And the connected letters, should have the same order like the sorted numbers. sorry my question wasn't clear. Maybe I sh... | 0 | 2010-01-13T19:25:31Z | 2,059,714 | <pre><code>>>> a = ['a','b','d','c']
>>> b = [1, 2, 4, 3]
>>> c = zip(a, b)
>>> c
[('a', 1), ('b', 2), ('d', 4), ('c', 3)]
>>> c.sort(key=lambda x: x[1])
>>> c
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]
</code></pre>
| 1 | 2010-01-13T19:47:29Z | [
"python",
"list",
"sorting"
] |
Python: sort the list | 2,059,564 | <p>I want to sort the array c. But I don't get the answer a,b,c,d. Instead I get a,b,d,c. What could I do, for sorting the whole array and not only one row?</p>
<p>EDIT: I want to sort the numbers. And the connected letters, should have the same order like the sorted numbers. sorry my question wasn't clear. Maybe I sh... | 0 | 2010-01-13T19:25:31Z | 2,059,721 | <p>Roger Pate gave a good answer, but you said "but now he sorts the letters. I want to sort the numbers."</p>
<p>Here is a modified version of Roger Pate's answer that sorts c by the numbers. Is this what you want?</p>
<pre><code>>>> def mykey(tup):
>>> return tup[1]
>>>
>>> ... | 0 | 2010-01-13T19:48:18Z | [
"python",
"list",
"sorting"
] |
Python: sort the list | 2,059,564 | <p>I want to sort the array c. But I don't get the answer a,b,c,d. Instead I get a,b,d,c. What could I do, for sorting the whole array and not only one row?</p>
<p>EDIT: I want to sort the numbers. And the connected letters, should have the same order like the sorted numbers. sorry my question wasn't clear. Maybe I sh... | 0 | 2010-01-13T19:25:31Z | 2,059,724 | <p>you have to provide the custom comparison function for sort to use.using lambda it is pretty simple:</p>
<pre>
<code>
cmp = lambda x,y: (x[1], x[0]) < (y[1], y[0])
L.sort(cmp = cmp)
</code>
</pre>
<p>Lambda is all anonymous function, in this case it reverses the order of elements, such that second element become... | 0 | 2010-01-13T19:48:44Z | [
"python",
"list",
"sorting"
] |
Python: sort the list | 2,059,564 | <p>I want to sort the array c. But I don't get the answer a,b,c,d. Instead I get a,b,d,c. What could I do, for sorting the whole array and not only one row?</p>
<p>EDIT: I want to sort the numbers. And the connected letters, should have the same order like the sorted numbers. sorry my question wasn't clear. Maybe I sh... | 0 | 2010-01-13T19:25:31Z | 2,059,765 | <p>You could try (for Python 3.x):</p>
<pre><code>def sort_a_based_on_b(a, b):
c = sorted(list(zip(b, a)))
return list(list(zip(*c))[1]) # Returns the sorted a
</code></pre>
<p>This returns the sorted a, based on the values in b.</p>
<pre><code>a = ['a','b','d','c']
b = [1,2,4,3]
print(sort_a_based_on_b(a,b... | 1 | 2010-01-13T19:55:35Z | [
"python",
"list",
"sorting"
] |
Python: sort the list | 2,059,564 | <p>I want to sort the array c. But I don't get the answer a,b,c,d. Instead I get a,b,d,c. What could I do, for sorting the whole array and not only one row?</p>
<p>EDIT: I want to sort the numbers. And the connected letters, should have the same order like the sorted numbers. sorry my question wasn't clear. Maybe I sh... | 0 | 2010-01-13T19:25:31Z | 2,060,192 | <p>Is this what you're after?</p>
<pre><code>>>> a = ['a','b','d','c']
>>> b = [1, 2, 4, 3]
>>> c = zip(b, a)
>>> c.sort()
>>> c = [(y, x) for (x, y) in c]
>>> print(c)
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]
</code></pre>
| 0 | 2010-01-13T20:55:41Z | [
"python",
"list",
"sorting"
] |
Catching warnings pre-python 2.6 | 2,059,675 | <p>In Python 2.6 it is possible to suppress warnings from the warnings module by using</p>
<pre><code>with warnings.catch_warnings():
warnings.simplefilter("ignore")
fxn()
</code></pre>
<p>Versions of Python before 2.6 don't support <code>with</code> however, so I'm wondering if there alternatives to the abov... | 7 | 2010-01-13T19:42:24Z | 2,059,751 | <p>This is similar:</p>
<pre><code># Save the existing list of warning filters before we modify it using simplefilter().
# Note: the '[:]' causes a copy of the list to be created. Without it, original_filter
# would alias the one and only 'real' list and then we'd have nothing to restore.
original_filters = warnings.f... | 3 | 2010-01-13T19:53:15Z | [
"python",
"warnings",
"suppress-warnings"
] |
Catching warnings pre-python 2.6 | 2,059,675 | <p>In Python 2.6 it is possible to suppress warnings from the warnings module by using</p>
<pre><code>with warnings.catch_warnings():
warnings.simplefilter("ignore")
fxn()
</code></pre>
<p>Versions of Python before 2.6 don't support <code>with</code> however, so I'm wondering if there alternatives to the abov... | 7 | 2010-01-13T19:42:24Z | 2,059,772 | <p>Depending on what the minimum version you need to support using Python 2.5's </p>
<pre><code>from __future__ import with_statement
</code></pre>
<p>might be an option, else you'll probably need to fallback to what Jon suggested.</p>
| -1 | 2010-01-13T19:56:38Z | [
"python",
"warnings",
"suppress-warnings"
] |
Python C API and data persistent in memory? | 2,059,685 | <p>I'm considering integrating some C code into a Python system (Django), and I was considering using the Python / C API. The alternative is two separate processes with IPC, but I'm looking into direct interaction first. I'm new to Python so I'm trying to get a feel for the right direction to take.</p>
<p>Is it possib... | 2 | 2010-01-13T19:43:57Z | 2,059,698 | <p><a href="http://www.cython.org/" rel="nofollow">Cython</a></p>
| 2 | 2010-01-13T19:45:14Z | [
"python",
"c",
"ipc"
] |
Python C API and data persistent in memory? | 2,059,685 | <p>I'm considering integrating some C code into a Python system (Django), and I was considering using the Python / C API. The alternative is two separate processes with IPC, but I'm looking into direct interaction first. I'm new to Python so I'm trying to get a feel for the right direction to take.</p>
<p>Is it possib... | 2 | 2010-01-13T19:43:57Z | 2,059,797 | <p>You can certainly use the C API to do what you want. You'll create a class in C, which can hold onto any memory it wants. That memory doesn't have to be exposed to Python at all if you don't want.</p>
<p>If you are comfortable building C DLLs, and don't need to perform Python operations in C, then ctypes might be... | 1 | 2010-01-13T20:00:56Z | [
"python",
"c",
"ipc"
] |
Opening multiple windows from a list in WxPython | 2,059,786 | <p>I have a little program that goes to news aggregater's, gets the hrefs, and returns in a window. I want to have multiple windows open if multiple sites are choosen, right now, it will only go to the first one in a list, and completes perfectly. I assume I am not passing the the contents of the list properly to the n... | 0 | 2010-01-13T19:58:47Z | 2,060,630 | <p>I am not familiar with WxPython but it appears that you have two <code>MainLoop</code>s running.<br>
I got your program to open two windows when I commented out the two lines as shown below:</p>
<pre><code> class MyHtmlFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame._... | 0 | 2010-01-13T22:03:44Z | [
"python",
"wxpython"
] |
Opening multiple windows from a list in WxPython | 2,059,786 | <p>I have a little program that goes to news aggregater's, gets the hrefs, and returns in a window. I want to have multiple windows open if multiple sites are choosen, right now, it will only go to the first one in a list, and completes perfectly. I assume I am not passing the the contents of the list properly to the n... | 0 | 2010-01-13T19:58:47Z | 2,061,043 | <p>Eeek! You're defining your MyHTMLFrame class -inside- an event handler function (not a good idea). </p>
<p>I can't run the script as I don't have the module PyParsing (always make samples that have as little dependencies as possible...)</p>
<p>Therefore, I'm not sure if this code runs, but it should give you the g... | 1 | 2010-01-13T23:15:34Z | [
"python",
"wxpython"
] |
Submitting queries to, and scraping results from aspx pages using python? | 2,059,822 | <p>I am trying to get results for a batch of queries to this demographics tools page: <a href="http://adlab.microsoft.com/Demographics-Prediction/DPUI.aspx" rel="nofollow">http://adlab.microsoft.com/Demographics-Prediction/DPUI.aspx</a></p>
<p>The POST action on the form calls the same page (_self) and is probably pos... | 1 | 2010-01-13T20:04:16Z | 2,059,843 | <p>Perhaps <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a> may be of use.</p>
| 1 | 2010-01-13T20:06:51Z | [
"python",
"screen-scraping",
"beautifulsoup"
] |
Submitting queries to, and scraping results from aspx pages using python? | 2,059,822 | <p>I am trying to get results for a batch of queries to this demographics tools page: <a href="http://adlab.microsoft.com/Demographics-Prediction/DPUI.aspx" rel="nofollow">http://adlab.microsoft.com/Demographics-Prediction/DPUI.aspx</a></p>
<p>The POST action on the form calls the same page (_self) and is probably pos... | 1 | 2010-01-13T20:04:16Z | 2,060,005 | <p>Use <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a>. Your POST data is a simple Python dictionary. Very easy to edit and maintain.</p>
<p>If your form contains hidden fields -- some of which are encoded -- then you need to do a GET to get the form and the various hidden field seed... | 1 | 2010-01-13T20:29:40Z | [
"python",
"screen-scraping",
"beautifulsoup"
] |
Submitting queries to, and scraping results from aspx pages using python? | 2,059,822 | <p>I am trying to get results for a batch of queries to this demographics tools page: <a href="http://adlab.microsoft.com/Demographics-Prediction/DPUI.aspx" rel="nofollow">http://adlab.microsoft.com/Demographics-Prediction/DPUI.aspx</a></p>
<p>The POST action on the form calls the same page (_self) and is probably pos... | 1 | 2010-01-13T20:04:16Z | 13,585,803 | <p>I've used a combination <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">requests</a> and <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">BeautifulSoup4</a> for a similar task.</p>
| 0 | 2012-11-27T13:56:32Z | [
"python",
"screen-scraping",
"beautifulsoup"
] |
Using an index to recursively get all files in a directory really fast | 2,059,912 | <p><strong>Attempt #2:</strong></p>
<p>People don't seem to be understanding what I'm trying to do. Let me see if I can state it more clearly:</p>
<p>1) Reading a list of files is much faster than walking a directory.</p>
<p>2) So let's have a function that walks a directory and writes the resulting list to a fil... | 2 | 2010-01-13T20:15:53Z | 2,059,939 | <p>Do not try to duplicate the work that the filesystem already does. You are not going to do better than it already does.</p>
<p>Your scheme is flawed in many ways and it will not get you an order-of-magnitude improvement.</p>
<p>Flaws and potential problems:</p>
<p>You are always going to be working with a snapsho... | 7 | 2010-01-13T20:20:40Z | [
"python",
"indexing",
"directory",
"performance",
"all-files"
] |
Using an index to recursively get all files in a directory really fast | 2,059,912 | <p><strong>Attempt #2:</strong></p>
<p>People don't seem to be understanding what I'm trying to do. Let me see if I can state it more clearly:</p>
<p>1) Reading a list of files is much faster than walking a directory.</p>
<p>2) So let's have a function that walks a directory and writes the resulting list to a fil... | 2 | 2010-01-13T20:15:53Z | 2,060,026 | <p>I would like to recommend you just use a combination of <code>os.walk</code> (to get directory trees) & <code>os.stat</code> (to get file information) for this. Using the std-lib will ensure it works on all platforms, and they do the job nicely. And no need to index anything.</p>
<p>As other have stated, I don... | 0 | 2010-01-13T20:33:16Z | [
"python",
"indexing",
"directory",
"performance",
"all-files"
] |
Using an index to recursively get all files in a directory really fast | 2,059,912 | <p><strong>Attempt #2:</strong></p>
<p>People don't seem to be understanding what I'm trying to do. Let me see if I can state it more clearly:</p>
<p>1) Reading a list of files is much faster than walking a directory.</p>
<p>2) So let's have a function that walks a directory and writes the resulting list to a fil... | 2 | 2010-01-13T20:15:53Z | 2,060,090 | <p>Doesn't Windows Desktop Search provide such an index as a byproduct? On the mac the spotlight index can be queried for filenames like this: <code>mdfind -onlyin . -name '*'</code>.</p>
<p>Of course it's much faster than walking the directory.</p>
| 2 | 2010-01-13T20:41:52Z | [
"python",
"indexing",
"directory",
"performance",
"all-files"
] |
Using an index to recursively get all files in a directory really fast | 2,059,912 | <p><strong>Attempt #2:</strong></p>
<p>People don't seem to be understanding what I'm trying to do. Let me see if I can state it more clearly:</p>
<p>1) Reading a list of files is much faster than walking a directory.</p>
<p>2) So let's have a function that walks a directory and writes the resulting list to a fil... | 2 | 2010-01-13T20:15:53Z | 2,060,719 | <p>I'm new to Python, but I'm using a combination of list comprehensions, iterator and a generator should scream according to reports I've read.</p>
<pre><code>class DirectoryIterator:
def __init__(self, start_dir, pattern):
self.directory = start_dir
self.pattern = pattern
def __iter__(self):
... | 0 | 2010-01-13T22:21:11Z | [
"python",
"indexing",
"directory",
"performance",
"all-files"
] |
Using an index to recursively get all files in a directory really fast | 2,059,912 | <p><strong>Attempt #2:</strong></p>
<p>People don't seem to be understanding what I'm trying to do. Let me see if I can state it more clearly:</p>
<p>1) Reading a list of files is much faster than walking a directory.</p>
<p>2) So let's have a function that walks a directory and writes the resulting list to a fil... | 2 | 2010-01-13T20:15:53Z | 2,061,763 | <p>The short answer is "no". You will not be able to build an indexing system in Python that will outpace the file system by an order of magnitude.</p>
<p>"Indexing" a filesystem is an intensive/slow task, regardless of the caching implementation. The only realistic way to avoid the huge overhead of building filesys... | 1 | 2010-01-14T02:15:28Z | [
"python",
"indexing",
"directory",
"performance",
"all-files"
] |
Using an index to recursively get all files in a directory really fast | 2,059,912 | <p><strong>Attempt #2:</strong></p>
<p>People don't seem to be understanding what I'm trying to do. Let me see if I can state it more clearly:</p>
<p>1) Reading a list of files is much faster than walking a directory.</p>
<p>2) So let's have a function that walks a directory and writes the resulting list to a fil... | 2 | 2010-01-13T20:15:53Z | 2,075,250 | <p>The best answer came from <a href="http://stackoverflow.com/users/232707/michal-marczyk">MichaÅ Marczyk</a> toward the bottom of the comment list on the initial question. He pointed out that what I'm describing is very close to the UNIX locate program. I found a Windows version here: <a href="http://locate32.net/... | 2 | 2010-01-15T22:41:10Z | [
"python",
"indexing",
"directory",
"performance",
"all-files"
] |
drop table in python with sqlite3 | 2,060,032 | <p>I have question about python and sqlite3. I want to drop a table from within Python. The command</p>
<pre><code>cur.execute('drop table if exists tab1')
</code></pre>
<p>Does not work.</p>
<pre><code>cur.executescript('drop table if exists tab1;')
</code></pre>
<p>does the job.</p>
<p>The execute method allow... | 7 | 2010-01-13T20:33:44Z | 2,060,099 | <p>The <code>cur.executescript</code> command issues a <code>COMMIT</code> before running the provided script. Additionally a <code>CREATE</code> executes a <code>COMMIT</code> intrinsically. Perhaps you have an open transaction that needs committed before your changes take place.</p>
| 7 | 2010-01-13T20:43:49Z | [
"python",
"sqlite"
] |
super() weirdness in Python 3 | 2,060,475 | <p>I know this has been discussed a number of times before, but there was never an explanation of what's going on "under the hood".</p>
<p>Can anyone provide a detailed explanation as to why commenting-in the last line of code causes an error to be raised? I know that that object.__init__ doesn't take any arguments, b... | 2 | 2010-01-13T21:39:28Z | 2,060,515 | <p>In Python 3 every method becomes a closure with a hidden value added for the "current class" being defined. This is accessed by <code>super()</code> (with no arguments).</p>
<p>Super returns an object which uses the class's Method Resolution Order (MRO), and for C instances this has B after A.</p>
<p>Without find... | 6 | 2010-01-13T21:45:34Z | [
"python",
"python-3.x",
"super"
] |
Draw a colored sphere from cartesian coordinates in pymol | 2,060,582 | <p>I was looking in the wiki how to convert the following information about beads, cartesian coordinates + energy :</p>
<p>23.4 54.6 12.3 -123.5 54.5 23.1 9.45 -56.7 .......</p>
<p>to a draw in pymol that contains for each atom a sphere of radius R, centered on its coordinates, and with color, in a rainbow gradient.<... | 5 | 2010-01-13T21:57:19Z | 2,075,684 | <p>Does what you're rendering actually have anything to do with molecular structure (i.e. what is the motivation for using PyMol)?</p>
<p>If you are drawing some molecular structure, I would recommend just outputting a custom PDB file with the sphere coordinates (you can use the B-factor field per ATOM line as a way o... | 7 | 2010-01-16T00:35:25Z | [
"python",
"visualization",
"bioinformatics"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 2,060,677 | <p>If you're going to perform transfers on the waveform data then perhaps you should use <a href="http://www.scipy.org/" rel="nofollow">SciPy</a>, specifically <a href="http://docs.scipy.org/doc/scipy/reference/tutorial/io.html#module-scipy.io.wavfile" rel="nofollow"><code>scipy.io.wavfile</code></a>.</p>
| 1 | 2010-01-13T22:11:21Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 2,061,184 | <p>Per <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.read.html">the sources</a>, <code>scipy.io.wavfile.read(somefile)</code> returns a tuple of two items: the first is the sampling rate in samples per second, the second is a <code>numpy</code> array with all the data read from the file.... | 36 | 2010-01-13T23:44:48Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 5,281,240 | <p>I did some research this evening and figured this out:</p>
<pre><code>import wave, struct
waveFile = wave.open('sine.wav', 'r')
length = waveFile.getnframes()
for i in range(0,length):
waveData = waveFile.readframes(1)
data = struct.unpack("<h", waveData)
print(int(data[0]))
</code></pre>
<p>Hopef... | 36 | 2011-03-12T07:21:08Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 6,392,333 | <p>You can accomplish this using the <a href="http://scikits.appspot.com/audiolab">scikits.audiolab</a> module. It requires NumPy and SciPy to function, and also libsndfile.</p>
<p>Note, I was only able to get it to work on Ubunutu and not on OSX.</p>
<pre><code>from scikits.audiolab import wavread
filename = "testf... | 6 | 2011-06-17T22:10:32Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 18,408,014 | <p>if its just two files and the sample rate is significantly high, you could just interleave them.</p>
<pre><code>from scipy.io import wavfile
rate1,dat1 = wavfile.read(File1)
rate2,dat2 = wavfile.read(File2)
if len(dat2) > len(dat1):#swap shortest
temp = dat2
dat2 = dat1
dat1 = temp
output = dat1
fo... | 0 | 2013-08-23T16:51:36Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 25,865,708 | <p>If you want to procces an audio block by block, some of the given solutions are quite awful in the sense that they imply loading the whole audio into memory producing many cache misses and slowing down your program. <a href="https://github.com/vokimon/python-wavefile" rel="nofollow">python-wavefile</a> provides some... | 2 | 2014-09-16T09:54:36Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 26,716,031 | <p>I have found 4 module to read wave audio file: scikits.audiolab, scipy.io.wavfile, wave, and numpy.</p>
<p>Warning: the data are not always the same in function of the method you use.
For example:</p>
<pre><code>from scikits import audiolab
from scipy.io import wavfile
from sys import argv
for filetest in argv[1:]... | 2 | 2014-11-03T14:13:58Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 30,832,148 | <p>I needed to read a 1-channel 24-bit WAV file. The post above by <a href="http://stackoverflow.com/users/656302/nak">Nak</a> was very useful. However, as mentioned above by <a href="http://stackoverflow.com/users/1422096/basj">basj</a> 24-bit is not straightforward. I finally got it working using the following snippe... | 0 | 2015-06-14T17:01:48Z | [
"python",
"audio",
"wav",
"wave"
] |
Reading *.wav files in Python | 2,060,628 | <p>I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use the wave package. However, I do not know how exactly it works. For example I did the following:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/vo... | 32 | 2010-01-13T22:03:28Z | 32,630,002 | <p>IMHO, the easiest way to get audio data from a sound file into a NumPy array is <a href="http://pysoundfile.readthedocs.org/" rel="nofollow">PySoundFile</a>:</p>
<pre><code>import soundfile as sf
data, fs = sf.read('/usr/share/sounds/ekiga/voicemail.wav')
</code></pre>
<p>This also supports 24-bit files out of the... | 3 | 2015-09-17T12:09:43Z | [
"python",
"audio",
"wav",
"wave"
] |
python windows vista/7 uac and copying (only reading) files? permissions/interaction of UAC? | 2,060,672 | <p>I'm currently making a program for a lan center that scans a users hard drive, and copies/archives certain save game files into a zip and uploads them to a FTP server. But I've created a lot of the program at this point and just had a major issue that I had not tested for spring to mind:</p>
<p>How does Vista/7's ... | 0 | 2010-01-13T22:09:43Z | 2,063,235 | <p>If your program is running as elevated admin, then it will not redirect to c:\users folder.
You can run the program as elevated admin by embedding a manifest to the file.
see <a href="http://en.wikipedia.org/wiki/User_Account_Control" rel="nofollow">http://en.wikipedia.org/wiki/User_Account_Control</a>
for details ... | 0 | 2010-01-14T09:38:39Z | [
"python",
"windows-7",
"windows-vista",
"uac"
] |
Override delete-function on multi-delete | 2,060,755 | <p>The following works great when going to the objects adminpage and select delete. The problem is that when using multiselect and deleting multiple items at once it doesn't use my delete-override. I've been looking for a solution but haven't found one so it's time to turn to the masters ;)</p>
<pre><code>class Photo(... | 0 | 2010-01-13T22:25:36Z | 2,061,062 | <blockquote>
<p>when using multiselect and deleting
multiple items at once</p>
</blockquote>
<p>I suspect this means you're doing something like:</p>
<pre><code>Photo.objects.filter(name='something').delete()
</code></pre>
<p>If that's the case, that will not call your custom <code>delete</code> method since it ... | 0 | 2010-01-13T23:20:13Z | [
"python",
"django"
] |
Override delete-function on multi-delete | 2,060,755 | <p>The following works great when going to the objects adminpage and select delete. The problem is that when using multiselect and deleting multiple items at once it doesn't use my delete-override. I've been looking for a solution but haven't found one so it's time to turn to the masters ;)</p>
<pre><code>class Photo(... | 0 | 2010-01-13T22:25:36Z | 2,063,904 | <p>Solved my problem :)</p>
<pre><code>class PhotoQuerySet(QuerySet):
def delete(self):
for x in self:
x.delete()
class PhotoManager(models.Manager):
def get_query_set(self):
return PhotoQuerySet(self.model)
class Photo(models.Model):
name = models.CharField(max_length=256, un... | 2 | 2010-01-14T12:09:54Z | [
"python",
"django"
] |
Override delete-function on multi-delete | 2,060,755 | <p>The following works great when going to the objects adminpage and select delete. The problem is that when using multiselect and deleting multiple items at once it doesn't use my delete-override. I've been looking for a solution but haven't found one so it's time to turn to the masters ;)</p>
<pre><code>class Photo(... | 0 | 2010-01-13T22:25:36Z | 11,453,180 | <p>Just for completeness, the model's delete method isn't called on a Model.objects.filter(...).delete() call: <a href="https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.delete" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.Q... | 1 | 2012-07-12T13:43:47Z | [
"python",
"django"
] |
Copy Table data from one DB to another | 2,060,823 | <p>For development I find myself needing to copy table information from one table to another quite often. I am just curious what are the easiest solutions to do this for Postgres. I have PGAdminIII but it looks like it really only support the long drawn out Backup/Restore.</p>
<p>Is there a python or bash script som... | 2 | 2010-01-13T22:36:40Z | 2,060,837 | <p>Kettle, aka pentaho data integration can do this for you.
<a href="http://sourceforge.net/projects/pentaho/files/Data%20Integration/">http://sourceforge.net/projects/pentaho/files/Data%20Integration/</a></p>
<ol>
<li>Download kettle and unzip. </li>
<li>Make sure you have a java runtime environment (1.5 and 1.6 wi... | 6 | 2010-01-13T22:38:18Z | [
"python",
"linux",
"osx",
"postgresql"
] |
Copy Table data from one DB to another | 2,060,823 | <p>For development I find myself needing to copy table information from one table to another quite often. I am just curious what are the easiest solutions to do this for Postgres. I have PGAdminIII but it looks like it really only support the long drawn out Backup/Restore.</p>
<p>Is there a python or bash script som... | 2 | 2010-01-13T22:36:40Z | 2,060,963 | <p>If you're just moving between two PostgreSQL databases, a good way is to just use pg_dump and pg_restore in a pipe (or pg_dump and psql). Basically</p>
<pre><code>pg_dump -Fc db1 | pg_restore -d db2 -c
</code></pre>
<p>(adjust switches as necessary for your environment, see the man pages)</p>
<p>It's tools you ha... | 3 | 2010-01-13T23:00:26Z | [
"python",
"linux",
"osx",
"postgresql"
] |
Is there anything out there that can take screenshots of website content and crop out the layout? | 2,060,865 | <p>Other ideas are also welcome. I am trying to take an excel file, using python to generate an xml for a javascript html webpage that will essentially display a gallery (or some sort of directory structure). The excel file would be pretty massive, but let us assume time isn't so crucial. </p>
<p>So far I can convert ... | 0 | 2010-01-13T22:45:36Z | 2,060,899 | <p>You could probably use <a href="http://code.google.com/p/pywebkitgtk/" rel="nofollow">pywebkitgtk</a> to render the HTML and then <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> to manipulate the image.</p>
| 1 | 2010-01-13T22:49:21Z | [
"python",
"image",
"automation",
"screenshot",
"crop"
] |
Subclassing Python dictionary to override __setitem__ | 2,060,972 | <p>I am building a class which subclasses <code>dict</code>, and overrides <code>__setitem__</code>. I would like to be certain that my method will be called in all instances where dictionary items could possibly be set.</p>
<p>I have discovered three situations where Python (in this case, 2.6.4) does not call my over... | 31 | 2010-01-13T23:01:58Z | 2,061,041 | <p>What is your use-case for subclassing dict? </p>
<p>You don't need to do this to implement a dict-like object, and it might be simpler in your case to write an ordinary class, then add support for the required subset of the dict interface.</p>
<p>The best way to accomplish what you're after is probably the Mutable... | 4 | 2010-01-13T23:15:21Z | [
"python",
"dictionary",
"subclass"
] |
Subclassing Python dictionary to override __setitem__ | 2,060,972 | <p>I am building a class which subclasses <code>dict</code>, and overrides <code>__setitem__</code>. I would like to be certain that my method will be called in all instances where dictionary items could possibly be set.</p>
<p>I have discovered three situations where Python (in this case, 2.6.4) does not call my over... | 31 | 2010-01-13T23:01:58Z | 2,588,648 | <p>I'm answering my own question, since I eventually decided that I really <em>do</em> want to subclass Dict, rather than creating a new mapping class, and UserDict still defers to the underlying Dict object in some cases, rather than using the provided <code>__setitem__</code>.</p>
<p>After reading and re-reading the... | 36 | 2010-04-06T21:57:52Z | [
"python",
"dictionary",
"subclass"
] |
Subclassing Python dictionary to override __setitem__ | 2,060,972 | <p>I am building a class which subclasses <code>dict</code>, and overrides <code>__setitem__</code>. I would like to be certain that my method will be called in all instances where dictionary items could possibly be set.</p>
<p>I have discovered three situations where Python (in this case, 2.6.4) does not call my over... | 31 | 2010-01-13T23:01:58Z | 15,874,013 | <p>Use object.keyname = value instead of object["keyname"] = value</p>
| 0 | 2013-04-08T07:55:56Z | [
"python",
"dictionary",
"subclass"
] |
Subclassing Python dictionary to override __setitem__ | 2,060,972 | <p>I am building a class which subclasses <code>dict</code>, and overrides <code>__setitem__</code>. I would like to be certain that my method will be called in all instances where dictionary items could possibly be set.</p>
<p>I have discovered three situations where Python (in this case, 2.6.4) does not call my over... | 31 | 2010-01-13T23:01:58Z | 24,907,335 | <p>I found Ian answer and comments very helpful and clear. I would just point out that maybe a first call to the super-class <code>__init__</code> method might be safer, when not necessary: I recently needed to implement a custom <a href="https://docs.python.org/2/library/collections.html#ordereddict-objects" rel="nof... | 2 | 2014-07-23T09:55:34Z | [
"python",
"dictionary",
"subclass"
] |
Yahoo OAuth question | 2,061,124 | <p>I'm keep getting oauth_problem=consumer_key_unknown error when trying oauth <a href="https://api.login.yahoo.com/oauth/v2/get_request_token" rel="nofollow">https://api.login.yahoo.com/oauth/v2/get_request_token</a></p>
<p>I'm pretty sure my consumer key is correct because it works locally (Runs via 127.0.0.1). Just... | 1 | 2010-01-13T23:33:17Z | 2,061,163 | <p>is it sending the right domain in requireSession (4th argument should be something like 'http://mydomain.com/' which should match exactly what you used to sign up...</p>
| 0 | 2010-01-13T23:40:39Z | [
"python",
"oauth",
"yahoo"
] |
What is the true difference between a dictionary and a hash table? | 2,061,222 | <p>I've always used dictionaries. I write in Python.</p>
| 21 | 2010-01-13T23:53:47Z | 2,061,236 | <p>A Python dictionary is internally implemented with a hashtable.</p>
| 5 | 2010-01-13T23:55:33Z | [
"python",
"data-structures",
"hash",
"dictionary",
"hashtable"
] |
What is the true difference between a dictionary and a hash table? | 2,061,222 | <p>I've always used dictionaries. I write in Python.</p>
| 21 | 2010-01-13T23:53:47Z | 2,061,248 | <p>A dictionary is a data structure that maps keys to values.</p>
<p>A hash table is a data structure that maps keys to values by taking the hash value of the key (by applying some hash function to it) and mapping that to a bucket where one or more values are stored.</p>
<p>IMO this is analogous to asking the differe... | 20 | 2010-01-13T23:57:27Z | [
"python",
"data-structures",
"hash",
"dictionary",
"hashtable"
] |
What is the true difference between a dictionary and a hash table? | 2,061,222 | <p>I've always used dictionaries. I write in Python.</p>
| 21 | 2010-01-13T23:53:47Z | 2,061,273 | <p>"A dictionary" has a few different meanings in programming, as <a href="http://en.wikipedia.org/wiki/Dictionary_%28disambiguation%29">wikipedia</a> will tell you -- "associative array", the sense in which Python uses the term (also known as "a mapping"), is one of those meanings (but "data dictionary", and "dictiona... | 12 | 2010-01-14T00:01:41Z | [
"python",
"data-structures",
"hash",
"dictionary",
"hashtable"
] |
What is the true difference between a dictionary and a hash table? | 2,061,222 | <p>I've always used dictionaries. I write in Python.</p>
| 21 | 2010-01-13T23:53:47Z | 2,061,300 | <p>Dictionary is implemented using hash tables. In my opinion the difference between the 2 can be thought of as the difference between Stacks and Arrays where we would be using arrays to implement Stacks.</p>
| 0 | 2010-01-14T00:06:43Z | [
"python",
"data-structures",
"hash",
"dictionary",
"hashtable"
] |
What is the true difference between a dictionary and a hash table? | 2,061,222 | <p>I've always used dictionaries. I write in Python.</p>
| 21 | 2010-01-13T23:53:47Z | 2,061,323 | <p>A hash table always uses some function operating on a value to determine where a value will be stored. A Dictionary (as I believe you intend it) is a more general term, and simply indicates a lookup mechanism, which might be a hash table or might be implemented by a simpler structure which does not consider the valu... | 1 | 2010-01-14T00:14:08Z | [
"python",
"data-structures",
"hash",
"dictionary",
"hashtable"
] |
What is the true difference between a dictionary and a hash table? | 2,061,222 | <p>I've always used dictionaries. I write in Python.</p>
| 21 | 2010-01-13T23:53:47Z | 2,061,406 | <p>A dictionary is a general concept that maps keys to values. There are many ways to implement such a mapping.</p>
<p>A hashtable is a specific way to implement a dictionary.</p>
<p>Besides hashtables, another common way to implement dictionaries is <a href="http://en.wikipedia.org/wiki/Red-black_tree">red-black tr... | 87 | 2010-01-14T00:29:15Z | [
"python",
"data-structures",
"hash",
"dictionary",
"hashtable"
] |
subprocess popen + curl + binary data | 2,061,420 | <p>The following statement works as expected:</p>
<pre><code>os.system("curl --data-binary \@"+input_file_path+" -o "+ file_name +" localhost:30")
</code></pre>
<p>But when trying it with <code>subprocess.popen</code>:</p>
<pre><code>Popen(['curl','--data-binary','\@'+input_file_path, '-o', file_name,'localhost:30']... | 0 | 2010-01-14T00:33:56Z | 2,061,456 | <p>You could try using the original string in <code>subprocess.Popen</code> with the additional keyword argument to <code>Popen</code> of <code>shell=True</code>:</p>
<pre><code>subprocess.Popen("curl --data-binary \@"+input_file_path+" -o "+ file_name +" localhost:30",
stdout=subprocess.PIPE,
shell=True)
</co... | 2 | 2010-01-14T00:45:03Z | [
"python",
"curl",
"popen"
] |
subprocess popen + curl + binary data | 2,061,420 | <p>The following statement works as expected:</p>
<pre><code>os.system("curl --data-binary \@"+input_file_path+" -o "+ file_name +" localhost:30")
</code></pre>
<p>But when trying it with <code>subprocess.popen</code>:</p>
<pre><code>Popen(['curl','--data-binary','\@'+input_file_path, '-o', file_name,'localhost:30']... | 0 | 2010-01-14T00:33:56Z | 2,061,549 | <p>how about <a href="http://pycurl.sourceforge.net/" rel="nofollow">using a library</a> instead of calling system's curl? </p>
| 3 | 2010-01-14T01:08:49Z | [
"python",
"curl",
"popen"
] |
Assigning value in a while comparison expression | 2,061,519 | <p>Hi I was wondering if it was possible to assign a value in the while comparison section of the code.</p>
<p>Here is an example of the code currently</p>
<pre><code>startIndex = find(target, key, startIndex)
while( startIndex != -1):
matchesFound += 1
startIndex = find(target, key, startIndex + 1)
return ma... | 0 | 2010-01-14T00:59:14Z | 2,061,535 | <p>No, you can't do that in Python. I think the main reason Python disallows this, is to avoid the frequent errors resulting from confusing assignment and equality checking.</p>
<p>Python claims to have readable code as a main guideline, so I think your original code is fine. No need to refactor...</p>
| 0 | 2010-01-14T01:04:10Z | [
"python"
] |
Assigning value in a while comparison expression | 2,061,519 | <p>Hi I was wondering if it was possible to assign a value in the while comparison section of the code.</p>
<p>Here is an example of the code currently</p>
<pre><code>startIndex = find(target, key, startIndex)
while( startIndex != -1):
matchesFound += 1
startIndex = find(target, key, startIndex + 1)
return ma... | 0 | 2010-01-14T00:59:14Z | 2,061,536 | <p>You're writing C in Python.</p>
<p>Try:</p>
<pre><code>startIndex = -1
while True:
startIndex = find(target, key, startIndex + 1)
if startIndex < 0:
break
matchesFound += 1
return matchesFound
</code></pre>
<p>Or perhaps even:</p>
<pre><code>return target.count(key)
</code></pre>
| 1 | 2010-01-14T01:04:17Z | [
"python"
] |
Assigning value in a while comparison expression | 2,061,519 | <p>Hi I was wondering if it was possible to assign a value in the while comparison section of the code.</p>
<p>Here is an example of the code currently</p>
<pre><code>startIndex = find(target, key, startIndex)
while( startIndex != -1):
matchesFound += 1
startIndex = find(target, key, startIndex + 1)
return ma... | 0 | 2010-01-14T00:59:14Z | 2,061,538 | <p>i would do it like this</p>
<pre><code>startIndex=0
while 1:
startIndex = find(target, key, startIndex+1)
if startIndex == -1: break
matchesFound += 1
</code></pre>
<p>you can put in more conditions inside the while loop like that. </p>
<p>Edit: @OP, in future, to count match of string, just use co... | 0 | 2010-01-14T01:04:55Z | [
"python"
] |
Assigning value in a while comparison expression | 2,061,519 | <p>Hi I was wondering if it was possible to assign a value in the while comparison section of the code.</p>
<p>Here is an example of the code currently</p>
<pre><code>startIndex = find(target, key, startIndex)
while( startIndex != -1):
matchesFound += 1
startIndex = find(target, key, startIndex + 1)
return ma... | 0 | 2010-01-14T00:59:14Z | 2,061,553 | <p>Edit. </p>
<p>We refactor it like this.</p>
<pre><code>matches = [ k for k in range(len(target)-len(key)) if target[k:].startswith(key) ]
matchesFound = len(matches)
</code></pre>
<p>We don't need C-style condition and assignment conflation.</p>
<p>Rarely do you simply want the count; the actual locations are a... | 0 | 2010-01-14T01:10:08Z | [
"python"
] |
Assigning value in a while comparison expression | 2,061,519 | <p>Hi I was wondering if it was possible to assign a value in the while comparison section of the code.</p>
<p>Here is an example of the code currently</p>
<pre><code>startIndex = find(target, key, startIndex)
while( startIndex != -1):
matchesFound += 1
startIndex = find(target, key, startIndex + 1)
return ma... | 0 | 2010-01-14T00:59:14Z | 2,061,557 | <p>If for some reason you can't use a more appropriate method from whatever you're searching, this is equivalent to your working code from the question:</p>
<pre><code>start = 0
count = 0
for match in iter(lambda: find(target, key, start), -1):
count += 1
start = match + 1
return count
</code></pre>
<p>However, y... | 2 | 2010-01-14T01:11:04Z | [
"python"
] |
Using Beautiful Soup Python module to replace tags with plain text | 2,061,718 | <p>I am using <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> to extract 'content' from web pages. I know some people have asked this <a href="http://stackoverflow.com/questions/796490/python-method-to-extract-content-excluding-navigation-from-an-html-page">question</a> before ... | 1 | 2010-01-14T01:58:36Z | 2,061,861 | <p>An approach that works for your specific example is:</p>
<pre><code>from BeautifulSoup import BeautifulSoup
ht = '''
<div id="abc">
some long text goes <a href="/"> here </a> and hopefully it
will get picked up by the parser as content
</div>
'''
soup = BeautifulSoup(ht)
anchors =... | 3 | 2010-01-14T02:49:02Z | [
"python",
"html-content-extraction"
] |
Using Beautiful Soup Python module to replace tags with plain text | 2,061,718 | <p>I am using <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> to extract 'content' from web pages. I know some people have asked this <a href="http://stackoverflow.com/questions/796490/python-method-to-extract-content-excluding-navigation-from-an-html-page">question</a> before ... | 1 | 2010-01-14T01:58:36Z | 3,167,711 | <p>When I tried to <em>flatten</em> tags in the document, that way, the tags' entire content would be pulled up to its parent node in place (I wanted to reduce the content of a <strong>p</strong> tag with all sub-paragraphs, lists, <strong>div</strong> and <strong>span</strong>, etc. inside but get rid of the <strong>s... | 1 | 2010-07-02T17:05:58Z | [
"python",
"html-content-extraction"
] |
machine readable language for writing notes | 2,061,806 | <p>I'd like to write notes for class in plain text.
I was wondering if there was a markup language for doing this, where I could parse the notes for key terms, titles, page #s etc programmatically with a language such as Ruby or Python.</p>
| 2 | 2010-01-14T02:30:34Z | 2,061,829 | <p>LYX! I used lyx all last semester and it was great. It takes a little while to get used to (like a week). By the end of the first week I was formatting equations and matrices just as fast as my classmates could write them down. The only problem is diagrams, but if you have a sheet of paper handy or even a tablet... | 2 | 2010-01-14T02:39:28Z | [
"python",
"ruby",
"markup"
] |
machine readable language for writing notes | 2,061,806 | <p>I'd like to write notes for class in plain text.
I was wondering if there was a markup language for doing this, where I could parse the notes for key terms, titles, page #s etc programmatically with a language such as Ruby or Python.</p>
| 2 | 2010-01-14T02:30:34Z | 2,061,834 | <p>In the Python world, <a href="http://docutils.sourceforge.net/rst.html" rel="nofollow">reStructuredText</a> is probably the most widely used markup language, and it's the result of a long-term and fairly <a href="http://docutils.sourceforge.net/docs/ref/rst/introduction.html#goals" rel="nofollow">rigorous design</a>... | 4 | 2010-01-14T02:40:42Z | [
"python",
"ruby",
"markup"
] |
Session in python? | 2,062,298 | <p>Does Python have a session feature or not? </p>
<p>If it does, then how can I use this and which library should I use?</p>
| 1 | 2010-01-14T05:14:01Z | 2,062,311 | <p><a href="http://beaker.groovie.org/index.html" rel="nofollow">Beaker</a> is pretty popular for WSGI reliant Python web apps, but you have to understand that Python is an all-purpose programming language, it is not geared 100% toward the web like PHP.</p>
<p>It would also help if you listed more information about th... | 2 | 2010-01-14T05:18:01Z | [
"python",
"session"
] |
Session in python? | 2,062,298 | <p>Does Python have a session feature or not? </p>
<p>If it does, then how can I use this and which library should I use?</p>
| 1 | 2010-01-14T05:14:01Z | 2,062,315 | <p>Some Python web frameworks do offer the concept of "session". (The language Python itself, of course, has nothing to do with it!-).</p>
<p>For example, <a href="http://beaker.groovie.org/index.html" rel="nofollow">Beaker</a> is an excellent lightweight WSGI middleware that supports sessions; since WSGI is generall... | 3 | 2010-01-14T05:19:31Z | [
"python",
"session"
] |
Session in python? | 2,062,298 | <p>Does Python have a session feature or not? </p>
<p>If it does, then how can I use this and which library should I use?</p>
| 1 | 2010-01-14T05:14:01Z | 8,758,212 | <p>This might be an old question, but I faced the same problem that there is no built-in session support in Python. I wrote a simple session handler that might be useful for someone :</p>
<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-
import tempfile
import hashlib
import os
import time
import random
import err... | 5 | 2012-01-06T13:03:22Z | [
"python",
"session"
] |
Finding intersections | 2,062,325 | <p>Given a scenario where there are millions of potentially overlapping bounding boxes of variable sizes less the 5km in width.</p>
<p>Create a fast function with the arguments findIntersections(Longitude,Latitude,Radius) and the output is a list of those bounding boxes ids where each bounding box origin is inside the... | 2 | 2010-01-14T05:23:02Z | 2,062,341 | <p>This is normally done using an <a href="http://en.wikipedia.org/wiki/R-tree" rel="nofollow">R-tree</a> data structure</p>
<p>dbs like mysql or postgresql have GIS modules that use an r-tree under the hood to quickly retrieve locations within a certain proximity to a point on a map.</p>
<p>From <a href="http://en.w... | 4 | 2010-01-14T05:26:29Z | [
"python",
"performance",
"algorithm",
"optimization",
"localization"
] |
Finding intersections | 2,062,325 | <p>Given a scenario where there are millions of potentially overlapping bounding boxes of variable sizes less the 5km in width.</p>
<p>Create a fast function with the arguments findIntersections(Longitude,Latitude,Radius) and the output is a list of those bounding boxes ids where each bounding box origin is inside the... | 2 | 2010-01-14T05:23:02Z | 2,062,906 | <p><a href="http://postgis.refractions.net/" rel="nofollow">PostGIS</a> is an open-source GIS extention for postgresql.</p>
<p>They have <a href="http://postgis.refractions.net/documentation/manual-1.4/ST_Intersects.html" rel="nofollow">ST_Intersects</a> and <a href="http://postgis.refractions.net/documentation/manual... | 1 | 2010-01-14T08:15:32Z | [
"python",
"performance",
"algorithm",
"optimization",
"localization"
] |
Finding intersections | 2,062,325 | <p>Given a scenario where there are millions of potentially overlapping bounding boxes of variable sizes less the 5km in width.</p>
<p>Create a fast function with the arguments findIntersections(Longitude,Latitude,Radius) and the output is a list of those bounding boxes ids where each bounding box origin is inside the... | 2 | 2010-01-14T05:23:02Z | 2,080,290 | <p>This seems like a better more general approach GiST</p>
<p><a href="http://en.wikipedia.org/wiki/GiST" rel="nofollow">http://en.wikipedia.org/wiki/GiST</a></p>
| 0 | 2010-01-17T07:24:19Z | [
"python",
"performance",
"algorithm",
"optimization",
"localization"
] |
Filter array to show rows with a specific value in a specific column | 2,062,368 | <p>Let's say i have a multidimensional list l:</p>
<pre><code>l = [['a', 1],['b', 2],['c', 3],['a', 4]]
</code></pre>
<p>and I want to return another list consisting only of the rows that has 'a' in their first list element:</p>
<pre><code>m = [['a', 1],['a', 4]]
</code></pre>
<p>What's a good and efficient way of ... | 5 | 2010-01-14T05:32:43Z | 2,062,377 | <pre><code>m = [i for i in l if i[0] == 'a']
</code></pre>
| 1 | 2010-01-14T05:35:21Z | [
"python",
"list"
] |
Filter array to show rows with a specific value in a specific column | 2,062,368 | <p>Let's say i have a multidimensional list l:</p>
<pre><code>l = [['a', 1],['b', 2],['c', 3],['a', 4]]
</code></pre>
<p>and I want to return another list consisting only of the rows that has 'a' in their first list element:</p>
<pre><code>m = [['a', 1],['a', 4]]
</code></pre>
<p>What's a good and efficient way of ... | 5 | 2010-01-14T05:32:43Z | 2,062,379 | <p>With the <a href="http://docs.python.org/library/functions.html#filter" rel="nofollow">filter</a> function:</p>
<pre><code>m = filter(lambda x: x[0] == 'a', l)
</code></pre>
<p>or as a list comprehension:</p>
<pre><code>m = [x for x in l where x[0] == 'a']
</code></pre>
| 0 | 2010-01-14T05:35:31Z | [
"python",
"list"
] |
Filter array to show rows with a specific value in a specific column | 2,062,368 | <p>Let's say i have a multidimensional list l:</p>
<pre><code>l = [['a', 1],['b', 2],['c', 3],['a', 4]]
</code></pre>
<p>and I want to return another list consisting only of the rows that has 'a' in their first list element:</p>
<pre><code>m = [['a', 1],['a', 4]]
</code></pre>
<p>What's a good and efficient way of ... | 5 | 2010-01-14T05:32:43Z | 2,062,385 | <p>What's wrong with just:</p>
<pre><code>m = [i for i in l if i[0] == 'a']
</code></pre>
<p>Or:</p>
<pre><code>m = filter(lambda x: x[0] == 'a', l)
</code></pre>
<p>I doubt the difference between these will be significant performance-wise. Use whichever is most convenient. I don't like <code>lambda</code>s, but th... | 0 | 2010-01-14T05:36:42Z | [
"python",
"list"
] |
Filter array to show rows with a specific value in a specific column | 2,062,368 | <p>Let's say i have a multidimensional list l:</p>
<pre><code>l = [['a', 1],['b', 2],['c', 3],['a', 4]]
</code></pre>
<p>and I want to return another list consisting only of the rows that has 'a' in their first list element:</p>
<pre><code>m = [['a', 1],['a', 4]]
</code></pre>
<p>What's a good and efficient way of ... | 5 | 2010-01-14T05:32:43Z | 2,062,391 | <pre><code>[i for i in l if i[0]=='a']
</code></pre>
<p>btw, take a look at Python's <a href="http://www.python.org/dev/peps/pep-0202/" rel="nofollow">list comprehension with conditions</a>.</p>
| 0 | 2010-01-14T05:37:48Z | [
"python",
"list"
] |
Filter array to show rows with a specific value in a specific column | 2,062,368 | <p>Let's say i have a multidimensional list l:</p>
<pre><code>l = [['a', 1],['b', 2],['c', 3],['a', 4]]
</code></pre>
<p>and I want to return another list consisting only of the rows that has 'a' in their first list element:</p>
<pre><code>m = [['a', 1],['a', 4]]
</code></pre>
<p>What's a good and efficient way of ... | 5 | 2010-01-14T05:32:43Z | 2,062,399 | <p>Definitely a case for a list comprehension:</p>
<pre><code>m = [row for row in l if 'a' in row[0]]
</code></pre>
<p>Here I'm taking your "having 'a' <strong>in</strong> the first element" literally, whence the use of the <code>in</code> operator. If you want to restrict this to "having 'a' <strong>as</strong> the... | 10 | 2010-01-14T05:39:19Z | [
"python",
"list"
] |
Google App Engine won't recognize facebook package unless I rename it | 2,062,504 | <p>I'm trying to intergrate Facebook Connect into an GAE app. I've got a basic folder structure like so:</p>
<pre><code>/gae-root
/myapp
/templates
/etc
app.yaml
settings.py
</code></pre>
<p>and I tried to add the PyFacebook library like so:</p>
<pre><code>/gae-root
/myapp
/t... | 0 | 2010-01-14T06:13:31Z | 2,186,752 | <p>It was a problem with an extra .pth file in my site-packages directory.</p>
| 0 | 2010-02-02T18:57:31Z | [
"python",
"google-app-engine",
"facebook"
] |
How to use "class" the word as parameter function calls in python | 2,062,683 | <p>I am writing an XML generator per my manager's request. For less typings' sake, I decided using ElementTree as parser and SimpleXMLWriter as writer.</p>
<p>The result XML require attributes named "class". e.g. </p>
<pre><code><Node class="oops"></Node>
</code></pre>
<p>As the official tutorial suggest... | 3 | 2010-01-14T07:08:01Z | 2,062,691 | <p><code>class</code> is a reserved word in Python. You just can't use it for a variable name, any more than you can have a variable called <code>class</code> in C++.</p>
<p>The usual abbreviation for <code>class</code> is either <code>klass</code> or <code>cls</code>.</p>
<p>Here is an official list of reserved wor... | 3 | 2010-01-14T07:10:27Z | [
"python",
"elementtree"
] |
How to use "class" the word as parameter function calls in python | 2,062,683 | <p>I am writing an XML generator per my manager's request. For less typings' sake, I decided using ElementTree as parser and SimpleXMLWriter as writer.</p>
<p>The result XML require attributes named "class". e.g. </p>
<pre><code><Node class="oops"></Node>
</code></pre>
<p>As the official tutorial suggest... | 3 | 2010-01-14T07:08:01Z | 2,062,703 | <p>What steveha has written is true. As in any language, keywords can't be used for different purposes.</p>
<p>What you can do, if you must use "class" is this:</p>
<pre><code>w.element("Node", **{'class': 'oops'})
</code></pre>
| 5 | 2010-01-14T07:15:12Z | [
"python",
"elementtree"
] |
How to use "class" the word as parameter function calls in python | 2,062,683 | <p>I am writing an XML generator per my manager's request. For less typings' sake, I decided using ElementTree as parser and SimpleXMLWriter as writer.</p>
<p>The result XML require attributes named "class". e.g. </p>
<pre><code><Node class="oops"></Node>
</code></pre>
<p>As the official tutorial suggest... | 3 | 2010-01-14T07:08:01Z | 2,062,746 | <p>I guess SimpleXMLWriter developers meant this solution:</p>
<pre><code>w.element("Node", None, {'class': 'oops'})
</code></pre>
<p>or </p>
<pre><code>w.element("Node", attrib={'class': 'oops'})
</code></pre>
| 7 | 2010-01-14T07:29:09Z | [
"python",
"elementtree"
] |
how to drag image in a wxpython frame | 2,062,864 | <p>hello
what is the easiest way to drag an image ( or text) in a wx window ?<br>
i need steps or a small example on how to do that.<br>
thanx in advance</p>
| 2 | 2010-01-14T08:04:37Z | 2,090,634 | <p>Take a look at the PseudoDC example in the wxPython demo. The sample displays some random shapes within the window which you can grab and move around, you should be able to apply the concepts for an image. </p>
<p>You can download the <strong>win32-docs-demos</strong> from <a href="http://wxpython.org/download.php#... | 1 | 2010-01-19T02:17:01Z | [
"python",
"drag-and-drop",
"wxpython",
"drawing",
"device-context"
] |
how to drag image in a wxpython frame | 2,062,864 | <p>hello
what is the easiest way to drag an image ( or text) in a wx window ?<br>
i need steps or a small example on how to do that.<br>
thanx in advance</p>
| 2 | 2010-01-14T08:04:37Z | 2,090,648 | <p>Install <a href="http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-docs-demos-2.8.10.1.exe" rel="nofollow">wxpython demos</a>, there is DragImage demostration in it.</p>
| 0 | 2010-01-19T02:20:39Z | [
"python",
"drag-and-drop",
"wxpython",
"drawing",
"device-context"
] |
Why scipy.io.wavfile.read does not return a tuple? | 2,063,046 | <p>I am trying to read a *.wav file using scipy. I do the following:</p>
<pre><code>import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
</code></pre>
<p>As a result of this code I get:</p>
<pre><code>Traceback (most recent call last):
File "test3.py", line 2, in <module>
x = sc... | 4 | 2010-01-14T08:51:43Z | 2,063,102 | <p>As the error says, scipy module does not have 'io'.</p>
<p><code>io.wavfile</code> is a submodule, you need to <code>from scipy.io import wavfile</code> and then do <code>wavfile.read("/usr/share/sounds/purple/receive.wav")</code></p>
<p>This gives me an error with the file you are using as an example, however...<... | 6 | 2010-01-14T09:06:30Z | [
"python",
"wav",
"scipy"
] |
ImportError: cannot import name NumpyTest | 2,063,124 | <p>I am trying to read a *.wav file using scipy. I do it in the following way:</p>
<pre><code>import scipy.io
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
</code></pre>
<p>As a result I get the following error message:</p>
<pre><code>Traceback (most recent call last):
File "test3.py", line 1, ... | 0 | 2010-01-14T09:13:48Z | 2,063,138 | <p>Do you have numpy installed? The package is most likely called <code>numpy</code> or <code>python-numpy</code> if you are running Linux</p>
<p>If your OS package manager does not have numpy package, download it from <a href="http://sourceforge.net/projects/numpy/files/" rel="nofollow">here</a></p>
| 0 | 2010-01-14T09:18:02Z | [
"python",
"numpy",
"wav",
"scipy",
"importerror"
] |
ImportError: cannot import name NumpyTest | 2,063,124 | <p>I am trying to read a *.wav file using scipy. I do it in the following way:</p>
<pre><code>import scipy.io
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
</code></pre>
<p>As a result I get the following error message:</p>
<pre><code>Traceback (most recent call last):
File "test3.py", line 1, ... | 0 | 2010-01-14T09:13:48Z | 2,069,894 | <p>Looks like you have upgraded your numpy version but haven't installed a <a href="http://projects.scipy.org/scipy/ticket/916" rel="nofollow">corresponding scipy version</a>.</p>
| 1 | 2010-01-15T06:40:54Z | [
"python",
"numpy",
"wav",
"scipy",
"importerror"
] |
Comments (#) go to start of line in the insert mode in Vim | 2,063,175 | <p>Whenever I want to add a comment to an indented line in vim, I hit <kbd>Shift</kbd>-<kbd>o</kbd> (open a new row above the current, switch to insert mode) and start typing a Python comment (using <code>#</code>). That hash is then magically moved to the start of the line (no indentation) and I have to click tab a fe... | 44 | 2010-01-14T09:24:05Z | 2,064,035 | <p>You may want to try <a href="http://www.vim.org/scripts/script.php?script_id=1218" rel="nofollow">Nerd Commenter</a>, which is a plugin that allows you to add comments to lines in most languages automatically. You simply place the cursor at the line you are interested in and type <kbd>,</kbd><kbd>c</kbd><kbd>Space</... | 1 | 2010-01-14T12:36:06Z | [
"python",
"vim",
"comments",
"indentation"
] |
Comments (#) go to start of line in the insert mode in Vim | 2,063,175 | <p>Whenever I want to add a comment to an indented line in vim, I hit <kbd>Shift</kbd>-<kbd>o</kbd> (open a new row above the current, switch to insert mode) and start typing a Python comment (using <code>#</code>). That hash is then magically moved to the start of the line (no indentation) and I have to click tab a fe... | 44 | 2010-01-14T09:24:05Z | 2,064,155 | <p>try putting that in your .vimrc:</p>
<pre><code>autocmd BufRead *.py inoremap # X<c-h>#
</code></pre>
<p>This will make that the insertion of the hash (pound) sign is always indented in Python source files.</p>
| 7 | 2010-01-14T12:58:32Z | [
"python",
"vim",
"comments",
"indentation"
] |
Comments (#) go to start of line in the insert mode in Vim | 2,063,175 | <p>Whenever I want to add a comment to an indented line in vim, I hit <kbd>Shift</kbd>-<kbd>o</kbd> (open a new row above the current, switch to insert mode) and start typing a Python comment (using <code>#</code>). That hash is then magically moved to the start of the line (no indentation) and I have to click tab a fe... | 44 | 2010-01-14T09:24:05Z | 2,064,318 | <p>I suppose you have <code>set smartindent</code> in your .vimrc</p>
<p>See <code>:h smartindent</code></p>
<pre><code>When typing '#' as the first character in a new line, the indent for
that line is removed, the '#' is put in the first column. The indent
is restored for the next line. If you don't want this, use... | 43 | 2010-01-14T13:26:45Z | [
"python",
"vim",
"comments",
"indentation"
] |
Trying to open a serial port with pyserial on WinXP -> "Access denied" | 2,063,257 | <p>I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port ... | 3 | 2010-01-14T09:44:51Z | 2,063,271 | <p>Try opening the port as <code>\\.\COMxx</code></p>
<p>Also make sure that the port isn't already open from another application. I recommend that you use Hyperterminal to see if the port is open.</p>
| 9 | 2010-01-14T09:49:00Z | [
"python",
"serial-port",
"access-denied",
"windows-xp",
"pyserial"
] |
Trying to open a serial port with pyserial on WinXP -> "Access denied" | 2,063,257 | <p>I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port ... | 3 | 2010-01-14T09:44:51Z | 2,137,296 | <p>Calling .close() before opening the port solved a problem that was driving me nuts!</p>
<p>I had it working on another machine running vista 64-bit using com0com virtual ports, not a hitch.</p>
<p>I was trying to work on the exact same scripts on my Windows 7 box - nada - XP Mode same thing. Access Denied or coul... | 0 | 2010-01-26T03:10:58Z | [
"python",
"serial-port",
"access-denied",
"windows-xp",
"pyserial"
] |
Trying to open a serial port with pyserial on WinXP -> "Access denied" | 2,063,257 | <p>I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port ... | 3 | 2010-01-14T09:44:51Z | 2,256,136 | <p>.close() before I called the .open() worked for me as well</p>
| 7 | 2010-02-13T01:28:42Z | [
"python",
"serial-port",
"access-denied",
"windows-xp",
"pyserial"
] |
Trying to open a serial port with pyserial on WinXP -> "Access denied" | 2,063,257 | <p>I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port ... | 3 | 2010-01-14T09:44:51Z | 4,521,386 | <p>When you execute</p>
<pre><code>self.ser=serial.Serial(port='\\.\COM1', baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1)
</code></pre>
<p>the serial port is already open. On Windows, you get an error if you run .open() if the port is already open, but y... | 3 | 2010-12-23T18:23:20Z | [
"python",
"serial-port",
"access-denied",
"windows-xp",
"pyserial"
] |
Trying to open a serial port with pyserial on WinXP -> "Access denied" | 2,063,257 | <p>I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port ... | 3 | 2010-01-14T09:44:51Z | 5,812,599 | <p>No need to call .open if you already pass the serial port name/number in the
constructor!</p>
| 4 | 2011-04-28T01:28:26Z | [
"python",
"serial-port",
"access-denied",
"windows-xp",
"pyserial"
] |
Trying to open a serial port with pyserial on WinXP -> "Access denied" | 2,063,257 | <p>I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port ... | 3 | 2010-01-14T09:44:51Z | 6,109,754 | <p>I had a similar problem when i was trying to get accelerometer values from TI Chronos. In the device manager i just disabled the COM port and enabled it again. Worked</p>
| 0 | 2011-05-24T11:35:14Z | [
"python",
"serial-port",
"access-denied",
"windows-xp",
"pyserial"
] |
XML parsing with lxml and Python | 2,063,274 | <p>Please help me to resolve my problem with lxml<br>
(I'm a newbie to lxml).<br>
How can I get "Comment 1" from the next file: </p>
<pre><code><?xml version="1.0" encoding="windows-1251" standalone="yes" ?>
<!--Comment 1-->
<a>
<!--Comment 2-->
</a>
</code></pre>
| 6 | 2010-01-14T09:49:56Z | 2,063,600 | <pre><code>>>> from lxml import etree
>>> tree = etree.parse('filename.xml')
>>> root = tree.getroot()
>>> print root.getprevious()
<!--Comment 1-->
</code></pre>
<p>Or to be sure (there might be more than one):</p>
<pre><code>>>> for i in root.itersiblings(tag=etree... | 6 | 2010-01-14T10:59:54Z | [
"python",
"lxml"
] |
XML parsing with lxml and Python | 2,063,274 | <p>Please help me to resolve my problem with lxml<br>
(I'm a newbie to lxml).<br>
How can I get "Comment 1" from the next file: </p>
<pre><code><?xml version="1.0" encoding="windows-1251" standalone="yes" ?>
<!--Comment 1-->
<a>
<!--Comment 2-->
</a>
</code></pre>
| 6 | 2010-01-14T09:49:56Z | 2,063,673 | <p>Docs: <a href="http://lxml.de/tutorial.html" rel="nofollow">the lxml tutorial</a>, and search for "Comments"</p>
<p>Code:</p>
<pre><code>import lxml.etree as et
text = """\
<?xml version="1.0" encoding="windows-1251" standalone="yes" ?>
<!--Comment 1a-->
<!--Comment 1b-->
<a> waffle
<... | 12 | 2010-01-14T11:17:20Z | [
"python",
"lxml"
] |
What is the easiest way to read wav-files using Python [summary]? | 2,063,284 | <p>I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).</p>
<ol>
<li>I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).</li>
<li>I have installed the "audiolab" but I had a problem with the ver... | 7 | 2010-01-14T09:51:35Z | 2,459,760 | <p><a href="http://cournape.github.com/audiolab/" rel="nofollow">audiolab</a> is the best way, but it doesn't work in every environment and the developer's not working on it. I'm still using Python 2.5 so I can use it.</p>
<p>Did you install <a href="http://www.mega-nerd.com/libsndfile/#Download" rel="nofollow">libsn... | 1 | 2010-03-17T03:37:45Z | [
"python",
"audio",
"wav",
"scipy",
"wave"
] |
What is the easiest way to read wav-files using Python [summary]? | 2,063,284 | <p>I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).</p>
<ol>
<li>I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).</li>
<li>I have installed the "audiolab" but I had a problem with the ver... | 7 | 2010-01-14T09:51:35Z | 2,602,334 | <p>Have you tried the wave module? It has fewer dependencies:</p>
<p><a href="http://docs.python.org/library/wave.html">http://docs.python.org/library/wave.html</a></p>
<pre><code>def everyOther (v, offset=0):
return [v[i] for i in range(offset, len(v), 2)]
def wavLoad (fname):
wav = wave.open (fname, "r")
... | 8 | 2010-04-08T18:05:21Z | [
"python",
"audio",
"wav",
"scipy",
"wave"
] |
What is the easiest way to read wav-files using Python [summary]? | 2,063,284 | <p>I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).</p>
<ol>
<li>I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).</li>
<li>I have installed the "audiolab" but I had a problem with the ver... | 7 | 2010-01-14T09:51:35Z | 3,774,418 | <p>After trying so many things that does not work I used the decode library from <a href="http://stackoverflow.com/questions/3507746/use-python-gstreamer-to-decode-audio-to-pcm-data">http://stackoverflow.com/questions/3507746/use-python-gstreamer-to-decode-audio-to-pcm-data</a> and build a function to parse the raw pcm... | 2 | 2010-09-22T23:36:04Z | [
"python",
"audio",
"wav",
"scipy",
"wave"
] |
What is the easiest way to read wav-files using Python [summary]? | 2,063,284 | <p>I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).</p>
<ol>
<li>I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).</li>
<li>I have installed the "audiolab" but I had a problem with the ver... | 7 | 2010-01-14T09:51:35Z | 5,758,515 | <p>This is good enough for me</p>
<pre><code>import numpy as np
x = np.fromfile(open('song.wav'),np.int16)[24:]
</code></pre>
<p>It ignores the first 24 values, because that's not audio, it the header.</p>
<p>Also, if the file was stereo, your channels will have alternating indexes, So I usually just reduce it to mo... | 5 | 2011-04-22T18:10:19Z | [
"python",
"audio",
"wav",
"scipy",
"wave"
] |
What is the easiest way to read wav-files using Python [summary]? | 2,063,284 | <p>I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).</p>
<ol>
<li>I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).</li>
<li>I have installed the "audiolab" but I had a problem with the ver... | 7 | 2010-01-14T09:51:35Z | 13,734,066 | <p>I wrote a simple wrapper over the wave module in the std lib. it's called <a href="http://pydub.com" rel="nofollow">pydub</a> and it has a method for reading samples from the audio data as ints.</p>
<pre><code>>>> from pydub import AudioSegment
>>> song = AudioSegment.from_wav("your_song.wav")
<... | 3 | 2012-12-05T22:58:44Z | [
"python",
"audio",
"wav",
"scipy",
"wave"
] |
What is the easiest way to read wav-files using Python [summary]? | 2,063,284 | <p>I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).</p>
<ol>
<li>I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).</li>
<li>I have installed the "audiolab" but I had a problem with the ver... | 7 | 2010-01-14T09:51:35Z | 24,318,782 | <p>You can also use the wave module along with the numpy.fromstring() function to convert it to an array</p>
<pre><code>import wave
import numpy
fp = wave.open('test.wav')
nchan = fp.getnchannels()
N = fp.getnframes()
dstr = fp.readframes(N*nchan)
data = numpy.fromstring(dstr, numpy.int16)
data = numpy.reshape(data, ... | 1 | 2014-06-20T01:46:21Z | [
"python",
"audio",
"wav",
"scipy",
"wave"
] |
What is the easiest way to read wav-files using Python [summary]? | 2,063,284 | <p>I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).</p>
<ol>
<li>I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).</li>
<li>I have installed the "audiolab" but I had a problem with the ver... | 7 | 2010-01-14T09:51:35Z | 32,629,765 | <p><a href="https://github.com/cournape/audiolab" rel="nofollow">audiolab</a> seems to be not maintained anymore, you should try <a href="http://pysoundfile.readthedocs.org/" rel="nofollow">PySoundFile</a>.</p>
<p>Installation is simple:</p>
<pre><code>pip install PySoundFile --user
</code></pre>
<p>And reading a so... | 0 | 2015-09-17T11:56:21Z | [
"python",
"audio",
"wav",
"scipy",
"wave"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.