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 |
|---|---|---|---|---|---|---|---|---|---|
Singleton python generator? Or, pickle a python generator? | 1,939,015 | <p>I am using the following code, with nested generators, to iterate over a text document and return training examples using <code>get_train_minibatch()</code>. I would like to persist (pickle) the generators, so I can get back to the same place in the text document. However, you cannot pickle generators.</p>
<ul>
<li... | 3 | 2009-12-21T09:08:40Z | 1,939,119 | <p>You can try create callable object: </p>
<pre><code>class TrainExampleGenerator:
def __call__(self):
for l in open(HYPERPARAMETERS["TRAIN_SENTENCES"]):
prevwords = []
for w in string.split(l):
w = string.strip(w)
id = None
prevwor... | -1 | 2009-12-21T09:33:08Z | [
"python",
"singleton",
"generator",
"pickle",
"persistent"
] |
Singleton python generator? Or, pickle a python generator? | 1,939,015 | <p>I am using the following code, with nested generators, to iterate over a text document and return training examples using <code>get_train_minibatch()</code>. I would like to persist (pickle) the generators, so I can get back to the same place in the text document. However, you cannot pickle generators.</p>
<ul>
<li... | 3 | 2009-12-21T09:08:40Z | 1,939,493 | <p>You can create a standard iterator object, it just won't be as convenient as the generator; you need to store the iterator's state on the instace (so that it is pickled), and define a next() function to return the next object:</p>
<pre><code>class TrainExampleIterator (object):
def __init__(self):
# set... | 2 | 2009-12-21T11:09:34Z | [
"python",
"singleton",
"generator",
"pickle",
"persistent"
] |
Singleton python generator? Or, pickle a python generator? | 1,939,015 | <p>I am using the following code, with nested generators, to iterate over a text document and return training examples using <code>get_train_minibatch()</code>. I would like to persist (pickle) the generators, so I can get back to the same place in the text document. However, you cannot pickle generators.</p>
<ul>
<li... | 3 | 2009-12-21T09:08:40Z | 1,941,488 | <p>This may not be an option for you, but Stackless Python (<a href="http://stackless.com" rel="nofollow">http://stackless.com</a>) <em>does</em> allow you to pickle things like functions and generators, under certain conditions. This will work:</p>
<p>In foo.py:</p>
<pre><code>def foo():
with open('foo.txt') as ... | 0 | 2009-12-21T17:34:21Z | [
"python",
"singleton",
"generator",
"pickle",
"persistent"
] |
Singleton python generator? Or, pickle a python generator? | 1,939,015 | <p>I am using the following code, with nested generators, to iterate over a text document and return training examples using <code>get_train_minibatch()</code>. I would like to persist (pickle) the generators, so I can get back to the same place in the text document. However, you cannot pickle generators.</p>
<ul>
<li... | 3 | 2009-12-21T09:08:40Z | 1,941,683 | <p>The following code should do more-or-less what you want. The first class defines something that acts like a file but can be pickled. (When you unpickle it, it re-opens the file, and seeks to the location where it was when you pickled it). The second class is an iterator that generates word windows.</p>
<pre><cod... | 1 | 2009-12-21T18:11:33Z | [
"python",
"singleton",
"generator",
"pickle",
"persistent"
] |
Singleton python generator? Or, pickle a python generator? | 1,939,015 | <p>I am using the following code, with nested generators, to iterate over a text document and return training examples using <code>get_train_minibatch()</code>. I would like to persist (pickle) the generators, so I can get back to the same place in the text document. However, you cannot pickle generators.</p>
<ul>
<li... | 3 | 2009-12-21T09:08:40Z | 1,941,710 | <p>You might also consider using NLTK's corpus readers:</p>
<ul>
<li><a href="http://nltk.googlecode.com/svn/trunk/doc/api/nltk.corpus.reader-module.html" rel="nofollow">http://nltk.googlecode.com/svn/trunk/doc/api/nltk.corpus.reader-module.html</a> </li>
<li><a href="http://nltk.googlecode.com/svn/trunk/doc/howto/cor... | 0 | 2009-12-21T18:15:51Z | [
"python",
"singleton",
"generator",
"pickle",
"persistent"
] |
Singleton python generator? Or, pickle a python generator? | 1,939,015 | <p>I am using the following code, with nested generators, to iterate over a text document and return training examples using <code>get_train_minibatch()</code>. I would like to persist (pickle) the generators, so I can get back to the same place in the text document. However, you cannot pickle generators.</p>
<ul>
<li... | 3 | 2009-12-21T09:08:40Z | 1,945,049 | <ol>
<li>Convert the generator to a class in which the generator code is the <code>__iter__</code> method</li>
<li>Add <code>__getstate__</code> and <code>__setstate__</code> methods to the class, to handling pickling. Remember that you canât pickle file objects. So <code>__setstate__</code> will have to re-open file... | 0 | 2009-12-22T08:57:16Z | [
"python",
"singleton",
"generator",
"pickle",
"persistent"
] |
Send a file with webpy and urllib2 | 1,939,048 | <p>I need to send a file to another server using oauth and webpy. For now I'll ignore the oauth part as sending the file itself is already a challenge.</p>
<p>Here's my partial code:</p>
<pre><code>class create_video:
def POST(self):
x = web.input(video_original={})
</code></pre>
<p>At this point I want to sen... | 1 | 2009-12-21T09:15:29Z | 1,940,853 | <p>You're coming from <a href="http://webpy.org/cookbook/fileupload" rel="nofollow">here</a>, I guess.</p>
<p>The <code>POST</code> method defines how to receive data via POST requests, rather than send any data. In your code, the data from an incoming POST request is saved in <code>x</code>. How do you want to procee... | 1 | 2009-12-21T15:47:28Z | [
"python",
"web.py"
] |
Simple example of use of __setstate__ and __getstate__ | 1,939,058 | <p>I don't know what the <code>__setstate__</code> and <code>__getstate__</code> methods do, so help me with a simple example.</p>
| 25 | 2009-12-21T09:17:07Z | 1,939,085 | <p>These methods are used for controlling how objects are pickled and unpickled by the <a href="http://docs.python.org/library/pickle.html#pickle-protocol" rel="nofollow">pickle</a> module. This is usually handled automatically, so unless you need to override how a class is pickled or unpickled you shouldn't need to w... | 3 | 2009-12-21T09:25:16Z | [
"python",
"serialization"
] |
Simple example of use of __setstate__ and __getstate__ | 1,939,058 | <p>I don't know what the <code>__setstate__</code> and <code>__getstate__</code> methods do, so help me with a simple example.</p>
| 25 | 2009-12-21T09:17:07Z | 1,939,384 | <p>Here's a very simple example for Python 2 that should supplement the <a href="http://docs.python.org/library/pickle.html#pickle-protocol">pickle docs</a>.</p>
<pre><code>class Foo(object):
def __init__(self, val=2):
self.val = val
def __getstate__(self):
print "I'm being pickled"
self.val *= 2
... | 23 | 2009-12-21T10:36:52Z | [
"python",
"serialization"
] |
python libraries for ssh handling | 1,939,107 | <p>I'm going to write first code for handling ssh commands on python and I did search over the stackoverflow and can see that there are several python libraries that can be used for handling commands passed through ssh, like <a href="https://github.com/paramiko/paramiko">paramiko</a>, <a href="http://pexpect.sourceforg... | 17 | 2009-12-21T09:31:28Z | 1,939,137 | <p>Try taking a look at <a href="http://twistedmatrix.com/trac/wiki/TwistedConch" rel="nofollow">Twisted Conch</a>. It handles everything you want. If you were just looking for SCP-style file transfer, you could always use the python module <a href="http://sourcefrog.net/weblog/projects/superlifter/python-filexfer.ht... | 2 | 2009-12-21T09:37:46Z | [
"python",
"ssh",
"libraries",
"paramiko",
"pexpect"
] |
python libraries for ssh handling | 1,939,107 | <p>I'm going to write first code for handling ssh commands on python and I did search over the stackoverflow and can see that there are several python libraries that can be used for handling commands passed through ssh, like <a href="https://github.com/paramiko/paramiko">paramiko</a>, <a href="http://pexpect.sourceforg... | 17 | 2009-12-21T09:31:28Z | 1,939,148 | <p>Libraries, Wrappers:</p>
<ol>
<li><p><a href="http://media.commandline.org.uk/code/ssh.txt">http://media.commandline.org.uk/code/ssh.txt</a> (example usage: <a href="http://commandline.org.uk/python/sftp-python-really-simple-ssh/">http://commandline.org.uk/python/sftp-python-really-simple-ssh/</a>)</p>
<pre><code>... | 17 | 2009-12-21T09:41:15Z | [
"python",
"ssh",
"libraries",
"paramiko",
"pexpect"
] |
python libraries for ssh handling | 1,939,107 | <p>I'm going to write first code for handling ssh commands on python and I did search over the stackoverflow and can see that there are several python libraries that can be used for handling commands passed through ssh, like <a href="https://github.com/paramiko/paramiko">paramiko</a>, <a href="http://pexpect.sourceforg... | 17 | 2009-12-21T09:31:28Z | 1,939,188 | <p>Since you're not doing anything special at the protocol level, you presumably don't need the protocol to be entirely implemented in python, and you could simply run ssh/scp commands using the <code>subprocess</code> module.</p>
<pre><code>import subprocess
subprocess.check_call(['ssh', 'server', 'command'])
subproc... | 14 | 2009-12-21T09:51:15Z | [
"python",
"ssh",
"libraries",
"paramiko",
"pexpect"
] |
python libraries for ssh handling | 1,939,107 | <p>I'm going to write first code for handling ssh commands on python and I did search over the stackoverflow and can see that there are several python libraries that can be used for handling commands passed through ssh, like <a href="https://github.com/paramiko/paramiko">paramiko</a>, <a href="http://pexpect.sourceforg... | 17 | 2009-12-21T09:31:28Z | 38,706,818 | <p>The one feature that none of the above-discussed libraries provide is a concurrent connection to multiple servers.In today's age where system admins need to run commands on hundreds of servers,libraries which can handle parallel command execution are very important. The two libraries that I know of are :</p>
<ol>
<... | 1 | 2016-08-01T19:37:52Z | [
"python",
"ssh",
"libraries",
"paramiko",
"pexpect"
] |
Python for Sony Ericsson | 1,939,181 | <p>Is it possible to install python on Sony Ericsson mobile phones?</p>
| 0 | 2009-12-21T09:49:37Z | 1,939,196 | <p>The <a href="http://www.electricpig.co.uk/2009/11/03/sony-ericsson-xperia-x10-hands-on-photofest/" rel="nofollow">Sony Ericsson Xperia x10</a> since Android phones can run <a href="http://google-opensource.blogspot.com/2009/06/introducing-android-scripting.html" rel="nofollow">python</a>. Not sure about other Sony E... | 1 | 2009-12-21T09:53:06Z | [
"python"
] |
Python for Sony Ericsson | 1,939,181 | <p>Is it possible to install python on Sony Ericsson mobile phones?</p>
| 0 | 2009-12-21T09:49:37Z | 1,939,328 | <p>Nokia Symbian S60 have Python:
<a href="http://opensource.nokia.com/projects/pythonfors60/" rel="nofollow">http://opensource.nokia.com/projects/pythonfors60/</a></p>
| 1 | 2009-12-21T10:25:24Z | [
"python"
] |
Constructing a python set from a numpy matrix | 1,939,228 | <p>I'm trying to execute the following</p>
<pre><code>>> from numpy import *
>> x = array([[3,2,3],[4,4,4]])
>> y = set(x)
TypeError: unhashable type: 'numpy.ndarray'
</code></pre>
<p>How can I easily and efficiently create a set from a numpy array?</p>
| 10 | 2009-12-21T10:02:03Z | 1,939,241 | <p>The immutable counterpart to an array is the tuple, hence, try convert the array of arrays into an array of tuples:</p>
<pre><code>>> from numpy import *
>> x = array([[3,2,3],[4,4,4]])
>> x_hashable = map(tuple, x)
>> y = set(x_hashable)
set([(3, 2, 3), (4, 4, 4)])
</code></pre>
| 7 | 2009-12-21T10:06:42Z | [
"python",
"arrays",
"numpy",
"set"
] |
Constructing a python set from a numpy matrix | 1,939,228 | <p>I'm trying to execute the following</p>
<pre><code>>> from numpy import *
>> x = array([[3,2,3],[4,4,4]])
>> y = set(x)
TypeError: unhashable type: 'numpy.ndarray'
</code></pre>
<p>How can I easily and efficiently create a set from a numpy array?</p>
| 10 | 2009-12-21T10:02:03Z | 1,939,258 | <p>If you want a set of the elements:</p>
<pre><code>>> y = set(e for r in x
for e in r)
set([2, 3, 4])
</code></pre>
<p>For a set of the rows:</p>
<pre><code>>> y = set(tuple(r) for r in x)
set([(3, 2, 3), (4, 4, 4)])
</code></pre>
| 3 | 2009-12-21T10:09:33Z | [
"python",
"arrays",
"numpy",
"set"
] |
Constructing a python set from a numpy matrix | 1,939,228 | <p>I'm trying to execute the following</p>
<pre><code>>> from numpy import *
>> x = array([[3,2,3],[4,4,4]])
>> y = set(x)
TypeError: unhashable type: 'numpy.ndarray'
</code></pre>
<p>How can I easily and efficiently create a set from a numpy array?</p>
| 10 | 2009-12-21T10:02:03Z | 1,939,362 | <p>If you want a set of the elements, here is another, probably faster way:</p>
<pre><code>y = set(x.flatten())
</code></pre>
<p>PS: after performing comparisons between <code>x.flat</code>, <code>x.flatten()</code>, and <code>x.ravel()</code> on a 10x100 array, I found out that they all perform at about the same spe... | 13 | 2009-12-21T10:31:18Z | [
"python",
"arrays",
"numpy",
"set"
] |
Constructing a python set from a numpy matrix | 1,939,228 | <p>I'm trying to execute the following</p>
<pre><code>>> from numpy import *
>> x = array([[3,2,3],[4,4,4]])
>> y = set(x)
TypeError: unhashable type: 'numpy.ndarray'
</code></pre>
<p>How can I easily and efficiently create a set from a numpy array?</p>
| 10 | 2009-12-21T10:02:03Z | 5,173,201 | <p>The above answers work if you want to create a set out of the <em>elements</em> contained in an <code>ndarray</code>, but if you want to create a set of <code>ndarray</code> objects â or use <code>ndarray</code> objects as keys in a dictionary â then you'll have to provide a hashable wrapper for them. See the co... | 4 | 2011-03-02T20:44:14Z | [
"python",
"arrays",
"numpy",
"set"
] |
Variables in python os.path | 1,939,496 | <p>I am new to python and I'm trying to create a program that creates a directory with todays date, create a sandbox into that directory and run the make file in the sandbox. I am having trouble getting the variables to be picked up in the os.path lines. The code is posted below:</p>
<pre><code>#!/usr/bin/python
imp... | 0 | 2009-12-21T11:10:35Z | 1,939,546 | <p>I think you want to change a few things:</p>
<pre><code>def makeSandbox():
sbdir = os.path.join('/home/build/test/sandboxes/',todaystr)
if not os.path.exists(sbdir):
os.mkdir(sbdir) # <- fully qualified path
else:
pass
</code></pre>
<p>And I don't really see what variables need to be picked u... | 1 | 2009-12-21T11:21:37Z | [
"python"
] |
Variables in python os.path | 1,939,496 | <p>I am new to python and I'm trying to create a program that creates a directory with todays date, create a sandbox into that directory and run the make file in the sandbox. I am having trouble getting the variables to be picked up in the os.path lines. The code is posted below:</p>
<pre><code>#!/usr/bin/python
imp... | 0 | 2009-12-21T11:10:35Z | 1,939,555 | <p>Not sure what the module mks_function does. But I see one issue with your code. </p>
<p>For example,</p>
<p><code></p>
<pre><code>if not os.path.exists('/home/build/test/sandboxes/'+todaystr):
os.mkdir(todaystr)
</code></pre>
<p></code></p>
<p>In the above chunk you check if the directory "/home/build/tes... | 0 | 2009-12-21T11:24:11Z | [
"python"
] |
Variables in python os.path | 1,939,496 | <p>I am new to python and I'm trying to create a program that creates a directory with todays date, create a sandbox into that directory and run the make file in the sandbox. I am having trouble getting the variables to be picked up in the os.path lines. The code is posted below:</p>
<pre><code>#!/usr/bin/python
imp... | 0 | 2009-12-21T11:10:35Z | 1,939,558 | <p>Please try adding chdir code before you call make</p>
<pre><code>if os.path.exists('/home/build/test/sandboxes/'+todaystr+'/new_sandbox/Makefile'):
os.chdir('/home/build/test/sandboxes/'+todaystr+'/new_sandbox/')
os.system("make >make_results.txt 2>&1")
</code></pre>
| 0 | 2009-12-21T11:24:44Z | [
"python"
] |
Variables in python os.path | 1,939,496 | <p>I am new to python and I'm trying to create a program that creates a directory with todays date, create a sandbox into that directory and run the make file in the sandbox. I am having trouble getting the variables to be picked up in the os.path lines. The code is posted below:</p>
<pre><code>#!/usr/bin/python
imp... | 0 | 2009-12-21T11:10:35Z | 1,939,564 | <p>a couple of notes: </p>
<pre><code>#!/usr/bin/env python
# import mks_function .. you won't need this ...
from mks_function import mks_create_sandbox
import os, datetime
# import time, sys .. these aren't used in this snippet
# import os.path .. just refer to os.path, since os is already imported
# get to... | 2 | 2009-12-21T11:25:59Z | [
"python"
] |
Variables in python os.path | 1,939,496 | <p>I am new to python and I'm trying to create a program that creates a directory with todays date, create a sandbox into that directory and run the make file in the sandbox. I am having trouble getting the variables to be picked up in the os.path lines. The code is posted below:</p>
<pre><code>#!/usr/bin/python
imp... | 0 | 2009-12-21T11:10:35Z | 1,939,728 | <p><a href="http://pypi.python.org/pypi/path.py/2.2" rel="nofollow"><code>path</code></a> module might help in this case:</p>
<pre><code>#!/usr/bin/env python
from mks_function import mks_create_sandbox
import os, datetime
from path import path
sandboxes = path('/home/build/test/sandboxes/')
today = sandboxes ... | 0 | 2009-12-21T12:00:46Z | [
"python"
] |
Dynamically import class by name for static access | 1,939,622 | <p>I am generating class names dynamically and then want to import that class by its name to access a static method.</p>
<p>This is the class to import in "the_module.py":</p>
<pre><code>class ToImport(object):
@classmethod
def initialize(cls, parameter):
print parameter
</code></pre>
<p>According t... | 0 | 2009-12-21T11:39:14Z | 1,939,885 | <p>I have done exactly what you did and I retrieved the class.</p>
<pre><code>In [1]: theModule = __import__("the_module")
In [2]: toImport = getattr(theModule, "ToImport")
In [3]: toImport.initialize("parameter")
parameter
</code></pre>
<p>I am using Python 2.6.4. Could you explain further, what exactly doesn't wo... | 2 | 2009-12-21T12:39:40Z | [
"python",
"class",
"import"
] |
Python sorts "u11-Phrase 1000.wav" before "u11-Phrase 101.wav"; how can I overcome this? | 1,940,056 | <p>I'm running Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32</p>
<p>When I'm asking Python</p>
<pre><code>>>> "u11-Phrase 099.wav" < "u11-Phrase 1000.wav"
True
</code></pre>
<p>That's fine. When I ask</p>
<pre><code>>>> "u11-Phrase 100.wav" < "u11-Phra... | 6 | 2009-12-21T13:17:45Z | 1,940,088 | <p>You are looking for <a href="http://nedbatchelder.com/blog/200712/human%5Fsorting.html">human sorting</a>.</p>
<p>The reason 101.wav is not less than 1000.wav is that computers (not just Python) sort strings character by character, and the first difference between these two strings is where the first string has a '... | 16 | 2009-12-21T13:23:39Z | [
"python",
"sorting"
] |
Python sorts "u11-Phrase 1000.wav" before "u11-Phrase 101.wav"; how can I overcome this? | 1,940,056 | <p>I'm running Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32</p>
<p>When I'm asking Python</p>
<pre><code>>>> "u11-Phrase 099.wav" < "u11-Phrase 1000.wav"
True
</code></pre>
<p>That's fine. When I ask</p>
<pre><code>>>> "u11-Phrase 100.wav" < "u11-Phra... | 6 | 2009-12-21T13:17:45Z | 1,940,105 | <p>You need to construct a proper sort key for each filename. Something like this should do what you want:</p>
<pre><code>import re
def k(s):
return [w.isdigit() and int(w) or w for w in re.split(r'(\d+)', s)]
files = ["u11-Phrase 099.wav", "u11-Phrase 1000.wav", "u11-Phrase 100.wav"]
print files
print sorted(f... | 9 | 2009-12-21T13:29:23Z | [
"python",
"sorting"
] |
Run XBMC plugins in a .net application | 1,940,150 | <p>Is there any way to use xbmc plugins in .net? im thinking about those plugins that provide access to media content like GameTrailers and stuff like that..</p>
| 2 | 2009-12-21T13:40:54Z | 1,940,200 | <p>I believe the plugin system is based on Python. You may be able to use IronPython to run some of the plugins in XBMC, although it may not be 100% compatible. You could also take the Python code and create a COM server object in which you could use .NET interop to interface with it.</p>
| 1 | 2009-12-21T13:51:50Z | [
".net",
"python",
"xbmc"
] |
Interactive mode in matplolib | 1,940,387 | <p>I want to dynamically update the scatter plot based on the y-axis data received from a socket connection. I used python matplot lib in interactive mode to do this, but during dynamic updation if i move the window to a different location or minimize the window then the plot updation stops abruptly. Please let me know... | 7 | 2009-12-21T14:23:23Z | 1,940,735 | <p>For this to work, you need to have a main loop for event handling, and your own event handler to redraw the plot when the window is resized or refreshed.</p>
<p>You'll find many examples for this on the web, or in the tutorials.</p>
<p>I think this is best handled by using a UI toolkit (e.g. <a href="http://www.wx... | 1 | 2009-12-21T15:27:25Z | [
"python",
"matplotlib"
] |
Interactive mode in matplolib | 1,940,387 | <p>I want to dynamically update the scatter plot based on the y-axis data received from a socket connection. I used python matplot lib in interactive mode to do this, but during dynamic updation if i move the window to a different location or minimize the window then the plot updation stops abruptly. Please let me know... | 7 | 2009-12-21T14:23:23Z | 1,940,941 | <p><a href="http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/" rel="nofollow">This page</a> contains a couple of examples of dynamic plots with matplotlib and wxPython. And <a href="http://eli.thegreenplace.net/2009/01/20/matplotlib-with-pyqt-guis/" rel="nofollow">here</a> is a version with PyQt.</... | 3 | 2009-12-21T16:01:22Z | [
"python",
"matplotlib"
] |
Python: Synchronize Input and Output Between Threads | 1,940,423 | <p>Currently, I am trying to do a small project with sockets in Python, a two-user chatting system.</p>
<pre><code>import socket
import threading
#Callback. Print doesn't work across threads
def data_recieved(data):
print data
#Thread class to gather input
class socket_read(threading.Thread):
sock = object
... | 3 | 2009-12-21T14:31:39Z | 1,940,550 | <p>What you have here is not so much a synchronization issue as it is a presentation/UI issue. I would suggest making your life easier and picking some UI toolkit (curses, wxPython, pyqt) to handle interaction with the user. Using input() is very handy for quick-and-dirty one-off code, but it is not very sophisticated.... | 1 | 2009-12-21T14:55:13Z | [
"python",
"input",
"multithreading"
] |
Python: Synchronize Input and Output Between Threads | 1,940,423 | <p>Currently, I am trying to do a small project with sockets in Python, a two-user chatting system.</p>
<pre><code>import socket
import threading
#Callback. Print doesn't work across threads
def data_recieved(data):
print data
#Thread class to gather input
class socket_read(threading.Thread):
sock = object
... | 3 | 2009-12-21T14:31:39Z | 1,940,679 | <p>Alright, sorry for such a quick answer to my own question, but callbacks are MAGICAL when using threading (at least on Linux's model).</p>
<p>Anyhow, did this:</p>
<pre><code>import socket
import threading
def msg_loop(socket):
msg = ""
if (server == True):
reader = socket_read(channel)
else:
... | 1 | 2009-12-21T15:16:45Z | [
"python",
"input",
"multithreading"
] |
Changing properties of inherited field | 1,940,459 | <p>I want to alter properties of a model field inherited from a base class. The way I try this below does not seem to have any effect. Any ideas? </p>
<pre><code>def __init__(self, *args, **kwargs):
super(SomeModel, self).__init__(*args, **kwargs)
f = self._meta.get_field('some_field')
f.blank = True
f.help_text =... | 2 | 2009-12-21T14:38:56Z | 1,943,464 | <p>OK, that's simply not possible, here is why:</p>
<p><a href="http://docs.djangoproject.com/en/1.1/topics/db/models/#field-name-hiding-is-not-permitted" rel="nofollow">http://docs.djangoproject.com/en/1.1/topics/db/models/#field-name-hiding-is-not-permitted</a></p>
<p><strong>EDIT:</strong>
And by the way: don't tr... | 0 | 2009-12-22T00:17:00Z | [
"python",
"django",
"django-models"
] |
Changing properties of inherited field | 1,940,459 | <p>I want to alter properties of a model field inherited from a base class. The way I try this below does not seem to have any effect. Any ideas? </p>
<pre><code>def __init__(self, *args, **kwargs):
super(SomeModel, self).__init__(*args, **kwargs)
f = self._meta.get_field('some_field')
f.blank = True
f.help_text =... | 2 | 2009-12-21T14:38:56Z | 1,954,300 | <p>So.. You need to change blank and help_text attributes.. And I assume that you want this feature just so the help_text is displayed in forms, and form does not raise "this field is required"</p>
<p>So do this in forms:</p>
<pre><code>class MyForm(ModelForm):
class Meta:
model = YourModel
some_field = ... | 3 | 2009-12-23T17:47:54Z | [
"python",
"django",
"django-models"
] |
Django index page best/most common practice | 1,940,528 | <p>I am working on a site currently (first one solo) and went to go make an index page. I have been attempting to follow django best practices as I go, so naturally I go search for this but couldn't a real standard in regards to this.</p>
<p>I have seen folks creating apps to serve this purpose named various things (m... | 20 | 2009-12-21T14:51:08Z | 1,940,720 | <p>If all of your dynamic content is handled in the template (for example, if it's just simple checking if a user is present on the request), then I recommend using a generic view, specificially the <a href="http://docs.djangoproject.com/en/1.1/ref/generic-views/#django-views-generic-simple-direct-to-template">direct t... | 19 | 2009-12-21T15:24:57Z | [
"python",
"django",
"indexing"
] |
Django index page best/most common practice | 1,940,528 | <p>I am working on a site currently (first one solo) and went to go make an index page. I have been attempting to follow django best practices as I go, so naturally I go search for this but couldn't a real standard in regards to this.</p>
<p>I have seen folks creating apps to serve this purpose named various things (m... | 20 | 2009-12-21T14:51:08Z | 1,940,751 | <p>I tend to create a <code>views.py</code> in the root of the project where I keep the <code>index</code> view.</p>
| 3 | 2009-12-21T15:29:22Z | [
"python",
"django",
"indexing"
] |
WindowsError: [Error 126] The specified module could not be found | 1,940,578 | <p>I am loading a dll in python using following code:</p>
<pre><code>if os.path.exists(dll_path):
my_dll = ctypes.cdll.LoadLibrary(dll_path)
</code></pre>
<p>But I am continuously getting the following error</p>
<p><strong>WindowsError: [Error 126] The specified module could not be found</strong></p>
<p>dll is... | 7 | 2009-12-21T14:59:12Z | 1,944,889 | <p>Check your dll name.. it must not contain any uppercase letter ..
it must have all lowercase characters to compile successfully </p>
| -3 | 2009-12-22T08:17:08Z | [
"python",
"ctypes"
] |
WindowsError: [Error 126] The specified module could not be found | 1,940,578 | <p>I am loading a dll in python using following code:</p>
<pre><code>if os.path.exists(dll_path):
my_dll = ctypes.cdll.LoadLibrary(dll_path)
</code></pre>
<p>But I am continuously getting the following error</p>
<p><strong>WindowsError: [Error 126] The specified module could not be found</strong></p>
<p>dll is... | 7 | 2009-12-21T14:59:12Z | 6,087,086 | <p>When I see things like this - it is usually because there are backslashes in the path which get converted.</p>
<p>For example - the following will fail - because \t in the string is converted to TAB character.</p>
<pre><code>>>> import ctypes
>>> ctypes.windll.LoadLibrary("c:\tools\depends\depend... | 8 | 2011-05-22T09:31:06Z | [
"python",
"ctypes"
] |
WindowsError: [Error 126] The specified module could not be found | 1,940,578 | <p>I am loading a dll in python using following code:</p>
<pre><code>if os.path.exists(dll_path):
my_dll = ctypes.cdll.LoadLibrary(dll_path)
</code></pre>
<p>But I am continuously getting the following error</p>
<p><strong>WindowsError: [Error 126] The specified module could not be found</strong></p>
<p>dll is... | 7 | 2009-12-21T14:59:12Z | 15,273,047 | <p>Also this could be that you have forgotten to set your working directory in eclipse to be the correct local for the application to run in.</p>
| 0 | 2013-03-07T13:56:22Z | [
"python",
"ctypes"
] |
WindowsError: [Error 126] The specified module could not be found | 1,940,578 | <p>I am loading a dll in python using following code:</p>
<pre><code>if os.path.exists(dll_path):
my_dll = ctypes.cdll.LoadLibrary(dll_path)
</code></pre>
<p>But I am continuously getting the following error</p>
<p><strong>WindowsError: [Error 126] The specified module could not be found</strong></p>
<p>dll is... | 7 | 2009-12-21T14:59:12Z | 25,492,172 | <p>Note that even if the DLL is in your path. If that DLL relies on other DLLs that are NOT in your path, you can get the same error. Windows could not find a dependency in this case. Windows is not real good at telling you what it could not find, only that it did not find something. It is up to you to figure that out.... | 8 | 2014-08-25T18:28:40Z | [
"python",
"ctypes"
] |
Syntax quirks or why is that valid python | 1,940,710 | <p>In python 2.6, why is the following line valid?</p>
<pre><code>my_line = 'foo' 'bar'
</code></pre>
<p>and if that is valid, why isn't the following:</p>
<pre><code>my_list = 1 2
</code></pre>
<p>The first example is string concatenation, however, the following isn't valid either (thanks god):</p>
<pre><code>foo... | 7 | 2009-12-21T15:23:16Z | 1,940,715 | <p><code>my_line = 'foo' 'bar'</code> is string concatenation.</p>
| 8 | 2009-12-21T15:24:16Z | [
"python",
"syntax"
] |
Syntax quirks or why is that valid python | 1,940,710 | <p>In python 2.6, why is the following line valid?</p>
<pre><code>my_line = 'foo' 'bar'
</code></pre>
<p>and if that is valid, why isn't the following:</p>
<pre><code>my_list = 1 2
</code></pre>
<p>The first example is string concatenation, however, the following isn't valid either (thanks god):</p>
<pre><code>foo... | 7 | 2009-12-21T15:23:16Z | 1,940,793 | <p>This is doing <a href="http://docs.python.org/reference/lexical%5Fanalysis.html#string-literal-concatenation">string literal concatenation</a>. As noted in the documentation, advantages include the following:</p>
<blockquote>
<p>This feature can be used to reduce the
number of backslashes needed, to split
lo... | 20 | 2009-12-21T15:36:25Z | [
"python",
"syntax"
] |
Syntax quirks or why is that valid python | 1,940,710 | <p>In python 2.6, why is the following line valid?</p>
<pre><code>my_line = 'foo' 'bar'
</code></pre>
<p>and if that is valid, why isn't the following:</p>
<pre><code>my_list = 1 2
</code></pre>
<p>The first example is string concatenation, however, the following isn't valid either (thanks god):</p>
<pre><code>foo... | 7 | 2009-12-21T15:23:16Z | 1,940,908 | <p>It isn't inconsistent. Strings and integers have different methods. </p>
<p>Integer concatenation is meaningless. </p>
<p>String concatenation is a meaningful default behavior. </p>
| 5 | 2009-12-21T15:56:56Z | [
"python",
"syntax"
] |
Syntax quirks or why is that valid python | 1,940,710 | <p>In python 2.6, why is the following line valid?</p>
<pre><code>my_line = 'foo' 'bar'
</code></pre>
<p>and if that is valid, why isn't the following:</p>
<pre><code>my_list = 1 2
</code></pre>
<p>The first example is string concatenation, however, the following isn't valid either (thanks god):</p>
<pre><code>foo... | 7 | 2009-12-21T15:23:16Z | 1,940,948 | <p>Perhaps this is of C's ancestry. In C, the following is perfectly valid:</p>
<pre><code>char* ptr = "hello " "world";
</code></pre>
<p>It is implemented by the C <a href="http://en.wikipedia.org/wiki/C%5Fsyntax#String%5Fliteral%5Fconcatenation">pre-processor (cpp)</a>, and the rationale given in that link is:</p>
... | 6 | 2009-12-21T16:02:56Z | [
"python",
"syntax"
] |
How does/should global data in modules across packages be managed in Python/other languages? | 1,940,934 | <p>I am trying to design the package and module system for a programming language (<a href="http://heron-language.googlecode.com" rel="nofollow">Heron</a>) which can be both compiled and interpreted, and from what I have seen I really like the Python approach. Python has a rich choice of modules, which seems to contrib... | 1 | 2009-12-21T16:00:34Z | 1,940,981 | <p>Global data is scoped at the interpreter level.</p>
<ol>
<li>"packages" can be compiled as a package is just a collection of modules which themselves can be compiled.</li>
<li>I am not sure I understand given the established scoping of data.</li>
</ol>
| 1 | 2009-12-21T16:08:18Z | [
"python",
"namespaces",
"module",
"language-design",
"package"
] |
How does/should global data in modules across packages be managed in Python/other languages? | 1,940,934 | <p>I am trying to design the package and module system for a programming language (<a href="http://heron-language.googlecode.com" rel="nofollow">Heron</a>) which can be both compiled and interpreted, and from what I have seen I really like the Python approach. Python has a rich choice of modules, which seems to contrib... | 1 | 2009-12-21T16:00:34Z | 1,941,144 | <p>Well, you asked a lot of questions. Here are some hints to get a bit further:</p>
<ol>
<li><p>a. Python code is lexed and compiled into Python specific instructions, but not compiled to machine executable code. The ".pyc" file is automatically created whenever you run python code that does not match the existin... | 3 | 2009-12-21T16:35:11Z | [
"python",
"namespaces",
"module",
"language-design",
"package"
] |
How does/should global data in modules across packages be managed in Python/other languages? | 1,940,934 | <p>I am trying to design the package and module system for a programming language (<a href="http://heron-language.googlecode.com" rel="nofollow">Heron</a>) which can be both compiled and interpreted, and from what I have seen I really like the Python approach. Python has a rich choice of modules, which seems to contrib... | 1 | 2009-12-21T16:00:34Z | 1,941,475 | <p>Modules are the only truly global objects in Python, with all other global data based around the module system (which uses sys.modules as a registry). Packages are simply modules with special semantics for importing submodules. "Compiling" a .py file into a .pyc or .pyo isn't compilation as understood for most lan... | 3 | 2009-12-21T17:32:07Z | [
"python",
"namespaces",
"module",
"language-design",
"package"
] |
howto scroll a gtk.scrolledwindow object from python code | 1,940,957 | <p>I'm writing a python application that has a glade gui. Using subprocess to execute some shell commands in the background.</p>
<p>Using a glade GUI which has a scrolledwindow widget and a textview widget inside the scrolledwindow widget. The textview gets populated as the subprocess.Popen object run and display thei... | 2 | 2009-12-21T16:03:53Z | 1,941,087 | <p>You need to get the horizontal and/or vertical gtk.Adjustment from the scrolledwindow, and change its values. See </p>
<ul>
<li><a href="http://library.gnome.org/devel/pygtk/stable/class-gtkscrolledwindow.html#method-gtkscrolledwindow--get-vadjustment" rel="nofollow">get_vadjustment</a></li>
<li><a href="http://lib... | 2 | 2009-12-21T16:25:57Z | [
"python",
"pygtk",
"subprocess",
"glade"
] |
howto scroll a gtk.scrolledwindow object from python code | 1,940,957 | <p>I'm writing a python application that has a glade gui. Using subprocess to execute some shell commands in the background.</p>
<p>Using a glade GUI which has a scrolledwindow widget and a textview widget inside the scrolledwindow widget. The textview gets populated as the subprocess.Popen object run and display thei... | 2 | 2009-12-21T16:03:53Z | 1,941,109 | <p>look at <code>gtk.ScrolledWindow.set_placement</code>.</p>
<p>(never tried)</p>
| 0 | 2009-12-21T16:29:51Z | [
"python",
"pygtk",
"subprocess",
"glade"
] |
howto scroll a gtk.scrolledwindow object from python code | 1,940,957 | <p>I'm writing a python application that has a glade gui. Using subprocess to execute some shell commands in the background.</p>
<p>Using a glade GUI which has a scrolledwindow widget and a textview widget inside the scrolledwindow widget. The textview gets populated as the subprocess.Popen object run and display thei... | 2 | 2009-12-21T16:03:53Z | 3,025,771 | <p>This is probably what you are looking for.</p>
<p><a href="http://faq.pygtk.org/index.py?req=show&file=faq14.010.htp" rel="nofollow">http://faq.pygtk.org/index.py?req=show&file=faq14.010.htp</a></p>
| 1 | 2010-06-11T19:52:12Z | [
"python",
"pygtk",
"subprocess",
"glade"
] |
Upper limit in Python time.sleep()? | 1,941,177 | <p>Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms.</p>
| 2 | 2009-12-21T16:39:12Z | 1,941,215 | <p>The spec says:</p>
<blockquote>
<p>Suspend execution for the given number
of seconds. The argument may be a
floating point number to indicate a
more precise sleep time. The actual
suspension time may be less than that
requested because any caught signal
will terminate the sleep() following
execution... | 1 | 2009-12-21T16:44:50Z | [
"python",
"time",
"limit",
"sleep"
] |
Upper limit in Python time.sleep()? | 1,941,177 | <p>Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms.</p>
| 2 | 2009-12-21T16:39:12Z | 1,941,216 | <p>I suppose the longer the time the more probable <a href="http://docs.python.org/library/time.html#time.sleep" rel="nofollow">situation described in the docs</a>:</p>
<blockquote>
<p>The actual suspension time may be less than that requested because any caught signal will terminate the <code>sleep()</code> follow... | 5 | 2009-12-21T16:44:54Z | [
"python",
"time",
"limit",
"sleep"
] |
Upper limit in Python time.sleep()? | 1,941,177 | <p>Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms.</p>
| 2 | 2009-12-21T16:39:12Z | 1,941,273 | <p>According to the documentation, time.sleep accepts any non-zero number [1], as you probably know. However you are under the influence of your operating systems scheduler as well [1].</p>
<p>[1] <a href="http://docs.python.org/library/time.html" rel="nofollow">http://docs.python.org/library/time.html</a></p>
| 1 | 2009-12-21T16:53:54Z | [
"python",
"time",
"limit",
"sleep"
] |
Upper limit in Python time.sleep()? | 1,941,177 | <p>Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms.</p>
| 2 | 2009-12-21T16:39:12Z | 1,941,355 | <p>you can prevent possible issues by putting the sleep with short delay into the loop:</p>
<pre><code>def sleep(n):
for i in xrange(n):
time.sleep(1)
</code></pre>
| 1 | 2009-12-21T17:07:42Z | [
"python",
"time",
"limit",
"sleep"
] |
Upper limit in Python time.sleep()? | 1,941,177 | <p>Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms.</p>
| 2 | 2009-12-21T16:39:12Z | 1,941,697 | <p>Others have explained why you might sleep for less than you asked for, but didn't show you how to deal with this. If you need to make sure you sleep for at least n seconds you can use code like:</p>
<pre><code>from time import time, sleep
def trusty_sleep(n):
start = time()
while (time() - start < n):
... | 7 | 2009-12-21T18:14:01Z | [
"python",
"time",
"limit",
"sleep"
] |
Redirect with additional variables | 1,941,362 | <p>I have view which in some cases redirects user to another addres.
How can I redirect user, with additional variables (not GET, beacause that variable can be long text)?
Currently I'm using HttpResponseRedirect.</p>
<p>Cheers.</p>
| 0 | 2009-12-21T17:08:52Z | 1,941,366 | <p>You can't force a POST on redirect. Perhaps your best option is to store the variables in <code>request.session</code>, and then check for the presence of these variables in the view handler for the redirected URL.</p>
<p>Here's some more info on <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/#t... | 7 | 2009-12-21T17:10:38Z | [
"python",
"django"
] |
Is there a python hamcrest matcher library for performing XML document matching? | 1,941,431 | <p>I'm interested in both xpath matching and full document comparisons:</p>
<pre><code>assert_that(mydoc, hasTextAtXPath('/foo/bar', 'text'))
assert_that(mydoc, matchesStructurally('<some_xml/>'))
</code></pre>
<p>Does any matcher library exist for this? If not, what is the best place to start with for this t... | 0 | 2009-12-21T17:23:24Z | 1,964,835 | <p>lxml has XPath matching: <a href="http://codespeak.net/lxml/" rel="nofollow">http://codespeak.net/lxml/</a></p>
| 0 | 2009-12-27T01:09:33Z | [
"python",
"xml",
"unit-testing",
"xpath",
"hamcrest"
] |
Is there a python hamcrest matcher library for performing XML document matching? | 1,941,431 | <p>I'm interested in both xpath matching and full document comparisons:</p>
<pre><code>assert_that(mydoc, hasTextAtXPath('/foo/bar', 'text'))
assert_that(mydoc, matchesStructurally('<some_xml/>'))
</code></pre>
<p>Does any matcher library exist for this? If not, what is the best place to start with for this t... | 0 | 2009-12-21T17:23:24Z | 2,032,238 | <p>There is a <a href="http://code.google.com/p/hamcrest/source/browse/#svn/trunk/hamcrest-python" rel="nofollow">Python version of Hamcrest</a>. It does not currently provide XML matchers. I'd be happy to work on some if you define what you need.</p>
| 0 | 2010-01-09T03:25:36Z | [
"python",
"xml",
"unit-testing",
"xpath",
"hamcrest"
] |
Why does Django throw an exception whenever I enable admin.autodiscover()? | 1,941,511 | <p>Here is my setup. I am using Django version 1.1.1 on Dreamhost, Python 2.4. The problem I am having is whenever I create a simple app and also have admin.autodiscover() enabled, Django will throw an exception. My setup:</p>
<pre><code>from django.conf.urls.defaults import *
from testapp.views import HelloWorld
fro... | 0 | 2009-12-21T17:37:28Z | 1,941,725 | <p>I'm going to guess that testapp/admin.py does not import the models.Model class you are creating admin for. Try the following:</p>
<pre><code>./manage.py shell # you may immediately get a stack trace
>> import testapp.admin # I'll bet it blows up.
</code></pre>
| 1 | 2009-12-21T18:18:07Z | [
"python",
"django",
"django-models",
"dreamhost"
] |
Why does Django throw an exception whenever I enable admin.autodiscover()? | 1,941,511 | <p>Here is my setup. I am using Django version 1.1.1 on Dreamhost, Python 2.4. The problem I am having is whenever I create a simple app and also have admin.autodiscover() enabled, Django will throw an exception. My setup:</p>
<pre><code>from django.conf.urls.defaults import *
from testapp.views import HelloWorld
fro... | 0 | 2009-12-21T17:37:28Z | 11,605,057 | <p>I've had a similar issue when I've renamed an app. Basically, if you've launched the app and used the admin using <code>admin.autodiscover()</code> in your <code>urls.py</code> file, it will cause an <code>admin.pyc</code> file to be created in your app folder. Delete this <code>admin.pyc</code> file and run the ser... | 4 | 2012-07-23T00:10:57Z | [
"python",
"django",
"django-models",
"dreamhost"
] |
Why does Django throw an exception whenever I enable admin.autodiscover()? | 1,941,511 | <p>Here is my setup. I am using Django version 1.1.1 on Dreamhost, Python 2.4. The problem I am having is whenever I create a simple app and also have admin.autodiscover() enabled, Django will throw an exception. My setup:</p>
<pre><code>from django.conf.urls.defaults import *
from testapp.views import HelloWorld
fro... | 0 | 2009-12-21T17:37:28Z | 38,238,473 | <p>Old question, but still relevant. I had a similar problem that stumped me today. The issue was that I had refactored a set of files in a directory within a Django app folder (<code>lib/cache</code>) into a single file (<code>lib/cache.py</code>). Because there was still an <code>__init__.py</code> in the <code>cache... | 0 | 2016-07-07T06:02:29Z | [
"python",
"django",
"django-models",
"dreamhost"
] |
Python, Huge Iteration Performance Problem | 1,941,712 | <p>I'm doing an iteration through 3 words, each about 5 million characters long, and I want to find sequences of 20 characters that identifies each word. That is, I want to find all sequences of length 20 in one word that is unique for that word. My problem is that the code I've written takes an extremely long time to ... | 9 | 2009-12-21T18:16:07Z | 1,941,852 | <pre><code>def slices(seq, length, prefer_last=False):
unique = {}
if prefer_last: # this doesn't have to be a parameter, just choose one
for start in xrange(len(seq) - length + 1):
unique[seq[start:start+length]] = start
else: # prefer first
for start in xrange(len(seq) - length, -1, -1):
uni... | 10 | 2009-12-21T18:42:06Z | [
"python",
"iteration",
"bioinformatics"
] |
Python, Huge Iteration Performance Problem | 1,941,712 | <p>I'm doing an iteration through 3 words, each about 5 million characters long, and I want to find sequences of 20 characters that identifies each word. That is, I want to find all sequences of length 20 in one word that is unique for that word. My problem is that the code I've written takes an extremely long time to ... | 9 | 2009-12-21T18:16:07Z | 1,946,878 | <p>You say you have a "word" 5 million characters long, but I find it hard to believe this is a word in the usual sense.</p>
<p>If you can provide more information about your input data, a specific solution might be available.</p>
<p>For example, English text (or any other written language) might be sufficiently repe... | 0 | 2009-12-22T14:56:16Z | [
"python",
"iteration",
"bioinformatics"
] |
Python, Huge Iteration Performance Problem | 1,941,712 | <p>I'm doing an iteration through 3 words, each about 5 million characters long, and I want to find sequences of 20 characters that identifies each word. That is, I want to find all sequences of length 20 in one word that is unique for that word. My problem is that the code I've written takes an extremely long time to ... | 9 | 2009-12-21T18:16:07Z | 1,949,444 | <p>Let me build off <a href="http://stackoverflow.com/questions/1941712/python-huge-iteration-performance-problem/1941852#1941852">Roger Pate's answer</a>. If memory is an issue, I'd suggest instead of using the strings as the keys to the dictionary, you could use a hashed value of the string. This would save the cos... | 0 | 2009-12-22T21:53:46Z | [
"python",
"iteration",
"bioinformatics"
] |
Python, Huge Iteration Performance Problem | 1,941,712 | <p>I'm doing an iteration through 3 words, each about 5 million characters long, and I want to find sequences of 20 characters that identifies each word. That is, I want to find all sequences of length 20 in one word that is unique for that word. My problem is that the code I've written takes an extremely long time to ... | 9 | 2009-12-21T18:16:07Z | 1,971,933 | <p>Let's attempt to improve on <a href="http://stackoverflow.com/questions/1941712/python-huge-iteration-performance-problem/1941852#1941852">Roger Pate's excellent answer</a>.</p>
<p>Firstly, let's keep sets instead of dictionaries - they manage uniqueness anyway.</p>
<p>Secondly, since we are likely to run out of m... | 0 | 2009-12-28T22:39:47Z | [
"python",
"iteration",
"bioinformatics"
] |
How can I debug a problem calling Python's copy.deepcopy() against a custom type? | 1,941,887 | <p>In my code I'm trying to take copies of instances a class using <code>copy.deepcopy</code>. The problem is that under some circumstances it is erroring with the following error:</p>
<pre><code>TypeError: 'object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__()'
</code></pre>
<p>After much... | 4 | 2009-12-21T18:50:12Z | 1,943,416 | <p>you could override the __deepcopy__ method: (<a href="http://docs.python.org/library/copy.html" rel="nofollow">python documentation</a>)</p>
<blockquote>
<p>In order for a class to define its own copy implementation, it can define special methods <strong>__copy__()</strong> and <strong>__deepcopy__()</strong>. Th... | 1 | 2009-12-21T23:59:42Z | [
"python",
"deep-copy"
] |
How can I debug a problem calling Python's copy.deepcopy() against a custom type? | 1,941,887 | <p>In my code I'm trying to take copies of instances a class using <code>copy.deepcopy</code>. The problem is that under some circumstances it is erroring with the following error:</p>
<pre><code>TypeError: 'object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__()'
</code></pre>
<p>After much... | 4 | 2009-12-21T18:50:12Z | 1,945,421 | <p>In the end I did some digging in the <code>copy</code> source code and came up with the following solution:</p>
<pre><code>from copy import deepcopy, _deepcopy_dispatch
from types import ModuleType
class MyType(object):
def __init__(self):
self.module = __builtins__
def copy(self):
''' Pa... | 3 | 2009-12-22T10:13:20Z | [
"python",
"deep-copy"
] |
How can I debug a problem calling Python's copy.deepcopy() against a custom type? | 1,941,887 | <p>In my code I'm trying to take copies of instances a class using <code>copy.deepcopy</code>. The problem is that under some circumstances it is erroring with the following error:</p>
<pre><code>TypeError: 'object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__()'
</code></pre>
<p>After much... | 4 | 2009-12-21T18:50:12Z | 1,954,463 | <p>You can override the deepcopy behavior of the class that contains a pointer to a module, by using the <a href="http://docs.python.org/library/pickle.html#the-pickle-protocol" rel="nofollow">pickle protocol</a>, which is supported by the copy module, as is stated <a href="http://docs.python.org/library/copy.html" rel... | 1 | 2009-12-23T18:18:18Z | [
"python",
"deep-copy"
] |
Creating a new virtualenv results in an error | 1,941,894 | <p>I'm trying to get virtualenv to work on my machine. I'm using python2.6, and after installing pip, and using pip to install virtualenv, running "virtualenv --no-site-packages cyclesg" results in the following:</p>
<pre><code>New python executable in cyclesg/bin/python
Installing setuptools....
Complete output fro... | 2 | 2009-12-21T18:53:09Z | 1,942,253 | <p>Are you on a linux based system? It looks like virtualenv is trying to build a new python exectable but can't find the files to do that. Try installing the <code>python-dev</code> package.</p>
| 0 | 2009-12-21T19:58:12Z | [
"python",
"virtualenv"
] |
Creating a new virtualenv results in an error | 1,941,894 | <p>I'm trying to get virtualenv to work on my machine. I'm using python2.6, and after installing pip, and using pip to install virtualenv, running "virtualenv --no-site-packages cyclesg" results in the following:</p>
<pre><code>New python executable in cyclesg/bin/python
Installing setuptools....
Complete output fro... | 2 | 2009-12-21T18:53:09Z | 1,942,370 | <p>Are you on mandriva?</p>
<p>In order to support multilib (mixing x86/x86_64) Mandriva messes up your python installation. They patched python, which breaks virtualenv; instead of fixing python, they then proceeded to patch virtualenv. This is useless if you are using your own virtualenv installed from pip.</p>
<p>... | 2 | 2009-12-21T20:18:48Z | [
"python",
"virtualenv"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 1,941,957 | <p><a href="http://bugs.python.org/issue15873" rel="nofollow">http://bugs.python.org/issue15873</a> (duplicate of <a href="http://bugs.python.org/issue5207" rel="nofollow">http://bugs.python.org/issue5207</a> )</p>
<p>Looks like there isn't a built-in as of yet.</p>
| 5 | 2009-12-21T19:05:04Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 1,941,968 | <p>No builtin, afaik.</p>
<p><strong>feed.date.rfc3339</strong>
This is a Python library module with functions for converting timestamp strings in RFC 3339 format to Python time float values, and vice versa. RFC 3339 is the timestamp format used by the Atom feed syndication format.</p>
<p>It is BSD-licensed.</p>
<p>... | 9 | 2009-12-21T19:06:26Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 1,942,000 | <p><a href="http://pypi.python.org/pypi/iso8601/">http://pypi.python.org/pypi/iso8601/</a> seems to be able to parse iso 8601, which RFC 3339 is a subset of, maybe this could be useful, but again, not built-in.</p>
| 7 | 2009-12-21T19:13:29Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 1,942,049 | <p>You don't include an example, but if you don't have a Z-offset or timezone, and assuming you don't want durations but just the basic time, then maybe this will suit you:</p>
<pre><code>import datetime as dt
>>> dt.datetime.strptime('1985-04-12T23:20:50.52', '%Y-%m-%dT%H:%M:%S.%f')
datetime.datetime(1985, 4... | 18 | 2009-12-21T19:20:43Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 1,942,888 | <p><a href="http://code.google.com/p/feedparser/" rel="nofollow">feedparser.py</a> provides robust/extensible way to parse various date formats that may be encountered in real-world atom/rss feeds:</p>
<pre><code>>>> from feedparser import _parse_date as parse_date
>>> parse_date('1985-04-12T23:20:50... | 5 | 2009-12-21T21:56:31Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 7,244,206 | <p>rfc3339 library: <a href="http://henry.precheur.org/python/rfc3339" rel="nofollow">http://henry.precheur.org/python/rfc3339</a></p>
| 0 | 2011-08-30T13:46:05Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 12,142,795 | <p>Came across the awesome <a href="http://stackoverflow.com/a/8525115/252556">dateutil.parser</a> module in another question, and tried it on my RFC3339 problem, and it appears to handle everything I throw at it with more sanity that any of the other responses in this question.</p>
| 0 | 2012-08-27T13:20:05Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 32,097,986 | <p>try this, it works fine for me</p>
<pre><code>datetime_obj = datetime.strptime("2014-01-01T00:00:00Z", '%Y-%m-%dT%H:%M:%SZ')
</code></pre>
<p>or</p>
<pre><code>datetime_obj = datetime.strptime("Mon, 01 Jun 2015 16:41:40 GMT", '%a, %d %b %Y %H:%M:%S GMT')
</code></pre>
| 1 | 2015-08-19T14:13:32Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 35,965,084 | <p>I struggled with RFC3339 datetime format a lot, but I found a suitable solution to convert date_string <=> datetime_object in both directions.</p>
<p>You need two different external modules, because one of them is is only able to do the conversion in one direction (unfortunately):</p>
<p>first install:</p>
<pr... | 2 | 2016-03-13T00:30:58Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 37,675,558 | <p>Using Python 3, you can use RegEx to break the RFC 3339 timestamp into its components.
Then, directly create the datetime object, no additional modules needed:</p>
<pre><code>import re
import datetime
def parse_rfc3339(dt):
broken = re.search(r'([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(... | 1 | 2016-06-07T09:31:38Z | [
"python",
"datetime",
"rfc3339"
] |
Convert an RFC 3339 time to a standard Python timestamp | 1,941,927 | <p>Is there an easy way to convert an <a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a> time into a regular Python timestamp?</p>
<p>I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file.</p>
<p>I notice... | 14 | 2009-12-21T19:00:30Z | 39,168,612 | <p>If you're using Django, you could use Django's function <a href="https://docs.djangoproject.com/en/stable/ref/utils/#django.utils.dateparse.parse_datetime" rel="nofollow"><code>parse_datetime</code></a>:</p>
<pre><code>>>> from django.utils.dateparse import parse_datetime
>>> parse_datetime("2016-... | 0 | 2016-08-26T14:25:31Z | [
"python",
"datetime",
"rfc3339"
] |
How to import constants from .h file into python module | 1,942,020 | <p>What is a recommended way to import a bunch of constants defined in a c-style (not c++, just plain old c) .h file into python module so that it can be used in python's part of a project. In the project we use a mix of languages and in perl I can do this importing by using h2xs utility to generate .pm module. </p>
<... | 3 | 2009-12-21T19:16:17Z | 1,942,171 | <p>I once had to do something similar, and in the end I did something strange but highly reliable. Dealing with all the possibilities for how values might be defined is tricky... for instance, you have to handle</p>
<pre><code>#include "someotherfile.h"
enum NewEnum {
A = -5,
B = SOME_OTHER_ENUM,
C,
D = 3... | 1 | 2009-12-21T19:42:06Z | [
"python",
"c"
] |
How to import constants from .h file into python module | 1,942,020 | <p>What is a recommended way to import a bunch of constants defined in a c-style (not c++, just plain old c) .h file into python module so that it can be used in python's part of a project. In the project we use a mix of languages and in perl I can do this importing by using h2xs utility to generate .pm module. </p>
<... | 3 | 2009-12-21T19:16:17Z | 1,943,573 | <p>I recently used the pyparsing library to scan for enum constants. Here it is, along with a sample string and the resulting output. Notice it also handles comments and commented out sections. With a little modification it could stuff the constants in a dictionary.</p>
<pre><code>from pyparsing import *
sample = ... | 3 | 2009-12-22T00:46:19Z | [
"python",
"c"
] |
How to import constants from .h file into python module | 1,942,020 | <p>What is a recommended way to import a bunch of constants defined in a c-style (not c++, just plain old c) .h file into python module so that it can be used in python's part of a project. In the project we use a mix of languages and in perl I can do this importing by using h2xs utility to generate .pm module. </p>
<... | 3 | 2009-12-21T19:16:17Z | 1,977,476 | <p>I'd suggest the other way round, if possible: define all your constants in a Python dict or module and auto-generate the .h in Python. It will be much, much easier.</p>
| 0 | 2009-12-29T23:03:43Z | [
"python",
"c"
] |
How to import constants from .h file into python module | 1,942,020 | <p>What is a recommended way to import a bunch of constants defined in a c-style (not c++, just plain old c) .h file into python module so that it can be used in python's part of a project. In the project we use a mix of languages and in perl I can do this importing by using h2xs utility to generate .pm module. </p>
<... | 3 | 2009-12-21T19:16:17Z | 2,360,032 | <p>Create a script/program that is called from make and creates the necessary python file. If you only need #define and enum it shouldn't be too hard to write. Then remember NOT to check this python file into source control as you want the build process to force the regeneration of the file every time.</p>
| 0 | 2010-03-01T23:58:34Z | [
"python",
"c"
] |
Python 3: create a list of possible ip addresses from a CIDR notation | 1,942,160 | <p>I have been handed the task of creating a function in python (3.1) that will take a CIDR notation and return the list of possible ip addresses. I have looked around python.org and found this:
<a href="http://docs.python.org/dev/py3k/library/ipaddr.html">http://docs.python.org/dev/py3k/library/ipaddr.html</a></p>
<... | 5 | 2009-12-21T19:39:03Z | 1,942,178 | <p>Have you checked out <a href="http://code.google.com/p/python-iptools/" rel="nofollow"><code>iptools</code></a>? It seems to be a fairly good fit.</p>
| 1 | 2009-12-21T19:43:28Z | [
"python",
"subnet",
"cidr"
] |
Python 3: create a list of possible ip addresses from a CIDR notation | 1,942,160 | <p>I have been handed the task of creating a function in python (3.1) that will take a CIDR notation and return the list of possible ip addresses. I have looked around python.org and found this:
<a href="http://docs.python.org/dev/py3k/library/ipaddr.html">http://docs.python.org/dev/py3k/library/ipaddr.html</a></p>
<... | 5 | 2009-12-21T19:39:03Z | 1,942,303 | <p>It's not in the documentation, but browsing the source suggests that <code>ipaddr</code> implements <code>__iter__</code> and <code>iterhosts</code>, which is exactly what you want.</p>
<p><hr></p>
<p>Err, nevermind.</p>
<ol>
<li>It looks like <code>ipaddr.py</code> was added to stdlib in 3.1 beta, but removed by... | 0 | 2009-12-21T20:06:42Z | [
"python",
"subnet",
"cidr"
] |
Python 3: create a list of possible ip addresses from a CIDR notation | 1,942,160 | <p>I have been handed the task of creating a function in python (3.1) that will take a CIDR notation and return the list of possible ip addresses. I have looked around python.org and found this:
<a href="http://docs.python.org/dev/py3k/library/ipaddr.html">http://docs.python.org/dev/py3k/library/ipaddr.html</a></p>
<... | 5 | 2009-12-21T19:39:03Z | 1,942,848 | <p>If you aren't married to using the built-in module, there is a project called <a href="http://code.google.com/p/netaddr/">netaddr</a> that is the best module I have used for working with IP networks.</p>
<p>Have a look at the <a href="http://code.google.com/p/netaddr/wiki/IPTutorial">IP Tutorial</a> which illustrat... | 15 | 2009-12-21T21:50:12Z | [
"python",
"subnet",
"cidr"
] |
Python 3: create a list of possible ip addresses from a CIDR notation | 1,942,160 | <p>I have been handed the task of creating a function in python (3.1) that will take a CIDR notation and return the list of possible ip addresses. I have looked around python.org and found this:
<a href="http://docs.python.org/dev/py3k/library/ipaddr.html">http://docs.python.org/dev/py3k/library/ipaddr.html</a></p>
<... | 5 | 2009-12-21T19:39:03Z | 39,653,669 | <p>Below code will generate range of IPs on providing IP and subnet. Expand the CIDR notation like(255.255.255.0)</p>
<pre><code>from netaddr import *
def getFirstIp(ipAddress,subnet):
ipBin = IPNetwork(ipAddress).ip.bits().split('.')
subBin = IPNetwork(subnet).ip.bits().split('.')
zipped = zip(ipBin,subBin)
... | 1 | 2016-09-23T06:06:35Z | [
"python",
"subnet",
"cidr"
] |
String class internals - caching character offset to byte relationship if using UTF-8 | 1,942,282 | <p>When writing a custom string class that stores <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow">UTF-8</a> internally (to save memory) rather than <a href="http://en.wikipedia.org/wiki/UTF-16/UCS-2" rel="nofollow">UTF-16</a> from scratch is it feasible to some extent cache the relationship between byte off... | 1 | 2009-12-21T20:03:41Z | 1,942,325 | <p>I think the answer is: in general, it's not really worth trying to do this. In your specific case, maybe.</p>
<p>If most of your characters are plain ASCII, and you rarely have UTF sequences, then it might be worth building some kind of sparse data structure with the offsets.</p>
<p>In the general case, every sin... | 1 | 2009-12-21T20:10:04Z | [
"java",
"python",
"objective-c",
"perl",
"utf-8"
] |
String class internals - caching character offset to byte relationship if using UTF-8 | 1,942,282 | <p>When writing a custom string class that stores <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow">UTF-8</a> internally (to save memory) rather than <a href="http://en.wikipedia.org/wiki/UTF-16/UCS-2" rel="nofollow">UTF-16</a> from scratch is it feasible to some extent cache the relationship between byte off... | 1 | 2009-12-21T20:03:41Z | 1,942,396 | <p>Java's strings are UTF-16 internally:</p>
<blockquote>
<p>A String represents a string in the UTF-16 format in which supplementary characters are represented by surrogate pairs (see the section Unicode Character Representations in the Character class for more information). Index values refer to char code units, s... | 1 | 2009-12-21T20:22:40Z | [
"java",
"python",
"objective-c",
"perl",
"utf-8"
] |
String class internals - caching character offset to byte relationship if using UTF-8 | 1,942,282 | <p>When writing a custom string class that stores <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow">UTF-8</a> internally (to save memory) rather than <a href="http://en.wikipedia.org/wiki/UTF-16/UCS-2" rel="nofollow">UTF-16</a> from scratch is it feasible to some extent cache the relationship between byte off... | 1 | 2009-12-21T20:03:41Z | 1,942,724 | <p>Perl distinguishes between Unicode and non-Unicode strings. Unicode strings are implemented using UTF-8 internally. Non-Unicode does not necessarily mean 7-bit ASCII, though, it could be any character that can be represented in the current locale as a single byte. </p>
| 2 | 2009-12-21T21:26:31Z | [
"java",
"python",
"objective-c",
"perl",
"utf-8"
] |
how to properly destroy gtk.Dialog objects/widgets | 1,942,295 | <p>Noob @ programming with python and pygtk.</p>
<p>I'm creating an application which includes a couple of dialogs for user interaction.</p>
<pre><code>#!usr/bin/env python
import gtk
info = gtk.MessageDialog(type=gtk.DIALOG_INFO, buttons=gtk.BUTTONS_OK)
info.set_property('title', 'Test info message')
info.set_proper... | 2 | 2009-12-21T20:05:28Z | 1,942,561 | <p>can you give me a last chance? ;)</p>
<p>there are some errors in your code:</p>
<ul>
<li><p>you did not close a bracket</p></li>
<li><p>your syntax in <code>.set_property</code> is wrong: use: <code>.set_property('property', 'value')</code></p></li>
</ul>
<p>but i think they are copy/paste errors.</p>
<p>try th... | 2 | 2009-12-21T20:53:09Z | [
"python",
"pygtk",
"dialog"
] |
how to properly destroy gtk.Dialog objects/widgets | 1,942,295 | <p>Noob @ programming with python and pygtk.</p>
<p>I'm creating an application which includes a couple of dialogs for user interaction.</p>
<pre><code>#!usr/bin/env python
import gtk
info = gtk.MessageDialog(type=gtk.DIALOG_INFO, buttons=gtk.BUTTONS_OK)
info.set_property('title', 'Test info message')
info.set_proper... | 2 | 2009-12-21T20:05:28Z | 1,942,698 | <p>@mg
My bad. Your code is correct (and I guess my initial code was too)
The reason my dialog was remaining on the screen is because my gtk.main loop is running on a separate thread.</p>
<p>So all I had to was enclose your code (corrected version of mine) in between a</p>
<pre><code>gtk.gdk.threads_enter()
</code></... | 3 | 2009-12-21T21:21:55Z | [
"python",
"pygtk",
"dialog"
] |
Wrapping a C library in Python: C, Cython or ctypes? | 1,942,298 | <p>I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices:</p>
<ol>
<li>Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning exte... | 185 | 2009-12-21T20:05:51Z | 1,942,321 | <p>I'll throw another one out there: <a href="http://www.swig.org/Doc1.3/Python.html">SWIG</a></p>
<p>It's easy to learn, does a lot of things right, and supports many more languages so the time spent learning it can be pretty useful.</p>
<p>If you use SWIG, you are creating a new python extension module, but with SW... | 18 | 2009-12-21T20:09:31Z | [
"python",
"c",
"ctypes",
"cython"
] |
Wrapping a C library in Python: C, Cython or ctypes? | 1,942,298 | <p>I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices:</p>
<ol>
<li>Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning exte... | 185 | 2009-12-21T20:05:51Z | 1,942,437 | <p>Cython is a pretty cool tool in itself, well worth learning, and is surprisingly close to the Python syntax. If you do any scientific computing with Numpy, then Cython is the way to go because it integrates with Numpy for fast matrix operations.</p>
<p>Cython is a superset of Python language. You can throw any vali... | 84 | 2009-12-21T20:32:22Z | [
"python",
"c",
"ctypes",
"cython"
] |
Wrapping a C library in Python: C, Cython or ctypes? | 1,942,298 | <p>I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices:</p>
<ol>
<li>Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning exte... | 185 | 2009-12-21T20:05:51Z | 1,942,468 | <p>Personally, I'd write an extension module in C. Don't be intimidated by Python C extensions -- they're not hard at all to write. The documentation is very clear and helpful. When I first wrote a C extension in Python, I think it took me about an hour to figure out how to write one -- not much time at all.</p>
| 15 | 2009-12-21T20:36:42Z | [
"python",
"c",
"ctypes",
"cython"
] |
Wrapping a C library in Python: C, Cython or ctypes? | 1,942,298 | <p>I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices:</p>
<ol>
<li>Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning exte... | 185 | 2009-12-21T20:05:51Z | 1,942,472 | <p><code>ctypes</code> is your best bet for getting it done quickly, and it's a pleasure to work with as you're still writing Python!</p>
<p>I recently wrapped an <a href="http://www.ftdichip.com/">FTDI</a> driver for communicating with a USB chip using ctypes and it was great. I had it all done and working in less t... | 76 | 2009-12-21T20:37:14Z | [
"python",
"c",
"ctypes",
"cython"
] |
Wrapping a C library in Python: C, Cython or ctypes? | 1,942,298 | <p>I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices:</p>
<ol>
<li>Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning exte... | 185 | 2009-12-21T20:05:51Z | 1,942,482 | <p>If you have already a library with a defined API, I think <code>ctypes</code> is the best option, as you only have to do a little initialization and then more or less call the library the way you're used to.</p>
<p>I think Cython or creating an extension module in C (which is not very difficult) are more useful wh... | 9 | 2009-12-21T20:37:56Z | [
"python",
"c",
"ctypes",
"cython"
] |
Wrapping a C library in Python: C, Cython or ctypes? | 1,942,298 | <p>I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices:</p>
<ol>
<li>Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning exte... | 185 | 2009-12-21T20:05:51Z | 1,966,170 | <p><a href="http://python.net/crew/theller/ctypes/">ctypes</a> is great when you've already got a compiled library blob to deal with (such as OS libraries). The calling overhead is severe, however, so if you'll be making a lot of calls into the library, and you're going to be writing the C code anyway (or at least comp... | 9 | 2009-12-27T15:13:27Z | [
"python",
"c",
"ctypes",
"cython"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.