title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Python: How to make a cross-module variable?
142,545
<p>The <code>__debug__</code> variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?</p> <p>The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is upd...
82
2008-09-26T23:59:47Z
142,669
<p>Global variables are usually a bad idea, but you can do this by assigning to <code>__builtins__</code>:</p> <pre><code>__builtins__.foo = 'something' print foo </code></pre> <p>Also, modules themselves are variables that you can access from any module. So if you define a module called <code>my_globals.py</code>:<...
6
2008-09-27T01:03:43Z
[ "python", "module", "global" ]
Python: How to make a cross-module variable?
142,545
<p>The <code>__debug__</code> variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?</p> <p>The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is upd...
82
2008-09-26T23:59:47Z
3,269,974
<p>You can pass the globals of one module to onother:</p> <p>In Module A:</p> <pre><code>import module_b my_var=2 module_b.do_something_with_my_globals(globals()) print my_var </code></pre> <p>In Module B:</p> <pre><code>def do_something_with_my_globals(glob): # glob is simply a dict. glob["my_var"]=3 </code></...
8
2010-07-17T02:22:22Z
[ "python", "module", "global" ]
Python: How to make a cross-module variable?
142,545
<p>The <code>__debug__</code> variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?</p> <p>The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is upd...
82
2008-09-26T23:59:47Z
3,911,089
<p>You can already do this with module-level variables. Modules are the same no matter what module they're being imported from. So you can make the variable a module-level variable in whatever module it makes sense to put it in, and access it or assign to it from other modules. It would be better to call a function ...
5
2010-10-12T01:26:37Z
[ "python", "module", "global" ]
Python: How to make a cross-module variable?
142,545
<p>The <code>__debug__</code> variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?</p> <p>The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is upd...
82
2008-09-26T23:59:47Z
10,158,462
<p>I use this for a couple built-in primitive functions that I felt were really missing. One example is a find function that has the same usage semantics as filter, map, reduce.</p> <pre><code>def builtin_find(f, x, d=None): for i in x: if f(i): return i return d import __builtin__ __buil...
0
2012-04-15T00:10:57Z
[ "python", "module", "global" ]
Python: How to make a cross-module variable?
142,545
<p>The <code>__debug__</code> variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?</p> <p>The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is upd...
82
2008-09-26T23:59:47Z
15,035,172
<p>I believe that there are plenty of circumstances in which it does make sense and it simplifies programming to have some globals that are known across several (tightly coupled) modules. In this spirit, I would like to elaborate a bit on the idea of having a module of globals which is imported by those modules which ...
13
2013-02-22T23:48:03Z
[ "python", "module", "global" ]
Python: How to make a cross-module variable?
142,545
<p>The <code>__debug__</code> variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?</p> <p>The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is upd...
82
2008-09-26T23:59:47Z
20,331,768
<p>I could achieve cross-module modifiable (or <strong>mutable</strong>) variables by using a dictionary:</p> <pre><code># in myapp.__init__ Timeouts = {} # cross-modules global mutable variables for testing purpose Timeouts['WAIT_APP_UP_IN_SECONDS'] = 60 # in myapp.mod1 from myapp import Timeouts def wait_app_up(pr...
0
2013-12-02T15:24:38Z
[ "python", "module", "global" ]
Python: How to make a cross-module variable?
142,545
<p>The <code>__debug__</code> variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?</p> <p>The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is upd...
82
2008-09-26T23:59:47Z
31,737,507
<p>I wanted to post an answer that there is a case where the variable won't be found.</p> <p>Cyclical imports may break the module behavior.</p> <p>For example:</p> <p>first.py</p> <pre><code>import second var = 1 </code></pre> <p>second.py</p> <pre><code>import first print(first.var) # will throw an error becau...
0
2015-07-31T03:14:05Z
[ "python", "module", "global" ]
How do I upgrade python 2.5.2 to python 2.6rc2 on ubuntu linux 8.04?
142,764
<p>I'd like to how to upgrade the default python installation(2.5.2) supplied with ubuntu 8.04 to python 2.6rc2. I'd like to make 2.6 the default python version on the system and migrate all the other useful installed python libraries installed on 2.5.2 to python 2.6rc2. Please let me know how I can achieve this.</p> ...
8
2008-09-27T02:15:03Z
142,770
<p>With the warning that I think it's a tremendously bad idea to replace the default Python with an unreleased beta version:</p> <p>First, install 2.6rc2. You can download the source from the <a href="http://www.python.org/download/releases/2.6/">Python website</a>. Standard <code>./configure &amp;&amp; make &amp;&amp...
15
2008-09-27T02:19:38Z
[ "python", "linux", "ubuntu", "installation" ]
How do I upgrade python 2.5.2 to python 2.6rc2 on ubuntu linux 8.04?
142,764
<p>I'd like to how to upgrade the default python installation(2.5.2) supplied with ubuntu 8.04 to python 2.6rc2. I'd like to make 2.6 the default python version on the system and migrate all the other useful installed python libraries installed on 2.5.2 to python 2.6rc2. Please let me know how I can achieve this.</p> ...
8
2008-09-27T02:15:03Z
142,777
<p>Is there any need to?</p> <p>Ubuntu in general doesn't package RC releases. 2.6 will not be available in Ubuntu until Jaunty Jackalope.</p> <p>However,, if you insist that you need to install it, then, you'll have to do so without a package manager.</p> <p>Download the package, and unzip it to a directory</p> <p...
1
2008-09-27T02:25:18Z
[ "python", "linux", "ubuntu", "installation" ]
How do I upgrade python 2.5.2 to python 2.6rc2 on ubuntu linux 8.04?
142,764
<p>I'd like to how to upgrade the default python installation(2.5.2) supplied with ubuntu 8.04 to python 2.6rc2. I'd like to make 2.6 the default python version on the system and migrate all the other useful installed python libraries installed on 2.5.2 to python 2.6rc2. Please let me know how I can achieve this.</p> ...
8
2008-09-27T02:15:03Z
152,185
<p>It would not be wise to change the default version of Python, i.e. what you get when you type "python" into a shell. However, you can have multiple versions of python installed. The trick is to make sure that the program named "python" on the path is the system supplied version. If you want to run your install of P...
1
2008-09-30T08:10:39Z
[ "python", "linux", "ubuntu", "installation" ]
How do I upgrade python 2.5.2 to python 2.6rc2 on ubuntu linux 8.04?
142,764
<p>I'd like to how to upgrade the default python installation(2.5.2) supplied with ubuntu 8.04 to python 2.6rc2. I'd like to make 2.6 the default python version on the system and migrate all the other useful installed python libraries installed on 2.5.2 to python 2.6rc2. Please let me know how I can achieve this.</p> ...
8
2008-09-27T02:15:03Z
633,753
<p>I have the same issue, and apparently pre-built binaries can be found here:</p> <pre><code># Python 2.6 deb http://ppa.launchpad.net/doko/ubuntu intrepid main deb-src http://ppa.launchpad.net/doko/ubuntu intrepid main </code></pre>
6
2009-03-11T08:41:01Z
[ "python", "linux", "ubuntu", "installation" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
142,821
<p>NumPy has a <a href="http://numpy.scipy.org/array_interface.shtml" rel="nofollow">array interface</a> module that you can use to make a bitfield.</p>
4
2008-09-27T02:52:13Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
142,846
<p>The BitVector package may be what you need. It's not built in to my python installation, but easy to track down on the python site.</p> <p><a href="https://pypi.python.org/pypi/BitVector" rel="nofollow">https://pypi.python.org/pypi/BitVector</a> for the current version.</p>
5
2008-09-27T03:03:16Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
143,221
<p><a href="http://pypi.python.org/pypi/bitarray/">Bitarray</a> was the best answer I found, when I recently had a similar need. It's a C extension (so much faster than BitVector, which is pure python) and stores its data in an actual bitfield (so it's eight times more memory efficient than a numpy boolean array, whic...
22
2008-09-27T08:20:43Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
143,247
<p>If your bitfield is short, you can probably use <a href="http://docs.python.org/lib/module-struct.html" rel="nofollow">the struct module</a>. Otherwise I'd recommend some sort of a wrapper around <a href="http://docs.python.org/lib/module-array.html" rel="nofollow">the array module</a>.</p> <p>Also, the ctypes modu...
2
2008-09-27T08:41:05Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
143,643
<p>I use the binary bit-wise operators !, &amp;, |, ^, >>, and &lt;&lt;. They work really well and are implemented directly in the underlying C, which is usually directly on the underlying hardware.</p>
4
2008-09-27T13:26:06Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
265,491
<p>Represent each of your values as a power of two:</p> <pre><code>testA = 2**0 testB = 2**1 testC = 2**3 </code></pre> <p>Then to set a value true:</p> <pre><code>table = table | testB </code></pre> <p>To set a value false:</p> <pre><code>table = table &amp; (~testC) </code></pre> <p>To test for a value:</p> <p...
5
2008-11-05T15:30:33Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
1,574,928
<p>You should take a look at the <a href="http://python-bitstring.googlecode.com">bitstring</a> module, which has recently reached version 2.0. The binary data is compactly stored as a byte array and can be easily created, modified and analysed.</p> <p>You can create <code>BitString</code> objects from binary, octal, ...
10
2009-10-15T20:43:54Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
3,730,785
<p>If you want to use ints (or long ints) to represent as arrays of bools (or as sets of integers), take a look at <a href="http://sourceforge.net/projects/pybitop/files/" rel="nofollow">http://sourceforge.net/projects/pybitop/files/</a></p> <p>It provides insert/extract of bitfields into long ints; finding the most-...
1
2010-09-16T21:01:07Z
[ "python", "bit-fields", "bitarray" ]
Does Python have a bitfield type?
142,812
<p>I need a compact representation of an array of booleans, does Python have a builtin bitfield type or will I need to find an alternate solution?</p>
34
2008-09-27T02:47:40Z
11,481,471
<p>If you mainly want to be able to name your bit fields and easily manipulate them, e.g. to work with flags represented as single bits in a communications protocol, then you can use the standard Structure and Union features of <a href="http://docs.python.org/library/ctypes.html">ctypes</a>, as described at <a href="ht...
24
2012-07-14T06:02:45Z
[ "python", "bit-fields", "bitarray" ]
Drag and drop onto Python script in Windows Explorer
142,844
<p>I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a command-line parameter, but Windows Explorer doesn't allow the script to be a drop target.</p> <p>Is there some kind of configuration that needs ...
37
2008-09-27T03:02:30Z
142,854
<p>Sure. From a <a href="http://mindlesstechnology.wordpress.com/2008/03/29/make-python-scripts-droppable-in-windows/">mindless technology article called "Make Python Scripts Droppable in Windows"</a>, you can add a drop handler by adding a registry key:</p> <blockquote> <p>Here’s a registry import file that you c...
46
2008-09-27T03:06:25Z
[ "python", "windows", "drag-and-drop", "windows-explorer" ]
Drag and drop onto Python script in Windows Explorer
142,844
<p>I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a command-line parameter, but Windows Explorer doesn't allow the script to be a drop target.</p> <p>Is there some kind of configuration that needs ...
37
2008-09-27T03:02:30Z
4,486,506
<p>Try using py2exe. Use py2exe to convert your python script into a windows executable. You should then be able to drag and drop input files to your script in Windows Explorer. You should also be able to create a shortcut on your desktop and drop input files onto it. And if your python script can take a file list ...
5
2010-12-20T02:47:21Z
[ "python", "windows", "drag-and-drop", "windows-explorer" ]
Drag and drop onto Python script in Windows Explorer
142,844
<p>I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a command-line parameter, but Windows Explorer doesn't allow the script to be a drop target.</p> <p>Is there some kind of configuration that needs ...
37
2008-09-27T03:02:30Z
10,246,159
<p>write a simple shell script (file.bat)</p> <pre><code>"c:\Python27\python.exe" yourprogram.py %1 </code></pre> <p>where %1 stands for the firs argument you pass to the script.</p> <p>Now drag%drop your target files on the file.bat icon.</p>
18
2012-04-20T12:21:36Z
[ "python", "windows", "drag-and-drop", "windows-explorer" ]
Drag and drop onto Python script in Windows Explorer
142,844
<p>I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a command-line parameter, but Windows Explorer doesn't allow the script to be a drop target.</p> <p>Is there some kind of configuration that needs ...
37
2008-09-27T03:02:30Z
21,840,490
<p>Create a shortcut of the file. In case you don't have python open .py files by default, go into the properties of the shortcut and edit the target of the shortcut to include the python version you're using. For example:</p> <p>Target: C:\Python26\python.exe &lt; shortcut target path></p> <p>I'm posting this bec...
0
2014-02-17T22:23:58Z
[ "python", "windows", "drag-and-drop", "windows-explorer" ]
Drag and drop onto Python script in Windows Explorer
142,844
<p>I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a command-line parameter, but Windows Explorer doesn't allow the script to be a drop target.</p> <p>Is there some kind of configuration that needs ...
37
2008-09-27T03:02:30Z
35,284,322
<p>The working directory may be in Window/System32 when get error: IOError: [Errno 2] No such file or directory: .... So you need to change to the script or input file directory firstly. Such as: </p> <p><code>os.chdir(os.path.split(sys.argv[0])[0])</code></p>
-1
2016-02-09T05:09:05Z
[ "python", "windows", "drag-and-drop", "windows-explorer" ]
OCSP libraries for python / java / c?
143,515
<p>Going back to my previous question on OCSP, does anybody know of "reliable" OCSP libraries for Python, Java and C?</p> <p>I need "client" OCSP functionality, as I'll be checking the status of Certs against an OCSP responder, so responder functionality is not that important.</p> <p>Thanks</p>
3
2008-09-27T12:12:32Z
143,996
<p>Have you check pyOpenSSL.. am sure openssl supports ocsp and python binding may support it</p>
1
2008-09-27T16:57:12Z
[ "java", "python", "c", "ocsp" ]
OCSP libraries for python / java / c?
143,515
<p>Going back to my previous question on OCSP, does anybody know of "reliable" OCSP libraries for Python, Java and C?</p> <p>I need "client" OCSP functionality, as I'll be checking the status of Certs against an OCSP responder, so responder functionality is not that important.</p> <p>Thanks</p>
3
2008-09-27T12:12:32Z
144,139
<p>Java 5 has support of revocation checking via <a href="http://java.sun.com/j2se/1.5.0/docs/guide/security/pki-tiger.html#OCSP" rel="nofollow">OCSP built in</a>. If you want to build an OCSP responder, or have finer control over revocation checking, check out <a href="http://www.bouncycastle.org/docs/docs1.5/overview...
3
2008-09-27T17:53:57Z
[ "java", "python", "c", "ocsp" ]
OCSP libraries for python / java / c?
143,515
<p>Going back to my previous question on OCSP, does anybody know of "reliable" OCSP libraries for Python, Java and C?</p> <p>I need "client" OCSP functionality, as I'll be checking the status of Certs against an OCSP responder, so responder functionality is not that important.</p> <p>Thanks</p>
3
2008-09-27T12:12:32Z
189,046
<p><a href="http://www.openssl.org/" rel="nofollow">OpenSSL</a> is the most widely used product for OCSP in C. It's quite reliable, although incredibly obtuse. I'd recommend looking at apps/ocsp.c for a pretty good example of how to make OCSP requests and validate responses.</p> <p>Vista and Server 2008 have built-in ...
1
2008-10-09T20:20:57Z
[ "java", "python", "c", "ocsp" ]
Crypto/X509 certificate parsing libraries for Python
143,632
<p>Any recommended crypto libraries for Python. I know I've asked something similar in <a href="http://stackoverflow.com/questions/143523/">x509 certificate parsing libraries for Java</a>, but I should've split the question in two.</p> <p>What I need is the ability to parse X.509 Certificates to extract the informatio...
5
2008-09-27T13:15:33Z
144,087
<p>You might want to try <a href="http://www.keyczar.org/" rel="nofollow">keyczar</a> as mentioned by me in your other post, since that library actually has implementations for both python and java. That would make it easier to use it in both contexts.</p> <p>A word of warning: I have not actually used this library 8(...
3
2008-09-27T17:28:36Z
[ "python", "cryptography", "openssl", "x509" ]
Crypto/X509 certificate parsing libraries for Python
143,632
<p>Any recommended crypto libraries for Python. I know I've asked something similar in <a href="http://stackoverflow.com/questions/143523/">x509 certificate parsing libraries for Java</a>, but I should've split the question in two.</p> <p>What I need is the ability to parse X.509 Certificates to extract the informatio...
5
2008-09-27T13:15:33Z
349,462
<p>Use M2Crypto, it is the most complete tool IMHO</p>
5
2008-12-08T12:58:51Z
[ "python", "cryptography", "openssl", "x509" ]
Crypto/X509 certificate parsing libraries for Python
143,632
<p>Any recommended crypto libraries for Python. I know I've asked something similar in <a href="http://stackoverflow.com/questions/143523/">x509 certificate parsing libraries for Java</a>, but I should've split the question in two.</p> <p>What I need is the ability to parse X.509 Certificates to extract the informatio...
5
2008-09-27T13:15:33Z
2,038,330
<p>My experience is that most crypto libraries are focused on a particular workflow - making a certain set of tasks easier and others hard or perhaps impossible. The exception to this would be ones that have really been around a long time and have matured (e.g. openssl, bounceycastle, but none of the python libraries i...
1
2010-01-10T19:48:35Z
[ "python", "cryptography", "openssl", "x509" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
144,212
<p><a href="http://www.sontek.net/python-with-a-modular-ide-vim" rel="nofollow">Here you can find some info</a> about this.</p> <p>It covers code completion, having a list of classes and functions in open files. I haven't got around to do a full configuration for vim, since I don't use Python primarily, but I have the...
17
2008-09-27T18:42:39Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
144,278
<p>Here is some info on Bazaar integration if you're interested:</p> <p>https://launchpad.net/bzr-vim-commands</p>
1
2008-09-27T19:29:39Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
144,646
<p>For refactoring: <a href="http://rope.sourceforge.net/ropevim.html" rel="nofollow">ropevim</a></p>
2
2008-09-27T22:38:49Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
149,921
<p><strong>Code completion:</strong> <a href="http://github.com/orestis/pysmell/tree/master" rel="nofollow">PySmell</a> looks promising. It's work-in-progress, but alredy useful.</p>
0
2008-09-29T18:04:00Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
150,378
<p>I use <a href="http://www.vim.org/scripts/script.php?script_id=910" rel="nofollow">pydoc.vim</a> (I actually wrote it) a lot, try it and tell me what you think. Another one that I think is quite useful is the updated syntax file with all it's extensions that you can enable, which you can find <a href="http://www.vim...
1
2008-09-29T19:55:24Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
1,148,862
<p>I use Pydiction (<a href="http://www.vim.org/scripts/script.php?script_id=850" rel="nofollow">http://www.vim.org/scripts/script.php?script_id=850</a>) it's a plugin for vim that lets you Tab-complete python modules/methods/attributes/keywords, including 3rd party stuff like Pygame, wxPython, Twisted, and literally e...
1
2009-07-18T23:24:25Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
3,113,907
<p>Old question, but I typed all this up for a misread question...</p> <p><strong>General plugin recommendations</strong>: <a href="http://www.vim.org/scripts/script.php?script_id=1581" rel="nofollow">LookupFile</a> and a plugin for your source control system (I like <a href="http://git-scm.com/" rel="nofollow">Git</a...
3
2010-06-24T21:12:36Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
7,780,004
<p>And I write another plugin: <a href="https://github.com/klen/python-mode" rel="nofollow">https://github.com/klen/python-mode</a></p> <p>Old (now its more powerful) screencast here: <a href="https://www.youtube.com/watch?v=67OZNp9Z0CQ" rel="nofollow">https://www.youtube.com/watch?v=67OZNp9Z0CQ</a></p>
4
2011-10-15T19:09:27Z
[ "python", "vim", "code-completion" ]
Has anyone found a good set of python plugins for vim -- specifically module completion?
144,201
<p>I'm looking for a suite of plugins that can help me finally switch over to vim full-time.</p> <p>Right now I'm using Komodo with some good success, but their vim bindings have enough little errors that I'm tired of it.</p> <p>What I do love in Komodo, though, is the code completion. So, here's what I'm looking for...
22
2008-09-27T18:28:42Z
18,787,006
<p>I personally think<a href="https://github.com/davidhalter/jedi-vim" rel="nofollow">Jedi Vim</a> is the best, but it is incompatible with python-mode.</p>
0
2013-09-13T13:02:44Z
[ "python", "vim", "code-completion" ]
Significant figures in the decimal module
144,218
<p>So I've decided to try to solve my physics homework by writing some python scripts to solve problems for me. One problem that I'm running into is that significant figures don't always seem to come out properly. For example this handles significant figures properly:</p> <pre><code>from decimal import Decimal &gt;&...
4
2008-09-27T18:47:54Z
144,225
<p>Decimal defaults to 28 places of precision.<br/> The only way to limit the number of digits it returns is by altering the precision.</p>
0
2008-09-27T18:53:49Z
[ "python", "floating-point", "decimal", "physics", "significance" ]
Significant figures in the decimal module
144,218
<p>So I've decided to try to solve my physics homework by writing some python scripts to solve problems for me. One problem that I'm running into is that significant figures don't always seem to come out properly. For example this handles significant figures properly:</p> <pre><code>from decimal import Decimal &gt;&...
4
2008-09-27T18:47:54Z
144,231
<p>Decimals won't throw away decimal places like that. If you really want to limit precision to 2 d.p. then try</p> <pre><code>decimal.getcontext().prec=2 </code></pre> <p>EDIT: You can alternatively call quantize() every time you multiply or divide (addition and subtraction will preserve the 2 dps).</p>
2
2008-09-27T18:58:37Z
[ "python", "floating-point", "decimal", "physics", "significance" ]
Significant figures in the decimal module
144,218
<p>So I've decided to try to solve my physics homework by writing some python scripts to solve problems for me. One problem that I'm running into is that significant figures don't always seem to come out properly. For example this handles significant figures properly:</p> <pre><code>from decimal import Decimal &gt;&...
4
2008-09-27T18:47:54Z
144,253
<p>If I undertand Decimal correctly, the "precision" is the number of digits after the decimal point in <em>decimal notation</em>.</p> <p>You seem to want something else: the number of significant digits. That is one more than the number of digits after the decimal point in <em>scientific notation</em>.</p> <p>I woul...
0
2008-09-27T19:11:46Z
[ "python", "floating-point", "decimal", "physics", "significance" ]
Significant figures in the decimal module
144,218
<p>So I've decided to try to solve my physics homework by writing some python scripts to solve problems for me. One problem that I'm running into is that significant figures don't always seem to come out properly. For example this handles significant figures properly:</p> <pre><code>from decimal import Decimal &gt;&...
4
2008-09-27T18:47:54Z
144,263
<p>What's wrong with floating point? </p> <pre><code>&gt;&gt;&gt; "%8.2e"% ( 1.0/3.0 ) '3.33e-01' </code></pre> <p>It was designed for scientific-style calculations with a limited number of significant digits.</p>
0
2008-09-27T19:17:57Z
[ "python", "floating-point", "decimal", "physics", "significance" ]
Significant figures in the decimal module
144,218
<p>So I've decided to try to solve my physics homework by writing some python scripts to solve problems for me. One problem that I'm running into is that significant figures don't always seem to come out properly. For example this handles significant figures properly:</p> <pre><code>from decimal import Decimal &gt;&...
4
2008-09-27T18:47:54Z
144,573
<p>Changing the decimal working precision to 2 digits is <em>not</em> a good idea, unless you absolutely only are going to perform a single operation.</p> <p>You should always perform calculations at higher precision than the level of significance, and only round the final result. If you perform a long sequence of cal...
6
2008-09-27T22:00:35Z
[ "python", "floating-point", "decimal", "physics", "significance" ]
Significant figures in the decimal module
144,218
<p>So I've decided to try to solve my physics homework by writing some python scripts to solve problems for me. One problem that I'm running into is that significant figures don't always seem to come out properly. For example this handles significant figures properly:</p> <pre><code>from decimal import Decimal &gt;&...
4
2008-09-27T18:47:54Z
719,519
<p>Just out of curiosity...is it necessary to use the decimal module? Why not floating point with a significant-figures rounding of numbers when you are ready to see them? Or are you trying to keep track of the significant figures of the computation (like when you have to do an error analysis of a result, calculating t...
1
2009-04-05T19:23:02Z
[ "python", "floating-point", "decimal", "physics", "significance" ]
Python PostgreSQL modules. Which is best?
144,448
<p>I've seen a number of postgresql modules for python like pygresql, pypgsql, psyco. Most of them are Python DB API 2.0 compliant, some are not being actively developed anymore. Which module do you recommend? Why?</p>
20
2008-09-27T20:55:04Z
144,462
<p>psycopg2 seems to be the most popular. I've never had any trouble with it. There's actually a pure Python interface for PostgreSQL too, called <a href="http://barryp.org/software/bpgsql/">bpgsql</a>. I wouldn't recommend it over psycopg2, but it's recently become capable enough to support Django and is useful if ...
15
2008-09-27T21:00:21Z
[ "python", "postgresql", "module" ]
Python PostgreSQL modules. Which is best?
144,448
<p>I've seen a number of postgresql modules for python like pygresql, pypgsql, psyco. Most of them are Python DB API 2.0 compliant, some are not being actively developed anymore. Which module do you recommend? Why?</p>
20
2008-09-27T20:55:04Z
145,801
<p>Psycopg1 is known for better performance in heavilyy threaded environments (like web applications) than Psycopg2, although not maintained. Both are well written and rock solid, I'd choose one of these two depending on use case.</p>
1
2008-09-28T13:04:17Z
[ "python", "postgresql", "module" ]
Python PostgreSQL modules. Which is best?
144,448
<p>I've seen a number of postgresql modules for python like pygresql, pypgsql, psyco. Most of them are Python DB API 2.0 compliant, some are not being actively developed anymore. Which module do you recommend? Why?</p>
20
2008-09-27T20:55:04Z
1,550,328
<p>I suggest Psycopg over Psycopg2 since the first one seems a bit more sable. At least in my experience. I have an application running 24/7 and sometimes I was getting random memory crashes (double free or corruption errors) from Psycopg2. Nothing I could have debug fast or easily since it's not a Python error but a C...
2
2009-10-11T10:06:27Z
[ "python", "postgresql", "module" ]
Python PostgreSQL modules. Which is best?
144,448
<p>I've seen a number of postgresql modules for python like pygresql, pypgsql, psyco. Most of them are Python DB API 2.0 compliant, some are not being actively developed anymore. Which module do you recommend? Why?</p>
20
2008-09-27T20:55:04Z
1,579,851
<p>I uses only psycopg2 and had no problems with that. </p>
0
2009-10-16T19:10:43Z
[ "python", "postgresql", "module" ]
Python PostgreSQL modules. Which is best?
144,448
<p>I've seen a number of postgresql modules for python like pygresql, pypgsql, psyco. Most of them are Python DB API 2.0 compliant, some are not being actively developed anymore. Which module do you recommend? Why?</p>
20
2008-09-27T20:55:04Z
36,021,904
<p>I've used pg8000 without any problems in the past 3 years. It's uptodate and available on pypi and works on both python2 and python3. You can use "pip install pg8000" to quickly get it (don't forget to use --proxy=yourproxy:yourport if you're behind a firewall).</p> <p>If you're worried about thread safety, it also...
0
2016-03-15T20:54:06Z
[ "python", "postgresql", "module" ]
Something like Explorer's icon grid view in a Python GUI
145,155
<p>I am making a Python gui project that needs to duplicate the look of a Windows gui environment (ie Explorer). I have my own custom icons to draw but they should be selectable by the same methods as usual; click, ctrl-click, drag box etc. Are any of the gui toolkits going to help with this or will I have to impleme...
2
2008-09-28T03:39:35Z
145,161
<p>I'll assume you're serious and suggest that you check out the many wonderful <a href="http://wiki.python.org/moin/GuiProgramming" rel="nofollow">GUI libraries</a> available for Python.</p>
1
2008-09-28T03:44:07Z
[ "python", "user-interface" ]
Something like Explorer's icon grid view in a Python GUI
145,155
<p>I am making a Python gui project that needs to duplicate the look of a Windows gui environment (ie Explorer). I have my own custom icons to draw but they should be selectable by the same methods as usual; click, ctrl-click, drag box etc. Are any of the gui toolkits going to help with this or will I have to impleme...
2
2008-09-28T03:39:35Z
145,162
<p>Python has extensions for accessing the Win32 API, but good luck trying to re-write explorer in <em>that</em> by yourself. Your best bet is to use a toolkit like <a href="http://doc.trolltech.com/4.4/gallery-windowsxp.html" rel="nofollow">Qt</a>, but you'll still have to write the vast majority of the application fr...
3
2008-09-28T03:45:09Z
[ "python", "user-interface" ]
Something like Explorer's icon grid view in a Python GUI
145,155
<p>I am making a Python gui project that needs to duplicate the look of a Windows gui environment (ie Explorer). I have my own custom icons to draw but they should be selectable by the same methods as usual; click, ctrl-click, drag box etc. Are any of the gui toolkits going to help with this or will I have to impleme...
2
2008-09-28T03:39:35Z
145,174
<p>In wxPython there's a plethora of ready-made list and tree controls (CustomTreeCtrl, TreeListCtrl, and others), a mixture of which you can use to create a simple explorer in minutes. The wxPython demo even has a few relevant examples (see the demo of MVCTree).</p>
2
2008-09-28T03:56:32Z
[ "python", "user-interface" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
145,283
<p>The quickest way to do this is using <a href="http://www.swig.org/">SWIG</a>.</p> <p>Example from SWIG <a href="http://www.swig.org/tutorial.html">tutorial</a>:</p> <pre><code>/* File : example.c */ int fact(int n) { if (n &lt;= 1) return 1; else return n*fact(n-1); } </code></pre> <p>Interface file:</p> ...
23
2008-09-28T05:44:11Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
145,287
<p>I’ve never used it but I’ve heard good things about <a href="https://docs.python.org/3.6/library/ctypes.html">ctypes</a>. If you’re trying to use it with C++, be sure to evade name mangling via <a href="http://stackoverflow.com/q/1041866/2157640"><code>extern "C"</code></a>. <em>Thanks for the comment, Florian...
12
2008-09-28T05:48:59Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
145,305
<p><a href="http://openwetware.org/wiki/Julius_B._Lucks/Projects/Python_All_A_Scientist_Needs">This paper, claiming python to be all a scientist needs,</a> basically says: first prototype everything in Python. Then when you need to speed a part up, use SWIG and translate this part to C.</p>
9
2008-09-28T06:00:56Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
145,347
<p>One of the official Python documents contains details on <a href="https://docs.python.org/3.6/extending/" rel="nofollow">extending Python using C/C++</a>. Even without the use of <a href="http://www.swig.org/" rel="nofollow">SWIG</a>, it’s quite straightforward and works perfectly well on Windows.</p>
2
2008-09-28T06:28:08Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
145,384
<p>Check out <a href="http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/">pyrex</a> or <a href="http://cython.org/">cython</a>. They're python-like languages for interfacing between C/C++ and python.</p>
16
2008-09-28T06:53:18Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
145,436
<p>You should have a look at <a href="http://www.boost.org/doc/libs/1_49_0/libs/python/doc/">Boost.Python</a>, here is the short introdution taken from their website:</p> <blockquote> <p>The Boost Python Library is a framework for interfacing Python and C++. It allows you to quickly and seamlessly expose C++ class...
69
2008-09-28T07:51:37Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
145,649
<p>I like <a href="http://docs.python.org/2/library/ctypes.html">ctypes</a> a lot, <a href="http://www.swig.org/">swig</a> always tended to give me <a href="http://groups.google.com/group/comp.lang.python/browse_thread/thread/d94badd9847fe43a?pli=1">problems</a>. Also ctypes has the advantage that you don't need to sat...
339
2008-09-28T10:53:31Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
19,786,993
<p>I think cffi for python can be an option.</p> <blockquote> <p>The goal is to call C code from Python. You should be able to do so without learning a 3rd language: every alternative requires you to learn their own language (Cython, SWIG) or API (ctypes). So we tried to assume that you know Python and C and m...
5
2013-11-05T10:39:23Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
23,865,947
<p>I started my journey in the python &lt;-> C++ binding from this page, with the objective of linking high level data types (multidimensional STL vectors with python lists) :-)</p> <p>Having tried the solutions based on both <a href="https://docs.python.org/2/library/ctypes.html">ctypes</a> and <a href="http://www.bo...
18
2014-05-26T08:30:54Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
29,853,756
<p>First you should decide what is your particular purpose. The official Python documentation on <a href="https://docs.python.org/2/extending/" rel="nofollow">extending and embedding the Python interpreter</a> was mentioned above, I can add a good <a href="https://python-packaging-user-guide.readthedocs.org/en/latest/e...
2
2015-04-24T17:23:23Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
32,264,764
<p>The question is how to call a C function from Python, if I understood correctly. Then the best bet are Ctypes (BTW portable across all variants of Python).</p> <pre><code>&gt;&gt;&gt; from ctypes import * &gt;&gt;&gt; libc = cdll.msvcrt &gt;&gt;&gt; print libc.time(None) 1438069008 &gt;&gt;&gt; printf = libc.printf...
2
2015-08-28T06:38:12Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
34,515,909
<p>Cython is definitely the way to go, unless you anticipate writing Java wrappers, in which case SWIG may be preferable. </p> <p>I recommend using the <code>runcython</code> command line utility, it makes the process of using Cython extremely easy. If you need to pass structured data to C++, take a look at Google's...
1
2015-12-29T17:27:16Z
[ "c++", "python", "c" ]
Calling C/C++ from python?
145,270
<p>What would be the quickest way to construct a python binding to a C or C++ library?</p> <p>(using windows if this matters)</p>
270
2008-09-28T05:34:20Z
38,542,539
<p>There is also <code>pybind11</code>, which is like a lightweight version of <code>Boost</code> and compatible with all modern C++ compilers : </p> <p><a href="https://pybind11.readthedocs.io/en/latest/" rel="nofollow">https://pybind11.readthedocs.io/en/latest/</a> </p>
1
2016-07-23T13:53:34Z
[ "c++", "python", "c" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
145,609
<p>Look at <a href="http://docs.python.org/lib/module-difflib.html" rel="nofollow">difflib</a>. (Python)</p> <p>That will calculate the diffs in various formats. You could then use the size of the context diff as a measure of how different two documents are?</p>
23
2008-09-28T10:14:43Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
145,623
<p>If you need a finer granularity than lines, you can use Levenshtein distance. Levenshtein distance is a straight-forward measure on how to similar two texts are.<br /> You can also use it to extract the edit logs and can a very fine-grained diff, similar to that on the edit history pages of SO. Be warned though that...
5
2008-09-28T10:27:49Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
145,632
<p>As stated, use difflib. Once you have the diffed output, you may find the <a href="http://en.wikipedia.org/wiki/Levenshtein_distance" rel="nofollow">Levenshtein distance</a> of the different strings as to give a "value" of how different they are.</p>
2
2008-09-28T10:33:09Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
145,634
<p><a href="http://bazaar-vcs.org/" rel="nofollow">Bazaar</a> contains an alternative difference algorithm, called <a href="http://bramcohen.livejournal.com/37690.html" rel="nofollow">patience diff</a> (there's more info in the comments on that page) which is claimed to be better than the traditional diff algorithm. Th...
10
2008-09-28T10:35:02Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
145,659
<p>I can recommend to take a look at Neil Fraser's code and articles:</p> <p><a href="http://code.google.com/p/google-diff-match-patch/">google-diff-match-patch</a></p> <blockquote> <p>Currently available in Java, JavaScript, C++ and Python. Regardless of language, each library features the same API and the s...
30
2008-09-28T11:04:31Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
146,530
<p>There are a number of distance metrics, as paradoja mentioned there is the Levenshtein distance, but there is also <a href="http://en.wikipedia.org/wiki/New_York_State_Identification_and_Intelligence_System" rel="nofollow">NYSIIS</a> and <a href="http://en.wikipedia.org/wiki/Soundex" rel="nofollow">Soundex</a>. In ...
3
2008-09-28T19:21:45Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
146,957
<p>In Python, there is <a href="http://docs.python.org/lib/module-difflib.html">difflib</a>, as also others have suggested.</p> <p><code>difflib</code> offers the <a href="http://docs.python.org/lib/sequence-matcher.html">SequenceMatcher</a> class, which can be used to give you a similarity ratio. Example function:</p...
25
2008-09-28T23:02:33Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
478,615
<p>My current understanding is that the best solution to the Shortest Edit Script (SES) problem is Myers "middle-snake" method with the Hirschberg linear space refinement.</p> <p>The Myers algorithm is described in:</p> <blockquote> <p>E. Myers, ``An O(ND) Difference Algorithm and Its Variations,''<br> Algorith...
8
2009-01-26T00:44:40Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
1,937,762
<p>You could use the <a href="http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Code_for_the_dynamic_programming_solution" rel="nofollow">solution to the Longest Common Subsequence (LCS) problem</a>. See also the discussion about possible ways to optimize this solution.</p>
1
2009-12-21T01:31:09Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
1,937,776
<p>One method I've employed for a different functionality, to calculate how much data was new in a modified file, could perhaps work for you as well.</p> <p>I have a diff/patch implementation C# that allows me to take two files, presumably old and new version of the same file, and calculate the "difference", but not i...
0
2009-12-21T01:39:30Z
[ "c#", "python", "diff" ]
Text difference algorithm
145,607
<p>I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word "similar" defined in the normal terms). It sounds easy to imp...
42
2008-09-28T10:12:25Z
9,992,986
<p>Take a look at the <a href="http://pypi.python.org/pypi/Fuzzy" rel="nofollow">Fuzzy</a> module. It has fast (written in C) based algorithms for soundex, NYSIIS and double-metaphone.</p> <p>A good introduction can be found at: <a href="http://www.informit.com/articles/article.aspx?p=1848528" rel="nofollow">http://ww...
0
2012-04-03T12:11:29Z
[ "c#", "python", "diff" ]
How do I successfully pass a function reference to Django’s reverse() function?
146,522
<p>I’ve got a brand new Django project. I’ve added one minimal view function to <code>views.py</code>, and one URL pattern to <code>urls.py</code>, passing the view by function reference instead of a string:</p> <pre><code># urls.py # ------- # coding=utf-8 from django.conf.urls.defaults import * from myapp imp...
8
2008-09-28T19:15:15Z
146,524
<p>Got it!! The problem is that some of the imports are of <code>myproject.myapp.views</code>, and some are just of <code>myapp.views</code>. This is confusing the Python module system enough that it no longer detects the functions as the same object. This is because your main <code>settings.py</code> probably has a li...
8
2008-09-28T19:17:44Z
[ "python", "django" ]
How do I successfully pass a function reference to Django’s reverse() function?
146,522
<p>I’ve got a brand new Django project. I’ve added one minimal view function to <code>views.py</code>, and one URL pattern to <code>urls.py</code>, passing the view by function reference instead of a string:</p> <pre><code># urls.py # ------- # coding=utf-8 from django.conf.urls.defaults import * from myapp imp...
8
2008-09-28T19:15:15Z
146,538
<p>If your two code pastes are complete, then it doesn't look like the second, which makes the actual call to reverse(), ever imports the urls module and therefor if the url mapping is ever actually achieved.</p>
1
2008-09-28T19:25:49Z
[ "python", "django" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,637
<p>Never create your own programming language. Ever. (I used to have an exception to this rule, but not any more.)</p> <p>There is always an existing language you can use which suits your needs better. If you elaborated on your use-case, people may help you select a suitable language.</p>
2
2008-09-28T20:19:40Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,639
<p>You can match both kind of quotes in one go with <code>r"(\"|')(.*?)\1"</code> - the <code>\1</code> refers to the first group, so it will only match matching quotes.</p>
1
2008-09-28T20:20:03Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,646
<p>Don't call search twice in a row (in the loop conditional, and the first statement in the loop). Call (and cache the result) once before the loop, and then in the final statement of the loop.</p>
0
2008-09-28T20:22:31Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,649
<p>You're calling re.compile quite a bit. A global variable for these wouldn't hurt here.</p>
1
2008-09-28T20:23:40Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,671
<p>The first thing that may improve things is to move the re.compile outside the function. The compilation is cached, but there is a speed hit in checking this to see if its compiled.</p> <p>Another possibility is to use a single regex as below:</p> <pre><code>MatchedQuotes = re.compile(r"(['\"])(.*)\1", re.LOCALE) ...
10
2008-09-28T20:31:44Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,683
<p><a href="http://docs.python.org/lib/node46.html" rel="nofollow"><code>sub</code></a> can take a callable as it's argument rather than a simple string. Using that, you can replace all variables with one function call:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; var_matcher = re.compile(r'&lt;%(.*?)%&gt;', re....
3
2008-09-28T20:36:43Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,710
<p>If a regexp only contains one .* wildcard and literals, then you can use find and rfind to locate the opening and closing delimiters.</p> <p>If it contains only a series of .*? wildcards, and literals, then you can just use a series of find's to do the work.</p> <p>If the code is time-critical, this switch away fr...
1
2008-09-28T20:47:53Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,734
<p>Creating a templating language is all well and good, but shouldn't one of the goals of the templating language be easy readability and efficient parsing? The example you gave seems to be neither.</p> <p>As Jamie Zawinsky famously said:</p> <blockquote> <p>Some people, when confronted with a problem, think "I k...
2
2008-09-28T21:05:37Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,784
<p>Why not use XML and XSLT instead of creating your own template language? What you want to do is pretty easy in XSLT.</p>
-3
2008-09-28T21:27:53Z
[ "regex", "algorithm", "optimization", "python" ]
I'm using Python regexes in a criminally inefficient manner
146,607
<p>My goal here is to create a very simple template language. At the moment, I'm working on replacing a variable with a value, like this:</p> <p>This input:</p> <blockquote> <p>&lt;%"TITLE"="This Is A Test Variable"%>The Web &lt;%"TITLE"%></p> </blockquote> <p>Should produce this output:</p> <blockquote> <p>The...
7
2008-09-28T20:03:14Z
146,862
<p>Why not use <a href="http://www.makotemplates.org/" rel="nofollow">Mako</a>? Seriously. What feature do you require that Mako doesn't have? Perhaps you can adapt or extend something that already works.</p>
1
2008-09-28T22:07:43Z
[ "regex", "algorithm", "optimization", "python" ]
In Django, where is the best place to put short snippets of HTML-formatted data?
146,789
<p>This question is related to (but perhaps not quite the same as):</p> <p><a href="http://stackoverflow.com/questions/61451/does-django-have-html-helpers">http://stackoverflow.com/questions/61451/does-django-have-html-helpers</a></p> <p>My problem is this: In Django, I am constantly reproducing the basic formatting ...
8
2008-09-28T21:31:21Z
146,829
<p>I would use a template tag outputting data using a template html-file a k a <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags" rel="nofollow">inclusion-tag</a></p>
2
2008-09-28T21:52:19Z
[ "python", "django", "model-view-controller", "design-patterns" ]
In Django, where is the best place to put short snippets of HTML-formatted data?
146,789
<p>This question is related to (but perhaps not quite the same as):</p> <p><a href="http://stackoverflow.com/questions/61451/does-django-have-html-helpers">http://stackoverflow.com/questions/61451/does-django-have-html-helpers</a></p> <p>My problem is this: In Django, I am constantly reproducing the basic formatting ...
8
2008-09-28T21:31:21Z
146,833
<p>Sounds like an <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags" rel="nofollow">inclusion tag</a> is what you're looking for. You could have a template and tag for each major variation and use the tag's arguments to customise the context for each template as required.</p> <p>...
12
2008-09-28T21:53:27Z
[ "python", "django", "model-view-controller", "design-patterns" ]
In Django, where is the best place to put short snippets of HTML-formatted data?
146,789
<p>This question is related to (but perhaps not quite the same as):</p> <p><a href="http://stackoverflow.com/questions/61451/does-django-have-html-helpers">http://stackoverflow.com/questions/61451/does-django-have-html-helpers</a></p> <p>My problem is this: In Django, I am constantly reproducing the basic formatting ...
8
2008-09-28T21:31:21Z
153,012
<p>I think template filter will be useful too. You can pass filter on each object, for example:</p> <pre><code>{{ value|linebreaks }} # standard django filter </code></pre> <p>Will produce:</p> <pre><code>If value is Joel\nis a slug, the output will be &lt;p&gt;Joel&lt;br&gt;is a slug&lt;/p&gt;. </code></pre> <p>Se...
1
2008-09-30T13:26:16Z
[ "python", "django", "model-view-controller", "design-patterns" ]
Difflib.SequenceMatcher isjunk optional parameter query: how to ignore whitespaces, tabs, empty lines?
147,437
<p>I am trying to use Difflib.SequenceMatcher to compute the similarities between two files. These two files are almost identical except that one contains some extra whitespaces, empty lines and other doesn't. I am trying to use</p> <pre><code>s=difflib.SequenceMatcher(isjunk,text1,text2) ratio =s.ratio() </code></pre...
2
2008-09-29T03:41:45Z
147,443
<p>I haven't used Difflib.SequenceMatcher, but have you considered pre-processing the files to remove all blank lines and whitespace (perhaps via regular expressions) and then doing the compare?</p>
1
2008-09-29T03:47:19Z
[ "python" ]
Difflib.SequenceMatcher isjunk optional parameter query: how to ignore whitespaces, tabs, empty lines?
147,437
<p>I am trying to use Difflib.SequenceMatcher to compute the similarities between two files. These two files are almost identical except that one contains some extra whitespaces, empty lines and other doesn't. I am trying to use</p> <pre><code>s=difflib.SequenceMatcher(isjunk,text1,text2) ratio =s.ratio() </code></pre...
2
2008-09-29T03:41:45Z
147,732
<p>Using your sample strings:</p> <pre><code>&gt;&gt;&gt; s=difflib.SequenceMatcher(lambda x: x == '\n', s1, s2) &gt;&gt;&gt; s.ratio() 0.94669848846459825 </code></pre> <p>Interestingly if ' ' is also included as junk:</p> <pre><code>&gt;&gt;&gt; s=difflib.SequenceMatcher(lambda x: x in ' \n', s1, s2) &gt;&gt;&gt; ...
1
2008-09-29T06:43:27Z
[ "python" ]
Difflib.SequenceMatcher isjunk optional parameter query: how to ignore whitespaces, tabs, empty lines?
147,437
<p>I am trying to use Difflib.SequenceMatcher to compute the similarities between two files. These two files are almost identical except that one contains some extra whitespaces, empty lines and other doesn't. I am trying to use</p> <pre><code>s=difflib.SequenceMatcher(isjunk,text1,text2) ratio =s.ratio() </code></pre...
2
2008-09-29T03:41:45Z
147,791
<p>If you match all whitespaces the similarity is better:</p> <pre><code>difflib.SequenceMatcher(lambda x: x in " \t\n", doc1, doc2).ratio() </code></pre> <p>However, difflib is not ideal to such a problem because these are two nearly identical documents, but typos and such produce differences for difflib where a hum...
5
2008-09-29T07:17:02Z
[ "python" ]
Difflib.SequenceMatcher isjunk optional parameter query: how to ignore whitespaces, tabs, empty lines?
147,437
<p>I am trying to use Difflib.SequenceMatcher to compute the similarities between two files. These two files are almost identical except that one contains some extra whitespaces, empty lines and other doesn't. I am trying to use</p> <pre><code>s=difflib.SequenceMatcher(isjunk,text1,text2) ratio =s.ratio() </code></pre...
2
2008-09-29T03:41:45Z
148,364
<p>Given the texts above, the test is indeed as suggested:</p> <pre><code>difflib.SequenceMatcher(lambda x: x in " \t\n", doc1, doc2).ratio() </code></pre> <p>However, to speed up things a little, you can take advantage of CPython's <a href="http://mail.python.org/pipermail/python-list/2005-April/320354.html" rel="no...
1
2008-09-29T11:48:48Z
[ "python" ]
How does one do the equivalent of "import * from module" with Python's __import__ function?
147,507
<p>Given a string with a module name, how do you import everything in the module as if you had called:</p> <pre><code>from module import * </code></pre> <p>i.e. given string S="module", how does one get the equivalent of the following:</p> <pre><code>__import__(S, fromlist="*") </code></pre> <p>This doesn't seem to...
14
2008-09-29T04:28:41Z
147,541
<p>Please reconsider. The only thing worse than <code>import *</code> is <em>magic</em> <code>import *</code>.</p> <p>If you really want to:</p> <pre><code>m = __import__ (S) try: attrlist = m.__all__ except AttributeError: attrlist = dir (m) for attr in attrlist: globals()[attr] = getattr (m, attr) </cod...
26
2008-09-29T04:45:07Z
[ "python", "python-import" ]
How does one do the equivalent of "import * from module" with Python's __import__ function?
147,507
<p>Given a string with a module name, how do you import everything in the module as if you had called:</p> <pre><code>from module import * </code></pre> <p>i.e. given string S="module", how does one get the equivalent of the following:</p> <pre><code>__import__(S, fromlist="*") </code></pre> <p>This doesn't seem to...
14
2008-09-29T04:28:41Z
160,636
<p>The underlying problem is that I am developing some Django, but on more than one host (with colleagues), all with different settings. I was hoping to do something like this in the project/settings.py file:</p> <pre><code>from platform import node settings_files = { 'BMH.lan': 'settings_bmh.py", ... } __import__(...
0
2008-10-02T02:33:33Z
[ "python", "python-import" ]
How does one do the equivalent of "import * from module" with Python's __import__ function?
147,507
<p>Given a string with a module name, how do you import everything in the module as if you had called:</p> <pre><code>from module import * </code></pre> <p>i.e. given string S="module", how does one get the equivalent of the following:</p> <pre><code>__import__(S, fromlist="*") </code></pre> <p>This doesn't seem to...
14
2008-09-29T04:28:41Z
293,189
<p>I didn't find a good way to do it so I took a simpler but ugly way from <a href="http://www.djangosnippets.org/snippets/600/" rel="nofollow">http://www.djangosnippets.org/snippets/600/</a></p> <pre><code>try: import socket hostname = socket.gethostname().replace('.','_') exec "from host_settings.%s impo...
-2
2008-11-15T22:55:08Z
[ "python", "python-import" ]