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
HTTPS connection Python
2,146,383
<p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p> <pre><code>import httplib conn = ht...
27
2010-01-27T11:22:00Z
33,430,895
<p>If using <strong>httplib.HTTPSConnection:</strong></p> <p>Please take a look at: Changed in version 2.7.9: </p> <p>This class now performs all the necessary certificate and hostname checks by default. To revert to the previous, unverified, behavior ssl._create_unverified_context() can be passed to the context para...
4
2015-10-30T07:39:24Z
[ "python", "ssl", "https", "httplib", "pyopenssl" ]
Python: Simulate search algorithms in network models
2,146,395
<p>I am using networkx package to draw power law graphs. I want to simulate a search algorithm on this graph and want to visually see the algorithm move from one node to another on the graph. How do I do that?</p>
3
2010-01-27T11:23:29Z
2,261,735
<p>On a mac you could use NodeBox: <a href="http://nodebox.net/" rel="nofollow">http://nodebox.net/</a>. </p>
1
2010-02-14T16:16:28Z
[ "python", "networkx", "graph-drawing" ]
Python: Simulate search algorithms in network models
2,146,395
<p>I am using networkx package to draw power law graphs. I want to simulate a search algorithm on this graph and want to visually see the algorithm move from one node to another on the graph. How do I do that?</p>
3
2010-01-27T11:23:29Z
2,261,755
<p>NetworkX supports drawing using <a href="http://www.graphviz.org" rel="nofollow">Graphviz</a> and <a href="http://matplotlib.sourceforge.net/" rel="nofollow">matplotlib</a>. Did you read the <a href="http://networkx.lanl.gov/reference/drawing.html" rel="nofollow">drawing</a>-chapter in its documentation?</p>
1
2010-02-14T16:21:11Z
[ "python", "networkx", "graph-drawing" ]
How to do while loops with multiple conditions
2,146,419
<p>I have a while loop in python</p> <pre><code>condition1=False condition1=False val = -1 while condition1==False and condition2==False and val==-1: val,something1,something2 = getstuff() if something1==10: condition1 = True if something2==20: condition2 = True ' ' </code></pre> <p>I ...
10
2010-01-27T11:27:32Z
2,146,427
<p>Change the <code>and</code>s to <code>or</code>s.</p>
10
2010-01-27T11:28:54Z
[ "python", "logic" ]
How to do while loops with multiple conditions
2,146,419
<p>I have a while loop in python</p> <pre><code>condition1=False condition1=False val = -1 while condition1==False and condition2==False and val==-1: val,something1,something2 = getstuff() if something1==10: condition1 = True if something2==20: condition2 = True ' ' </code></pre> <p>I ...
10
2010-01-27T11:27:32Z
2,146,444
<p>use an infinity loop like what you have originally done. Its cleanest and you can incorporate many conditions as you wish</p> <pre><code>while 1: if condition1 and condition2: break ... ... if condition3: break ... ... </code></pre>
-1
2010-01-27T11:31:44Z
[ "python", "logic" ]
How to do while loops with multiple conditions
2,146,419
<p>I have a while loop in python</p> <pre><code>condition1=False condition1=False val = -1 while condition1==False and condition2==False and val==-1: val,something1,something2 = getstuff() if something1==10: condition1 = True if something2==20: condition2 = True ' ' </code></pre> <p>I ...
10
2010-01-27T11:27:32Z
2,146,459
<pre><code>while not condition1 or not condition2 or val == -1: </code></pre> <p>But there was nothing wrong with your original of using an if inside of a while True.</p>
1
2010-01-27T11:33:06Z
[ "python", "logic" ]
How to do while loops with multiple conditions
2,146,419
<p>I have a while loop in python</p> <pre><code>condition1=False condition1=False val = -1 while condition1==False and condition2==False and val==-1: val,something1,something2 = getstuff() if something1==10: condition1 = True if something2==20: condition2 = True ' ' </code></pre> <p>I ...
10
2010-01-27T11:27:32Z
2,146,535
<p>I am not sure it would read better but you could do the following:</p> <pre><code>while any((not condition1, not condition2, val == -1)): val,something1,something2 = getstuff() if something1==10: condition1 = True if something2==20: condition2 = True </code></pre>
-1
2010-01-27T11:45:42Z
[ "python", "logic" ]
How to do while loops with multiple conditions
2,146,419
<p>I have a while loop in python</p> <pre><code>condition1=False condition1=False val = -1 while condition1==False and condition2==False and val==-1: val,something1,something2 = getstuff() if something1==10: condition1 = True if something2==20: condition2 = True ' ' </code></pre> <p>I ...
10
2010-01-27T11:27:32Z
2,149,931
<p>Have you noticed that in the code you posted, <code>condition2</code> is never set to <code>False</code>? This way, your loop body is never executed.</p> <p>Also, note that in Python, <code>not condition</code> is preferred to <code>condition == False</code>; likewise, <code>condition</code> is preferred to <code>c...
0
2010-01-27T20:13:58Z
[ "python", "logic" ]
Raising an exception vs printing?
2,146,618
<p>Whats the difference between raising an exception and simply printing an error. </p> <p>For example, whats the benefit of using the following:</p> <pre><code>if size &lt; 0: raise ValueError('number must be non-negative') </code></pre> <p>instead of simply:</p> <pre><code>if size &lt; 0: print 'n...
7
2010-01-27T11:59:15Z
2,146,649
<p>It depends if you can handle <code>size &lt; 0</code> at the point where <code>size &lt; 0</code> is detected.</p> <p>If you can handle it by printing straight away, then <code>print</code>, otherwise, raise an exception, to delegate the handling of that condition to something further up the callstack, like this:</...
5
2010-01-27T12:04:13Z
[ "python", "exception", "printing" ]
Raising an exception vs printing?
2,146,618
<p>Whats the difference between raising an exception and simply printing an error. </p> <p>For example, whats the benefit of using the following:</p> <pre><code>if size &lt; 0: raise ValueError('number must be non-negative') </code></pre> <p>instead of simply:</p> <pre><code>if size &lt; 0: print 'n...
7
2010-01-27T11:59:15Z
2,146,650
<p><a href="http://docs.python.org/reference/simple_stmts.html#the-raise-statement" rel="nofollow">Raising an error</a> halts the entire program at that point (unless the exception is caught), whereas <a href="http://docs.python.org/reference/simple_stmts.html#the-print-statement" rel="nofollow">printing</a> the messag...
6
2010-01-27T12:04:23Z
[ "python", "exception", "printing" ]
Raising an exception vs printing?
2,146,618
<p>Whats the difference between raising an exception and simply printing an error. </p> <p>For example, whats the benefit of using the following:</p> <pre><code>if size &lt; 0: raise ValueError('number must be non-negative') </code></pre> <p>instead of simply:</p> <pre><code>if size &lt; 0: print 'n...
7
2010-01-27T11:59:15Z
2,146,690
<p>The key difference is whether or not the program will continue to run after your error checking.</p> <p>For this case:</p> <pre><code>if size &lt; 0: print 'number must be non-negative' </code></pre> <p>This will just print the message to standard output and the program will continue past your check. So if at...
2
2010-01-27T12:11:04Z
[ "python", "exception", "printing" ]
Raising an exception vs printing?
2,146,618
<p>Whats the difference between raising an exception and simply printing an error. </p> <p>For example, whats the benefit of using the following:</p> <pre><code>if size &lt; 0: raise ValueError('number must be non-negative') </code></pre> <p>instead of simply:</p> <pre><code>if size &lt; 0: print 'n...
7
2010-01-27T11:59:15Z
2,147,605
<p>Another consideration is when developing a module that maybe used in other programs. In that case it is preferable to throw an exception and let the calling code handle the error. The caller should know that something went wrong and act accordingly.</p> <p>...richie</p>
2
2010-01-27T14:31:42Z
[ "python", "exception", "printing" ]
How to avoid gcc warning in Python C extension when using Py_BEGIN_ALLOW_THREADS
2,147,029
<p>The simplest way to manipulate the GIL in Python C extensions is to use the macros provided:</p> <pre><code>my_awesome_C_function() { blah; Py_BEGIN_ALLOW_THREADS // do stuff that doesn't need the GIL if (should_i_call_back) { Py_BLOCK_THREADS // do stuff that needs the GIL ...
7
2010-01-27T13:11:32Z
2,147,130
<ol> <li>Yes, it is possible to suppress uninitialized warnings using the -Wno- prefix. </li> </ol> <p><code>-Wall -Wno-uninitialized</code></p> <p>If you want to remove just this warning, you could simply initialize <code>_save</code> to a null pointer so that it doesn't rely on a function return value... that one l...
3
2010-01-27T13:29:29Z
[ "python", "gcc", "gil", "cextension" ]
How to avoid gcc warning in Python C extension when using Py_BEGIN_ALLOW_THREADS
2,147,029
<p>The simplest way to manipulate the GIL in Python C extensions is to use the macros provided:</p> <pre><code>my_awesome_C_function() { blah; Py_BEGIN_ALLOW_THREADS // do stuff that doesn't need the GIL if (should_i_call_back) { Py_BLOCK_THREADS // do stuff that needs the GIL ...
7
2010-01-27T13:11:32Z
2,147,138
<p>My two cents:</p> <ol> <li>You can suppress specific warnings, but I guess you already knew that.</li> <li>It says <em>might</em> be uninitialized :-)</li> <li>The only reason I can imagine is compatibility with older C compilers.</li> </ol> <p>I tried digging into <a href="http://www.google.com/codesearch/p?hl=en...
0
2010-01-27T13:30:18Z
[ "python", "gcc", "gil", "cextension" ]
How to avoid gcc warning in Python C extension when using Py_BEGIN_ALLOW_THREADS
2,147,029
<p>The simplest way to manipulate the GIL in Python C extensions is to use the macros provided:</p> <pre><code>my_awesome_C_function() { blah; Py_BEGIN_ALLOW_THREADS // do stuff that doesn't need the GIL if (should_i_call_back) { Py_BLOCK_THREADS // do stuff that needs the GIL ...
7
2010-01-27T13:11:32Z
2,148,130
<p>Ned, you can try <a href="http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas" rel="nofollow">one of these</a>:</p> <pre><code>#pragma GCC diagnostic warning "-Wno-unitialized" #pragma GCC diagnostic error "-Wno-uninitialized" #pragma GCC diagnostic ignored "-Wno-uninialized" </code></pre> ...
0
2010-01-27T15:30:24Z
[ "python", "gcc", "gil", "cextension" ]
twisted http client
2,147,148
<p>I am after an example describing the usage of Twisted's HTTP Client. </p> <p>After reading the excellent <a href="http://krondo.com/blog/?page_id=1327">blog post on the internals of Twisted</a>, I understand how the "Factory" and "Protocol" components play their role but I am unclear on how to introduce "Request" i...
13
2010-01-27T13:31:50Z
2,147,398
<p>As of Twisted 9.0, there are actually two HTTP clients available. The older one has quite a few features, such as automatically following redirects, interpreting cookie headers, etc. You can find an example of its usage here:</p> <p><a href="http://twistedmatrix.com/documents/current/web/examples/">http://twisted...
17
2010-01-27T14:02:26Z
[ "python", "http", "client", "twisted" ]
twisted http client
2,147,148
<p>I am after an example describing the usage of Twisted's HTTP Client. </p> <p>After reading the excellent <a href="http://krondo.com/blog/?page_id=1327">blog post on the internals of Twisted</a>, I understand how the "Factory" and "Protocol" components play their role but I am unclear on how to introduce "Request" i...
13
2010-01-27T13:31:50Z
5,399,165
<p>As of Twisted 10, you may want to use the <code>Agent</code> class.</p> <p>Please follow this link: <a href="http://twistedmatrix.com/documents/10.2.0/web/howto/client.html" rel="nofollow">http://twistedmatrix.com/documents/10.2.0/web/howto/client.html</a></p>
1
2011-03-22T23:32:44Z
[ "python", "http", "client", "twisted" ]
twisted http client
2,147,148
<p>I am after an example describing the usage of Twisted's HTTP Client. </p> <p>After reading the excellent <a href="http://krondo.com/blog/?page_id=1327">blog post on the internals of Twisted</a>, I understand how the "Factory" and "Protocol" components play their role but I am unclear on how to introduce "Request" i...
13
2010-01-27T13:31:50Z
19,477,013
<p>I started using treq with twisted. treq has an API which is very similar to Requests. <a href="https://pypi.python.org/pypi/treq/0.2.0" rel="nofollow">https://pypi.python.org/pypi/treq/0.2.0</a></p>
2
2013-10-20T11:52:08Z
[ "python", "http", "client", "twisted" ]
Should a class or method which processes a file close the file as a side effect?
2,147,153
<p>I'm wondering which is the more 'Pythonic' / better way to write methods which process files. Should the method which processes the file close that file as a side effect? Should the concept of the data being a 'file' be completely abstracted from the method which is processing the data, meaning it should expect some...
2
2010-01-27T13:32:38Z
2,147,165
<p>Generally, it is better practice for the opener of a file to close the file. In your question, the second example is better.</p> <p>This is to prevent possible confusion and invalid operations.</p> <p><strike> <strong>Edit:</strong> If your real code isn't any more complex than your example code, then it might be ...
4
2010-01-27T13:34:37Z
[ "file-io", "python" ]
Should a class or method which processes a file close the file as a side effect?
2,147,153
<p>I'm wondering which is the more 'Pythonic' / better way to write methods which process files. Should the method which processes the file close that file as a side effect? Should the concept of the data being a 'file' be completely abstracted from the method which is processing the data, meaning it should expect some...
2
2010-01-27T13:32:38Z
2,147,169
<p>Using <code>with</code> means not having to worry about this.</p> <p>At least, not on 2.5+.</p>
4
2010-01-27T13:35:34Z
[ "file-io", "python" ]
Should a class or method which processes a file close the file as a side effect?
2,147,153
<p>I'm wondering which is the more 'Pythonic' / better way to write methods which process files. Should the method which processes the file close that file as a side effect? Should the concept of the data being a 'file' be completely abstracted from the method which is processing the data, meaning it should expect some...
2
2010-01-27T13:32:38Z
2,147,261
<p>No, because it reduces flexibility: if function doesn't close file and caller doesn't need it - caller can close file. If it does but caller still need file open - caller stuck with reopening file, using StringIO, or something else.</p> <p>Also closing file object require additional assumptions on it's real type (...
0
2010-01-27T13:45:58Z
[ "file-io", "python" ]
Reading XML DOCTYPE info with Python
2,147,436
<p>I need to parse a version of an XML file as follows.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE twReport [ &lt;!ELEMENT twReport (twHead?, (twWarn | twDebug | twInfo)*, twBody, twSum?, twDebug*, twFoot?, twClientInfo?)&gt; &lt;!ATTLIST twReport version CDATA "10,4"&g...
3
2010-01-27T14:08:53Z
2,148,315
<p>How about <a href="http://www.garshol.priv.no/download/software/xmlproc/" rel="nofollow">xmlproc</a>'s <a href="http://www.garshol.priv.no/download/software/xmlproc/dtd-api-doco.html" rel="nofollow">DTD api</a>?</p> <p>Here's a random snippet of code I wrote years and years ago to do some work with DTDs from Python...
2
2010-01-27T15:53:47Z
[ "python", "xml" ]
Reading XML DOCTYPE info with Python
2,147,436
<p>I need to parse a version of an XML file as follows.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE twReport [ &lt;!ELEMENT twReport (twHead?, (twWarn | twDebug | twInfo)*, twBody, twSum?, twDebug*, twFoot?, twClientInfo?)&gt; &lt;!ATTLIST twReport version CDATA "10,4"&g...
3
2010-01-27T14:08:53Z
2,155,040
<p>Because both of the the standard library XML libraries (<code>xml.dom.minidom</code> and <code>xml.etree</code>) use the same parser (<code>xml.parsers.expat</code>) you are limited in the "quality" of XML data you are able to successfully parse. </p> <p>You're better off using the tried-and-true 3rd party modules ...
0
2010-01-28T14:10:46Z
[ "python", "xml" ]
Connecting to a Multicast Server in Python
2,147,501
<p>This is my code for connecting to a multicast server, is this the best way of handling the exception. What I would like to do is to retry to connect if an exception occurs</p> <pre><code>def initialiseMulticastTrackerComms(): try: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(so...
1
2010-01-27T14:17:55Z
2,147,560
<p>The simplest solution would be to wrap your try-except-else block in a loop.</p> <p>Something like this</p> <pre><code>def initSock(): message = "" for i in range(MAX_TRIES): try: #...socket opening code except socket.error, (value, message): message = message ...
1
2010-01-27T14:26:17Z
[ "python", "sockets", "exception", "multicast" ]
Using getcwd when running in Eclipse
2,147,575
<p>When running a project in eclipse the eclipse saves a copy of the .py file inside the workspace defined in project creation. But the file that imported to project can be in other location.</p> <p>If using <code>os.getcwd()</code> and running the script from the command line, the return value would be the real path ...
1
2010-01-27T14:27:57Z
2,148,633
<p><code>os.getcwd()</code> returns the current working directory.</p> <p>When running a Python program from Eclipse you can specify what the working directory should be on the Arguments tab of the Run Configuration. This will let you override the value from the project folder (or whatever the default might be.)</p> ...
1
2010-01-27T16:40:22Z
[ "python", "eclipse" ]
How do I change which version of python mod_python uses
2,147,695
<p>I'm doing some introductory work with django which seems really easy (and fun) so far but I have been doing all this from Python 2.6 which I installed in /opt/local (RedHat 5.3) because the python that came with redhat was 2.4. I set up a symlink:</p> <pre><code>/usr/bin/python2.6 -&gt; /opt/local/bin/python </code...
2
2010-01-27T14:41:53Z
2,147,774
<p>You would have to rebuild mod_python against your python2.6 installation. Since mod_python loads python as a library the version is fixed at compile time.</p>
5
2010-01-27T14:50:38Z
[ "python", "django", "apache", "mod-python" ]
How do I change which version of python mod_python uses
2,147,695
<p>I'm doing some introductory work with django which seems really easy (and fun) so far but I have been doing all this from Python 2.6 which I installed in /opt/local (RedHat 5.3) because the python that came with redhat was 2.4. I set up a symlink:</p> <pre><code>/usr/bin/python2.6 -&gt; /opt/local/bin/python </code...
2
2010-01-27T14:41:53Z
2,148,276
<p>Don't use mod_python any more. mod_wsgi is the recommended way to deploy Django appliations now.</p>
3
2010-01-27T15:47:10Z
[ "python", "django", "apache", "mod-python" ]
How do I change which version of python mod_python uses
2,147,695
<p>I'm doing some introductory work with django which seems really easy (and fun) so far but I have been doing all this from Python 2.6 which I installed in /opt/local (RedHat 5.3) because the python that came with redhat was 2.4. I set up a symlink:</p> <pre><code>/usr/bin/python2.6 -&gt; /opt/local/bin/python </code...
2
2010-01-27T14:41:53Z
2,157,832
<p>You <em>can</em> rebuild mod_python to link against libpython dynamically so that you can pick up version updates to your libpython but it takes some chicanery.</p> <p>You will need to edit the configure script for mod_python as follows (remove -L${PyLIBPL}):</p> <pre><code>$ diff configure.orig configure &lt; ...
2
2010-01-28T20:47:39Z
[ "python", "django", "apache", "mod-python" ]
Serializing list to JSON
2,147,701
<p>I am sending information between client and Django server, and I would like to use JSON to this. I am sending simple information - list of strings. I tried using <code>django.core.serializers</code>, but when I did, I got </p> <pre><code>AttributeError: 'str' object has no attribute '_meta' </code></pre> <p>It see...
16
2010-01-27T14:42:07Z
2,147,791
<p>You can use pure Python to do it:</p> <pre><code>import json list = [1, 2, (3, 4)] # Note that the 3rd element is a tuple (3, 4) json.dumps(list) # '[1, 2, [3, 4]]' </code></pre>
33
2010-01-27T14:53:03Z
[ "python", "django", "json", "serialization" ]
Serializing list to JSON
2,147,701
<p>I am sending information between client and Django server, and I would like to use JSON to this. I am sending simple information - list of strings. I tried using <code>django.core.serializers</code>, but when I did, I got </p> <pre><code>AttributeError: 'str' object has no attribute '_meta' </code></pre> <p>It see...
16
2010-01-27T14:42:07Z
2,147,877
<p>If using Python 2.5, you may need to import <code>simplejson</code>: </p> <pre><code>try: import json except ImportError: import simplejson as json </code></pre>
4
2010-01-27T15:01:38Z
[ "python", "django", "json", "serialization" ]
Serializing list to JSON
2,147,701
<p>I am sending information between client and Django server, and I would like to use JSON to this. I am sending simple information - list of strings. I tried using <code>django.core.serializers</code>, but when I did, I got </p> <pre><code>AttributeError: 'str' object has no attribute '_meta' </code></pre> <p>It see...
16
2010-01-27T14:42:07Z
11,364,797
<p>Yes, but then what do you do about the django objects? simple json tends to choke on them. </p> <p>If the objects are individual model objects (not querysets, e.g.), I have occasionally stored the model object type and the pk, like so:</p> <pre><code>seralized_dict = simplejson.dumps(my_dict, ...
2
2012-07-06T15:05:19Z
[ "python", "django", "json", "serialization" ]
Using KWallet in PyQt4
2,147,724
<p>It would be great if anyone could show me how to use KWallet with pyqt4</p>
4
2010-01-27T14:44:59Z
4,852,973
<p>Well i found a good example about it in <a href="http://www.brighthub.com/hubfolio/matthew-casperson/articles/75598.aspx" rel="nofollow">here</a>, you will also need to use PyKDE4 not only PyQt.</p>
0
2011-01-31T15:58:38Z
[ "python", "pyqt4" ]
Using KWallet in PyQt4
2,147,724
<p>It would be great if anyone could show me how to use KWallet with pyqt4</p>
4
2010-01-27T14:44:59Z
7,133,221
<h1>Tutorial in the Python command line</h1> <p>First I will show how kwallet can be used from the Python command line to read and write a password:</p> <pre><code>$ python # We import the necessary modules. &gt;&gt;&gt; from PyKDE4.kdeui import KWallet &gt;&gt;&gt; from PyQt4 import QtGui # We create a QApplicatio...
5
2011-08-20T16:52:24Z
[ "python", "pyqt4" ]
DLL file loaded twice with DLL redirection through manifest
2,147,729
<p>I'm including <code>python.h</code> in my <a href="http://en.wikipedia.org/wiki/Visual_C++#32-bit_versions" rel="nofollow">Visual C++</a> DLL file project which causes an implicit linking with <code>python25.dll</code>. However, I want to load a specific <code>python25.dll</code> (several can be present on the compu...
6
2010-01-27T14:45:31Z
2,149,652
<p><a href="http://en.wikipedia.org/wiki/Dependency_Walker" rel="nofollow">Dependency Walker</a> is usually the best tool for resolving this kind of problem. I'm not too sure how well it handles manifests though...</p> <p>Where in this entangled mess is the actual process executable file?</p> <p>Two possibilities com...
1
2010-01-27T19:17:51Z
[ "c++", "python", "visual-studio", "dll", "manifest" ]
DLL file loaded twice with DLL redirection through manifest
2,147,729
<p>I'm including <code>python.h</code> in my <a href="http://en.wikipedia.org/wiki/Visual_C++#32-bit_versions" rel="nofollow">Visual C++</a> DLL file project which causes an implicit linking with <code>python25.dll</code>. However, I want to load a specific <code>python25.dll</code> (several can be present on the compu...
6
2010-01-27T14:45:31Z
2,154,262
<p>I made some progress for the understanding of the issue.</p> <p>First let me clarify the scenario:</p> <ul> <li>I'm building a DLL file that both embeds and extends Python, using the Python C API and Boost.Python.</li> <li>Thus, I'm providing a <code>python25.dll</code> in the same folder as my DLL file, as well a...
2
2010-01-28T11:58:45Z
[ "c++", "python", "visual-studio", "dll", "manifest" ]
DLL file loaded twice with DLL redirection through manifest
2,147,729
<p>I'm including <code>python.h</code> in my <a href="http://en.wikipedia.org/wiki/Visual_C++#32-bit_versions" rel="nofollow">Visual C++</a> DLL file project which causes an implicit linking with <code>python25.dll</code>. However, I want to load a specific <code>python25.dll</code> (several can be present on the compu...
6
2010-01-27T14:45:31Z
5,423,561
<p>After exhaustive battle with WinSxS and DLL redirection, here's my advice for you:</p> <h3>Some background</h3> <p>Various things can cause a DLL to be loaded under Windows:</p> <ul> <li>Explicit linking (<code>LoadLibrary</code>) -- the loader uses the current activation context of the running <code>exe</code>. ...
3
2011-03-24T18:12:32Z
[ "c++", "python", "visual-studio", "dll", "manifest" ]
DLL file loaded twice with DLL redirection through manifest
2,147,729
<p>I'm including <code>python.h</code> in my <a href="http://en.wikipedia.org/wiki/Visual_C++#32-bit_versions" rel="nofollow">Visual C++</a> DLL file project which causes an implicit linking with <code>python25.dll</code>. However, I want to load a specific <code>python25.dll</code> (several can be present on the compu...
6
2010-01-27T14:45:31Z
19,244,390
<p>Recently, I hit a very <a href="https://mail.python.org/pipermail/capi-sig/2013-October/000604.html" rel="nofollow">similar problem</a></p> <ol> <li>My application embedding Python loads the <strong>python32.dll</strong> from a known location, that is a <a href="http://en.wikipedia.org/wiki/Side-by-side_assembly" r...
0
2013-10-08T09:48:22Z
[ "c++", "python", "visual-studio", "dll", "manifest" ]
Emptying the datastore in GAE
2,147,787
<p>I know what you're thinking, 'O not that again!', but here we are since Google have not yet provided a simpler method.</p> <p>I have been using a queue based solution which worked fine:</p> <p>import datetime from models import *</p> <pre><code>DELETABLE_MODELS = [Alpha, Beta, AlphaBeta] def initiate_purge(): ...
1
2010-01-27T14:52:36Z
2,150,425
<p>I don't believe that trying to delete an entity that has references to still-existing entities is really a problem, but you can always rules this out be re-writing your task to delete the entities serially instead of in parallel:</p> <pre><code>def initiate_purge(): deferred.defer(delete_entities, Alpha, _queue...
1
2010-01-27T21:35:12Z
[ "python", "google-app-engine", "gae-datastore" ]
How do I represent and work with n-bit vectors in Python?
2,147,848
<p>In an assignment I am currently working on we need to work with bit vectors, but I am very unsure of how to do this in Python. They should be able to be from 4 bits to 20 bits. I have never worked with bit vector before, but I guess that one would one create arrays of unsigned bytes that you manipulated using the us...
5
2010-01-27T14:59:13Z
2,147,865
<p>It has lists, which you can populate with bools:</p> <pre><code>[False] * 20 </code></pre>
5
2010-01-27T15:00:49Z
[ "python", "bit-manipulation", "bitarray", "bitvector" ]
How do I represent and work with n-bit vectors in Python?
2,147,848
<p>In an assignment I am currently working on we need to work with bit vectors, but I am very unsure of how to do this in Python. They should be able to be from 4 bits to 20 bits. I have never worked with bit vector before, but I guess that one would one create arrays of unsigned bytes that you manipulated using the us...
5
2010-01-27T14:59:13Z
2,147,866
<p>Use <a href="http://docs.python.org/library/struct.html" rel="nofollow">struct</a> module.</p>
0
2010-01-27T15:00:52Z
[ "python", "bit-manipulation", "bitarray", "bitvector" ]
How do I represent and work with n-bit vectors in Python?
2,147,848
<p>In an assignment I am currently working on we need to work with bit vectors, but I am very unsure of how to do this in Python. They should be able to be from 4 bits to 20 bits. I have never worked with bit vector before, but I guess that one would one create arrays of unsigned bytes that you manipulated using the us...
5
2010-01-27T14:59:13Z
2,147,873
<p>The library <a href="https://engineering.purdue.edu/kak/dist/BitVector-3.1.1.html" rel="nofollow" title="BitVector">BitVector</a> is a pure-Python library for this purpose, and should suit the needs you specified.</p>
4
2010-01-27T15:01:19Z
[ "python", "bit-manipulation", "bitarray", "bitvector" ]
How do I represent and work with n-bit vectors in Python?
2,147,848
<p>In an assignment I am currently working on we need to work with bit vectors, but I am very unsure of how to do this in Python. They should be able to be from 4 bits to 20 bits. I have never worked with bit vector before, but I guess that one would one create arrays of unsigned bytes that you manipulated using the us...
5
2010-01-27T14:59:13Z
2,147,880
<p>The <a href="http://pypi.python.org/pypi/bitarray">bitarray</a> module does this efficiently with booleans.</p>
7
2010-01-27T15:02:15Z
[ "python", "bit-manipulation", "bitarray", "bitvector" ]
How do I represent and work with n-bit vectors in Python?
2,147,848
<p>In an assignment I am currently working on we need to work with bit vectors, but I am very unsure of how to do this in Python. They should be able to be from 4 bits to 20 bits. I have never worked with bit vector before, but I guess that one would one create arrays of unsigned bytes that you manipulated using the us...
5
2010-01-27T14:59:13Z
12,858,956
<p>There is also the pure-Python <strong><a href="http://code.google.com/p/python-bitstring/" rel="nofollow">python-bitstring</a></strong> (with Python 3 support).</p>
1
2012-10-12T12:20:37Z
[ "python", "bit-manipulation", "bitarray", "bitvector" ]
How to retrieve the values for only one table field in Django
2,147,882
<p>If I have following database fields: <code>id, name, emp_id</code>.</p> <p>How do I make a query in Django to get the values of column <code>name</code> only with a where clause.</p> <p>Thanks...</p>
0
2010-01-27T15:02:19Z
2,147,897
<pre><code>Model.objects.filter(...).values('name') </code></pre>
7
2010-01-27T15:04:05Z
[ "python", "django" ]
How to retrieve the values for only one table field in Django
2,147,882
<p>If I have following database fields: <code>id, name, emp_id</code>.</p> <p>How do I make a query in Django to get the values of column <code>name</code> only with a where clause.</p> <p>Thanks...</p>
0
2010-01-27T15:02:19Z
2,147,965
<p>In addition to the answer provided by Ignacio Vazquez-Abrams, you could also use <code>values_list</code> to get the names in a flat list (instead of a dictionary). </p> <pre><code>Model.objects.filter(...).values_list('name', flat=True) </code></pre> <p>See the <a href="http://docs.djangoproject.com/en/1.1/ref...
5
2010-01-27T15:12:09Z
[ "python", "django" ]
Looking for the fastest way to find the exact overlap between two arrays of equal length in numpy
2,148,110
<p>I am looking for the optimal (fastest) way to find the exact overlap between two arrays in numpy. Given two arrays x and y</p> <pre><code>x = array([1,0,3,0,5,0,7,4],dtype=int) y = array([1,4,0,0,5,0,6,4],dtype=int) </code></pre> <p>What I want to get is, an array of the same length that contains only the numbers ...
1
2010-01-27T15:28:08Z
2,148,172
<pre><code>result = numpy.where(x == y, x, 0) </code></pre> <p>Have a look at <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow"><code>numpy.where</code></a> documentation for explanation. Basically, <code>numpy.where(a, b, c)</code>, for a condition <code>a</code> returns a...
5
2010-01-27T15:35:19Z
[ "python", "numpy" ]
Looking for the fastest way to find the exact overlap between two arrays of equal length in numpy
2,148,110
<p>I am looking for the optimal (fastest) way to find the exact overlap between two arrays in numpy. Given two arrays x and y</p> <pre><code>x = array([1,0,3,0,5,0,7,4],dtype=int) y = array([1,4,0,0,5,0,6,4],dtype=int) </code></pre> <p>What I want to get is, an array of the same length that contains only the numbers ...
1
2010-01-27T15:28:08Z
2,167,995
<p>Using <code>numpy.where</code> is the most general solution. but in this particular case, and because it is a useful programming practice, you could use <code>x==y</code> as a mask:</p> <pre><code>mask = x==y # mask is array([ True, False, False, True, True, True, False, True], dtype=bool) xf = mask * x # x...
2
2010-01-30T13:30:19Z
[ "python", "numpy" ]
Looking for the fastest way to find the exact overlap between two arrays of equal length in numpy
2,148,110
<p>I am looking for the optimal (fastest) way to find the exact overlap between two arrays in numpy. Given two arrays x and y</p> <pre><code>x = array([1,0,3,0,5,0,7,4],dtype=int) y = array([1,4,0,0,5,0,6,4],dtype=int) </code></pre> <p>What I want to get is, an array of the same length that contains only the numbers ...
1
2010-01-27T15:28:08Z
17,025,691
<p>try numpy.in1d... from the documentation....</p> <p>Test whether each element of a 1D array is also present in a second array.</p> <p>Returns a boolean array the same length as <code>ar1</code> that is True where an element of <code>ar1</code> is in <code>ar2</code> and False otherwise.</p> <h2>Parameters</h2> <...
0
2013-06-10T14:00:30Z
[ "python", "numpy" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
2,148,166
<p>The easiest to use XML parser for Python is ElementTree (as of 2.5x and above it is in the standard library xml.etree.ElementTree). I don't think there is anything that does exactly what you want out of the box. It would be pretty trivial to write something to do what you want using ElementTree, but why convert to a...
1
2010-01-27T15:34:48Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
2,148,169
<p>Here's a link to an <a href="http://code.activestate.com/recipes/116539/" rel="nofollow">ActiveState solution</a> - and the code in case it disappears again.</p> <pre><code>================================================== xmlreader.py: ================================================== from xml.dom.minidom import...
1
2010-01-27T15:35:15Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
5,807,028
<p>This is a great module that someone created. I've used it several times. <a href="http://code.activestate.com/recipes/410469-xml-as-dictionary/">http://code.activestate.com/recipes/410469-xml-as-dictionary/</a></p> <p>Here is the code from the website just in case the link goes bad. </p> <pre><code>import cElemen...
22
2011-04-27T15:58:19Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
7,531,652
<p>The most recent versions of the PicklingTools libraries (1.3.0 and 1.3.1) support tools for converting from XML to a Python dict.</p> <p>The download is available here: <a href="http://www.picklingtools.com/downloads">PicklingTools 1.3.1</a></p> <p>There is quite a bit of documentation for the converters <a href=...
6
2011-09-23T15:52:44Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
9,558,269
<p>At one point I had to parse and write XML that only consisted of elements without attributes so a 1:1 mapping from XML to dict was possible easily. This is what I came up with in case someone else also doesnt need attributes:</p> <pre class="lang-py prettyprint-override"><code>def xmltodict(element): if not isi...
0
2012-03-04T19:53:41Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
10,077,069
<p>The following XML-to-Python-dict snippet parses entities as well as attributes following <a href="http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html" rel="nofollow">this XML-to-JSON "specification"</a>. It is the most general solution handling all cases of XML.</p> <pre><code>from collections ...
20
2012-04-09T17:23:43Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
10,199,714
<p><a href="https://github.com/martinblech/xmltodict">xmltodict</a> (full disclosure: I wrote it) does exactly that:</p> <pre><code>xmltodict.parse(""" &lt;?xml version="1.0" ?&gt; &lt;person&gt; &lt;name&gt;john&lt;/name&gt; &lt;age&gt;20&lt;/age&gt; &lt;/person&gt;""") # {u'person': {u'age': u'20', u'name': u'jo...
142
2012-04-17T21:51:24Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
15,812,174
<pre><code>def xml_to_dict(node): u''' @param node:lxml_node @return: dict ''' return {'tag': node.tag, 'text': node.text, 'attrib': node.attrib, 'children': {child.tag: xml_to_dict(child) for child in node}} </code></pre>
0
2013-04-04T13:09:26Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
24,317,971
<p>@dibrovsd: Solution will not work if the xml have more than one tag with same name</p> <p>On your line of thought, I have modified the code a bit and written it for general node instead of root:</p> <pre><code>from collections import defaultdict def xml2dict(node): d, count = defaultdict(list), 1 for i in ...
0
2014-06-19T23:49:49Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
24,926,806
<p>The code from <a href="http://code.activestate.com/recipes/410469-xml-as-dictionary/" rel="nofollow">http://code.activestate.com/recipes/410469-xml-as-dictionary/</a> works well, but if there are multiple elements that are the same at a given place in the hierarchy it just overrides them.</p> <p>I added a shim betw...
1
2014-07-24T06:45:59Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
30,923,963
<p>This lightweight version, while not configurable, is pretty easy to tailor as needed, and works in old pythons. Also it is rigid - meaning the results are the same regardless of the existence of attributes.</p> <pre><code>import xml.etree.ElementTree as ET from copy import copy def dictify(r,root=True): if r...
6
2015-06-18T19:19:37Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
31,438,957
<p>You can do this quite easily with lxml. First install it:</p> <pre><code>[sudo] pip install lxml </code></pre> <p>Here is a recursive function I wrote that does the heavy lifting for you:</p> <pre><code>from lxml import objectify as xml_objectify def xml_to_dict(xml_str): """ Convert xml to dict, using lxml...
0
2015-07-15T19:05:35Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
32,842,402
<p>From @K3---rnc <a href="http://stackoverflow.com/questions/2148119/how-to-convert-an-xml-string-to-a-dictionary-in-python#10077069">response</a> (the best for me) I've added a small modifications to get an OrderedDict from an XML text (some times order matters):</p> <pre><code>def etree_to_ordereddict(t): d = Order...
0
2015-09-29T11:11:13Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
How to convert an xml string to a dictionary in Python?
2,148,119
<p>I have a program that reads an xml document from a socket. I have the xml document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p> <p>Take as an example:</p> <pre><code>str ="&lt;?xml version="1.0" ?&gt;&lt;p...
60
2010-01-27T15:28:49Z
39,539,757
<p>Disclaimer: This modified XML parser was inspired by <a href="http://stackoverflow.com/a/24926806/1440565">Adam Clark</a> The original XML parser works for most of simple cases. However, it didn't work for some complicated XML files. I debugged the code line by line and finally fixed some issues. If you find some b...
1
2016-09-16T20:38:43Z
[ "python", "xml", "json", "dictionary", "xml-deserialization" ]
Virtualenv problem
2,148,213
<p>I have created a new environement in virtualenv with --no-site-packages and executed activate file. So, shouldn't my current Django app show any error? Environement doesn't have Django installed. I think, my site is using my old python with Django. How can I change it?<br> Maybe it's because my .htaccess file, here ...
0
2010-01-27T15:40:10Z
2,148,311
<p>With mod_wsgi, you can set <code>WSGIPythonHome</code> to where your virtualenv is. mod_python doesn't let you set the interpreter easily, however (there may be a way involving setting PYTHONEXECUTABLE at apache startup).</p> <p>See what <code>bin/python</code> (next to <code>bin/activate</code>) does to <code>sys....
4
2010-01-27T15:53:20Z
[ "python", "django", "virtualenv" ]
Errors with python-openid and Google Apps Federated Login
2,148,267
<h2>UPDATE</h2> <p>I managed to get it working although I'm not quite sure why ;) It seems like python-openid uses a POST-request to issue the openid mode=associate and for some reason Google doesn't like that. When I patched python-openid to use a GET-request instead everything worked fine. I'll continue my investiga...
4
2010-01-27T15:45:59Z
2,153,239
<p>Okay. I don't have an Apps account so I can't test logging in, but I can successfully associate with an apps domain with python-openid 2.2.4. Here's a little debugging tool for making association requests: <a href="http://gist.github.com/288560" rel="nofollow">http://gist.github.com/288560</a></p> <p>Your patch s...
2
2010-01-28T08:47:47Z
[ "python", "openid", "trac", "google-apps", "python-openid" ]
Errors with python-openid and Google Apps Federated Login
2,148,267
<h2>UPDATE</h2> <p>I managed to get it working although I'm not quite sure why ;) It seems like python-openid uses a POST-request to issue the openid mode=associate and for some reason Google doesn't like that. When I patched python-openid to use a GET-request instead everything worked fine. I'll continue my investiga...
4
2010-01-27T15:45:59Z
4,175,621
<p>You mentioned that you're using Python <strong>2.6.2</strong> with python-openid. The Requirements section of the README file <em>currently</em> only lists Python 2.3, 2.4, or 2.5. It's good to hear you got it working.</p>
0
2010-11-14T01:09:11Z
[ "python", "openid", "trac", "google-apps", "python-openid" ]
Python: Embed Chaco in PyQt4 Mystery
2,148,279
<p>How do i go about adding Chaco to an existing PyQt4 application?</p> <p>Hours of searches yielded little (<a href="http://www.google.com/search?hl=en&amp;q=filetype%3apy+chaco+pyqt4">search for yourself</a>). So far i've figured i need the following lines:</p> <pre><code>import os os.environ['ETS_TOOLKIT']='qt4' <...
8
2010-01-27T15:47:33Z
2,148,775
<p>I don't know Chaco but a quick look tells me that this is not possible.</p> <p>Both Chaco and PyQt are graphical toolkits designed to interact with the user. Chaco is plot oriented and PyQt more application oriented. Each one has its own way of managing what a window is, how to detect user clicks, how to handle pai...
-1
2010-01-27T16:59:33Z
[ "python", "pyqt", "pyqt4", "chaco" ]
Python: Embed Chaco in PyQt4 Mystery
2,148,279
<p>How do i go about adding Chaco to an existing PyQt4 application?</p> <p>Hours of searches yielded little (<a href="http://www.google.com/search?hl=en&amp;q=filetype%3apy+chaco+pyqt4">search for yourself</a>). So far i've figured i need the following lines:</p> <pre><code>import os os.environ['ETS_TOOLKIT']='qt4' <...
8
2010-01-27T15:47:33Z
2,150,137
<p>I don't know about Chaco, but I'm using VTK, here is code to draw some lines, having a (x,y,z) coordinates of them.</p> <pre><code> """Define an actor and its properties, to be drawn on the scene using 'lines' representation.""" ren = vtk.vtkRenderer() apd=vtk.vtkAppendPolyData() for i in xrange(len...
0
2010-01-27T20:48:18Z
[ "python", "pyqt", "pyqt4", "chaco" ]
Python: Embed Chaco in PyQt4 Mystery
2,148,279
<p>How do i go about adding Chaco to an existing PyQt4 application?</p> <p>Hours of searches yielded little (<a href="http://www.google.com/search?hl=en&amp;q=filetype%3apy+chaco+pyqt4">search for yourself</a>). So far i've figured i need the following lines:</p> <pre><code>import os os.environ['ETS_TOOLKIT']='qt4' <...
8
2010-01-27T15:47:33Z
2,151,067
<p>here is what you need:</p> <pre><code>import os, sys os.environ['ETS_TOOLKIT'] = 'qt4' from PyQt4 import QtGui app = QtGui.QApplication(sys.argv) from numpy import linspace, pi, sin from enthought.enable.api import Component, Container, Window from enthought.chaco.api import create_line_plot, \ ...
7
2010-01-27T23:17:07Z
[ "python", "pyqt", "pyqt4", "chaco" ]
Python: Embed Chaco in PyQt4 Mystery
2,148,279
<p>How do i go about adding Chaco to an existing PyQt4 application?</p> <p>Hours of searches yielded little (<a href="http://www.google.com/search?hl=en&amp;q=filetype%3apy+chaco+pyqt4">search for yourself</a>). So far i've figured i need the following lines:</p> <pre><code>import os os.environ['ETS_TOOLKIT']='qt4' <...
8
2010-01-27T15:47:33Z
2,248,631
<p>I just saw this today. It is absolutely possible and fairly straightforward to embed Chaco inside Qt as well as WX. In fact, all of the examples, when run with your ETS_TOOLKIT environment var set to "qt4", are doing exactly this. (Chaco <em>requires</em> there to be an underlying GUI toolkit.)</p> <p>I have wri...
8
2010-02-11T23:40:36Z
[ "python", "pyqt", "pyqt4", "chaco" ]
Python: Rar Brute Forcer
2,148,393
<p>I am trying to brute force a RAR archive which is protected by a password with 3 characters:</p> <pre><code>import os Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for a in range(0,26): for b in range(0,26): for c in range(0,26): Brute = Alphabets[a] + Alphabets[b] + Alphabets[c] os.popen4("Rar.exe x -p" + Brut...
4
2010-01-27T16:04:11Z
2,148,427
<p>you might consider using some stdlib modules:</p> <pre><code>&gt;&gt;&gt; import string &gt;&gt;&gt; import itertools &gt;&gt;&gt; from subprocess import Popen, PIPE &gt;&gt;&gt; for i in itertools.product(string.ascii_uppercase, repeat=3): pr = Popen(['rar.exe', 'x', '-p', ''.join(i), 'protected.rar'], stdin=P...
5
2010-01-27T16:09:13Z
[ "python", "performance" ]
Python: Rar Brute Forcer
2,148,393
<p>I am trying to brute force a RAR archive which is protected by a password with 3 characters:</p> <pre><code>import os Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for a in range(0,26): for b in range(0,26): for c in range(0,26): Brute = Alphabets[a] + Alphabets[b] + Alphabets[c] os.popen4("Rar.exe x -p" + Brut...
4
2010-01-27T16:04:11Z
2,148,444
<p>You could use (or learn from) <a href="http://sourceforge.net/projects/rarcrack/" rel="nofollow">rarcrack</a>. It is written in C and compiles without problems on Linux (Windows with lots of changes).</p> <p>In general, opening a process for every single tested password is very expensive. You should try and open th...
7
2010-01-27T16:12:06Z
[ "python", "performance" ]
Python: Rar Brute Forcer
2,148,393
<p>I am trying to brute force a RAR archive which is protected by a password with 3 characters:</p> <pre><code>import os Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for a in range(0,26): for b in range(0,26): for c in range(0,26): Brute = Alphabets[a] + Alphabets[b] + Alphabets[c] os.popen4("Rar.exe x -p" + Brut...
4
2010-01-27T16:04:11Z
2,148,487
<p>The generating of the passwords is trivial, that's why it takes only 5 seconds to create the 26^3 = 17576 passwords. What takes the most time is opening and attempting to decrypt the archive - and you don't have control over that.</p> <p>There isn't much you can do about speeding this up - the rar binary and the i...
3
2010-01-27T16:19:05Z
[ "python", "performance" ]
Python: Rar Brute Forcer
2,148,393
<p>I am trying to brute force a RAR archive which is protected by a password with 3 characters:</p> <pre><code>import os Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for a in range(0,26): for b in range(0,26): for c in range(0,26): Brute = Alphabets[a] + Alphabets[b] + Alphabets[c] os.popen4("Rar.exe x -p" + Brut...
4
2010-01-27T16:04:11Z
2,148,542
<p>What about generating the passwords first an then parallelize the rar.exe process call(which seems to be the bottleneck)?</p>
0
2010-01-27T16:26:44Z
[ "python", "performance" ]
Python: Rar Brute Forcer
2,148,393
<p>I am trying to brute force a RAR archive which is protected by a password with 3 characters:</p> <pre><code>import os Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for a in range(0,26): for b in range(0,26): for c in range(0,26): Brute = Alphabets[a] + Alphabets[b] + Alphabets[c] os.popen4("Rar.exe x -p" + Brut...
4
2010-01-27T16:04:11Z
2,148,973
<p>You may not be able to cut down on the time it takes to make the attempt to decrypt the archive, but, assuming that the password is not completely random (which it may be), you may get to the correct password more quickly if you <strong>order the letters in decreasing likelihood of use</strong>.</p> <p>For example,...
0
2010-01-27T17:30:45Z
[ "python", "performance" ]
Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?
2,148,480
<p>I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count?</p> <p>(I've defined an <code>__eq__</code> to define uniqueness on my object definition).</p> <p>So in RDBMS-land, something like this:</p>...
4
2010-01-27T16:18:18Z
2,148,512
<p>Not easily doable as a list comprehension.</p> <pre><code>from collections import defaultdict def group_by( someList ): counts = defaultdict(int) for value in someList: counts[value.aKey] += 1 return counts </code></pre> <p>This is a very Pythonic solution. But not a list comprehension.</p>
6
2010-01-27T16:23:21Z
[ "python", "list", "count", "python-2.6" ]
Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?
2,148,480
<p>I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count?</p> <p>(I've defined an <code>__eq__</code> to define uniqueness on my object definition).</p> <p>So in RDBMS-land, something like this:</p>...
4
2010-01-27T16:18:18Z
2,148,531
<p><a href="http://stackoverflow.com/questions/2134416/pyparsing-where-order-of-tokens-in-unpredictable/2134640#2134640">Lennart Regebro provided a nice one-liner</a> that does what you want: </p> <pre><code>&gt;&gt;&gt; values = [1,1,1,2] &gt;&gt;&gt; print [(x,values.count(x)) for x in set(values)] [(1, 3), (2, 1...
10
2010-01-27T16:25:17Z
[ "python", "list", "count", "python-2.6" ]
Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?
2,148,480
<p>I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count?</p> <p>(I've defined an <code>__eq__</code> to define uniqueness on my object definition).</p> <p>So in RDBMS-land, something like this:</p>...
4
2010-01-27T16:18:18Z
2,148,555
<pre><code>&gt;&gt;&gt; from collections import Counter &gt;&gt;&gt; Counter([1,1,1,2]) Counter({1: 3, 2: 1}) </code></pre> <p><a href="http://docs.python.org/3.1/library/collections.html#collections.Counter">Counter</a> only available in py3.1, inherits from the <code>dict</code>.</p>
11
2010-01-27T16:28:14Z
[ "python", "list", "count", "python-2.6" ]
Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?
2,148,480
<p>I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count?</p> <p>(I've defined an <code>__eq__</code> to define uniqueness on my object definition).</p> <p>So in RDBMS-land, something like this:</p>...
4
2010-01-27T16:18:18Z
2,148,590
<p>You can use <a href="http://docs.python.org/library/itertools.html#itertools.groupby" rel="nofollow"><code>groupby</code></a> from the <code>itertools</code> module:</p> <blockquote> <p>Make an iterator that returns consecutive keys and groups from the iterable. The key is a function computing a key value for eac...
4
2010-01-27T16:33:54Z
[ "python", "list", "count", "python-2.6" ]
Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?
2,148,480
<p>I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count?</p> <p>(I've defined an <code>__eq__</code> to define uniqueness on my object definition).</p> <p>So in RDBMS-land, something like this:</p>...
4
2010-01-27T16:18:18Z
7,209,532
<p>The following works in Python 2.4 and <em>should</em> therefore work in Python 2.6:</p> <pre><code>lst = [1,1,2,2,3,4,5,6,5] lst_tmp = [] lst_dups = [] for item in lst: if item in lst_tmp: lst_dups.append(item) else: lst_tmp.append(item) if len(lst_dups): lst_dups = sorted(set(lst_dups...
1
2011-08-26T19:17:49Z
[ "python", "list", "count", "python-2.6" ]
scrape html generated by javascript with python
2,148,493
<p>I need to scrape a site with python. I obtain the source html code with the urlib module, but I need to scrape also some html code that is generated by a javascript function (which is included in the html source). What this functions does "in" the site is that when you press a button it outputs some html code. How c...
16
2010-01-27T16:20:22Z
2,148,595
<p>I have had to do this before (in .NET) and you are basically going to have to host a browser, get it to click the button, and then interrogate the DOM (document object model) of the browser to get at the generated HTML.</p> <p>This is definitely one of the downsides to web apps moving towards an Ajax/Javascript app...
4
2010-01-27T16:34:52Z
[ "javascript", "python", "browser", "screen-scraping" ]
scrape html generated by javascript with python
2,148,493
<p>I need to scrape a site with python. I obtain the source html code with the urlib module, but I need to scrape also some html code that is generated by a javascript function (which is included in the html source). What this functions does "in" the site is that when you press a button it outputs some html code. How c...
16
2010-01-27T16:20:22Z
5,272,521
<p>In Python, I think <a href="http://seleniumhq.org/projects/remote-control/">Selenium 1.0</a> is the way to go. It’s a library that allows you to control a real web browser from your language of choice.</p> <p>You need to have the web browser in question installed on the machine your script runs on, but it looks l...
10
2011-03-11T11:49:34Z
[ "javascript", "python", "browser", "screen-scraping" ]
scrape html generated by javascript with python
2,148,493
<p>I need to scrape a site with python. I obtain the source html code with the urlib module, but I need to scrape also some html code that is generated by a javascript function (which is included in the html source). What this functions does "in" the site is that when you press a button it outputs some html code. How c...
16
2010-01-27T16:20:22Z
8,365,246
<p>I use webkit, which is the browser renderer behind Chrome and Safari. There are <a href="http://www.pyside.org/docs/pyside/PySide/QtWebKit/index.html" rel="nofollow">Python bindings to webkit through Qt</a>. And here is a full <a href="http://webscraping.com/blog/Scraping-JavaScript-webpages-with-webkit/" rel="nofol...
3
2011-12-03T03:24:21Z
[ "javascript", "python", "browser", "screen-scraping" ]
scrape html generated by javascript with python
2,148,493
<p>I need to scrape a site with python. I obtain the source html code with the urlib module, but I need to scrape also some html code that is generated by a javascript function (which is included in the html source). What this functions does "in" the site is that when you press a button it outputs some html code. How c...
16
2010-01-27T16:20:22Z
15,016,098
<p>No need for Python or any scripts.</p> <p>In Safari 5.1.7 on Mac 10.6.8, I activated the Develop menu:</p> <ol> <li>Launch Safari</li> <li>Select Safari > Preferences in the menubar.</li> <li>In the window that opens, select the Advanced tab.</li> <li>Check the button Show Develop Menu In Menu Bar.</li> </ol> <p>...
0
2013-02-22T02:57:21Z
[ "javascript", "python", "browser", "screen-scraping" ]
scrape html generated by javascript with python
2,148,493
<p>I need to scrape a site with python. I obtain the source html code with the urlib module, but I need to scrape also some html code that is generated by a javascript function (which is included in the html source). What this functions does "in" the site is that when you press a button it outputs some html code. How c...
16
2010-01-27T16:20:22Z
19,835,401
<p>For <a href="http://scrapy.org/" rel="nofollow">Scrapy</a> (great python scraping framework) there is <a href="https://github.com/scrapinghub/scrapyjs" rel="nofollow">scrapyjs</a>: an additional downloader handler / middleware handler able to scraping javascript generated content.</p> <p>It's based on webkit engine...
0
2013-11-07T12:01:13Z
[ "javascript", "python", "browser", "screen-scraping" ]
scrape html generated by javascript with python
2,148,493
<p>I need to scrape a site with python. I obtain the source html code with the urlib module, but I need to scrape also some html code that is generated by a javascript function (which is included in the html source). What this functions does "in" the site is that when you press a button it outputs some html code. How c...
16
2010-01-27T16:20:22Z
36,289,608
<p>Since there is no comprehensive answer here, I'll go ahead and write one.</p> <p>To scrape off JS rendered pages, we will need a browser that has a JavaScript engine (e.i, support JavaScript rendering)</p> <p>Options like <em>Mechanize</em>, <em>url2lib</em> will not work since they <strong>DO NOT</strong> support...
0
2016-03-29T16:11:42Z
[ "javascript", "python", "browser", "screen-scraping" ]
Python: strange numbers being pulled from binary file /confusion with hex and decimals
2,148,538
<p>This might be extremely trivial, and if so I apologise, but I'm getting really confused with the outputs I'm getting: hex? decimal? what?</p> <p>Here's an example, and what it returns:</p> <pre><code>&gt;&gt;&gt; print 'Rx State: ADC Clk=', ADC_Clock_MHz,'MHz DDC Clk=', DDC_Clock_kHz,'kHz Temperature=', Temperatur...
1
2010-01-27T16:26:37Z
2,148,574
<p>The contents are in pairs because you assign a pair to the variables (e.g. <code>ADC_Clock_MHz = v1</code> and <code>v1 = [content[pos+1], content[pos]]</code>).</p> <p>You are basically assigning a list of two elements to <code>v1</code> where the first element is the element in the index <code>pos+1</code> in the...
0
2010-01-27T16:30:58Z
[ "python", "binary", "numpy", "hex" ]
Python: strange numbers being pulled from binary file /confusion with hex and decimals
2,148,538
<p>This might be extremely trivial, and if so I apologise, but I'm getting really confused with the outputs I'm getting: hex? decimal? what?</p> <p>Here's an example, and what it returns:</p> <pre><code>&gt;&gt;&gt; print 'Rx State: ADC Clk=', ADC_Clock_MHz,'MHz DDC Clk=', DDC_Clock_kHz,'kHz Temperature=', Temperatur...
1
2010-01-27T16:26:37Z
2,149,963
<p>You might be happier with something like the following to read this block.</p> <p>If your data isn't unpacking properly, the most likely cause is that the header is not simply 2 Long integers. Or, it's possible that the doesn't reflect the "endian-ness" of your platform.</p> <p>Using <code>struct</code> allows yo...
0
2010-01-27T20:19:00Z
[ "python", "binary", "numpy", "hex" ]
Python: strange numbers being pulled from binary file /confusion with hex and decimals
2,148,538
<p>This might be extremely trivial, and if so I apologise, but I'm getting really confused with the outputs I'm getting: hex? decimal? what?</p> <p>Here's an example, and what it returns:</p> <pre><code>&gt;&gt;&gt; print 'Rx State: ADC Clk=', ADC_Clock_MHz,'MHz DDC Clk=', DDC_Clock_kHz,'kHz Temperature=', Temperatur...
1
2010-01-27T16:26:37Z
2,267,107
<p>Found out it's incredibly easy to do this with numpy.fromfile</p> <p>Specify what you want to extract (e.g. uint32, int16 etc.) and it extracts it as an array. You can even specify your own types as a collection of existing types, meaning you can extract known structures in one go (e.g. 2 uint32s then 1 string then...
0
2010-02-15T15:57:16Z
[ "python", "binary", "numpy", "hex" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
2,148,739
<p>You should map from classes to a row in your confusion matrix.</p> <p>Here the mapping is trivial:</p> <pre><code>def row_of_class(classe): return {1: 0, 2: 1}[classe] </code></pre> <p>In your loop, compute <code>expected_row</code>, <code>correct_row</code>, and increment <code>conf_arr[expected_row][correct...
0
2010-01-27T16:54:25Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
2,148,747
<p>This function creates confusion matrices for any number of classes. </p> <pre><code>def create_conf_matrix(expected, predicted, n_classes): m = [[0] * n_classes for i in range(n_classes)] for pred, exp in zip(predicted, expected): m[pred][exp] += 1 return m def calc_accuracy(conf_matrix): t...
1
2010-01-27T16:55:38Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
2,148,845
<p>In a general sense, you're going to need to change your probability array. Instead of having one number for each instance and classifying based on whether or not it is greater than 0.5, you're going to need a list of scores (one for each class), then take the largest of the scores as the class that was chosen (a.k....
0
2010-01-27T17:08:26Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
2,149,301
<p>You can make your code more concise and (sometimes) to run faster using <a href="http://numpy.scipy.org/" rel="nofollow"><code>numpy</code></a>. For example, in two-classes case your function can be rewritten as (see <a href="https://mlpy.fbk.eu/browser/trunk/mlpy/_bmetrics.py#L130" rel="nofollow"><code>mply.acc()</...
0
2010-01-27T18:18:04Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
2,150,271
<p>Here's a confusion matrix class that supports pretty-printing, etc:</p> <p><a href="http://nltk.googlecode.com/svn/trunk/doc/api/nltk.metrics.confusionmatrix-pysrc.html" rel="nofollow">http://nltk.googlecode.com/svn/trunk/doc/api/nltk.metrics.confusionmatrix-pysrc.html</a></p>
2
2010-01-27T21:10:37Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
14,271,799
<p><a href="http://scikit-learn.org/stable/">Scikit-learn</a> (which I recommend using anyways) has it included in the <code>metrics</code> module:</p> <pre><code>&gt;&gt;&gt; from sklearn.metrics import confusion_matrix &gt;&gt;&gt; y_true = [0, 1, 2, 0, 1, 2, 0, 1, 2] &gt;&gt;&gt; y_pred = [0, 0, 0, 0, 1, 1, 0, 2, 2...
10
2013-01-11T04:41:36Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
29,877,565
<p>Scikit-Learn provide a <code>confusion_matrix</code> function</p> <pre><code>from sklearn.metrics import confusion_matrix y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2] y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2] confusion_matrix(y_actu, y_pred) </code></pre> <p>which output a Numpy array</p> <pre><code>array([[...
21
2015-04-26T12:22:11Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
30,385,488
<p>If you don't want scikit-learn to do the work for you...</p> <pre><code> import numpy actual = numpy.array(actual) predicted = numpy.array(predicted) # calculate the confusion matrix; labels is numpy array of classification labels cm = numpy.zeros((len(labels), len(labels))) for a, p in zip(...
0
2015-05-21T22:37:03Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
32,630,822
<p>I wrote a simple class to build a confusion matrix without the need to depend on a machine learning library.</p> <p>The class can be used such as:</p> <pre class="lang-py prettyprint-override"><code>labels = ["cat", "dog", "velociraptor", "kraken", "pony"] confusionMatrix = ConfusionMatrix(labels) confusionMatrix...
0
2015-09-17T12:54:49Z
[ "python", "machine-learning" ]
How to write a confusion matrix in Python?
2,148,543
<p>I wrote a confusion matrix calculation code in Python:</p> <pre><code>def conf_mat(prob_arr, input_arr): # confusion matrix conf_arr = [[0, 0], [0, 0]] for i in range(len(prob_arr)): if int(input_arr[i]) == 1: if float(prob_arr[i]) &lt; 0.5: ...
11
2010-01-27T16:27:19Z
38,854,537
<p>Only with numpy, we can do as follow considering efficiency:</p> <pre><code>def confusion_matrix(pred, label, nc=None): assert pred.size == label.size if nc is None: nc = len(unique(label)) logging.debug("Number of classes assumed to be {}".format(nc)) confusion = np.zeros([nc, nc]) ...
0
2016-08-09T15:13:44Z
[ "python", "machine-learning" ]
How do I find the shortest overlapping match using regular expressions?
2,148,700
<p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p> <pre><code>import re string = "A|B|A|B|C|D|E|F|G" my_pattern = 'a.*?b.*?c' my_regex = re.compile(my_p...
12
2010-01-27T16:49:34Z
2,148,782
<p>No. Perl returns the longest, leftmost match, while obeying your non-greedy quantifiers. You'll have to loop, I'm afraid.</p> <p>Edit: Yes, I realize I said Perl above, but I believe it is true for Python.</p>
1
2010-01-27T17:00:40Z
[ "python", "regex" ]
How do I find the shortest overlapping match using regular expressions?
2,148,700
<p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p> <pre><code>import re string = "A|B|A|B|C|D|E|F|G" my_pattern = 'a.*?b.*?c' my_regex = re.compile(my_p...
12
2010-01-27T16:49:34Z
2,148,812
<p>The regex engine starts searching from the beginning of the string till it finds a match and then exits. Thus if it finds a match before it even considers the smaller one, there is no way for you to force it to consider later matches in the same run - you will have to rerun the regex on substrings.</p> <p>Setting t...
0
2010-01-27T17:04:12Z
[ "python", "regex" ]