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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Binary array in python | 751,055 | <p>How to create big array in python, how efficient creating that</p>
<p>in C/C++:</p>
<pre><code>byte *data = (byte*)memalloc(10000);
</code></pre>
<p>or</p>
<pre><code>byte *data = new byte[10000];
</code></pre>
<p>in python...?</p>
| 4 | 2009-04-15T10:21:22Z | 751,071 | <p>Typically with python, you'd just create a list</p>
<pre><code>mylist = []
</code></pre>
<p>and use it as an array. Alternatively, I think you might be looking for the array module. See <a href="http://docs.python.org/library/array.html" rel="nofollow">http://docs.python.org/library/array.html</a>.</p>
| 0 | 2009-04-15T10:27:30Z | [
"python"
] |
Binary array in python | 751,055 | <p>How to create big array in python, how efficient creating that</p>
<p>in C/C++:</p>
<pre><code>byte *data = (byte*)memalloc(10000);
</code></pre>
<p>or</p>
<pre><code>byte *data = new byte[10000];
</code></pre>
<p>in python...?</p>
| 4 | 2009-04-15T10:21:22Z | 751,080 | <p>Have a look at the <a href="http://docs.python.org/library/array.html">array module</a>:</p>
<pre><code>import array
array.array('B', [0] * 10000)
</code></pre>
<p>Instead of passing a list to initialize it, you can pass a generator, which is more memory efficient.</p>
| 7 | 2009-04-15T10:29:37Z | [
"python"
] |
Binary array in python | 751,055 | <p>How to create big array in python, how efficient creating that</p>
<p>in C/C++:</p>
<pre><code>byte *data = (byte*)memalloc(10000);
</code></pre>
<p>or</p>
<pre><code>byte *data = new byte[10000];
</code></pre>
<p>in python...?</p>
| 4 | 2009-04-15T10:21:22Z | 751,087 | <p>You can pre-allocate a list with:</p>
<pre><code>l = [0] * 10000
</code></pre>
<p>which will be slightly faster than .appending to it (as it avoids intermediate reallocations). However, this will generally allocate space for a list of pointers to integer objects, which will be larger than an array of bytes in C.<... | 6 | 2009-04-15T10:31:49Z | [
"python"
] |
Binary array in python | 751,055 | <p>How to create big array in python, how efficient creating that</p>
<p>in C/C++:</p>
<pre><code>byte *data = (byte*)memalloc(10000);
</code></pre>
<p>or</p>
<pre><code>byte *data = new byte[10000];
</code></pre>
<p>in python...?</p>
| 4 | 2009-04-15T10:21:22Z | 751,096 | <p>You can efficiently create big array with <strong>array</strong> module, but using it won't be as fast as C. If you intend to do some math, you'd be better off with <strong>numpy.array</strong></p>
<p>Check <a href="http://stackoverflow.com/questions/111983/python-array-versus-numpy-array">this question</a> for com... | 0 | 2009-04-15T10:37:23Z | [
"python"
] |
How do I use the wx.lib.docview package? | 751,159 | <p>I'm currently working on a simple wxPython app that's essentially document based. So far I've been manually implementing the usual open/save/undo/redo etc etc stuff.</p>
<p>It occurred to me that wxPython must have something to help me out and after a bit of searching revealed the <a href="http://www.wxpython.org/... | 2 | 2009-04-15T11:00:46Z | 819,173 | <p>You might take a look at the docviewdemo.py from the <a href="http://wxpython.org/download.php" rel="nofollow">wxPython Docs and Demos</a>:</p>
<p>on my machine they are located:</p>
<ul>
<li>C:\Program Files\wxPython2.8 Docs and Demos\samples\pydocview\</li>
<li>C:\Program Files\wxPython2.8 Docs and Demos\sample... | 1 | 2009-05-04T07:52:38Z | [
"python",
"user-interface",
"wxpython",
"docview"
] |
How do I use the wx.lib.docview package? | 751,159 | <p>I'm currently working on a simple wxPython app that's essentially document based. So far I've been manually implementing the usual open/save/undo/redo etc etc stuff.</p>
<p>It occurred to me that wxPython must have something to help me out and after a bit of searching revealed the <a href="http://www.wxpython.org/... | 2 | 2009-04-15T11:00:46Z | 1,499,852 | <p>In addition to the ones mentioned, there is quite an extensive example docview/pydocview in the samples\ide. If you want it to run you will have to make a few code corrections (I have submitted a ticket that outlines the fixes at trac.wxwidgets.org #11237). It is pretty complex but I found it handy to figure out h... | 1 | 2009-09-30T18:22:46Z | [
"python",
"user-interface",
"wxpython",
"docview"
] |
Why does this pyd file not import on some computers? | 751,339 | <p>My python project has a C++ component which is compiled and distributed as a .pyd file inside a Python egg. I've noticed that it seems to be incompatible with only some of our our brand new 64 bit Windows servers. We have 4 (allegedly) identically provisioned machines - each of them runs Windows 2003 server 64 bit e... | 6 | 2009-04-15T11:45:05Z | 751,353 | <p>Have you tried checking which DLLs that PYD links?
You can do that for example with either with <a href="http://www.dependencywalker.com/" rel="nofollow">Dependency Walker</a> or VS's depends.exe.</p>
| 4 | 2009-04-15T11:49:07Z | [
"python",
"windows"
] |
Why does this pyd file not import on some computers? | 751,339 | <p>My python project has a C++ component which is compiled and distributed as a .pyd file inside a Python egg. I've noticed that it seems to be incompatible with only some of our our brand new 64 bit Windows servers. We have 4 (allegedly) identically provisioned machines - each of them runs Windows 2003 server 64 bit e... | 6 | 2009-04-15T11:45:05Z | 751,364 | <p>You could try something like <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="nofollow">Process Monitor</a>, to watch what DLLs it tries to load. I'd assume that one of the other DLLs it relies on can't be found.</p>
<p>Edit: It looks like you've already managed to get some useful info o... | 4 | 2009-04-15T11:53:12Z | [
"python",
"windows"
] |
Why does this pyd file not import on some computers? | 751,339 | <p>My python project has a C++ component which is compiled and distributed as a .pyd file inside a Python egg. I've noticed that it seems to be incompatible with only some of our our brand new 64 bit Windows servers. We have 4 (allegedly) identically provisioned machines - each of them runs Windows 2003 server 64 bit e... | 6 | 2009-04-15T11:45:05Z | 751,372 | <p>Maybe you're missing the C++ runtime/standard-library DLLs on the machines where it doesn't work, and the module is trying to use them?</p>
| 1 | 2009-04-15T11:54:28Z | [
"python",
"windows"
] |
Why does this pyd file not import on some computers? | 751,339 | <p>My python project has a C++ component which is compiled and distributed as a .pyd file inside a Python egg. I've noticed that it seems to be incompatible with only some of our our brand new 64 bit Windows servers. We have 4 (allegedly) identically provisioned machines - each of them runs Windows 2003 server 64 bit e... | 6 | 2009-04-15T11:45:05Z | 751,620 | <p>According to <a href="http://support.microsoft.com/kb/316091" rel="nofollow">Microsoft's Knowledgebase</a>, mscoree.dll is part of the .NET Framework. To be exact, it's the Microsoft .NET Runtime Execution Engine.</p>
<p>The way to get it would be to (re)install the .NET Framework.</p>
| 2 | 2009-04-15T13:10:49Z | [
"python",
"windows"
] |
Why does this pyd file not import on some computers? | 751,339 | <p>My python project has a C++ component which is compiled and distributed as a .pyd file inside a Python egg. I've noticed that it seems to be incompatible with only some of our our brand new 64 bit Windows servers. We have 4 (allegedly) identically provisioned machines - each of them runs Windows 2003 server 64 bit e... | 6 | 2009-04-15T11:45:05Z | 32,173,541 | <p>Just had the same problem and depends.exe showed me that <code>foo.pyd</code> was build with <code>python25.lib</code> instead of <code>python27.lib</code>. So it couldn't find <code>python25.dll</code>.</p>
| 0 | 2015-08-24T02:02:34Z | [
"python",
"windows"
] |
dispatcher python | 751,455 | <p>hy all, I have the following "wrong" dispatcher:</p>
<pre><code>def _load_methods(self):
import os, sys, glob
sys.path.insert(0, 'modules\commands')
for c in glob.glob('modules\commands\Command*.py'):
if os.path.isdir(c):
continue
c = os.path.splitext(c)[0]
parts = c.split(os.path.sep )
module, name =... | 0 | 2009-04-15T12:22:08Z | 751,712 | <blockquote>
<p>sys.path.insert(0, 'modules\commands')</p>
</blockquote>
<p>It's best not to put a relative path into sys.path. If the current directory changes during execution it'll break.</p>
<p>Also if you are running from a different directory to the script it won't work. If you want to make it relative to the... | 1 | 2009-04-15T13:33:23Z | [
"python"
] |
dispatcher python | 751,455 | <p>hy all, I have the following "wrong" dispatcher:</p>
<pre><code>def _load_methods(self):
import os, sys, glob
sys.path.insert(0, 'modules\commands')
for c in glob.glob('modules\commands\Command*.py'):
if os.path.isdir(c):
continue
c = os.path.splitext(c)[0]
parts = c.split(os.path.sep )
module, name =... | 0 | 2009-04-15T12:22:08Z | 753,115 | <p>Do you actually need to import things as modules? If you're just loading code from arbitrary positions in the filesystem, then rather than fiddling with the module path etc, you could just use <a href="http://docs.python.org/library/functions.html#execfile" rel="nofollow"><code>execfile</code></a>.</p>
<p>ie. </p>... | 1 | 2009-04-15T18:41:04Z | [
"python"
] |
can a method call be chained to the 'set()' built-in? (and why not?) | 751,457 | <p>If I try:</p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set(mi_list)
mi_set.remove('small')
print mi_set
</code></pre>
<p>I get: </p>
<pre><code>set(['three', 'words'])
</code></pre>
<p>which is what I expect. Whereas If I try: </p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set... | 3 | 2009-04-15T12:23:08Z | 751,495 | <p>Are you sure that the <code>remove</code> function returns a value?</p>
| 0 | 2009-04-15T12:33:33Z | [
"python"
] |
can a method call be chained to the 'set()' built-in? (and why not?) | 751,457 | <p>If I try:</p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set(mi_list)
mi_set.remove('small')
print mi_set
</code></pre>
<p>I get: </p>
<pre><code>set(['three', 'words'])
</code></pre>
<p>which is what I expect. Whereas If I try: </p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set... | 3 | 2009-04-15T12:23:08Z | 751,497 | <p><code>set.remove</code> returns nothing (None).</p>
<p>Your code assigns the return value of <code>set.remove</code> to the variable <code>mi_set</code>. Therefore, mi_set is None.</p>
| 20 | 2009-04-15T12:33:57Z | [
"python"
] |
can a method call be chained to the 'set()' built-in? (and why not?) | 751,457 | <p>If I try:</p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set(mi_list)
mi_set.remove('small')
print mi_set
</code></pre>
<p>I get: </p>
<pre><code>set(['three', 'words'])
</code></pre>
<p>which is what I expect. Whereas If I try: </p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set... | 3 | 2009-04-15T12:23:08Z | 751,535 | <p>The way to go, in your case, would be to use the <strong>difference</strong> member:</p>
<pre><code>>>> a = set(["a", "b", "c"])
>>> a = a.difference(["a"])
>>> print a
set(['c', 'b'])
</code></pre>
<p>The difference is that <strong>remove</strong> acts on the current set (python library... | 1 | 2009-04-15T12:48:02Z | [
"python"
] |
can a method call be chained to the 'set()' built-in? (and why not?) | 751,457 | <p>If I try:</p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set(mi_list)
mi_set.remove('small')
print mi_set
</code></pre>
<p>I get: </p>
<pre><code>set(['three', 'words'])
</code></pre>
<p>which is what I expect. Whereas If I try: </p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set... | 3 | 2009-04-15T12:23:08Z | 751,576 | <p>Why does it return <code>None</code>? Because .remove, .add, etc. return <code>None</code> :) That's it. They do not support chaining.</p>
<p><code>set</code> is using methods that change it in place. You could create your own version of set that uses chaining, but that can cause some problems:</p>
<pre><code>clas... | 1 | 2009-04-15T13:00:11Z | [
"python"
] |
can a method call be chained to the 'set()' built-in? (and why not?) | 751,457 | <p>If I try:</p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set(mi_list)
mi_set.remove('small')
print mi_set
</code></pre>
<p>I get: </p>
<pre><code>set(['three', 'words'])
</code></pre>
<p>which is what I expect. Whereas If I try: </p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set... | 3 | 2009-04-15T12:23:08Z | 753,944 | <p>There is a general convention in python that <em>methods which cause <a href="http://en.wikipedia.org/wiki/Side%5Feffect%5F%28computer%5Fscience%29">side-effects</a> return None</em>. Examples include list.sort, list.append, set.add, set.remove, dict.update, etc.</p>
<p>This is essentially to help you avoid bugs. ... | 8 | 2009-04-15T22:11:55Z | [
"python"
] |
can a method call be chained to the 'set()' built-in? (and why not?) | 751,457 | <p>If I try:</p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set(mi_list)
mi_set.remove('small')
print mi_set
</code></pre>
<p>I get: </p>
<pre><code>set(['three', 'words'])
</code></pre>
<p>which is what I expect. Whereas If I try: </p>
<pre><code>mi_list = ['three', 'small', 'words']
mi_set = set... | 3 | 2009-04-15T12:23:08Z | 755,136 | <p>remove modifies the original set without returning anything (or rather, it returns None). This example shows what happens to the original object when you call remove on it:</p>
<pre><code>Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "li... | 0 | 2009-04-16T07:50:46Z | [
"python"
] |
Parse shell file output with Python | 751,557 | <p>I have a file with data. The file is the output generated from a shell scripting file:</p>
<pre><code>|a |869 |
|b |835 |
|c |0 |
|d |0 |
|e |34 |
|f |... | 4 | 2009-04-15T12:55:18Z | 751,587 | <p>You can also use <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv</a> module with delimiter <code>|</code>.</p>
| 3 | 2009-04-15T13:02:19Z | [
"python"
] |
Parse shell file output with Python | 751,557 | <p>I have a file with data. The file is the output generated from a shell scripting file:</p>
<pre><code>|a |869 |
|b |835 |
|c |0 |
|d |0 |
|e |34 |
|f |... | 4 | 2009-04-15T12:55:18Z | 751,596 | <p>You could do this:</p>
<pre><code>output = {}
for line in open("myfile"):
parts = line.split('|')
output[parts[1].strip()] = parts[2].strip()
print output['a'] // prints 869
print output['f'] // prints 3337
</code></pre>
<p>Or, using the <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv... | 9 | 2009-04-15T13:04:10Z | [
"python"
] |
Parse shell file output with Python | 751,557 | <p>I have a file with data. The file is the output generated from a shell scripting file:</p>
<pre><code>|a |869 |
|b |835 |
|c |0 |
|d |0 |
|e |34 |
|f |... | 4 | 2009-04-15T12:55:18Z | 751,613 | <pre><code>lines = file("test.txt").readlines()
d = dict([[i.strip() for i in l.split("|")[1:3]] for l in lines if l.strip()])
</code></pre>
<p>For example:</p>
<pre><code>>>> lines = file("test.txt").readlines()
>>> d = dict([[i.strip() for i in l.split("|")[1:3]] for l in lines if l.strip()])
&g... | 4 | 2009-04-15T13:09:13Z | [
"python"
] |
Parse shell file output with Python | 751,557 | <p>I have a file with data. The file is the output generated from a shell scripting file:</p>
<pre><code>|a |869 |
|b |835 |
|c |0 |
|d |0 |
|e |34 |
|f |... | 4 | 2009-04-15T12:55:18Z | 751,633 | <p>Maybe not the most Pythonic way, but this should work if your shell output is stored in f.txt and you are looking for every line to be processed:</p>
<pre><code>h = open("f.txt", "rt")
inp = h.readline()
while inp:
flds = inp.split('|')
str = flds[1].strip() + " = " + flds[2].strip()
print str
inp = h.readl... | 0 | 2009-04-15T13:13:08Z | [
"python"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 752,329 | <pre><code>def splitter(A):
B = A[0:len(A)//2]
C = A[len(A)//2:]
return (B,C)
</code></pre>
<p>I tested, and the double slash is required to force int division in python 3. My original post was correct, although wysiwyg broke in Opera, for some reason.</p>
| 6 | 2009-04-15T15:49:40Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 752,330 | <pre><code>A = [1,2,3,4,5,6]
B = A[:len(A)/2]
C = A[len(A)/2:]
</code></pre>
<p>If you want a function:</p>
<pre><code>def split_list(a_list):
half = len(a_list)/2
return a_list[:half], a_list[half:]
A = [1,2,3,4,5,6]
B, C = split_list(A)
</code></pre>
| 85 | 2009-04-15T15:49:42Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 752,333 | <p><code>B,C=A[:len(A)/2],A[len(A)/2:]</code></p>
| 9 | 2009-04-15T15:50:08Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 752,553 | <p>Using <a href="http://docs.python.org/tutorial/introduction.html#lists" rel="nofollow">list slicing</a>. The syntax is basically <code>my_list[start_index:end_index]</code></p>
<pre><code>>>> i = [0,1,2,3,4,5]
>>> i[:3] # same as i[0:3] - grabs from first to third index (0->2)
[0, 1, 2]
>>... | 2 | 2009-04-15T16:28:30Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 752,562 | <p>A little more generic solution (you can specify the number of parts you want, not just split 'in half'):</p>
<p><strong>EDIT</strong>: updated post to handle odd list lengths</p>
<p><strong>EDIT2</strong>: update post again based on Brians informative comments </p>
<pre><code>def split_list(alist, wanted_parts=1)... | 44 | 2009-04-15T16:30:41Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 753,229 | <p>While the answers above are more or less correct, you may run into trouble if the size of your array isn't divisible by 2, as the result of <code>a / 2</code>, a being odd, is a float in python 3.0, and in earlier version if you specify <code>from __future__ import division</code> at the beginning of your script. Yo... | 2 | 2009-04-15T19:03:34Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 2,215,676 | <pre><code>f = lambda A, n=3: [A[i:i+n] for i in range(0, len(A), n)]
f(A)
</code></pre>
<p><code>n</code> - the predefined length of result arrays </p>
| 23 | 2010-02-07T02:30:56Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 5,750,112 | <p>There is an official Python receipe for the more generalized case of splitting an array into smaller arrays of size <code>n</code>.</p>
<pre><code>from itertools import izip_longest
def grouper(n, iterable, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# grouper(3, 'ABCDEFG', 'x') -->... | 3 | 2011-04-21T21:44:10Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 6,328,533 | <p>If you don't care about the order... </p>
<pre><code>def split(list):
return list[::2], list[1::2]
</code></pre>
<p><code>list[::2]</code> gets every second element in the list starting from the 0th element.<br>
<code>list[1::2]</code> gets every second element in the list starting from the 1st element.</p>... | 3 | 2011-06-13T09:11:54Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 11,574,640 | <p>Here is a common solution, split arr into count part</p>
<pre><code>def split(arr, count):
return [arr[i::count] for i in range(count)]
</code></pre>
| 3 | 2012-07-20T07:17:29Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 11,771,019 | <p>With hints from @ChristopheD</p>
<pre><code>def line_split(N, K=1):
length = len(N)
return [N[i*length/K:(i+1)*length/K] for i in range(K)]
A = [0,1,2,3,4,5,6,7,8,9]
print line_split(A,1)
print line_split(A,2)
</code></pre>
| 0 | 2012-08-02T04:24:25Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 23,148,997 | <pre><code>def split(arr, size):
arrs = []
while len(arr) > size:
pice = arr[:size]
arrs.append(pice)
arr = arr[size:]
arrs.append(arr)
return arrs
</code></pre>
<p>Test:</p>
<pre><code>x=[1,2,3,4,5,6,7,8,9,10,11,12,13]
print(split(x,5))
</code></pre>
<p>result:</p... | 5 | 2014-04-18T06:54:33Z | [
"python",
"list",
"split"
] |
Split list into smaller lists | 752,308 | <p>I am looking for a way to easily split a python list in half.</p>
<p>So that if I have an array:</p>
<pre><code>A = [0,1,2,3,4,5]
</code></pre>
<p>I would be able to get:</p>
<pre><code>B = [0,1,2]
C = [3,4,5]
</code></pre>
| 57 | 2009-04-15T15:44:40Z | 23,895,329 | <p>This is similar to other solutions, but a little faster.</p>
<pre><code># Usage: split_half([1,2,3,4,5]) Result: ([1, 2], [3, 4, 5])
def split_half(a):
half = len(a) >> 1
return a[:half], a[half:]
</code></pre>
| 0 | 2014-05-27T17:17:30Z | [
"python",
"list",
"split"
] |
Has anyone here tried using the iSeries Python port? | 752,349 | <p>I found <a href="http://www.iseriespython.com/" rel="nofollow">http://www.iseriespython.com/</a>, which is a version of Python for the iSeries apparently including some system specific data access classes. I am keen to try this out, but will have to get approval at work to do so. My questions are:</p>
<p>Does the p... | 9 | 2009-04-15T15:52:06Z | 753,006 | <p>It sounds like it is would work as expected. Support for other libraries might be pretty limited, though.</p>
<p>Timothy Prickett talks about some Python ports for the iSeries in this article:</p>
<p><a href="http://www.itjungle.com/tfh/tfh041706-story02.html" rel="nofollow">http://www.itjungle.com/tfh/tfh041706-... | 5 | 2009-04-15T18:13:31Z | [
"python",
"ibm-midrange"
] |
Has anyone here tried using the iSeries Python port? | 752,349 | <p>I found <a href="http://www.iseriespython.com/" rel="nofollow">http://www.iseriespython.com/</a>, which is a version of Python for the iSeries apparently including some system specific data access classes. I am keen to try this out, but will have to get approval at work to do so. My questions are:</p>
<p>Does the p... | 9 | 2009-04-15T15:52:06Z | 753,731 | <p>Another place to look is on the mailing list <a href="http://lists.midrange.com/listinfo/midrange-l" rel="nofollow">MIDRANGE-L</a> or search the archives for the list at <a href="http://archive.midrange.com/midrange-l/index.htm" rel="nofollow">midrange.com</a>. I know they have talked about this a while back.</p>
| 0 | 2009-04-15T21:08:52Z | [
"python",
"ibm-midrange"
] |
Has anyone here tried using the iSeries Python port? | 752,349 | <p>I found <a href="http://www.iseriespython.com/" rel="nofollow">http://www.iseriespython.com/</a>, which is a version of Python for the iSeries apparently including some system specific data access classes. I am keen to try this out, but will have to get approval at work to do so. My questions are:</p>
<p>Does the p... | 9 | 2009-04-15T15:52:06Z | 788,298 | <p>From what I have seen so far, it works pretty well. Note that I'm using iSeries Python 2.3.3. The fact that strings are natively EBCDIC can be a problem; it's definitely one of the reasons many third-party packages won't work as-is, even if they are pure Python. (In some cases they can be tweaked and massaged int... | 7 | 2009-04-25T05:35:36Z | [
"python",
"ibm-midrange"
] |
Has anyone here tried using the iSeries Python port? | 752,349 | <p>I found <a href="http://www.iseriespython.com/" rel="nofollow">http://www.iseriespython.com/</a>, which is a version of Python for the iSeries apparently including some system specific data access classes. I am keen to try this out, but will have to get approval at work to do so. My questions are:</p>
<p>Does the p... | 9 | 2009-04-15T15:52:06Z | 2,552,847 | <p>I got permission to install iSeries Python on a box about 3 years ago. I found that it worked pretty much as advertised. I contacted the developer and he was very good about answering questions. However, before I could think about using it in production, I had to approach the developer regarding a support contract. ... | 3 | 2010-03-31T12:31:20Z | [
"python",
"ibm-midrange"
] |
Has anyone here tried using the iSeries Python port? | 752,349 | <p>I found <a href="http://www.iseriespython.com/" rel="nofollow">http://www.iseriespython.com/</a>, which is a version of Python for the iSeries apparently including some system specific data access classes. I am keen to try this out, but will have to get approval at work to do so. My questions are:</p>
<p>Does the p... | 9 | 2009-04-15T15:52:06Z | 3,139,913 | <p>iSeriesPython is working very well.
We are usning it since 2005 (or earlier) in our Development and Production Environments as an utility language, for generating of COBOL source code, generating of PCML interfaces, sending SMS, validating/correcting some data ... etc.
With iSeriesPython you can access the iSeries ... | 4 | 2010-06-29T10:47:07Z | [
"python",
"ibm-midrange"
] |
Is it safe to rely on condition evaluation order in if statements? | 752,373 | <p>Is it bad practice to use the following format when <code>my_var</code> can be None?</p>
<pre><code>if my_var and 'something' in my_var:
#do something
</code></pre>
<p>*The issue is that <code>'something' in my_var</code> will throw a TypeError if my_var is None.*</p>
<p>Or should I use:</p>
<pre><code>if my... | 39 | 2009-04-15T15:57:19Z | 752,390 | <p>It's safe to depend on the order of conditionals (<a href="http://docs.python.org/library/stdtypes.html#boolean-operations-and-or-not">Python reference here</a>), specifically because of the problem you point out - it's very useful to be able to short-circuit evaluation that could cause problems in a string of condi... | 49 | 2009-04-15T15:59:25Z | [
"python",
"if-statement"
] |
Is it safe to rely on condition evaluation order in if statements? | 752,373 | <p>Is it bad practice to use the following format when <code>my_var</code> can be None?</p>
<pre><code>if my_var and 'something' in my_var:
#do something
</code></pre>
<p>*The issue is that <code>'something' in my_var</code> will throw a TypeError if my_var is None.*</p>
<p>Or should I use:</p>
<pre><code>if my... | 39 | 2009-04-15T15:57:19Z | 752,392 | <p>It's perfectly safe and I do it all the time.</p>
| 1 | 2009-04-15T15:59:43Z | [
"python",
"if-statement"
] |
Is it safe to rely on condition evaluation order in if statements? | 752,373 | <p>Is it bad practice to use the following format when <code>my_var</code> can be None?</p>
<pre><code>if my_var and 'something' in my_var:
#do something
</code></pre>
<p>*The issue is that <code>'something' in my_var</code> will throw a TypeError if my_var is None.*</p>
<p>Or should I use:</p>
<pre><code>if my... | 39 | 2009-04-15T15:57:19Z | 752,396 | <p>I would go with the try/except, but it depends on what you know about the variable.</p>
<p>If you are expecting that the variable will exist most of the time, then a try/except is less operations. If you are expecting the variable to be None most of the time, then an IF statement will be less operations.</p>
| 1 | 2009-04-15T16:00:04Z | [
"python",
"if-statement"
] |
Is it safe to rely on condition evaluation order in if statements? | 752,373 | <p>Is it bad practice to use the following format when <code>my_var</code> can be None?</p>
<pre><code>if my_var and 'something' in my_var:
#do something
</code></pre>
<p>*The issue is that <code>'something' in my_var</code> will throw a TypeError if my_var is None.*</p>
<p>Or should I use:</p>
<pre><code>if my... | 39 | 2009-04-15T15:57:19Z | 752,447 | <p>Yes it is safe, it's explicitly and very clearly defined in the language reference:</p>
<blockquote>
<p>The expression <code>x and y</code> first evaluates
<code>x</code>; if <code>x</code> is <code>false</code>, its value is
returned; otherwise, <code>y</code> is evaluated
and the resulting value is retur... | 22 | 2009-04-15T16:08:21Z | [
"python",
"if-statement"
] |
Is it safe to rely on condition evaluation order in if statements? | 752,373 | <p>Is it bad practice to use the following format when <code>my_var</code> can be None?</p>
<pre><code>if my_var and 'something' in my_var:
#do something
</code></pre>
<p>*The issue is that <code>'something' in my_var</code> will throw a TypeError if my_var is None.*</p>
<p>Or should I use:</p>
<pre><code>if my... | 39 | 2009-04-15T15:57:19Z | 955,865 | <p>It's not that simple. As a C# dude I am very used to doing something like:</p>
<pre><code>if(x != null && ! string.isnullorempty(x.Name))
{
//do something
}
</code></pre>
<p>The above works great and is evaluated as expected. However in VB.Net the following would produce a result you were NOT expecting:... | 1 | 2009-06-05T13:31:51Z | [
"python",
"if-statement"
] |
Is it safe to rely on condition evaluation order in if statements? | 752,373 | <p>Is it bad practice to use the following format when <code>my_var</code> can be None?</p>
<pre><code>if my_var and 'something' in my_var:
#do something
</code></pre>
<p>*The issue is that <code>'something' in my_var</code> will throw a TypeError if my_var is None.*</p>
<p>Or should I use:</p>
<pre><code>if my... | 39 | 2009-04-15T15:57:19Z | 1,361,992 | <p>I may be being a little pedantic here, but I would say the best answer is</p>
<pre><code>if my_var is not None and 'something' in my_var:
#do something
</code></pre>
<p>The difference being the explicit check for <code>None</code>, rather than the implicit conversion of <code>my_var</code> to <code>True</code>... | 1 | 2009-09-01T11:37:32Z | [
"python",
"if-statement"
] |
Can I compile numpy & scipy as eggs for free on Windows32? | 752,482 | <p>I've been asked to provide Numpy & Scipy as python egg files. Unfortunately Numpy and Scipy do not make official releases of their product in .egg form for a Win32 platform - that means if I want eggs then I have to compile them myself.</p>
<p>At the moment my employer provides Visual Studio.Net 2003, which wil... | 1 | 2009-04-15T16:14:35Z | 752,536 | <p>Try compiling the whole Python stack with <a href="http://www.mingw.org/" rel="nofollow">MinGW32.</a> This is a GCC-Win32 development environment that can be used to build Python and a wide variety of software. You will probably have to compile the whole Python distribution with it. <a href="http://uucode.com/tex... | 2 | 2009-04-15T16:24:41Z | [
"python",
"windows",
"numpy",
"scipy"
] |
Can I compile numpy & scipy as eggs for free on Windows32? | 752,482 | <p>I've been asked to provide Numpy & Scipy as python egg files. Unfortunately Numpy and Scipy do not make official releases of their product in .egg form for a Win32 platform - that means if I want eggs then I have to compile them myself.</p>
<p>At the moment my employer provides Visual Studio.Net 2003, which wil... | 1 | 2009-04-15T16:14:35Z | 752,550 | <p>You could try <a href="http://gcc.gnu.org/install/specific.html#windows" rel="nofollow">GCC for Windows</a>. GCC is the compiler most often used for compiling Numpy/Scipy (or anything else, really) on Linux, so it seems reasonable that it should work on Windows too. (Never tried it myself, though)</p>
<p>And of cou... | 1 | 2009-04-15T16:27:43Z | [
"python",
"windows",
"numpy",
"scipy"
] |
Can I compile numpy & scipy as eggs for free on Windows32? | 752,482 | <p>I've been asked to provide Numpy & Scipy as python egg files. Unfortunately Numpy and Scipy do not make official releases of their product in .egg form for a Win32 platform - that means if I want eggs then I have to compile them myself.</p>
<p>At the moment my employer provides Visual Studio.Net 2003, which wil... | 1 | 2009-04-15T16:14:35Z | 752,551 | <p>If you just need the compiler, it is part of the .NET framework.</p>
<p>For instance, you can find the 3.5 framework (Which is used be visual studio 2008) in:</p>
<pre><code>"C:\Windows\Microsoft.NET\Framework\v3.5"
</code></pre>
| 0 | 2009-04-15T16:27:58Z | [
"python",
"windows",
"numpy",
"scipy"
] |
"Slicing" in Python Expressions documentation | 752,602 | <p>I don't understand the following part of the Python docs:</p>
<p><a href="http://docs.python.org/reference/expressions.html#slicings">http://docs.python.org/reference/expressions.html#slicings</a></p>
<p>Is this referring to list slicing ( <code>x=[1,2,3,4]; x[0:2]</code> )..? Particularly the parts referring to e... | 10 | 2009-04-15T16:39:42Z | 752,693 | <p>What happens is this. See <a href="http://docs.python.org/reference/datamodel.html#types">http://docs.python.org/reference/datamodel.html#types</a> and <a href="http://docs.python.org/library/functions.html#slice">http://docs.python.org/library/functions.html#slice</a></p>
<blockquote>
<p>Slice objects are used ... | 7 | 2009-04-15T16:56:45Z | [
"python",
"syntax",
"documentation"
] |
"Slicing" in Python Expressions documentation | 752,602 | <p>I don't understand the following part of the Python docs:</p>
<p><a href="http://docs.python.org/reference/expressions.html#slicings">http://docs.python.org/reference/expressions.html#slicings</a></p>
<p>Is this referring to list slicing ( <code>x=[1,2,3,4]; x[0:2]</code> )..? Particularly the parts referring to e... | 10 | 2009-04-15T16:39:42Z | 752,895 | <p>Defining simple test class that just prints what is being passed:</p>
<pre><code>>>> class TestGetitem(object):
... def __getitem__(self, item):
... print type(item), item
...
>>> t = TestGetitem()
</code></pre>
<p>Expression example:</p>
<pre><code>>>> t[1]
<type 'int'> 1
... | 11 | 2009-04-15T17:42:17Z | [
"python",
"syntax",
"documentation"
] |
"Slicing" in Python Expressions documentation | 752,602 | <p>I don't understand the following part of the Python docs:</p>
<p><a href="http://docs.python.org/reference/expressions.html#slicings">http://docs.python.org/reference/expressions.html#slicings</a></p>
<p>Is this referring to list slicing ( <code>x=[1,2,3,4]; x[0:2]</code> )..? Particularly the parts referring to e... | 10 | 2009-04-15T16:39:42Z | 753,260 | <p><a href="http://docs.python.org/dev/library/constants.html#Ellipsis">Ellipsis</a> is used mainly by the <a href="http://numpy.scipy.org/">numeric python</a> extension, which adds a multidementional array type. Since there are more than one dimensions, <a href="http://numpy.scipy.org/">slicing</a> becomes more compl... | 15 | 2009-04-15T19:12:07Z | [
"python",
"syntax",
"documentation"
] |
How to work with unicode in Python | 752,998 | <p>I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automat... | 14 | 2009-04-15T18:11:45Z | 753,019 | <p>Look at the <a href="http://docs.python.org/library/codecs.html" rel="nofollow">codecs</a> standard library, specifically the <strong>encode</strong> and <strong>decode</strong> methods provided in the Codec base class.</p>
<p>There's also a good article <a href="http://boodebr.org/main/python/all-about-python-and-... | 4 | 2009-04-15T18:17:29Z | [
"python",
"string",
"unicode",
"replace",
"unicode-string"
] |
How to work with unicode in Python | 752,998 | <p>I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automat... | 14 | 2009-04-15T18:11:45Z | 753,027 | <p>Just a note regarding HTML cleaning. It is very very hard, since</p>
<pre><code><
body
>
</code></pre>
<p>Is a valid way to write HTML. Just an fyi.</p>
| 1 | 2009-04-15T18:18:02Z | [
"python",
"string",
"unicode",
"replace",
"unicode-string"
] |
How to work with unicode in Python | 752,998 | <p>I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automat... | 14 | 2009-04-15T18:11:45Z | 753,028 | <p>You can convert it to unicode in this way:</p>
<pre><code>print u'Hello, \xa0World' # print Hello, World
</code></pre>
| 0 | 2009-04-15T18:18:07Z | [
"python",
"string",
"unicode",
"replace",
"unicode-string"
] |
How to work with unicode in Python | 752,998 | <p>I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automat... | 14 | 2009-04-15T18:11:45Z | 753,044 | <p>may be you should be doing</p>
<pre><code>s=unicodestring.replace(u'\xa0',u'')
</code></pre>
| 23 | 2009-04-15T18:22:48Z | [
"python",
"string",
"unicode",
"replace",
"unicode-string"
] |
How to work with unicode in Python | 752,998 | <p>I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automat... | 14 | 2009-04-15T18:11:45Z | 753,578 | <pre><code>s=unicodestring.replace('\xa0','')
</code></pre>
<p>..is trying to create the unicode character <code>\xa0</code>, which is not valid in an ASCII sctring (the default string type in Python until version 3.x)</p>
<p>The reason <code>r'\xa0'</code> did not error is because in a raw string, escape sequences h... | 6 | 2009-04-15T20:33:03Z | [
"python",
"string",
"unicode",
"replace",
"unicode-string"
] |
How to work with unicode in Python | 752,998 | <p>I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automat... | 14 | 2009-04-15T18:11:45Z | 12,407,255 | <p>Instead of this, it's better to use standard python features.</p>
<p>For example:</p>
<pre><code>string = unicode('Hello, \xa0World', 'utf-8', 'replace')
</code></pre>
<p>or </p>
<pre><code>string = unicode('Hello, \xa0World', 'utf-8', 'ignore')
</code></pre>
<p>where <code>replace</code> will replace <code>\xa... | 2 | 2012-09-13T13:19:28Z | [
"python",
"string",
"unicode",
"replace",
"unicode-string"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 753,083 | <p>You can use either a different HTML parser (<a href="http://codespeak.net/lxml/" rel="nofollow">like lxml</a>, or <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>) -- one that offers functions to extract just text. Or, you can run a regex on your line string that strips out t... | 2 | 2009-04-15T18:31:01Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 925,630 | <p>I always used this function to strip HTML tags, as it requires only the Python stdlib:</p>
<p>On Python 2</p>
<pre><code>from HTMLParser import HTMLParser
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
d... | 282 | 2009-05-29T11:47:41Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 3,856,657 | <p>You can write your own function:</p>
<pre><code>def StripTags(text):
finished = 0
while not finished:
finished = 1
start = text.find("<")
if start >= 0:
stop = text[start:].find(">")
if stop >= 0:
text = text[:start] + text[... | 1 | 2010-10-04T15:26:49Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 4,869,782 | <p>I haven't thought much about the cases it will miss, but you can do a simple regex:</p>
<pre><code>re.sub('<[^<]+?>', '', text)
</code></pre>
<p>For those that don't understand regex, this searches for a string <code><...></code>, where the inner content is made of one or more (<code>+</code>) chara... | 98 | 2011-02-02T01:09:16Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 4,869,866 | <p>This method works flawlessly for me and requires no additional installations:</p>
<pre><code>import re
import htmlentitydefs
def convertentity(m):
if m.group(1)=='#':
try:
return unichr(int(m.group(2)))
except ValueError:
return '&#%s;' % m.group(2)
try:
... | -1 | 2011-02-02T01:23:05Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 7,778,368 | <p>I needed a way to strip tags <em>and</em> decode HTML entities to plain text. The following solution is based on Eloff's answer (which I couldn't use because it strips entities).</p>
<pre><code>from HTMLParser import HTMLParser
import htmlentitydefs
class HTMLTextExtractor(HTMLParser):
def __init__(self):
... | 22 | 2011-10-15T14:19:55Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 11,086,026 | <p>I have used Eloff's answer successfully for Python 3.1 [many thanks!].</p>
<p>I upgraded to Python 3.2.3, and ran into errors. </p>
<p>The solution, provided <a href="http://stackoverflow.com/questions/11061058/using-htmlparser-in-python-3-2">here</a> thanks to the responder Thomas K, is to insert <code>super().__... | 1 | 2012-06-18T15:29:15Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 13,703,994 | <p>If you need to preserve HTML entities (i.e. <code>&amp;</code>), I added "handle_entityref" method to <a href="http://stackoverflow.com/a/925630/1094246">Eloff's answer</a>.</p>
<pre><code>from HTMLParser import HTMLParser
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.... | 16 | 2012-12-04T13:25:42Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 14,464,381 | <p>There's a simple way to this:</p>
<pre><code>def remove_html_markup(s):
tag = False
quote = False
out = ""
for c in s:
if c == '<' and not quote:
tag = True
elif c == '>' and not quote:
tag = False
elif (c == '"' or c == "'")... | 9 | 2013-01-22T17:22:29Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 14,603,269 | <p>If you want to strip all HTML tags the easiest way I found is using BeautifulSoup:</p>
<pre><code>from bs4 import BeautifulSoup # Or from BeautifulSoup import BeautifulSoup
def stripHtmlTags(self, htmlTxt):
if htmlTxt is None:
return None
else:
return ''.join(BeautifulSoup(html... | 8 | 2013-01-30T11:47:49Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 19,730,306 | <h2>Short version!</h2>
<pre><code>import re, cgi
tag_re = re.compile(r'(<!--.*?-->|<[^>]*>)')
# Remove well-formed tags, fixing mistakes by legitimate users
no_tags = tag_re.sub('', user_input)
# Clean up anything else by escaping
ready_for_web = cgi.escape(no_tags)
</code></pre>
<p><a href="https:/... | 14 | 2013-11-01T15:51:12Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 21,333,355 | <p>The solutions with HTML-Parser are all breakable, if they run only once:</p>
<pre><code>html_to_text('<<b>script>alert("hacked")<</b>/script>
</code></pre>
<p>results in:</p>
<pre><code><script>alert("hacked")</script>
</code></pre>
<p>what you intend to prevent. if you use a ... | 1 | 2014-01-24T12:58:15Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 31,869,361 | <p>This is a quick fix and can be even more optimized but it will work fine. This code will replace all non empty tags with "" and strips all html tags form a given input text .You can run it using ./file.py input output</p>
<pre><code> #!/usr/bin/python
import sys
def replace(strng,replaceText):
rpl = 0
w... | 1 | 2015-08-07T03:45:42Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 34,532,382 | <p>Why all of you do it the hard way?
You can use BeautifulSoup <code>get_text()</code> feature.</p>
<pre><code>from bs4 import BeautifulSoup
text = '''
<td><a href="http://www.fakewebsite.com">Please can you strip me?</a>
<br/><a href="http://www.fakewebsite.com">I am waiting....</a&... | 1 | 2015-12-30T15:31:13Z | [
"python",
"html"
] |
Strip HTML from strings in Python | 753,052 | <pre><code>from mechanize import Browser
br = Browser()
br.open('http://somewebpage')
html = br.response().readlines()
for line in html:
print line
</code></pre>
<p>When printing a line in an HTML file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds... | 166 | 2009-04-15T18:24:26Z | 34,564,725 | <p>I'm parsing Github readmes and I find that the following really works well:</p>
<pre><code>import re
import lxml.html
def strip_markdown(x):
links_sub = re.sub(r'\[(.+)\]\([^\)]+\)', r'\1', x)
bold_sub = re.sub(r'\*\*([^*]+)\*\*', r'\1', links_sub)
emph_sub = re.sub(r'\*([^*]+)\*', r'\1', bold_sub)
... | 0 | 2016-01-02T10:10:52Z | [
"python",
"html"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 753,832 | <p>Well, now I'm using ImageMagick. I save my frames as PNG files and then invoke ImageMagick's convert.exe from Python to create an animated GIF. The nice thing about this approach is I can specify a frame duration for each frame individually. Unfortunately this depends on ImageMagick being installed on the machine... | 29 | 2009-04-15T21:34:42Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 753,979 | <p>It's not a python library, but mencoder can do that: <a href="http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-images.html" rel="nofollow">Encoding from multiple input image files</a>. You can execute mencoder from python like this:</p>
<pre><code>import os
os.system("mencoder ...")
</code></pre>
| 4 | 2009-04-15T22:24:43Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 777,713 | <p>Have you tried <a href="http://pymedia.org/" rel="nofollow">PyMedia</a>? I am not 100% sure but it looks like <a href="http://pymedia.org/tut/src/make%5Fvideo.py.html" rel="nofollow">this tutorial example</a> targets your problem.</p>
| 4 | 2009-04-22T15:08:02Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 1,204,455 | <p>To create a video, you could use <a href="http://sourceforge.net/projects/opencvlibrary/">opencv</a>,</p>
<pre><code>#load your frames
frames = ...
#create a video writer
writer = cvCreateVideoWriter(filename, -1, fps, frame_size, is_color=1)
#and write your frames in a loop if you want
cvWriteFrame(writer, frames[... | 17 | 2009-07-30T04:29:45Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 2,376,032 | <p>As of June 2009 the originally cited blog post has a method to create animated GIFs <a href="http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-library-pil-and-animated-gifs/#comment-197921" rel="nofollow">in the comments</a>. Download the script <a href="https://pypi.python.org/pypi/images2gif" rel=... | 38 | 2010-03-04T00:13:13Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 10,376,713 | <p>I used <a href="http://sites.google.com/site/almarklein/files-1/images2gif.py">images2gif.py</a> which was easy to use. It did seem to double the file size though..</p>
<p>26 110kb PNG files, I expected 26*110kb = 2860kb, but my_gif.GIF was 5.7mb</p>
<p>Also because the GIF was 8bit, the nice png's became a little... | 23 | 2012-04-29T22:51:44Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 12,092,932 | <p>The matplotlib user manual has a solution example using mencoder.</p>
<p><a href="http://matplotlib.sourceforge.net/faq/howto_faq.html#make-a-movie" rel="nofollow">http://matplotlib.sourceforge.net/faq/howto_faq.html#make-a-movie</a></p>
| 2 | 2012-08-23T13:38:49Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 28,275,187 | <p>The task can be completed by running the two line python script from the same folder as the sequence of picture files. For png formatted files the script is - </p>
<pre><code>from scitools.std import movie
movie('*.png',fps=1,output_file='thisismygif.gif')
</code></pre>
| 2 | 2015-02-02T10:07:11Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 32,978,565 | <p>Old question, lots of good answers, but there might still be interest in another alternative...</p>
<p>The <code>numpngw</code> module that I recently put up on github (<a href="https://github.com/WarrenWeckesser/numpngw" rel="nofollow">https://github.com/WarrenWeckesser/numpngw</a>) can write animated PNG files fr... | 2 | 2015-10-06T19:55:45Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 34,555,939 | <p>With windows7, python2.7, opencv 3.0, the following works for me:</p>
<pre><code>import cv2
import os
vvw = cv2.VideoWriter('mymovie.avi',cv2.VideoWriter_fourcc('X','V','I','D'),24,(640,480))
frameslist = os.listdir('.\\frames')
howmanyframes = len(frameslist)
print('Frames count: '+str(howmanyf... | 4 | 2016-01-01T12:02:05Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 35,943,809 | <p>I'd recommend not using images2gif from visvis because it has problems with PIL/Pillow and is not actively maintained (I should know, because I am the author).</p>
<p>Instead, please use <a href="http://imageio.github.io">imageio</a>, which was developed to solve this problem and more, and is intended to stay.</p>
... | 23 | 2016-03-11T15:19:07Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Programmatically generate video or animated GIF in Python? | 753,190 | <p>I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create ... | 83 | 2009-04-15T18:57:14Z | 37,758,902 | <p>Like Warren said <em>last year</em>, this is an old question. Since people still seem to be viewing the page, I'd like to redirect them to a more modern solution. Like blakev said <a href="http://stackoverflow.com/questions/24688802/saving-an-animated-gif-in-pillow">here</a>, there is a Pillow example on <a href="ht... | 1 | 2016-06-11T00:46:10Z | [
"python",
"video",
"wxpython",
"animated-gif"
] |
Accessing the class that owns a decorated method from the decorator | 753,537 | <p>I'm writing a decorator for methods that must inspect the parent methods (the methods of the same name in the parents of the class in which I'm decorating).</p>
<p>Example (from the fourth example of <a href="http://www.python.org/dev/peps/pep-0318/#examples" rel="nofollow" title="here">PEP 318</a>):</p>
<pre><cod... | 4 | 2009-04-15T20:23:35Z | 753,617 | <blockquote>
<p>here I want to reach the class owning the decorated method f</p>
</blockquote>
<p>You can't because at the point of decoration, no class owns the method f.</p>
<pre><code>class A(object):
@returns(int)
def compute(self, value):
return value * 3
</code></pre>
<p>Is the same as saying... | 6 | 2009-04-15T20:40:03Z | [
"python",
"decorator"
] |
Accessing the class that owns a decorated method from the decorator | 753,537 | <p>I'm writing a decorator for methods that must inspect the parent methods (the methods of the same name in the parents of the class in which I'm decorating).</p>
<p>Example (from the fourth example of <a href="http://www.python.org/dev/peps/pep-0318/#examples" rel="nofollow" title="here">PEP 318</a>):</p>
<pre><cod... | 4 | 2009-04-15T20:23:35Z | 754,066 | <p>As <a href="http://stackoverflow.com/questions/753537/accessing-the-class-that-owns-a-decorated-method-from-the-decorator/753617#753617">bobince said it</a>, you can't access the surrounding class, because at the time the decorator is invoked, the class does not exist yet. If you need access to the full dictionary o... | 6 | 2009-04-15T22:51:32Z | [
"python",
"decorator"
] |
Inheritance and Overriding __init__ in python | 753,640 | <p>I was reading 'Dive Into Python' and in the chapter on classes it gives this example:</p>
<pre><code>class FileInfo(UserDict):
"store file metadata"
def __init__(self, filename=None):
UserDict.__init__(self)
self["name"] = filename
</code></pre>
<p>The author then says that if you want to o... | 84 | 2009-04-15T20:45:46Z | 753,654 | <p>If the FileInfo class has more than one ancestor class then you should definitely call all of their __init__() functions. You should also do the same for the __del__() function, which is a destructor.</p>
| 3 | 2009-04-15T20:49:08Z | [
"python",
"override",
"superclass"
] |
Inheritance and Overriding __init__ in python | 753,640 | <p>I was reading 'Dive Into Python' and in the chapter on classes it gives this example:</p>
<pre><code>class FileInfo(UserDict):
"store file metadata"
def __init__(self, filename=None):
UserDict.__init__(self)
self["name"] = filename
</code></pre>
<p>The author then says that if you want to o... | 84 | 2009-04-15T20:45:46Z | 753,657 | <p>The book is a bit dated with respect to subclass-superclass calling. It's also a little dated with respect to subclass built-in classes.</p>
<p>It looks like this nowadays.</p>
<pre><code>class FileInfo(dict):
"""store file metadata"""
def __init__(self, filename=None):
super( FileInfo, self ).__i... | 108 | 2009-04-15T20:49:52Z | [
"python",
"override",
"superclass"
] |
Inheritance and Overriding __init__ in python | 753,640 | <p>I was reading 'Dive Into Python' and in the chapter on classes it gives this example:</p>
<pre><code>class FileInfo(UserDict):
"store file metadata"
def __init__(self, filename=None):
UserDict.__init__(self)
self["name"] = filename
</code></pre>
<p>The author then says that if you want to o... | 84 | 2009-04-15T20:45:46Z | 753,661 | <p>Yes, you must call <code>__init__</code> for each parent class. The same goes for functions, if you are overriding a function that exists in both parents.</p>
| 2 | 2009-04-15T20:50:35Z | [
"python",
"override",
"superclass"
] |
Inheritance and Overriding __init__ in python | 753,640 | <p>I was reading 'Dive Into Python' and in the chapter on classes it gives this example:</p>
<pre><code>class FileInfo(UserDict):
"store file metadata"
def __init__(self, filename=None):
UserDict.__init__(self)
self["name"] = filename
</code></pre>
<p>The author then says that if you want to o... | 84 | 2009-04-15T20:45:46Z | 753,705 | <p>You don't really <em>have</em> to call the <code>__init__</code> methods of the base class(es), but you usually <em>want</em> to do it because the base classes will do some important initializations there that are needed for rest of the classes methods to work.</p>
<p>For other methods it depends on your intentions... | 8 | 2009-04-15T21:00:40Z | [
"python",
"override",
"superclass"
] |
Inheritance and Overriding __init__ in python | 753,640 | <p>I was reading 'Dive Into Python' and in the chapter on classes it gives this example:</p>
<pre><code>class FileInfo(UserDict):
"store file metadata"
def __init__(self, filename=None):
UserDict.__init__(self)
self["name"] = filename
</code></pre>
<p>The author then says that if you want to o... | 84 | 2009-04-15T20:45:46Z | 11,055,691 | <p>In each class that you need to inherit from, you can run a loop of each class that needs init'd upon initiation of the child class...an example that can copied might be better understood...</p>
<pre><code>class Female_Grandparent:
def __init__(self):
self.grandma_name = 'Grandma'
class Male_Grandparent... | 14 | 2012-06-15T17:43:42Z | [
"python",
"override",
"superclass"
] |
How do you order lists in the same way QuerySets are ordered in Django? | 753,687 | <p>I have a model that has an ordering field under its Meta class. When I perform a query and get back a QuerySet for the model it is in the order specified. However if I have instances of this model that are in a list and execute the sort method on the list the order is different from the one I want. Is there a wa... | 1 | 2009-04-15T20:57:34Z | 753,788 | <p>The answer to your question is varying degrees of yes, with some manual requirements. If by <code>list</code> you mean a <code>queryset</code> that has been formed by some complicated query, then, sure:</p>
<pre><code>queryset.order_by(ClassName.Meta.ordering)
</code></pre>
<p>or</p>
<pre><code>queryset.order_by... | 3 | 2009-04-15T21:23:23Z | [
"python",
"django",
"django-models"
] |
How do you order lists in the same way QuerySets are ordered in Django? | 753,687 | <p>I have a model that has an ordering field under its Meta class. When I perform a query and get back a QuerySet for the model it is in the order specified. However if I have instances of this model that are in a list and execute the sort method on the list the order is different from the one I want. Is there a wa... | 1 | 2009-04-15T20:57:34Z | 756,132 | <p>Not automatically, but with a bit of work, yes. You need to define a comparator function (or <strong>cmp</strong> method on the model class) that can compare two model instances according to the relevant attribute. For instance:</p>
<pre><code>class Dated(models.Model):
...
created = models.DateTimeField(defa... | 3 | 2009-04-16T13:31:44Z | [
"python",
"django",
"django-models"
] |
How do you order lists in the same way QuerySets are ordered in Django? | 753,687 | <p>I have a model that has an ordering field under its Meta class. When I perform a query and get back a QuerySet for the model it is in the order specified. However if I have instances of this model that are in a list and execute the sort method on the list the order is different from the one I want. Is there a wa... | 1 | 2009-04-15T20:57:34Z | 758,263 | <p>Building on Carl's answer, you could easily add the ability to use all the ordering fields and even detect the ones that are in reverse order.</p>
<pre><code>class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
birthday = date = models.DateField(... | 2 | 2009-04-16T22:17:51Z | [
"python",
"django",
"django-models"
] |
Need to build (or otherwise obtain) python-devel 2.3 and add to LD_LIBRARY_PATH | 753,749 | <p>I am supporting an application with a hard dependency on python-devel 2.3.7. The application runs the python interpreter embedded, attempting to load libpython2.3.so - but since the local machine has libpython2.4.so under /usr/lib64, the application is failing.</p>
<p>I see that there are RPMs for python-devel (but... | 2 | 2009-04-15T21:13:47Z | 753,903 | <p>Can you use one of these rpm's?
What specific distro are you on?</p>
<ul>
<li><a href="http://www.python.org/download/releases/2.3.3/rpms/" rel="nofollow">http://www.python.org/download/releases/2.3.3/rpms/</a></li>
<li><a href="http://rpm.pbone.net/index.php3/stat/4/idpl/3171326/com/python-devel-2.3-4.i586.rpm.htm... | 0 | 2009-04-15T21:58:03Z | [
"python",
"linux",
"build"
] |
Need to build (or otherwise obtain) python-devel 2.3 and add to LD_LIBRARY_PATH | 753,749 | <p>I am supporting an application with a hard dependency on python-devel 2.3.7. The application runs the python interpreter embedded, attempting to load libpython2.3.so - but since the local machine has libpython2.4.so under /usr/lib64, the application is failing.</p>
<p>I see that there are RPMs for python-devel (but... | 2 | 2009-04-15T21:13:47Z | 754,180 | <p>You can use the python RPM's linked to from the python home page ChristopheD mentioned.
You can extract the RPM's using cpio, as they are just specialized cpio archives.
Your method of extracting them to your home directory and setting LD_LIBRARY_PATH and PATH should work; I use this all the time for hand-built newe... | 2 | 2009-04-15T23:37:08Z | [
"python",
"linux",
"build"
] |
Is there a more pythonic way to build this dictionary? | 753,986 | <p>What is the "most pythonic" way to build a dictionary where I have the values in a sequence and each key will be a function of its value? I'm currently using the following, but I feel like I'm just missing a cleaner way. NOTE: <code>values</code> is a list that is not related to any dictionary.</p>
<pre><code>for v... | 6 | 2009-04-15T22:26:44Z | 754,002 | <p>At least it's shorter:</p>
<pre><code>dict((key_from_value(value), value) for value in values)
</code></pre>
| 18 | 2009-04-15T22:30:23Z | [
"python"
] |
Is there a more pythonic way to build this dictionary? | 753,986 | <p>What is the "most pythonic" way to build a dictionary where I have the values in a sequence and each key will be a function of its value? I'm currently using the following, but I feel like I'm just missing a cleaner way. NOTE: <code>values</code> is a list that is not related to any dictionary.</p>
<pre><code>for v... | 6 | 2009-04-15T22:26:44Z | 754,024 | <pre><code>>>> l = [ 1, 2, 3, 4 ]
>>> dict( ( v, v**2 ) for v in l )
{1: 1, 2: 4, 3: 9, 4: 16}
</code></pre>
<p>In Python 3.0 you can use a "dict comprehension" which is basically a shorthand for the above:</p>
<pre><code>{ v : v**2 for v in l }
</code></pre>
| 15 | 2009-04-15T22:36:49Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.