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 |
|---|---|---|---|---|---|---|---|---|---|
Unbuffered subprocess output (last line missing) | 2,432,556 | <p>I must be overlooking something terribly obvious. I need to execute a C program, display its output in real time and finally parse its last line, which should be straightforward as the last line printed is <em>always</em> the same.</p>
<pre><code>process = subprocess.Popen(args, shell = True,
... | 3 | 2010-03-12T12:10:14Z | 2,432,698 | <p>The problem is that you are reading lines till the process exits, (<code>process.poll()</code>) while you do use buffering because of the shell flag.</p>
<p>You would have to keep reading process.stdout till you reach the end of the file or the empty line.</p>
| 3 | 2010-03-12T12:36:23Z | [
"python",
"subprocess",
"popen"
] |
OpenCV performance in different languages | 2,432,792 | <p>I'm doing some prototyping with OpenCV for a hobby project involving processing of real time camera data. I wonder if it is worth the effort to reimplement this in C or C++ when I have it all figured out or if no significant performance boost can be expected. The program basically chains OpenCV functions, so the mai... | 1 | 2010-03-12T12:54:08Z | 2,433,626 | <p>You've answered your own question pretty well. Most of the expensive computations should be within the OpenCV library, and thus independent of the language you use. </p>
<p>If you're really concerned about efficiency, you could profile your code and confirm that this is indeed the case. If need be, your custom proc... | 5 | 2010-03-12T15:12:51Z | [
"c++",
"python",
"c",
"performance",
"opencv"
] |
OpenCV performance in different languages | 2,432,792 | <p>I'm doing some prototyping with OpenCV for a hobby project involving processing of real time camera data. I wonder if it is worth the effort to reimplement this in C or C++ when I have it all figured out or if no significant performance boost can be expected. The program basically chains OpenCV functions, so the mai... | 1 | 2010-03-12T12:54:08Z | 2,470,491 | <p>OpenCV used to utilize IPP, which is very fast. However, OpenCV 2.0 does not. You might customize your OpenCV using IPP, for example color conversion routines. </p>
| 0 | 2010-03-18T14:20:27Z | [
"c++",
"python",
"c",
"performance",
"opencv"
] |
python blocking sockets, send returns immediately | 2,432,814 | <p>I am writing a multithreaded socket application in Python using the socket module.
the server listens for connections and when it gets one it spawns a thread for that socket.</p>
<p>the server thread sends some data to the client. but the client is not yet ready to receive it. I thought this would have caused the s... | 2 | 2010-03-12T12:58:47Z | 2,433,403 | <blockquote>
<p>any ideas why send() is returning straight away?</p>
</blockquote>
<p>all send() does is fill the network buffer and return the ammount of bytes sent.</p>
<p>if you want a send that blocks just recv an acknowledgement message from the client. </p>
| 4 | 2010-03-12T14:36:08Z | [
"python",
"sockets",
"multithreading",
"blocking",
"send"
] |
python blocking sockets, send returns immediately | 2,432,814 | <p>I am writing a multithreaded socket application in Python using the socket module.
the server listens for connections and when it gets one it spawns a thread for that socket.</p>
<p>the server thread sends some data to the client. but the client is not yet ready to receive it. I thought this would have caused the s... | 2 | 2010-03-12T12:58:47Z | 2,436,116 | <p>The client doesn't have to be ready to receive data - data will queue up in the socket's receive buffer until you are ready to recv() it. Send returns instantly because the send buffer isn't full - if it was full, send() would block until there was room for the data you wanted to send.</p>
<p>Most of the time you'l... | 1 | 2010-03-12T21:47:00Z | [
"python",
"sockets",
"multithreading",
"blocking",
"send"
] |
python blocking sockets, send returns immediately | 2,432,814 | <p>I am writing a multithreaded socket application in Python using the socket module.
the server listens for connections and when it gets one it spawns a thread for that socket.</p>
<p>the server thread sends some data to the client. but the client is not yet ready to receive it. I thought this would have caused the s... | 2 | 2010-03-12T12:58:47Z | 2,761,553 | <p>Sorry about the delay i fixed the problem shortly after asking this question. @Lee thanks for your answer it pointed me in the right direction.
the solution was to send a 4byte int specifying the size of the data to follow. the client would always receive these four bytes and then the size of the data.</p>
<pre><co... | 1 | 2010-05-03T22:09:53Z | [
"python",
"sockets",
"multithreading",
"blocking",
"send"
] |
SQLAlchemy - full load instance before detach | 2,432,941 | <p><br>
is there a way how to fully load some SQLAlchemy ORM mapped instance (together with its related objects) before detaching it from the Session? I want to send it via pipe into another processs and I don't want to merge it into session in this new process.</p>
<p>Thank you<br>
Jan</p>
| 4 | 2010-03-12T13:18:48Z | 2,433,701 | <p>I believe you'll want to use the <a href="http://www.sqlalchemy.org/docs/05/reference/orm/query.html?highlight=eagerload#query-options" rel="nofollow"><code>options()</code> method on the Query, with <code>eagerload()</code> or <code>eagerload_all()</code></a>.</p>
<p>Here's an example of use from one of our apps, ... | 2 | 2010-03-12T15:22:28Z | [
"python",
"sqlalchemy"
] |
Many producer, single consumer with python/mod_wsgi | 2,432,956 | <p>I have a Pylons web application served by Apache (mod_wsgi, prefork). Because of Apache, there are multiple separate processes running my application code concurrently. Some of the non-critical tasks that the application does I want to defer for processing in background to improve "live" response times. So I'm think... | 1 | 2010-03-12T13:21:34Z | 2,433,423 | <p>A message broker like Apache's <a href="http://activemq.apache.org/" rel="nofollow">ActiveMQ</a> is an ideal solution here.</p>
<p>The pipeline could be following:</p>
<ul>
<li>Application process that is responsible for handling HTTP requests generates replies quickly and sends low-priority, heavy tasks to AMQ qu... | 1 | 2010-03-12T14:39:19Z | [
"python",
"apache",
"concurrency",
"synchronization",
"producer"
] |
Many producer, single consumer with python/mod_wsgi | 2,432,956 | <p>I have a Pylons web application served by Apache (mod_wsgi, prefork). Because of Apache, there are multiple separate processes running my application code concurrently. Some of the non-critical tasks that the application does I want to defer for processing in background to improve "live" response times. So I'm think... | 1 | 2010-03-12T13:21:34Z | 2,433,425 | <p>A web server (any web server) is multi-producer, single-consumer process.</p>
<p>A simple solution is to build a <a href="http://docs.python.org/library/wsgiref.html" rel="nofollow">wsgiref</a> or <a href="http://werkzeug.pocoo.org/" rel="nofollow">Werkzeug</a> backend server to handle your backend requests. </p>... | 0 | 2010-03-12T14:39:43Z | [
"python",
"apache",
"concurrency",
"synchronization",
"producer"
] |
What is a faster way of merging the values of this Python structure into a single dictionary? | 2,433,027 | <p>I've refactored how the merged-dictionary (<code>all_classes</code>) below is created, but I'm wondering if it can be more efficient.</p>
<p>I have a dictionary of dictionaries, like this:</p>
<pre><code>groups_and_classes = {'group_1': {'class_A': [1, 2, 3],
'class_B': [1, 3, 5, ... | 3 | 2010-03-12T13:34:37Z | 2,433,059 | <p>Here's a tweak for conciseness, though I'm not sure about performance:</p>
<pre><code>from collections import defaultdict
all_classes = defaultdict(set)
for group in groups_and_classes.values():
for c, vals in group.iteritems():
all_classes[c].update(set(vals))
</code></pre>
<p>Defaultdicts are not qui... | 4 | 2010-03-12T13:40:42Z | [
"python",
"data-structures",
"refactoring",
"performance"
] |
What is a faster way of merging the values of this Python structure into a single dictionary? | 2,433,027 | <p>I've refactored how the merged-dictionary (<code>all_classes</code>) below is created, but I'm wondering if it can be more efficient.</p>
<p>I have a dictionary of dictionaries, like this:</p>
<pre><code>groups_and_classes = {'group_1': {'class_A': [1, 2, 3],
'class_B': [1, 3, 5, ... | 3 | 2010-03-12T13:34:37Z | 2,433,112 | <p>One thing that might improve things slightly is to avoid the redundant conversion to a set, and just use:</p>
<pre><code>all_classes[c].update(vals)
</code></pre>
<p><code>update</code> can actually take an arbitrary iterable, as it essentially just iterates and adds, so you can avoid an extra conversion step.</p>... | 2 | 2010-03-12T13:51:02Z | [
"python",
"data-structures",
"refactoring",
"performance"
] |
What is a faster way of merging the values of this Python structure into a single dictionary? | 2,433,027 | <p>I've refactored how the merged-dictionary (<code>all_classes</code>) below is created, but I'm wondering if it can be more efficient.</p>
<p>I have a dictionary of dictionaries, like this:</p>
<pre><code>groups_and_classes = {'group_1': {'class_A': [1, 2, 3],
'class_B': [1, 3, 5, ... | 3 | 2010-03-12T13:34:37Z | 2,433,121 | <p><a href="http://stackoverflow.com/questions/1495510/combining-dictionaries-of-lists-in-python"><strong>Combining Dictionaries Of Lists In Python</strong></a>.</p>
<pre><code>def merge_dols(dol1, dol2):
result = dict(dol1, **dol2)
result.update((k, dol1[k] + dol2[k]) for k in set(dol1).intersection(dol2))
... | 2 | 2010-03-12T13:52:29Z | [
"python",
"data-structures",
"refactoring",
"performance"
] |
Can someone here explain constructors and destructors in python - simple explanation required - new to programming | 2,433,130 | <p>i will try to see if it makes sense :- </p>
<pre><code>class Person:
'''Represents a person '''
population = 0
def __init__(self,name):
//some statements and population += 1
def __del__(self):
//some statements and population -= 1
def sayHi(self):
'''grettings from ... | 2 | 2010-03-12T13:53:05Z | 2,433,475 | <p>As I understood them from my early CPTS experiance:</p>
<p>Constructors: Constructors are mainly used in classes to initialze the class with values, and gives an oppurtunity to do some background work based on creation. If you pass in values during the creation of an object, this is where you can handle assignment... | 1 | 2010-03-12T14:49:01Z | [
"python",
"class",
"destructor"
] |
Can someone here explain constructors and destructors in python - simple explanation required - new to programming | 2,433,130 | <p>i will try to see if it makes sense :- </p>
<pre><code>class Person:
'''Represents a person '''
population = 0
def __init__(self,name):
//some statements and population += 1
def __del__(self):
//some statements and population -= 1
def sayHi(self):
'''grettings from ... | 2 | 2010-03-12T13:53:05Z | 2,433,847 | <p>Here is a slightly opinionated answer.</p>
<p>Don't use <code>__del__</code>. This is not C++ or a language built for destructors. The <code>__del__</code> method really should be gone in Python 3.x, though I'm sure someone will find a use case that makes sense. If you need to use <code>__del __</code>, be aware ... | 9 | 2010-03-12T15:44:57Z | [
"python",
"class",
"destructor"
] |
Python optimization | 2,433,167 | <pre><code>f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
for l in range(33,127):
if n==1:
b = chr(l) + '\n'
f.write(b)
hh += 1
elif n==2:
for s0 in range(33, 127):
b = chr(l) + c... | 2 | 2010-03-12T13:58:54Z | 2,433,190 | <p>The outer loop seems pretty pointless. Why not simply:</p>
<pre><code>for l in range(33,127)
.. your code for the n==1 case
for l in range(33,127)
.. your code for the n==2 case
for l in range(33,127)
.. your code for the n==3 case
for l in range(33,127)
.. your code for the n==4 case
</code></pre>
... | 2 | 2010-03-12T14:02:46Z | [
"python",
"optimization"
] |
Python optimization | 2,433,167 | <pre><code>f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
for l in range(33,127):
if n==1:
b = chr(l) + '\n'
f.write(b)
hh += 1
elif n==2:
for s0 in range(33, 127):
b = chr(l) + c... | 2 | 2010-03-12T13:58:54Z | 2,433,225 | <p>You can create the <code>range(33, 127)</code> once and save it off. Not having to create it repeatedly cuts the runtime in half on my machine.</p>
<pre><code>chars = [chr(c) for c in range(33, 127)]
...
for s0 in chars:
for s1 in chars:
for s2 in chars:
b = l + s0 + s1 + s2 + '\n'
... | 6 | 2010-03-12T14:09:41Z | [
"python",
"optimization"
] |
Python optimization | 2,433,167 | <pre><code>f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
for l in range(33,127):
if n==1:
b = chr(l) + '\n'
f.write(b)
hh += 1
elif n==2:
for s0 in range(33, 127):
b = chr(l) + c... | 2 | 2010-03-12T13:58:54Z | 2,433,354 | <p>How about this it workes with arbitary word lengths: (Password generator?)</p>
<pre><code>f = open('wl4.txt', 'w')
hh=0
chars = map(chr,xrange(33, 127))
def func(n, result):
if (n == 0):
f.write(result + "\n")
hh +=1
else:
for c in chars:
func(n-1, result+c)
for n in ra... | 1 | 2010-03-12T14:29:10Z | [
"python",
"optimization"
] |
Python optimization | 2,433,167 | <pre><code>f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
for l in range(33,127):
if n==1:
b = chr(l) + '\n'
f.write(b)
hh += 1
elif n==2:
for s0 in range(33, 127):
b = chr(l) + c... | 2 | 2010-03-12T13:58:54Z | 2,434,799 | <p>Do you need all of the words sorted by their length? If you can mingle the lengths together, you can improve slightly on John Kugelman's answer like this:</p>
<pre><code>f = open("wl4.txt", "w")
chars = [chr(c) for c in range(33, 127)]
c = len(chars)
count = c + c*c + c**3 + c**4
for c0 in chars:
print >&g... | 0 | 2010-03-12T18:08:31Z | [
"python",
"optimization"
] |
Python optimization | 2,433,167 | <pre><code>f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
for l in range(33,127):
if n==1:
b = chr(l) + '\n'
f.write(b)
hh += 1
elif n==2:
for s0 in range(33, 127):
b = chr(l) + c... | 2 | 2010-03-12T13:58:54Z | 2,435,091 | <p>When doing operations that involve iterating a lot, a good place to start is the <a href="http://docs.python.org/library/itertools.html" rel="nofollow"><code>itertools</code></a> package.</p>
<p>In this case it looks like you want the <a href="http://docs.python.org/library/itertools.html#itertools.product" rel="no... | 2 | 2010-03-12T19:05:10Z | [
"python",
"optimization"
] |
Python optimization | 2,433,167 | <pre><code>f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
for l in range(33,127):
if n==1:
b = chr(l) + '\n'
f.write(b)
hh += 1
elif n==2:
for s0 in range(33, 127):
b = chr(l) + c... | 2 | 2010-03-12T13:58:54Z | 2,436,616 | <p><strong>Further significant improvements are possible.</strong></p>
<p>The following script file demonstrates these, using (for brevity) only the size 4 loop (which takes up well over 90% of the time).</p>
<p>method 0: the OP's original code</p>
<p>method 1: John Kugleman's solution</p>
<p>method 2: (1) and move... | 8 | 2010-03-12T23:54:23Z | [
"python",
"optimization"
] |
Python optimization | 2,433,167 | <pre><code>f = open('wl4.txt', 'w')
hh = 0
######################################
for n in range(1,5):
for l in range(33,127):
if n==1:
b = chr(l) + '\n'
f.write(b)
hh += 1
elif n==2:
for s0 in range(33, 127):
b = chr(l) + c... | 2 | 2010-03-12T13:58:54Z | 2,437,775 | <p>Here's a short recursive solution.</p>
<pre><code>def AllWords(n, CHARS=[chr(i) for i in xrange(33, 127)]):
if n == 1: return CHARS
return (w + c for w in AllWords(n - 1) for c in CHARS)
for i in xrange(1, 5):
for w in AllWords(i):
print w
</code></pre>
<p>PS: is it an error that character 127... | 0 | 2010-03-13T08:48:25Z | [
"python",
"optimization"
] |
Object for storing strings in Python | 2,433,194 | <pre><code>class MyWriter:
def __init__(self, stdout):
self.stdout = stdout
self.dumps = []
def write(self, text):
self.stdout.write(smart_unicode(text).encode('cp1251'))
self.dumps.append(text)
def close(self):
self.stdout.close()
writer = MyWriter(sys.stdout)... | 1 | 2010-03-12T14:03:31Z | 2,433,318 | <p>I am quite sure, that a single <code>'\n'.join(self.dumps)</code> will be much faster than <code>self.dumps += text</code>.</p>
<p><strong>Explanation:</strong> In Python, strings are immutable, so if you concat two strings, a new string is generated and the two other strings are copied into it. That's not a proble... | 1 | 2010-03-12T14:24:27Z | [
"python",
"string"
] |
Object for storing strings in Python | 2,433,194 | <pre><code>class MyWriter:
def __init__(self, stdout):
self.stdout = stdout
self.dumps = []
def write(self, text):
self.stdout.write(smart_unicode(text).encode('cp1251'))
self.dumps.append(text)
def close(self):
self.stdout.close()
writer = MyWriter(sys.stdout)... | 1 | 2010-03-12T14:03:31Z | 2,433,985 | <p>A list of strings to be joined with <code>''.join</code> is just fine. However, if you prefer a more direct solution:</p>
<pre><code>import cStringIO
class MyWriter(object):
def __init__(self, stdout):
self.stdout = stdout
self.dumps = cStringIO.StringIO()
self.final = None
def w... | 2 | 2010-03-12T16:07:55Z | [
"python",
"string"
] |
how to read url data | 2,433,216 | <pre><code>from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db
from google.appengine.api import urlfetch
class TrakHtml(db.Model):
hawb = db.StringProperty(required=False)
htmlData = db.TextProperty()
class MainHandler(webapp.RequestHandler):
... | 0 | 2010-03-12T14:07:58Z | 2,433,243 | <p>You have read the result twice (once in <code>self.responce.out.write</code> and once a line below).
Store the value as a string first:</p>
<pre><code>htmlData = result.read()
self.response.out.write(htmlData)
trak.htmlData = htmlData
</code></pre>
<p>I would expect <code>result.read()</code> to move to the end of... | 3 | 2010-03-12T14:12:04Z | [
"python"
] |
EOL character in Linux and Windows | 2,433,293 | <p>I'm writing a simple script, that just connects to telnet port, listens everything on it, staying connected and when some string, for example '123' appears, script do something.
I use tn.read_until("123", 2), but when '123' appears, script just disconnects. How to make it stay online?</p>
| 0 | 2010-03-12T14:21:11Z | 2,433,355 | <p>Put tn.read_until("123", 2) in a loop.</p>
| 1 | 2010-03-12T14:29:13Z | [
"python",
"telnet"
] |
EOL character in Linux and Windows | 2,433,293 | <p>I'm writing a simple script, that just connects to telnet port, listens everything on it, staying connected and when some string, for example '123' appears, script do something.
I use tn.read_until("123", 2), but when '123' appears, script just disconnects. How to make it stay online?</p>
| 0 | 2010-03-12T14:21:11Z | 2,433,944 | <p>You can try this:</p>
<pre><code>import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 21))
s.listen(1)
conn = s.accept()
run = True
while run==True:
data = conn.recv(1000)
if data == '123':
#do something
else:
#do something
conn.close()
</code></pre>
<p>is th... | 0 | 2010-03-12T16:00:23Z | [
"python",
"telnet"
] |
vectorize is indeterminate | 2,433,587 | <p>I'm trying to vectorize a simple function in numpy and getting inconsistent behavior. I expect my code to return 0 for values < 0.5 and the unchanged value otherwise. Strangely, different runs of the script from the command line yield varying results: sometimes it works correctly, and sometimes I get all 0's. ... | 1 | 2010-03-12T15:07:47Z | 2,433,615 | <p>If this really is the problem you want to solve, then there's a much better solution:</p>
<pre><code>A[A<=0.5] = 0.0
</code></pre>
<p>The problem with your code, however, is that if the condition passes, you are returning the <em>integer</em> 0, not the <em>float</em> 0.0. From the documentation:</p>
<blockquo... | 7 | 2010-03-12T15:11:49Z | [
"python",
"numpy"
] |
Python twisted Reactor class | 2,433,616 | <p>What is the significance of the decorators</p>
<pre><code> @reactor.callWhenRunning,
@results_deferred.addCallback
@results_deferred.addErrback.
</code></pre>
<p>Also what are deferred strings, for example in the </p>
<pre><code> twisted.internet.utils.getProcessOutput()
</code></pre>
<p>returns a deferred str... | 3 | 2010-03-12T15:11:51Z | 2,433,692 | <p>A deferred is a like a promise to return output in the future. You really should read the documentation on Deferreds <a href="http://twistedmatrix.com/documents/current/core/howto/deferredindepth.html" rel="nofollow">here</a> and <a href="http://twistedmatrix.com/documents/current/core/howto/defer.html" rel="nofollo... | 3 | 2010-03-12T15:20:58Z | [
"python",
"twisted"
] |
Python twisted Reactor class | 2,433,616 | <p>What is the significance of the decorators</p>
<pre><code> @reactor.callWhenRunning,
@results_deferred.addCallback
@results_deferred.addErrback.
</code></pre>
<p>Also what are deferred strings, for example in the </p>
<pre><code> twisted.internet.utils.getProcessOutput()
</code></pre>
<p>returns a deferred str... | 3 | 2010-03-12T15:11:51Z | 2,435,948 | <p>I am not sure about python , but this looks a like Active object pattern, and Futures. Futures is going to be standard in next c++ version. If you read through Active object and Futures you will get an idea</p>
| 1 | 2010-03-12T21:14:50Z | [
"python",
"twisted"
] |
Python twisted Reactor class | 2,433,616 | <p>What is the significance of the decorators</p>
<pre><code> @reactor.callWhenRunning,
@results_deferred.addCallback
@results_deferred.addErrback.
</code></pre>
<p>Also what are deferred strings, for example in the </p>
<pre><code> twisted.internet.utils.getProcessOutput()
</code></pre>
<p>returns a deferred str... | 3 | 2010-03-12T15:11:51Z | 2,438,466 | <p>In the normal programming practice you'd do</p>
<pre><code>db = Database.connect()
result = db.getResult()
processResult(result)
</code></pre>
<p>Now depending on your Database and network, these 3 statements can take anywhere from a millisecond to a few seconds.</p>
<p>We've all been programming this way for dec... | 4 | 2010-03-13T13:16:51Z | [
"python",
"twisted"
] |
Match multiline regex in file object | 2,433,648 | <p>How can I extract the groups from this regex from a file object (data.txt)?</p>
<pre><code>import numpy as np
import re
import os
ifile = open("data.txt",'r')
# Regex pattern
pattern = re.compile(r"""
^Time:(\d{2}:\d{2}:\d{2}) # Time: 12:34:56 at beginning of line
\r{2} ... | 10 | 2010-03-12T15:14:59Z | 2,433,678 | <p>You can read the data from the file object into a string with <code>ifile.read()</code></p>
| 5 | 2010-03-12T15:18:46Z | [
"python",
"regex",
"multiline"
] |
Match multiline regex in file object | 2,433,648 | <p>How can I extract the groups from this regex from a file object (data.txt)?</p>
<pre><code>import numpy as np
import re
import os
ifile = open("data.txt",'r')
# Regex pattern
pattern = re.compile(r"""
^Time:(\d{2}:\d{2}:\d{2}) # Time: 12:34:56 at beginning of line
\r{2} ... | 10 | 2010-03-12T15:14:59Z | 2,433,689 | <p>Why don't you read the whole file into a buffer using</p>
<pre><code>buffer = open("data.txt").read()
</code></pre>
<p>and then do a search with that?</p>
| 1 | 2010-03-12T15:20:07Z | [
"python",
"regex",
"multiline"
] |
Match multiline regex in file object | 2,433,648 | <p>How can I extract the groups from this regex from a file object (data.txt)?</p>
<pre><code>import numpy as np
import re
import os
ifile = open("data.txt",'r')
# Regex pattern
pattern = re.compile(r"""
^Time:(\d{2}:\d{2}:\d{2}) # Time: 12:34:56 at beginning of line
\r{2} ... | 10 | 2010-03-12T15:14:59Z | 2,433,875 | <pre><code>times = [match.group(1) for match in pattern.finditer(ifile.read())]
</code></pre>
<p><a href="http://docs.python.org/library/re.html#re.finditer" rel="nofollow"><code>finditer</code> yield <code>MatchObjects</code></a>. If the regex doesn't match anything <code>times</code> will be an empty list.</p>
<p>Y... | 1 | 2010-03-12T15:49:51Z | [
"python",
"regex",
"multiline"
] |
Python ImportError when executing 'import.py', but not when executing 'python import.py' | 2,433,703 | <p>I am running Cygwin Python version 2.5.2.</p>
<p>I have a three-line source file, called import.py:</p>
<pre><code>#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
</code></pre>
<p>When I execute "python import.py", it works:</p>
<pre><code>C:\Temp>python import.py
Success!
</code></pre>
... | 0 | 2010-03-12T15:23:01Z | 2,433,740 | <p>Try:</p>
<pre><code>./import.py
</code></pre>
<p>Most people don't have "." in their path.</p>
<p>just typing python will call the cygwin python.</p>
<p>import.py will likely call whichever python is associated with .py files under windows. </p>
<p>You are using two different python executables.</p>
| 0 | 2010-03-12T15:30:01Z | [
"python",
"import"
] |
Python ImportError when executing 'import.py', but not when executing 'python import.py' | 2,433,703 | <p>I am running Cygwin Python version 2.5.2.</p>
<p>I have a three-line source file, called import.py:</p>
<pre><code>#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
</code></pre>
<p>When I execute "python import.py", it works:</p>
<pre><code>C:\Temp>python import.py
Success!
</code></pre>
... | 0 | 2010-03-12T15:23:01Z | 2,433,747 | <p>Probably py extension is connected to some other python interpreter than the one in /usr/bin/python</p>
| 1 | 2010-03-12T15:31:25Z | [
"python",
"import"
] |
Python ImportError when executing 'import.py', but not when executing 'python import.py' | 2,433,703 | <p>I am running Cygwin Python version 2.5.2.</p>
<p>I have a three-line source file, called import.py:</p>
<pre><code>#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
</code></pre>
<p>When I execute "python import.py", it works:</p>
<pre><code>C:\Temp>python import.py
Success!
</code></pre>
... | 0 | 2010-03-12T15:23:01Z | 2,433,755 | <p>Create a batch file next to your program that calls it the right way ... and I'm fairly sure you've got the problem because of an ambiguity between "windows python" (a python interpreter compiled for windows) and "cygwin python" (a python interpreter running on cygwin).</p>
| 0 | 2010-03-12T15:32:50Z | [
"python",
"import"
] |
Python ImportError when executing 'import.py', but not when executing 'python import.py' | 2,433,703 | <p>I am running Cygwin Python version 2.5.2.</p>
<p>I have a three-line source file, called import.py:</p>
<pre><code>#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
</code></pre>
<p>When I execute "python import.py", it works:</p>
<pre><code>C:\Temp>python import.py
Success!
</code></pre>
... | 0 | 2010-03-12T15:23:01Z | 2,433,758 | <p>I have the feeling that </p>
<pre><code>C:\Temp>import.py
</code></pre>
<p>uses a different interpreter. Can you try with the following scripts:</p>
<pre><code>#!/usr/bin/env python
import sys
print sys.executable
import xml.etree.ElementTree as ET
print "Success!"
</code></pre>
| 3 | 2010-03-12T15:33:02Z | [
"python",
"import"
] |
Odd nested dictionary behavior in python | 2,433,805 | <p>Im new two python and am trying to grow a dictionary of dictionaries. I have done this in php and perl but python is behaving very differently. Im sure it makes sense to those more familiar with python. Here is my code:</p>
<pre><code>colnames = ['name','dob','id'];
tablehashcopy = {};
tablehashcopy = dict.fromkeys... | 0 | 2010-03-12T15:39:18Z | 2,433,826 | <p>The issue is with your fromkeys call. You passed it an empty dictionary, and it used that exact same empty dictionary as the value for all of the keys. Since the exact same dictionary is being used as the value, adding an element to it means you'll see that same element for all the keys' dictionaries.</p>
| 3 | 2010-03-12T15:42:03Z | [
"python",
"dictionary",
"nested"
] |
Odd nested dictionary behavior in python | 2,433,805 | <p>Im new two python and am trying to grow a dictionary of dictionaries. I have done this in php and perl but python is behaving very differently. Im sure it makes sense to those more familiar with python. Here is my code:</p>
<pre><code>colnames = ['name','dob','id'];
tablehashcopy = {};
tablehashcopy = dict.fromkeys... | 0 | 2010-03-12T15:39:18Z | 2,433,859 | <p>dict.fromkeys(seq, [value]) - value defaults to None if nothing is passed, but since you passed a dict instead, that's what it's using for each key-value pair.</p>
| 1 | 2010-03-12T15:46:51Z | [
"python",
"dictionary",
"nested"
] |
Odd nested dictionary behavior in python | 2,433,805 | <p>Im new two python and am trying to grow a dictionary of dictionaries. I have done this in php and perl but python is behaving very differently. Im sure it makes sense to those more familiar with python. Here is my code:</p>
<pre><code>colnames = ['name','dob','id'];
tablehashcopy = {};
tablehashcopy = dict.fromkeys... | 0 | 2010-03-12T15:39:18Z | 2,433,881 | <p>As msalib says, your problem is that dict.fromkeys makes all the entries in the dictionary point to the same object. Try this instead to create a separate empty dictionary for each key:</p>
<pre><code>tablehashcopy=dict((key,{}) for key in colnames)
</code></pre>
| 2 | 2010-03-12T15:50:57Z | [
"python",
"dictionary",
"nested"
] |
Odd nested dictionary behavior in python | 2,433,805 | <p>Im new two python and am trying to grow a dictionary of dictionaries. I have done this in php and perl but python is behaving very differently. Im sure it makes sense to those more familiar with python. Here is my code:</p>
<pre><code>colnames = ['name','dob','id'];
tablehashcopy = {};
tablehashcopy = dict.fromkeys... | 0 | 2010-03-12T15:39:18Z | 2,433,891 | <p>In your source, only one inner dictionary object is created and used 3 times. So when you modificate it, you will see the change 3 times too, because everything is bound to the same variable.</p>
<p>You can do something like the following to solve the problem. This will create several <code>(key, {})</code> tuples ... | 1 | 2010-03-12T15:53:02Z | [
"python",
"dictionary",
"nested"
] |
What is the difference between trapping and handling an exception? | 2,433,816 | <p>I'm looking into exception handling in python and a blog post I read differentiated between trapping and handling an exception. Can someone explain the core difference between these two, both in python specifically and the overall conceptual difference? A google search for 'exception trapping handling' isn't super-u... | 0 | 2010-03-12T15:41:06Z | 2,433,856 | <p>I would say that "trapping" and "catching" an exception are the same thing: you have to trap/catch it to be able to handle it, but the act of trapping it is not the same as handling it. </p>
<p><code>Trapping-but-not-handling = supressing</code>, in other words. Handling implies that you actually do something with ... | 2 | 2010-03-12T15:46:37Z | [
"python",
"exception-handling"
] |
What is the difference between trapping and handling an exception? | 2,433,816 | <p>I'm looking into exception handling in python and a blog post I read differentiated between trapping and handling an exception. Can someone explain the core difference between these two, both in python specifically and the overall conceptual difference? A google search for 'exception trapping handling' isn't super-u... | 0 | 2010-03-12T15:41:06Z | 2,433,888 | <p>In terms of a conceptual difference, I'd define <strong>Trapping</strong> as adding code to limit the impact of an error extending to other parts of the code or being displayed by the OS to the user.</p>
<p><strong>Handling</strong> an error would be doing something appropriate in response to the error.</p>
<p>Fro... | 0 | 2010-03-12T15:52:34Z | [
"python",
"exception-handling"
] |
Removing duplicates (within a given tolerance) from a Numpy array of vectors | 2,433,882 | <p>I have an Nx5 array containing N vectors of form 'id', 'x', 'y', 'z' and 'energy'. I need to remove duplicate points (i.e. where x, y, z all match) within a tolerance of say 0.1. Ideally I could create a function where I pass in the array, columns that need to match and a tolerance on the match.</p>
<p>Following <a... | 4 | 2010-03-12T15:51:09Z | 2,434,136 | <p>You might look at <a href="http://docs.scipy.org/doc/scipy/reference/spatial.html" rel="nofollow">scipy.spatial.KDTree</a>.
How big is N ?<br>
Added: oops, <code>tree.query_pairs</code> is not in scipy 0.7.1 .</p>
<p>When in doubt, use brute force: split the space (here side^3) into little cells,
one point per cell... | 2 | 2010-03-12T16:29:40Z | [
"python",
"sorting",
"numpy"
] |
Removing duplicates (within a given tolerance) from a Numpy array of vectors | 2,433,882 | <p>I have an Nx5 array containing N vectors of form 'id', 'x', 'y', 'z' and 'energy'. I need to remove duplicate points (i.e. where x, y, z all match) within a tolerance of say 0.1. Ideally I could create a function where I pass in the array, columns that need to match and a tolerance on the match.</p>
<p>Following <a... | 4 | 2010-03-12T15:51:09Z | 2,444,546 | <p>Have not tested this but if you sort your array along x then y then z this should get you the list of duplicates. You then need to choose which to keep.</p>
<pre><code>def find_dup_xyz(anarray, x, y, z): #for example in an data = array([id,x,y,z,energy]) x=1 y=2 z=3
dup_xyz=[]
for i, row in enumerated(sorte... | 0 | 2010-03-15T01:14:45Z | [
"python",
"sorting",
"numpy"
] |
Removing duplicates (within a given tolerance) from a Numpy array of vectors | 2,433,882 | <p>I have an Nx5 array containing N vectors of form 'id', 'x', 'y', 'z' and 'energy'. I need to remove duplicate points (i.e. where x, y, z all match) within a tolerance of say 0.1. Ideally I could create a function where I pass in the array, columns that need to match and a tolerance on the match.</p>
<p>Following <a... | 4 | 2010-03-12T15:51:09Z | 2,603,205 | <p>I have finally got a solution that I am happy with, this is a slightly cleaned up cut and paste from my own code. There may yet be some bugs.</p>
<p>Note: that it still uses a 'for' loop. I could use Denis's idea of KDTree above coupled with the rounding to get the full solution.</p>
<pre><code>import numpy as np
... | 0 | 2010-04-08T20:26:57Z | [
"python",
"sorting",
"numpy"
] |
Python to MATLAB: exporting list of strings using scipy.io | 2,433,924 | <p>I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical matrices (which I learned to do <a href="http://stackoverflow.com/questions/1095265/matrix-from-python-to-matlab">here</a>) and text cell arrays.<... | 11 | 2010-03-12T15:57:26Z | 2,434,186 | <p>It looks like the contents of the list are exported properly, they are just transposed and placed in a character array. You can easily convert it to the desired cell array of strings in MATLAB by transposing it and using <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/cellstr.html" rel="nofollow">... | 1 | 2010-03-12T16:35:55Z | [
"python",
"string",
"matlab",
"scipy",
"mat-file"
] |
Python to MATLAB: exporting list of strings using scipy.io | 2,433,924 | <p>I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical matrices (which I learned to do <a href="http://stackoverflow.com/questions/1095265/matrix-from-python-to-matlab">here</a>) and text cell arrays.<... | 11 | 2010-03-12T15:57:26Z | 2,434,258 | <p>You need to make my_list an array of numpy objects:</p>
<pre><code>import scipy.io
import numpy as np
my_list = np.zeros((3,), dtype=np.object)
my_list[:] = ['abc', 'def', 'ghi']
scipy.io.savemat('test.mat', mdict={'my_list': my_list})
</code></pre>
<p>Then it will be saved in a cell format. There might be a bette... | 10 | 2010-03-12T16:45:43Z | [
"python",
"string",
"matlab",
"scipy",
"mat-file"
] |
error in fetching url data | 2,434,119 | <pre><code>from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db
from google.appengine.api import urlfetch
class TrakHtml(db.Model):
hawb = db.StringProperty(required=False)
htmlData = db.TextProperty()
class MainHandler(webapp.RequestHandler):
... | 0 | 2010-03-12T16:26:58Z | 2,434,168 | <p>you call <code>result.read()</code> twice. That's probably why it's fragmented.</p>
| 1 | 2010-03-12T16:33:10Z | [
"python",
"google-app-engine"
] |
error in fetching url data | 2,434,119 | <pre><code>from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db
from google.appengine.api import urlfetch
class TrakHtml(db.Model):
hawb = db.StringProperty(required=False)
htmlData = db.TextProperty()
class MainHandler(webapp.RequestHandler):
... | 0 | 2010-03-12T16:26:58Z | 2,434,180 | <p>This link has info on the return value of <code>urlfetch.fetch(url)</code></p>
<p><a href="http://code.google.com/appengine/docs/python/urlfetch/responseobjects.html" rel="nofollow">http://code.google.com/appengine/docs/python/urlfetch/responseobjects.html</a></p>
<p>It looks like you want to do <code>result.conte... | 0 | 2010-03-12T16:35:23Z | [
"python",
"google-app-engine"
] |
error in fetching url data | 2,434,119 | <pre><code>from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db
from google.appengine.api import urlfetch
class TrakHtml(db.Model):
hawb = db.StringProperty(required=False)
htmlData = db.TextProperty()
class MainHandler(webapp.RequestHandler):
... | 0 | 2010-03-12T16:26:58Z | 2,434,184 | <p>I note that you are calling read() twice, which may be the problem.</p>
<p>When I look at the specs for urlfetch.fetch(), it returns a <a href="http://code.google.com/appengine/docs/python/urlfetch/responseobjects.html" rel="nofollow">response object</a>.</p>
<p>The contents are directly accessible as result.conte... | 0 | 2010-03-12T16:35:49Z | [
"python",
"google-app-engine"
] |
How can I set controls for a web page? | 2,434,126 | <p>I have this login page with https, and i reach to this approach::</p>
<pre><code>import ClientForm
import urllib2
request = urllib2.Request("http://ritaj.birzeit.edu")
response = urllib2.urlopen(request)
forms = ClientForms.ParseResponseEx(response)
response.close()
f = forms[0]
username = str(raw_input("Username... | 0 | 2010-03-12T16:27:54Z | 2,434,254 | <p>You set <code>f['username'] = username</code> and <code>f['password'] = password</code>, and when you <code>f.click()</code> you'll get a response that you'll need to examine in order to determine whether those strings were the ones the site you're visiting expected -- how the site communicates that depends on the s... | 1 | 2010-03-12T16:45:31Z | [
"python",
"browser"
] |
Finding unique maximum values in a list using python | 2,434,251 | <p>I have a list of points as shown below</p>
<pre><code>points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]
</code></pre>
<p>Some of the points have duplicate x,y values. What I want to do is to extract the unique maximum value x,y points </p>
<p>For example, if I have points <code>[1,2,5] [1,1,3] ... | 1 | 2010-03-12T16:45:25Z | 2,434,278 | <p>For example:</p>
<pre><code>import itertools
def getxy(point): return point[:2]
sortedpoints = sorted(points, key=getxy)
results = []
for xy, g in itertools.groupby(sortedpoints, key=getxy):
results.append(max(g, key=operator.itemgetter(2)))
</code></pre>
<p>that is: sort and group the points by xy, for ever... | 8 | 2010-03-12T16:48:28Z | [
"python",
"set",
"unique"
] |
Finding unique maximum values in a list using python | 2,434,251 | <p>I have a list of points as shown below</p>
<pre><code>points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]
</code></pre>
<p>Some of the points have duplicate x,y values. What I want to do is to extract the unique maximum value x,y points </p>
<p>For example, if I have points <code>[1,2,5] [1,1,3] ... | 1 | 2010-03-12T16:45:25Z | 2,434,439 | <p>You can use <code>dict</code> achieve this, using the <a href="http://file:///Large%20Files/Programming/python-2.6.1-docs-html/library/stdtypes.html#mapping-types-dict" rel="nofollow">property</a> that "If a given key is seen more than once, the last value associated with it is retained in the new dictionary." This ... | 0 | 2010-03-12T17:10:13Z | [
"python",
"set",
"unique"
] |
Finding unique maximum values in a list using python | 2,434,251 | <p>I have a list of points as shown below</p>
<pre><code>points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]
</code></pre>
<p>Some of the points have duplicate x,y values. What I want to do is to extract the unique maximum value x,y points </p>
<p>For example, if I have points <code>[1,2,5] [1,1,3] ... | 1 | 2010-03-12T16:45:25Z | 2,434,732 | <p>If I understand your question .. maybe use a dictionary to map <code>(x,y)</code> to the max z</p>
<p>something like this (not tested)</p>
<pre><code>dict = {}
for x,y,z in list
if dict.has_key((x,y)):
dict[(x,y)] = max(dict[(x,y)], z)
else:
dict[(x,y)] = z
</code></pre>
<p>Though the orde... | 0 | 2010-03-12T17:54:54Z | [
"python",
"set",
"unique"
] |
What is the best, python or bash for selectively concatenating lots of files? | 2,434,689 | <p>I have around 20000 files coming from the output of some program, and their names follow the format:</p>
<pre><code>data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt
</code></pre>
<p>I would like to write a script that gets as input argument the number N. Then it makes b... | 3 | 2010-03-12T17:47:59Z | 2,434,752 | <p>Since this can easily be done in any shell I would simply use that.</p>
<p>This should do it:</p>
<pre><code>#!/bin/sh
FILES=$1
FILENO=1
for i in data[0-9]*.txt; do
FILES=`expr $FILES - 1`
if [ $FILES -eq 0 ]; then
FILENO=`expr $FILENO + 1`
FILES=$1
fi
cat $i >> "data_new_${... | 0 | 2010-03-12T17:58:17Z | [
"python",
"bash"
] |
What is the best, python or bash for selectively concatenating lots of files? | 2,434,689 | <p>I have around 20000 files coming from the output of some program, and their names follow the format:</p>
<pre><code>data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt
</code></pre>
<p>I would like to write a script that gets as input argument the number N. Then it makes b... | 3 | 2010-03-12T17:47:59Z | 2,434,783 | <p>Best in what sense? Bash can do this quite well, but it may be harder for you to write a good bash script if you are more familiar with another scripting language. Do you want to optimize for something specific?</p>
<p>That said, here's a bash implementation:</p>
<pre><code> declare blocksize=5
declare i=1
decla... | 1 | 2010-03-12T18:04:33Z | [
"python",
"bash"
] |
What is the best, python or bash for selectively concatenating lots of files? | 2,434,689 | <p>I have around 20000 files coming from the output of some program, and their names follow the format:</p>
<pre><code>data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt
</code></pre>
<p>I would like to write a script that gets as input argument the number N. Then it makes b... | 3 | 2010-03-12T17:47:59Z | 2,434,855 | <p>Here's a Python (2.6) version (if you have Python 2.5, add a first line that says</p>
<pre><code>from __future__ import with_statement
</code></pre>
<p>and the script will also work)...:</p>
<pre><code>import sys
def main(N):
rN = range(N)
for iout, iin in enumerate(xrange(1, 99999, N)):
with open('... | 4 | 2010-03-12T18:20:52Z | [
"python",
"bash"
] |
What is the best, python or bash for selectively concatenating lots of files? | 2,434,689 | <p>I have around 20000 files coming from the output of some program, and their names follow the format:</p>
<pre><code>data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt
</code></pre>
<p>I would like to write a script that gets as input argument the number N. Then it makes b... | 3 | 2010-03-12T17:47:59Z | 2,434,899 | <p>Let's say, if you have a simple script that concatenates files and keeps a counter for you, like the following:</p>
<pre><code>#!/usr/bin/bash
COUNT=0
if [ -f counter ]; then
COUNT=`cat counter`
fi
COUNT=$[$COUNT+1]
echo $COUNT > counter
cat $@ > $COUNT.data
</code></pre>
<p>The a command line will do:</p>... | 0 | 2010-03-12T18:29:18Z | [
"python",
"bash"
] |
What is the best, python or bash for selectively concatenating lots of files? | 2,434,689 | <p>I have around 20000 files coming from the output of some program, and their names follow the format:</p>
<pre><code>data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt
</code></pre>
<p>I would like to write a script that gets as input argument the number N. Then it makes b... | 3 | 2010-03-12T17:47:59Z | 2,434,994 | <p>I like this one which saves on executing processes, only 1 cat per block</p>
<pre><code>#! /bin/bash
N=5 # block size
S=1 # start
E=20000 # end
for n in $(seq $S $N $E)
do
CMD="cat "
i=$n
while [ $i -lt $((n + N)) ]
do
CMD+="data$((i++)).txt "
done
$CMD > data_new_$((n / N + 1))... | 1 | 2010-03-12T18:46:05Z | [
"python",
"bash"
] |
What is the best, python or bash for selectively concatenating lots of files? | 2,434,689 | <p>I have around 20000 files coming from the output of some program, and their names follow the format:</p>
<pre><code>data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt
</code></pre>
<p>I would like to write a script that gets as input argument the number N. Then it makes b... | 3 | 2010-03-12T17:47:59Z | 2,435,298 | <p>Simple enough?</p>
<p>make_cat.py</p>
<pre><code>limit = 1000
n = 5
for i in xrange( 0, (limit+n-1)//n ):
names = [ "data{0}.txt".format(j) for j in range(i*n,i*n+n) ]
print "cat {0} >data_new_{1}.txt".format( " ".join(names), i )
</code></pre>
<p>Script</p>
<pre><code>python make_cat.py | sh
</code... | 0 | 2010-03-12T19:34:42Z | [
"python",
"bash"
] |
What is the best, python or bash for selectively concatenating lots of files? | 2,434,689 | <p>I have around 20000 files coming from the output of some program, and their names follow the format:</p>
<pre><code>data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt
</code></pre>
<p>I would like to write a script that gets as input argument the number N. Then it makes b... | 3 | 2010-03-12T17:47:59Z | 2,436,951 | <p>how about a one liner ? :)</p>
<pre><code>ls data[0-9]*txt|sort -nk1.5|awk 'BEGIN{rn=5;i=1}{while((getline _<$0)>0){print _ >"data_new_"i".txt"}close($0)}NR%rn==0{i++}'
</code></pre>
| 1 | 2010-03-13T01:48:47Z | [
"python",
"bash"
] |
Last matching symbol in Regex | 2,434,749 | <p>I couldn't find a more descriptive title, but here there is an example:</p>
<pre><code>import re
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Menda Remix)")
m.group("remixer") # returns 'Menda' OK
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Blabla) (Menda Remix)")
m.group("remixer") #... | 2 | 2010-03-12T17:57:55Z | 2,434,759 | <pre><code>re.search(r"\((?P<remixer>[^)]+) (Remix)\)", "Title (Blabla) (Menda Remix)")
</code></pre>
| 3 | 2010-03-12T18:00:13Z | [
"python",
"regex"
] |
Last matching symbol in Regex | 2,434,749 | <p>I couldn't find a more descriptive title, but here there is an example:</p>
<pre><code>import re
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Menda Remix)")
m.group("remixer") # returns 'Menda' OK
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Blabla) (Menda Remix)")
m.group("remixer") #... | 2 | 2010-03-12T17:57:55Z | 2,434,763 | <p>Use <code>[^()]+</code> instead of <code>.+</code> to not to match the parenthesis.</p>
| 1 | 2010-03-12T18:00:58Z | [
"python",
"regex"
] |
Last matching symbol in Regex | 2,434,749 | <p>I couldn't find a more descriptive title, but here there is an example:</p>
<pre><code>import re
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Menda Remix)")
m.group("remixer") # returns 'Menda' OK
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Blabla) (Menda Remix)")
m.group("remixer") #... | 2 | 2010-03-12T17:57:55Z | 2,434,764 | <p>I would probably do this:</p>
<pre><code>m = re.search(r".*\((?P<remixer>.+) (Remix)\)", "Title (Blabla) (Menda Remix)")
</code></pre>
| 1 | 2010-03-12T18:01:12Z | [
"python",
"regex"
] |
Last matching symbol in Regex | 2,434,749 | <p>I couldn't find a more descriptive title, but here there is an example:</p>
<pre><code>import re
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Menda Remix)")
m.group("remixer") # returns 'Menda' OK
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Blabla) (Menda Remix)")
m.group("remixer") #... | 2 | 2010-03-12T17:57:55Z | 2,434,768 | <p>Just add a <code>$</code> to the end of the pattern and you're done :)</p>
<pre><code>import re
m = re.search(r"\((?P<remixer>[^)]+) (Remix)\)$", "Title (Menda Remix)")
print m.group("remixer") # returns 'Menda' OK
m = re.search(r"\((?P<remixer>[^)]+) (Remix)\)$", "Title (Blabla) (Menda Remix)")
print m... | 1 | 2010-03-12T18:01:55Z | [
"python",
"regex"
] |
How i can convert integer in to 'binary' in python | 2,434,806 | <p>In Ruby i do so</p>
<pre><code>asd = 123
asd = '%b' % asd # => "1111011"
</code></pre>
| 2 | 2010-03-12T18:09:33Z | 2,434,817 | <p>in Python >= 2.6 with <a href="http://docs.python.org/library/functions.html"><code>bin()</code></a>:</p>
<pre><code>asd = bin(123) # => '0b1111011'
</code></pre>
<p>To remove the leading <code>0b</code> you can just take the substring <code>bin(123)[2:]</code>.</p>
<blockquote>
<p><strong>bin(x)</strong><br... | 7 | 2010-03-12T18:11:57Z | [
"python",
"ruby"
] |
How i can convert integer in to 'binary' in python | 2,434,806 | <p>In Ruby i do so</p>
<pre><code>asd = 123
asd = '%b' % asd # => "1111011"
</code></pre>
| 2 | 2010-03-12T18:09:33Z | 2,434,836 | <p>you can also do string formatting, which doesn't contain <code>'0b'</code>:</p>
<pre><code>>>> '{:b}'.format(123) #{0:b} in python 2.6
'1111011'
</code></pre>
| 7 | 2010-03-12T18:16:18Z | [
"python",
"ruby"
] |
How i can convert integer in to 'binary' in python | 2,434,806 | <p>In Ruby i do so</p>
<pre><code>asd = 123
asd = '%b' % asd # => "1111011"
</code></pre>
| 2 | 2010-03-12T18:09:33Z | 2,435,768 | <p>bin() works, as Felix mentioned. For completeness, you can go the other way as
well.</p>
<pre><code>>>> int('01101100',2)
108
>>> bin(108)
'0b1101100'
>>> bin(108)[2:]
'1101100'
</code></pre>
| 0 | 2010-03-12T20:45:35Z | [
"python",
"ruby"
] |
Python - Why use anything other than uuid4() for unique strings? | 2,434,931 | <p>I see quit a few implementations of unique string generation for things like uploaded image names, session IDs, et al, and many of them employ the usage of hashes like SHA1, or others.</p>
<p>I'm not questioning the legitimacy of using custom methods like this, but rather just the reason. If I want a unique string,... | 24 | 2010-03-12T18:35:41Z | 2,434,945 | <p>One possible reason is that you want the unique string to be human-readable. UUIDs just aren't easy to read.</p>
| 5 | 2010-03-12T18:37:43Z | [
"python",
"unique",
"uuid"
] |
Python - Why use anything other than uuid4() for unique strings? | 2,434,931 | <p>I see quit a few implementations of unique string generation for things like uploaded image names, session IDs, et al, and many of them employ the usage of hashes like SHA1, or others.</p>
<p>I'm not questioning the legitimacy of using custom methods like this, but rather just the reason. If I want a unique string,... | 24 | 2010-03-12T18:35:41Z | 2,434,951 | <p>Well, sometimes you want collisions. If someone uploads the same exact image twice, maybe you'd rather tell them it's a duplicate rather than just make another copy with a new name.</p>
| 11 | 2010-03-12T18:38:06Z | [
"python",
"unique",
"uuid"
] |
Python - Why use anything other than uuid4() for unique strings? | 2,434,931 | <p>I see quit a few implementations of unique string generation for things like uploaded image names, session IDs, et al, and many of them employ the usage of hashes like SHA1, or others.</p>
<p>I'm not questioning the legitimacy of using custom methods like this, but rather just the reason. If I want a unique string,... | 24 | 2010-03-12T18:35:41Z | 2,434,976 | <p>uuids are long, and meaningless (for instance, if you order by uuid, you get a meaningless result).</p>
<p>And, because it's too long, I wouldn't want to put it in a URL or expose it to the user in any shape or form.</p>
| 3 | 2010-03-12T18:41:50Z | [
"python",
"unique",
"uuid"
] |
Python - Why use anything other than uuid4() for unique strings? | 2,434,931 | <p>I see quit a few implementations of unique string generation for things like uploaded image names, session IDs, et al, and many of them employ the usage of hashes like SHA1, or others.</p>
<p>I'm not questioning the legitimacy of using custom methods like this, but rather just the reason. If I want a unique string,... | 24 | 2010-03-12T18:35:41Z | 12,360,168 | <p>Using a hash to uniquely identify a resource allows you to generate a 'unique' reference from the object. For instance, Git uses SHA hashing to make a unique hash that represents the exact changeset of a single a commit. Since hashing is deterministic, you'll get the same hash for the same file every time. </p>
<p>... | 17 | 2012-09-10T22:12:33Z | [
"python",
"unique",
"uuid"
] |
Python - Why use anything other than uuid4() for unique strings? | 2,434,931 | <p>I see quit a few implementations of unique string generation for things like uploaded image names, session IDs, et al, and many of them employ the usage of hashes like SHA1, or others.</p>
<p>I'm not questioning the legitimacy of using custom methods like this, but rather just the reason. If I want a unique string,... | 24 | 2010-03-12T18:35:41Z | 26,555,857 | <p>In addition to the other answers, hashes are really good for things that should be immutable. The name is unique and can be used to check the integrity of whatever it is attached to at any time.</p>
| 1 | 2014-10-24T20:34:15Z | [
"python",
"unique",
"uuid"
] |
Python - Why use anything other than uuid4() for unique strings? | 2,434,931 | <p>I see quit a few implementations of unique string generation for things like uploaded image names, session IDs, et al, and many of them employ the usage of hashes like SHA1, or others.</p>
<p>I'm not questioning the legitimacy of using custom methods like this, but rather just the reason. If I want a unique string,... | 24 | 2010-03-12T18:35:41Z | 35,138,426 | <p>Also note other kinds of UUID could even be appropriate. For example, if you want your identifier to be orderable, UUID1 is based in part on a timestamp. It's all really about your application requirements...</p>
| 1 | 2016-02-01T19:15:43Z | [
"python",
"unique",
"uuid"
] |
How to get path to the installed GIT in Python? | 2,435,015 | <p>I need to get a path to the GIT on Max OS X 10.6 using Python 2.6.1 into script variables. I use this code for that:</p>
<pre><code>r = subprocess.Popen(shlex.split("which git"), stdout=subprocess.PIPE)
print r.stdout.read()
</code></pre>
<p>but the problem is that output is empty (I tried <code>stderr</code> too)... | 2 | 2010-03-12T18:49:35Z | 2,435,028 | <p>All which does is iterate over the directories in $PATH, checking to see if the file is there. Just write a small method to do likewise.</p>
| 2 | 2010-03-12T18:51:12Z | [
"python",
"subprocess",
"osx-snow-leopard"
] |
What is the new way of checking "callable" methods in python 3.x? | 2,435,066 | <p>I was studying introspection in Python, and as I was getting through basic examples, I found out that the <code>callable</code> built-in function is no longer available in Python 3.1.</p>
<p>How can I check if a method is callable now?</p>
<p>Thank you</p>
| 5 | 2010-03-12T18:59:01Z | 2,435,074 | <pre><code>if hasattr(f, "__call__"):
</code></pre>
<p><a href="http://docs.python.org/dev/3.0/whatsnew/3.0.html#builtins">What's New In Python 3.0</a></p>
| 5 | 2010-03-12T19:00:58Z | [
"python",
"python-3.x",
"introspection"
] |
What is the new way of checking "callable" methods in python 3.x? | 2,435,066 | <p>I was studying introspection in Python, and as I was getting through basic examples, I found out that the <code>callable</code> built-in function is no longer available in Python 3.1.</p>
<p>How can I check if a method is callable now?</p>
<p>Thank you</p>
| 5 | 2010-03-12T18:59:01Z | 2,435,089 | <pre><code>isinstance(f, collections.Callable)
</code></pre>
| 2 | 2010-03-12T19:05:03Z | [
"python",
"python-3.x",
"introspection"
] |
What is the new way of checking "callable" methods in python 3.x? | 2,435,066 | <p>I was studying introspection in Python, and as I was getting through basic examples, I found out that the <code>callable</code> built-in function is no longer available in Python 3.1.</p>
<p>How can I check if a method is callable now?</p>
<p>Thank you</p>
| 5 | 2010-03-12T18:59:01Z | 5,876,453 | <p>The callable() builtin function from Py2.x was resurrected in python3.2.</p>
| 13 | 2011-05-03T22:26:31Z | [
"python",
"python-3.x",
"introspection"
] |
Trying to get django app to work with mod_wsgi on CentOS 5 | 2,435,125 | <p>I'm running CentOS 5, and am trying to get a django application working with mod_wsgi. I'm using .wsgi settings I got working on Ubuntu. I'm also using an alternate installation of python (/opt/python2.6/) since my django application needs >2.5 and the OS uses 2.3</p>
<p>Here is the error:</p>
<pre><code>[Thu Mar ... | 7 | 2010-03-12T19:09:54Z | 2,436,341 | <p><code>SystemError: dynamic module not initialized properly</code> is the exception that is thrown when a dll (or .so) that is being loaded cannot be properly initialized. In function <code>_PyImport_LoadDynamicModule</code> of <code>Python/importdl.c</code> in case anyone is interested.</p>
<p>Now, the dll/so in qu... | 7 | 2010-03-12T22:34:17Z | [
"python",
"django",
"mod-wsgi",
"centos5"
] |
Passing a Python list using JSON and Django | 2,435,261 | <p>I'm trying to send a Python list in to client side (encoded as JSON). This is the code snippet which I have written:</p>
<pre><code>array_to_js = [vld_id, vld_error, False]
array_to_js[2] = True
jsonValidateReturn = simplejson.dumps(array_to_js)
return HttpResponse(jsonValidateReturn, mimetype='application/json')
<... | 1 | 2010-03-12T19:29:30Z | 2,435,279 | <p>The JSON array will be dumped without a name / assignment.</p>
<p>That is, in order to give it a name, in your JavaScript code you would do something like this:</p>
<pre><code>var my_json_data_dump = function_that_gets_json_data();
</code></pre>
<p>If you want to visualize it, for example, substitute:</p>
<pre><... | 1 | 2010-03-12T19:32:32Z | [
"python",
"django",
"json"
] |
Passing a Python list using JSON and Django | 2,435,261 | <p>I'm trying to send a Python list in to client side (encoded as JSON). This is the code snippet which I have written:</p>
<pre><code>array_to_js = [vld_id, vld_error, False]
array_to_js[2] = True
jsonValidateReturn = simplejson.dumps(array_to_js)
return HttpResponse(jsonValidateReturn, mimetype='application/json')
<... | 1 | 2010-03-12T19:29:30Z | 2,435,447 | <p>If both client and server are in Python, here's what you need to know.</p>
<p><strong>Server</strong>. Use a dictionary to get labels on the fields. Write this as the response.</p>
<pre><code>>>> import json
>>> json.dumps( {'vld_id':1,'vls_error':2,'something_else':True} )
'{"vld_id": 1, "some... | 0 | 2010-03-12T19:56:13Z | [
"python",
"django",
"json"
] |
Database: storing data from user registration form | 2,435,281 | <p>Let's say I have an user registration form. In this form, I have the option for the user to upload a photo. I have an User table and Photo table. My User table has a "PathToPhoto" column. My question is how do I fill in the "PathToPhoto" column if the photo is uploaded and inserted into Photo table before the use... | 0 | 2010-03-12T19:32:49Z | 2,435,639 | <p>To make sure we're on the same page, is the following correct?</p>
<ul>
<li>You're inserting the photo information into the Photo table immediately after the user uploads the photo but before he/she submits the form;</li>
<li>When the user submits the form, you're inserting a row into the User table;</li>
<li>One o... | 0 | 2010-03-12T20:25:53Z | [
"python",
"database",
"postgresql"
] |
using DES/3DES with python | 2,435,283 | <p>what is the best module /package in python to use des /3des for encryption /decryption.
could someone provide example to encrypt data with des/3des on python.</p>
| 8 | 2010-03-12T19:33:11Z | 2,438,609 | <p><a href="http://twhiteman.netfirms.com/des.html"><strong>pyDes</strong></a> can be used for both, DES and 3DES. Sample usage:</p>
<pre><code>from pyDes import *
data = "Please encrypt my data"
k = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
d = k.encrypt(data)
print "Encrypted: %r" % d
pr... | 14 | 2010-03-13T14:09:32Z | [
"python",
"cryptography",
"3des"
] |
using DES/3DES with python | 2,435,283 | <p>what is the best module /package in python to use des /3des for encryption /decryption.
could someone provide example to encrypt data with des/3des on python.</p>
| 8 | 2010-03-12T19:33:11Z | 3,568,824 | <p>You can use the <a href="http://chandlerproject.org/Projects/MeTooCrypto">M2Crypto</a> Python wrapper for <a href="http://www.openssl.org/">OpenSSL</a>. It has the advantage of being fast (as fast as OpenSSL), but the disadvantage of the documentation being limited.</p>
<p>Here is the example from <a href="http://... | 6 | 2010-08-25T17:54:34Z | [
"python",
"cryptography",
"3des"
] |
File size in Python server | 2,435,294 | <p>We have server on Python and client + web service on Ruby. That works only if file from URL is less than 800 k. It seems like "socket.puts data" in a client works, but "output = socket.gets" - not. I think problem is in a Python part. For big files tests run "Connection reset by peer". Is it buffer size variable by ... | 0 | 2010-03-12T19:34:14Z | 2,435,731 | <p>Could you add a little more information and code to your example?</p>
<p>Are you thinking about sock.recv_into() which takes a buffer and buffer size as arguments? Alternately, are you hitting a timeout issue by failing to have a keepalive on the Ruby side?</p>
<p>Guessing in advance of knowledge.</p>
| 0 | 2010-03-12T20:40:43Z | [
"python",
"ruby",
"client",
"size"
] |
pdf viewer for pyqt4 application? | 2,435,470 | <p>I'm writing a Python+Qt4 application that would ideally need to pop up a window every once in a while, to display pdf documents and allow very basic operations, namely scrolling through the different pages and printing the document.</p>
<p>I've found the reportLab to create pdf files, but nothing about pdf viewers.... | 8 | 2010-03-12T19:59:36Z | 2,435,514 | <p>you can use <a href="http://doc.trolltech.com/qq/qq27-poppler.html">Poppler</a> for that.</p>
| 8 | 2010-03-12T20:05:44Z | [
"python",
"pdf",
"qt4",
"pyqt4"
] |
pdf viewer for pyqt4 application? | 2,435,470 | <p>I'm writing a Python+Qt4 application that would ideally need to pop up a window every once in a while, to display pdf documents and allow very basic operations, namely scrolling through the different pages and printing the document.</p>
<p>I've found the reportLab to create pdf files, but nothing about pdf viewers.... | 8 | 2010-03-12T19:59:36Z | 2,435,561 | <p>what about okular? It is a full app, but it can always be call from another app.</p>
| -1 | 2010-03-12T20:12:09Z | [
"python",
"pdf",
"qt4",
"pyqt4"
] |
pdf viewer for pyqt4 application? | 2,435,470 | <p>I'm writing a Python+Qt4 application that would ideally need to pop up a window every once in a while, to display pdf documents and allow very basic operations, namely scrolling through the different pages and printing the document.</p>
<p>I've found the reportLab to create pdf files, but nothing about pdf viewers.... | 8 | 2010-03-12T19:59:36Z | 19,167,507 | <p>A Python binding to poppler-qt4 that aims for completeness and for being actively maintained.
<a href="https://code.google.com/p/python-poppler-qt4/" rel="nofollow">https://code.google.com/p/python-poppler-qt4/</a></p>
| 0 | 2013-10-03T19:21:57Z | [
"python",
"pdf",
"qt4",
"pyqt4"
] |
How to differentiate between method and function in a decorator? | 2,435,764 | <p>I want to write a decorator that acts differently depending on whether it is applied to a function or to a method.</p>
<pre><code>def some_decorator(func):
if the_magic_happens_here(func): # <---- Point of interest
print 'Yay, found a method ^_^ (unbound jet)'
else:
print 'Meh, just an or... | 6 | 2010-03-12T20:45:32Z | 2,436,061 | <p>I would rely on the convention that functions that will become methods have a first argument named <code>self</code>, and other functions don't. Fragile, but then, there's no really solid way.</p>
<p>So (pseudocode as I have comments in lieu of what you want to do in either case...):</p>
<pre><code>import inspect... | 5 | 2010-03-12T21:35:11Z | [
"python",
"decorator"
] |
How to differentiate between method and function in a decorator? | 2,435,764 | <p>I want to write a decorator that acts differently depending on whether it is applied to a function or to a method.</p>
<pre><code>def some_decorator(func):
if the_magic_happens_here(func): # <---- Point of interest
print 'Yay, found a method ^_^ (unbound jet)'
else:
print 'Meh, just an or... | 6 | 2010-03-12T20:45:32Z | 2,436,414 | <p>Do you need to have the magic happen where you choose which wrapper to return, or can you defer the magic until the function is actually called?
You could always try a parameter to your decorator to indicate which of the two wrappers it should use, like</p>
<pre><code>def some_decorator( clams ):
def _mydecor(fu... | 1 | 2010-03-12T22:51:42Z | [
"python",
"decorator"
] |
How to differentiate between method and function in a decorator? | 2,435,764 | <p>I want to write a decorator that acts differently depending on whether it is applied to a function or to a method.</p>
<pre><code>def some_decorator(func):
if the_magic_happens_here(func): # <---- Point of interest
print 'Yay, found a method ^_^ (unbound jet)'
else:
print 'Meh, just an or... | 6 | 2010-03-12T20:45:32Z | 2,437,025 | <p>You just need to check to see if the function being decorated has an <code>im_func</code> attribute. If it does, then it is a method. If it doesn't then it is a function.</p>
<p><strong>Note</strong> that the code sample below does the detection at call time but you can do it at decoration time as well. Just move t... | -2 | 2010-03-13T02:23:16Z | [
"python",
"decorator"
] |
how execute a Python Script with activeresource? | 2,435,778 | <p>I need to execute this python script: <a href="http://superjared.com/static/code/googleMX.py" rel="nofollow">http://superjared.com/static/code/googleMX.py</a></p>
<p>I installed pyactiveresource, but when I executed it: python googleMX.py I had this response.</p>
<p>Traceback (most recent call last):
File "google... | 1 | 2010-03-12T20:47:21Z | 2,827,360 | <p>by Responding myself...</p>
<p>It was using an older version of pyactiveresource. The author (Lucky) creates another one <a href="http://gist.github.com/330832" rel="nofollow">http://gist.github.com/330832</a></p>
| 0 | 2010-05-13T14:02:24Z | [
"python",
"activeresource"
] |
Django : proper way to use model, duplicates! | 2,435,825 | <p>I have a question about the proper, best way to manage the model.
I am relative newbie to django, so I think I need to read more docs, tutorials,etc (suggestions for this would be cool!).</p>
<p>Anyway, this is my question :</p>
<p>I have a python web crawler, that is "connected" with django model.</p>
<p>Crawlin... | 0 | 2010-03-12T20:53:43Z | 2,435,882 | <p>Use the <code>get_or_create()</code> method of the manager, then modify the returned instance as needed.</p>
| 6 | 2010-03-12T21:02:43Z | [
"python",
"django"
] |
What is the paste deploy uri syntax? | 2,435,865 | <p>Paste Deploy can reference code with uris such as</p>
<pre><code>[section]
use = egg:FooBar#baz
</code></pre>
<p>What is the full syntax for these uris?</p>
| 0 | 2010-03-12T20:59:33Z | 2,457,870 | <p>Those URIs are <a href="http://pythonpaste.org/deploy/#basic-usage" rel="nofollow">fully detailed in the documentation</a>. It boils down to <code>config:</code>, <code>egg:</code>, and prefix-less URIs that point to other sections.</p>
| 2 | 2010-03-16T20:27:37Z | [
"python",
"paster"
] |
How to display a foreign key fields in the objects listing of the Django admin? | 2,435,884 | <p>hi
i have the following models setup </p>
<pre><code>class Player(models.Model):
#slug = models.slugField(max_length=200)
Player_Name = models.CharField(max_length=100)
Nick = models.CharField(max_length=100, blank=True)
Jersy_Number = models.IntegerField()
Team_id = models.ForeignKey('Team') ... | 2 | 2010-03-12T21:03:01Z | 2,435,899 | <p>You are almost there, you have commented it out and forgot to call the attribute properly:</p>
<pre><code>def __unicode__(self):
return self.Team_Name
</code></pre>
<p>Read the <a href="http://docs.djangoproject.com/en/dev/ref/models/instances/#unicode" rel="nofollow">documentation</a>.</p>
| 3 | 2010-03-12T21:05:09Z | [
"python",
"django",
"django-models",
"django-admin"
] |
How to display a foreign key fields in the objects listing of the Django admin? | 2,435,884 | <p>hi
i have the following models setup </p>
<pre><code>class Player(models.Model):
#slug = models.slugField(max_length=200)
Player_Name = models.CharField(max_length=100)
Nick = models.CharField(max_length=100, blank=True)
Jersy_Number = models.IntegerField()
Team_id = models.ForeignKey('Team') ... | 2 | 2010-03-12T21:03:01Z | 2,435,900 | <p>Add a <a href="http://www.djangoproject.com/documentation/models/str/" rel="nofollow"><strong>unicode</strong></a> method to the team object:</p>
<pre><code>def __unicode__(self):
return self.Team_name
</code></pre>
| 1 | 2010-03-12T21:05:10Z | [
"python",
"django",
"django-models",
"django-admin"
] |
How to display a foreign key fields in the objects listing of the Django admin? | 2,435,884 | <p>hi
i have the following models setup </p>
<pre><code>class Player(models.Model):
#slug = models.slugField(max_length=200)
Player_Name = models.CharField(max_length=100)
Nick = models.CharField(max_length=100, blank=True)
Jersy_Number = models.IntegerField()
Team_id = models.ForeignKey('Team') ... | 2 | 2010-03-12T21:03:01Z | 35,134,547 | <p>And for updated developers (Python 3.x):</p>
<pre><code>def __str__(self):
return self.Team_name
</code></pre>
| 1 | 2016-02-01T15:45:29Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Inserting a WAV at a certain point in an audio file using python | 2,435,961 | <p>My problem is the following:
I have a 2-minute long WAV file, and my aim is to insert another WAV file (7 seconds long), at a certain point in the first WAV file (say, 0:48), essentially combining the two WAVs, using python. Unfortunately I haven't been able to figure out how to do that, and was wondering if there w... | 2 | 2010-03-12T21:17:49Z | 2,435,969 | <p>If they're PCM-encoded then you can use <a href="http://docs.python.org/library/wave.html" rel="nofollow"><code>wave</code></a>, otherwise use something like <a href="http://gstreamer.freedesktop.org/modules/gst-python.html" rel="nofollow"><code>pygst</code></a>.</p>
| 1 | 2010-03-12T21:19:55Z | [
"python",
"audio"
] |
Inserting a WAV at a certain point in an audio file using python | 2,435,961 | <p>My problem is the following:
I have a 2-minute long WAV file, and my aim is to insert another WAV file (7 seconds long), at a certain point in the first WAV file (say, 0:48), essentially combining the two WAVs, using python. Unfortunately I haven't been able to figure out how to do that, and was wondering if there w... | 2 | 2010-03-12T21:17:49Z | 2,436,393 | <p>Here's some code to get you in the right direction:</p>
<pre><code>wf = wave.open('in1.wav','rb')
wf2 = wave.open('in2.wav','rb')
wfout = wave.open('out.wav','wb')
wfout.setparams(wf.getparams())
sr = wf.getframerate()
for x in xrange(48):
wfout.writeframes(wf.readframes(sr)
wfout.writeframes(wf2.readframes(s... | 0 | 2010-03-12T22:48:36Z | [
"python",
"audio"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.