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 |
|---|---|---|---|---|---|---|---|---|---|
How to get the size of a list | 1,712,227 | <pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD::
items.amount() # Should return 3
</code></pre>
<p>How do I do it right?</p>
| 996 | 2009-11-11T00:30:54Z | 1,712,236 | <p>The <a href="https://docs.python.org/2/library/functions.html#len"><code>len()</code></a> function can be used with a lot of types in <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> - both built-in types and library types.</p>
<pre><code>>>> len([1,2,3])
3
</code></pre>
| 1,389 | 2009-11-11T00:33:22Z | [
"python",
"list"
] |
How to get the size of a list | 1,712,227 | <pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD::
items.amount() # Should return 3
</code></pre>
<p>How do I do it right?</p>
| 996 | 2009-11-11T00:30:54Z | 16,114,025 | <p>While this may not be useful due to the fact that it'd make a lot more sense as being "out of the box" functionality, a fairly simple hack would be to build a class with a <code>length</code> property:</p>
<pre><code>class slist(list):
@property
def length(self):
return len(self)
</code></pre>
<p>Y... | 37 | 2013-04-19T21:51:10Z | [
"python",
"list"
] |
How to get the size of a list | 1,712,227 | <pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD::
items.amount() # Should return 3
</code></pre>
<p>How do I do it right?</p>
| 996 | 2009-11-11T00:30:54Z | 27,137,427 | <blockquote>
<h1>How to get the size of a list?</h1>
</blockquote>
<p>To find the size of a list, use the builtin function, <code>len</code>:</p>
<pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
</code></pre>
<p>And now:</p>
<pre><code>len(items)
</code></pre>
<p>returns ... | 29 | 2014-11-25T21:51:55Z | [
"python",
"list"
] |
How to get the size of a list | 1,712,227 | <pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD::
items.amount() # Should return 3
</code></pre>
<p>How do I do it right?</p>
| 996 | 2009-11-11T00:30:54Z | 31,401,712 | <p>Answering your question as the examples also givven above:</p>
<pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
print items.__len__()
</code></pre>
| 5 | 2015-07-14T08:36:42Z | [
"python",
"list"
] |
How to get the size of a list | 1,712,227 | <pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD::
items.amount() # Should return 3
</code></pre>
<p>How do I do it right?</p>
| 996 | 2009-11-11T00:30:54Z | 34,679,389 | <p>If you need to know MEMORY USAGE of a given type, you can use the function sys.getsizeof</p>
<pre><code>>>> from sys import getsizeof
>>> l = []
>>> getsizeof(l)
64
>>> l.append(10)
>>> getsizeof(l)
96
>>> getsizeof(10)
28
>>> l.append(True)
>>>... | 5 | 2016-01-08T14:28:35Z | [
"python",
"list"
] |
How to get the size of a list | 1,712,227 | <pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD::
items.amount() # Should return 3
</code></pre>
<p>How do I do it right?</p>
| 996 | 2009-11-11T00:30:54Z | 36,571,352 | <p>Python <code>len()</code> function is enough for determining list size. There is also <code>__len__()</code> function you can use.</p>
<pre><code>items = []
items.append("apple")
items.append("orange")
items.append("banana")
print len(items) #it will print 3
print items.__len__() #it will print 3
</code></pre>
... | 2 | 2016-04-12T11:02:05Z | [
"python",
"list"
] |
Python JSON RPC server with ability to stream | 1,712,249 | <p>I have come across several guides and packages on implementing a python JSON RPC server, e.g.:</p>
<ul>
<li><a href="http://json-rpc.org/wiki/python-json-rpc" rel="nofollow">http://json-rpc.org/wiki/python-json-rpc</a></li>
<li><a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/552751" rel="nofollow">... | 3 | 2009-11-11T00:37:04Z | 1,712,845 | <p>if the typical JSON-RPC frameworks doesn't allow you to dump such huge data effectively, why not just use a HTTP server and return json data, that way you can stream and read streamed data, good thing is you may even gzip it for faster transfer, and you will be able to use many standard servers too e.g. apache .</p>... | 2 | 2009-11-11T03:34:24Z | [
"python",
"json",
"rpc"
] |
Tail read a growing dynamic file and extract two columns and then print a graph | 1,712,276 | <p>What is the best way to read a 1 GB file that gets time series data logged in it and generate a real time graph with two of its columns (one time and other a number)? I see that you have different ways of tailign the file.</p>
| 2 | 2009-11-11T00:42:51Z | 1,712,360 | <p>Sounds like a good job for <a href="http://oss.oetiker.ch/rrdtool/" rel="nofollow">RRDTool</a>. </p>
<p>But if you want to stick with Python, I would use tail to stream the data into my program (this is assuming the file is continuously written to, otherwise a straight open() in Python will work).</p>
<pre><code>... | 5 | 2009-11-11T01:07:23Z | [
"python",
"graph",
"tail",
"matplotlib"
] |
Tail read a growing dynamic file and extract two columns and then print a graph | 1,712,276 | <p>What is the best way to read a 1 GB file that gets time series data logged in it and generate a real time graph with two of its columns (one time and other a number)? I see that you have different ways of tailign the file.</p>
| 2 | 2009-11-11T00:42:51Z | 1,713,023 | <p>As John mentioned, you can input the tail output into your file, but if you due to some reason wants to handle everything in your file and also want an example of somewhat dynamic graph, here it is</p>
<pre><code>import math
import time
import pylab
def getDataTest(filePath):
s = 0
inc = .05
x_list=p... | 2 | 2009-11-11T04:31:11Z | [
"python",
"graph",
"tail",
"matplotlib"
] |
Tail read a growing dynamic file and extract two columns and then print a graph | 1,712,276 | <p>What is the best way to read a 1 GB file that gets time series data logged in it and generate a real time graph with two of its columns (one time and other a number)? I see that you have different ways of tailign the file.</p>
| 2 | 2009-11-11T00:42:51Z | 26,554,100 | <p>Here's the unix pipe which has 3 parts: the tail'er, the filter (gawk), and the plotter (python).</p>
<pre><code>tail -f yourfile.log | gawk '/PCM1/{print $21; fflush();}' | python -u tailplot.py
</code></pre>
<p>and here is the python script. You can feed it 1 (y) or 2 (x y) columns of data. If you don't use <co... | 0 | 2014-10-24T18:32:01Z | [
"python",
"graph",
"tail",
"matplotlib"
] |
In Python: how do I say: if line.partition('#' or 'tab') ... do something | 1,712,348 | <p>In Python: how do I say: </p>
<pre><code>line = line.partition('#' or 'tab')[0] ... do something with
</code></pre>
<p>I know I can do: </p>
<pre><code>line = line.partition('#')[0] ... do something
</code></pre>
<p>But what is the code for the tab character, and can I say # or tab? </p>
<p>Update: I'm tryi... | 3 | 2009-11-11T01:04:18Z | 1,712,372 | <p>partition doesn't allow for options, so you may need <code>re.split</code>:</p>
<pre><code>re.split("(#|\t)", line, 1)
</code></pre>
<p><code>re.split</code> has the interesting property that if the pattern is enclosed in parens, then the separator is returned in the results, and you can use maxsplit (as I have he... | 10 | 2009-11-11T01:11:22Z | [
"python",
"string"
] |
In Python: how do I say: if line.partition('#' or 'tab') ... do something | 1,712,348 | <p>In Python: how do I say: </p>
<pre><code>line = line.partition('#' or 'tab')[0] ... do something with
</code></pre>
<p>I know I can do: </p>
<pre><code>line = line.partition('#')[0] ... do something
</code></pre>
<p>But what is the code for the tab character, and can I say # or tab? </p>
<p>Update: I'm tryi... | 3 | 2009-11-11T01:04:18Z | 1,712,378 | <p><code>'\t'</code> is the string containing a tab.</p>
<pre><code>import re
match = re.search('[#\t]', line)
if match:
i, j = match.span()
return (line[:i], line[i:j], line[j:])
return (line, '', '')
</code></pre>
<p>This will give results similar to partition: a tuple of (head, sep, tail).</p>
| 2 | 2009-11-11T01:13:09Z | [
"python",
"string"
] |
In Python: how do I say: if line.partition('#' or 'tab') ... do something | 1,712,348 | <p>In Python: how do I say: </p>
<pre><code>line = line.partition('#' or 'tab')[0] ... do something with
</code></pre>
<p>I know I can do: </p>
<pre><code>line = line.partition('#')[0] ... do something
</code></pre>
<p>But what is the code for the tab character, and can I say # or tab? </p>
<p>Update: I'm tryi... | 3 | 2009-11-11T01:04:18Z | 1,714,506 | <p>Since the comment is from # to end-of-line, what we usually do is this.</p>
<pre><code>raw_data, _, _ = line.partition("#")
data= raw_data.strip()
if len(data) == 0:
continue # or whatever, the data part of the line is empty
# you have data
</code></pre>
<p>The point is to not try and combine the comment proce... | 2 | 2009-11-11T11:09:59Z | [
"python",
"string"
] |
In Python: how do I say: if line.partition('#' or 'tab') ... do something | 1,712,348 | <p>In Python: how do I say: </p>
<pre><code>line = line.partition('#' or 'tab')[0] ... do something with
</code></pre>
<p>I know I can do: </p>
<pre><code>line = line.partition('#')[0] ... do something
</code></pre>
<p>But what is the code for the tab character, and can I say # or tab? </p>
<p>Update: I'm tryi... | 3 | 2009-11-11T01:04:18Z | 23,457,097 | <p>I would just first split the line into three part with partition for # and then again for '\t'.</p>
<p>What can be done (with partition as stated above) is:</p>
<p>first_word, space, rest = Line.partition('\t')</p>
<p>now in first_word you have the part split for \t (tab). However you can further split this in ca... | 0 | 2014-05-04T13:59:28Z | [
"python",
"string"
] |
Making a multi-table inheritance design generic in Django | 1,712,683 | <p>First of all, some links to pages I've used for reference: <a href="http://stackoverflow.com/questions/416007/how-can-i-define-a-polymorphic-relation-between-models-in-django">A SO question</a>, and the Django docs on <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1" rel="nofollow">generic... | 4 | 2009-11-11T02:46:01Z | 1,712,719 | <p>It would be better to compose the models of an Item model and an ItemType model. Subclassing models sounds nice and is useful in a few edge cases, but generally, it is safest and most efficient to stick to tactics that work with your database, rather than against it.</p>
| 1 | 2009-11-11T02:57:17Z | [
"python",
"django",
"inheritance"
] |
Making a multi-table inheritance design generic in Django | 1,712,683 | <p>First of all, some links to pages I've used for reference: <a href="http://stackoverflow.com/questions/416007/how-can-i-define-a-polymorphic-relation-between-models-in-django">A SO question</a>, and the Django docs on <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1" rel="nofollow">generic... | 4 | 2009-11-11T02:46:01Z | 1,712,737 | <p>I have done something similar to method 2 in one of my projects:</p>
<pre><code>from django.db import models
from django.contrib.contenttypes.models import ContentType
class BaseModel(models.Model):
type = models.ForeignKey(ContentType,editable=False)
# other base fields here
def save(self,force_inser... | 4 | 2009-11-11T03:03:16Z | [
"python",
"django",
"inheritance"
] |
What Jabber/XMPP libraries are available for PyS60 (Python for Symbian S60) interpreter? | 1,712,768 | <p>I'm interested in developing a XMPP client on the mobile S60 Symbian platform using the Python interpreter PyS60. I've done a search on Google for possible libraries, but turned up empty. </p>
<p>I'm hoping that by asking this on SO, I can get a definite answer on whether there is actually an existing library that ... | 2 | 2009-11-11T03:11:45Z | 1,716,884 | <p>It's fairly easy to add native extensions to Python and there are lots of C/C++ libraries for XMPP that would port easily.</p>
<p>The previous pyexpat module is just bindings for native expat on Symbian, which is ported to S60 3rd Edition, so you should be able to get pyexpat working too. Of course you need some a... | 0 | 2009-11-11T17:44:54Z | [
"python",
"symbian",
"xmpp",
"pys60"
] |
Pylons deployment questions | 1,712,883 | <p>I'm a beginner with Pylons and I've mostly developed on my localhost using the built-in web server. I think it's time to start deployment for my personal blog, I have a Debian Lenny server with <code>apache2-mpm-prefork</code> module and <code>mod_wsgi</code> - I've never really used <code>mod_wsgi</code> or <code>f... | 0 | 2009-11-11T03:50:01Z | 1,712,913 | <ol>
<li><p>mod_wsgi. It's more efficient. FastCGI can be troublesome to setup, whereas I've never known anyone to have a problem using mod_wsgi with a supported version of Python (2.5, 2.6, 3.1 included). WSGI exists for Python (by Python, &c.) and so it makes for a more "Pythonic" experience. Prior to WSGI I ... | 2 | 2009-11-11T03:56:29Z | [
"python",
"apache",
"deployment",
"apache2",
"pylons"
] |
ImportError: No module named etree.ElementTree when running Yahoo BOSS for the first time | 1,713,015 | <p>I installed Yahoo BOSS (it's a Python installation that allows you to use their search features). I followed everything perfectly. However, when I run the example to confirm that it works, I get this:</p>
<pre><code>$ python ex3.py
Traceback (most recent call last):
File "ex3.py", line 16, in ?
from yos.yql i... | -5 | 2009-11-11T04:29:46Z | 1,713,025 | <p>A google search reveals that you need to install the <a href="http://effbot.org/downloads/#elementtree" rel="nofollow">effbot elementtree</a> Python module.</p>
| 0 | 2009-11-11T04:31:50Z | [
"python",
"python-2.4",
"yahoo-boss-api"
] |
ImportError: No module named etree.ElementTree when running Yahoo BOSS for the first time | 1,713,015 | <p>I installed Yahoo BOSS (it's a Python installation that allows you to use their search features). I followed everything perfectly. However, when I run the example to confirm that it works, I get this:</p>
<pre><code>$ python ex3.py
Traceback (most recent call last):
File "ex3.py", line 16, in ?
from yos.yql i... | -5 | 2009-11-11T04:29:46Z | 1,713,027 | <p>Use Python 2.5 or above: xml.etree.ElementTree was added in 2.5.</p>
<p><a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">http://docs.python.org/library/xml.etree.elementtree.html</a></p>
| 3 | 2009-11-11T04:32:37Z | [
"python",
"python-2.4",
"yahoo-boss-api"
] |
super() fails with error: TypeError "argument 1 must be type, not classobj" | 1,713,038 | <p>I get some error that I can't figure out. Any clue what is wrong with my sample code?</p>
<pre><code>class B:
def meth(self, arg):
print arg
class C(B):
def meth(self, arg):
super(C, self).meth(arg)
print C().meth(1)
</code></pre>
<p>I got the sample test code from help of 'super' built-i... | 52 | 2009-11-11T04:36:05Z | 1,713,052 | <p>Your problem is that class B is not declared as a "new-style" class. Change it like so:</p>
<pre><code>class B(object):
</code></pre>
<p>and it will work.</p>
<p><code>super()</code> and all subclass/superclass stuff only works with new-style classes. I recommend you get in the habit of always typing that <code... | 102 | 2009-11-11T04:40:10Z | [
"python"
] |
super() fails with error: TypeError "argument 1 must be type, not classobj" | 1,713,038 | <p>I get some error that I can't figure out. Any clue what is wrong with my sample code?</p>
<pre><code>class B:
def meth(self, arg):
print arg
class C(B):
def meth(self, arg):
super(C, self).meth(arg)
print C().meth(1)
</code></pre>
<p>I got the sample test code from help of 'super' built-i... | 52 | 2009-11-11T04:36:05Z | 18,392,639 | <p>Also, if you can't change class B, you can fix the error by using multiple inheritance.</p>
<pre><code>class B:
def meth(self, arg):
print arg
class C(B, object):
def meth(self, arg):
super(C, self).meth(arg)
print C().meth(1)
</code></pre>
| 41 | 2013-08-23T00:02:15Z | [
"python"
] |
super() fails with error: TypeError "argument 1 must be type, not classobj" | 1,713,038 | <p>I get some error that I can't figure out. Any clue what is wrong with my sample code?</p>
<pre><code>class B:
def meth(self, arg):
print arg
class C(B):
def meth(self, arg):
super(C, self).meth(arg)
print C().meth(1)
</code></pre>
<p>I got the sample test code from help of 'super' built-i... | 52 | 2009-11-11T04:36:05Z | 31,821,900 | <p>If the python version is 3.X, it's okay.</p>
<p>I think your python version is 2.X, the super would work when adding this code</p>
<pre><code>__metaclass__ = type
</code></pre>
<p>so the code is</p>
<pre><code>__metaclass__ = type
class B:
def meth(self, arg):
print arg
class C(B):
def meth(self,... | 0 | 2015-08-05T01:17:47Z | [
"python"
] |
Python 3 Function List | 1,713,077 | <p>I've just started learning Python and would like to know if there is a <strong><em>searchable</em></strong> list of Python (3.1) functions available online, like there is for PHP (php.net)?</p>
<p>Thanks.</p>
| -1 | 2009-11-11T04:48:09Z | 1,713,087 | <p><a href="http://docs.python.org/3.1/" rel="nofollow">http://docs.python.org/3.1/</a></p>
<p>If you want search, I usually just use a search engine with</p>
<pre><code>python <term>
</code></pre>
| 7 | 2009-11-11T04:50:45Z | [
"python",
"function",
"documentation",
"reference",
"python-3.x"
] |
Python 3 Function List | 1,713,077 | <p>I've just started learning Python and would like to know if there is a <strong><em>searchable</em></strong> list of Python (3.1) functions available online, like there is for PHP (php.net)?</p>
<p>Thanks.</p>
| -1 | 2009-11-11T04:48:09Z | 1,713,089 | <p><a href="http://docs.python.org/3.1/library/index.html" rel="nofollow">Python's library reference.</a></p>
| 2 | 2009-11-11T04:51:39Z | [
"python",
"function",
"documentation",
"reference",
"python-3.x"
] |
Python 3 Function List | 1,713,077 | <p>I've just started learning Python and would like to know if there is a <strong><em>searchable</em></strong> list of Python (3.1) functions available online, like there is for PHP (php.net)?</p>
<p>Thanks.</p>
| -1 | 2009-11-11T04:48:09Z | 1,713,213 | <p>If you mean <strong>built-in</strong> functions, they're documented <a href="http://docs.python.org/3.1/library/functions.html" rel="nofollow">here</a>. Of course, there are many more in other modules of the <a href="http://docs.python.org/3.1/library/index.html" rel="nofollow">standard library</a>, and more still ... | 4 | 2009-11-11T05:23:52Z | [
"python",
"function",
"documentation",
"reference",
"python-3.x"
] |
Python, Asyncore and forks | 1,713,078 | <p>Just for starters, I used Twisted and SocketServer with both ForkMixIn, ThreadMixIn and tried the "thread-pool" recepies.</p>
<p>However, I wanted to make something particular work in Python.</p>
<p>Alittle background. Previously I wrote in C a simple TCP deamon that would bind to a socket and listen on it, then p... | 2 | 2009-11-11T04:48:14Z | 1,713,444 | <p>You should use code markup for traceback, otherwise it's displayed messed and we don't see exception type. </p>
<p>But I believe it's <code>TypeError: 'NoneType' object is not iterable</code> since <code>self.accept()</code> can return <code>None</code>. The reason is that several processes can get read event for l... | 2 | 2009-11-11T06:33:48Z | [
"python",
"sockets",
"twisted",
"asyncore"
] |
How to load a bitmap on a window on PyQt | 1,713,306 | <p>I currently have a PIL Image that I'd like to display on a PyQt window. I know this must be easy, but I can't find anywhere how to do it. Could anyone give me a hand on this?
Here is the code of the window I currently have:</p>
<pre><code>import sys
from PyQt4 import QtGui
class Window(QtGui.QWidget):
def __in... | 2 | 2009-11-11T05:48:39Z | 1,713,704 | <p>Regarging to <a href="http://lists.trolltech.com/qt-interest/2005-02/thread00600-0.html" rel="nofollow">this discussion</a>, the fastest way would be to use GLPainter in order to benefit of the Graphic Card performance.</p>
| 1 | 2009-11-11T07:53:12Z | [
"python",
"pyqt",
"pyqt4"
] |
How to load a bitmap on a window on PyQt | 1,713,306 | <p>I currently have a PIL Image that I'd like to display on a PyQt window. I know this must be easy, but I can't find anywhere how to do it. Could anyone give me a hand on this?
Here is the code of the window I currently have:</p>
<pre><code>import sys
from PyQt4 import QtGui
class Window(QtGui.QWidget):
def __in... | 2 | 2009-11-11T05:48:39Z | 1,720,102 | <p>try something like this, you can use <a href="http://effbot.python-hosting.com/file/pil/PIL/ImageQt.py" rel="nofollow">http://effbot.python-hosting.com/file/pil/PIL/ImageQt.py</a> to convert any pil image to qimage</p>
<pre><code>import sys
from PyQt4 import QtGui
from PIL import Image
def get_pil_image(w, h):
... | 2 | 2009-11-12T05:32:46Z | [
"python",
"pyqt",
"pyqt4"
] |
Mac OS X app/service and stdin? | 1,713,329 | <p>I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like:</p>
<pre><code>open -a myapp.app < foo_in.txt
</code></pre>
<p>Is it possible to pass stuff to an .app's stdin at all?</p>
<p><strong>Edit</strong>... | 0 | 2009-11-10T15:57:54Z | 1,713,330 | <p>Well, </p>
<pre><code>open -a /Applications/myapp.app < foo_in.txt
</code></pre>
<p>will open foo_in.txt in your myapp.app application. You need the full path of the application, be it Applications, bin, or wherever it is...</p>
<p>It depends on what your application does. This may be more appropriate:</p>
<p... | 0 | 2009-11-10T18:14:37Z | [
"python",
"osx",
"service",
"py2app"
] |
Mac OS X app/service and stdin? | 1,713,329 | <p>I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like:</p>
<pre><code>open -a myapp.app < foo_in.txt
</code></pre>
<p>Is it possible to pass stuff to an .app's stdin at all?</p>
<p><strong>Edit</strong>... | 0 | 2009-11-10T15:57:54Z | 1,713,331 | <p>To start Finder as root, one would <em>not</em> use:</p>
<pre>sudo open -a /System/Library/CoreServices/Finder.app</pre>
<p>The above runs <code>open</code> as root, but still <code>open</code> runs Finder as the normal user. Instead, one would <a href="http://superuser.com/questions/35152/how-do-i-retrieve-files-... | 0 | 2009-11-10T21:29:48Z | [
"python",
"osx",
"service",
"py2app"
] |
Mac OS X app/service and stdin? | 1,713,329 | <p>I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like:</p>
<pre><code>open -a myapp.app < foo_in.txt
</code></pre>
<p>Is it possible to pass stuff to an .app's stdin at all?</p>
<p><strong>Edit</strong>... | 0 | 2009-11-10T15:57:54Z | 1,713,826 | <p>You should almost certainly be doing this through Mach ports or Distributed Objects or pretty much any other method of interapplication communication the OS makes available to you. </p>
| 0 | 2009-11-11T08:33:10Z | [
"python",
"osx",
"service",
"py2app"
] |
Mac OS X app/service and stdin? | 1,713,329 | <p>I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like:</p>
<pre><code>open -a myapp.app < foo_in.txt
</code></pre>
<p>Is it possible to pass stuff to an .app's stdin at all?</p>
<p><strong>Edit</strong>... | 0 | 2009-11-10T15:57:54Z | 1,714,094 | <p>What do you mean with using it as a service?</p>
<p>The example you show won't work, the open command calls LaunchServices to launch the application, and there is no place in the LaunchServices API to pass stdin data or similar to the application.</p>
<p>If you mean adding an item to the OS X Services Menu, you sh... | 1 | 2009-11-11T09:34:28Z | [
"python",
"osx",
"service",
"py2app"
] |
Mac OS X app/service and stdin? | 1,713,329 | <p>I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like:</p>
<pre><code>open -a myapp.app < foo_in.txt
</code></pre>
<p>Is it possible to pass stuff to an .app's stdin at all?</p>
<p><strong>Edit</strong>... | 0 | 2009-11-10T15:57:54Z | 1,714,112 | <p><code>open</code> creates an entirely new process. Therefore do not use it to redirect stuff into an application from Terminal.
You could try</p>
<pre><code>./Foo.app/Contents/MacOS/Foo < Foo.txt
</code></pre>
<p>Already mentioned <code>cat Foo.txt | ./Foo.app/Contents/MacOS/Foo</code> very much depending on wh... | 0 | 2009-11-11T09:40:15Z | [
"python",
"osx",
"service",
"py2app"
] |
Peak-finding algorithm for Python/SciPy | 1,713,335 | <p>I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?</p>
<p>My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc.</p>
<p>Spec... | 78 | 2009-11-11T05:54:48Z | 1,720,766 | <p>I do not think that what you are looking for is provided by SciPy. I would write the code myself, in this situation.</p>
<p>The spline interpolation and smoothing from scipy.interpolate are quite nice and might be quite helpful in fitting peaks and then finding the location of their maximum.</p>
| 10 | 2009-11-12T08:36:11Z | [
"python",
"scipy",
"fft",
"hough-transform"
] |
Peak-finding algorithm for Python/SciPy | 1,713,335 | <p>I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?</p>
<p>My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc.</p>
<p>Spec... | 78 | 2009-11-11T05:54:48Z | 1,720,954 | <p>There are standard statistical functions and methods for finding outliers to data, which is probably what you need in the first case. Using derivatives would solve your second. I'm not sure for a method which solves both continuous functions and sampled data, however.</p>
| 2 | 2009-11-12T09:17:01Z | [
"python",
"scipy",
"fft",
"hough-transform"
] |
Peak-finding algorithm for Python/SciPy | 1,713,335 | <p>I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?</p>
<p>My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc.</p>
<p>Spec... | 78 | 2009-11-11T05:54:48Z | 1,807,394 | <p>Detecting peaks in a spectrum in a reliable way has been studied quite a bit, for example all the work on sinusoidal modelling for music/audio signals in the 80ies. Look for "Sinusoidal Modeling" in the literature.</p>
<p>If your signals are as clean as the example, a simple "give me something with an amplitude hig... | 6 | 2009-11-27T08:20:25Z | [
"python",
"scipy",
"fft",
"hough-transform"
] |
Peak-finding algorithm for Python/SciPy | 1,713,335 | <p>I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?</p>
<p>My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc.</p>
<p>Spec... | 78 | 2009-11-11T05:54:48Z | 1,923,180 | <p>I'm looking at a similar problem, and I've found some of the best references come from chemistry (from peaks finding in mass-spec data). For a good thorough review of peaking finding algorithms read <a href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2631518/">this</a>. This is one of the best clearest reviews of... | 33 | 2009-12-17T17:06:46Z | [
"python",
"scipy",
"fft",
"hough-transform"
] |
Peak-finding algorithm for Python/SciPy | 1,713,335 | <p>I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?</p>
<p>My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc.</p>
<p>Spec... | 78 | 2009-11-11T05:54:48Z | 18,850,555 | <p>There is a function in scipy named <code>scipy.signal.find_peaks_cwt</code> which sounds like is suitable for your needs, however I didn't experience with it so I cannot recommend..</p>
<p><a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks_cwt.html">http://docs.scipy.org/doc/scipy/... | 7 | 2013-09-17T12:58:31Z | [
"python",
"scipy",
"fft",
"hough-transform"
] |
Peak-finding algorithm for Python/SciPy | 1,713,335 | <p>I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?</p>
<p>My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc.</p>
<p>Spec... | 78 | 2009-11-11T05:54:48Z | 31,493,914 | <p>For those not sure about which peak-finding algorithms to use in Python, here a rapid overview of the alternatives: <a href="https://github.com/MonsieurV/py-findpeaks">https://github.com/MonsieurV/py-findpeaks</a></p>
<p>Wanting myself an equivalent to the MatLab <code>findpeaks</code> function, I've found that the... | 6 | 2015-07-18T17:53:43Z | [
"python",
"scipy",
"fft",
"hough-transform"
] |
Peak-finding algorithm for Python/SciPy | 1,713,335 | <p>I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one?</p>
<p>My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc.</p>
<p>Spec... | 78 | 2009-11-11T05:54:48Z | 37,009,011 | <p>First things first, the definition of "peak" is vague if without further specifications. For example, for the following series, would you call 5-4-5 one peak or two?</p>
<p>1-2-1-2-1-1-5-4-5-1-1-5-1</p>
<p>In this case, you'll need at least two thresholds: 1) a high threshold only above which can an extreme value... | 1 | 2016-05-03T16:02:59Z | [
"python",
"scipy",
"fft",
"hough-transform"
] |
What if one of my programs runs in python 2.4, but IMPORTS something that requires python 2.5? | 1,713,398 | <p>Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5</p>
| 0 | 2009-11-11T06:20:24Z | 1,713,411 | <p>Then it fails.</p>
<p>You can't import a python 2.5 library while you're running python 2.4. It won't work.</p>
<p>Why can't you run python 2.5+?</p>
| 4 | 2009-11-11T06:22:35Z | [
"python",
"linux",
"unix"
] |
What if one of my programs runs in python 2.4, but IMPORTS something that requires python 2.5? | 1,713,398 | <p>Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5</p>
| 0 | 2009-11-11T06:20:24Z | 1,713,440 | <p>Consider upgrading to Python 2.5 (or, dare I say, 2.6!-) one of these decades... <a href="http://www.bobdylan.com/#/songs/times-they-are-changin" rel="nofollow">the times, they are a'changin'</a>! Meanwhile, for ElementTree in particular, you might manage to <a href="http://effbot.org/zone/element-index.htm" rel="n... | 6 | 2009-11-11T06:33:10Z | [
"python",
"linux",
"unix"
] |
What if one of my programs runs in python 2.4, but IMPORTS something that requires python 2.5? | 1,713,398 | <p>Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5</p>
| 0 | 2009-11-11T06:20:24Z | 1,713,609 | <p>This type of problem is not all that unusual, as not everyone has control over the version of Python that they use. A few years ago I had this very problem as most of my work took place on a Windows PC, but at one point we needed to run it on a large UNIX box which was subject to strict change control, meaning that ... | 1 | 2009-11-11T07:29:58Z | [
"python",
"linux",
"unix"
] |
What if one of my programs runs in python 2.4, but IMPORTS something that requires python 2.5? | 1,713,398 | <p>Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5</p>
| 0 | 2009-11-11T06:20:24Z | 1,714,127 | <p>You should be able to install ElementTree for Python 2.4. It is in debian under the package name <code>python2.4-elementtree</code> (and <code>..-celementtree</code>)</p>
<p>If you don't find a package for your OS, <a href="http://effbot.org/zone/element-index.htm#installation" rel="nofollow">you can install it rig... | 2 | 2009-11-11T09:44:39Z | [
"python",
"linux",
"unix"
] |
What if one of my programs runs in python 2.4, but IMPORTS something that requires python 2.5? | 1,713,398 | <p>Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5</p>
| 0 | 2009-11-11T06:20:24Z | 11,389,593 | <p>Now you can install separately the elementtree in Python 2.4, just go here <a href="http://effbot.org/zone/element-index.htm" rel="nofollow">http://effbot.org/zone/element-index.htm</a> and download elementtree. </p>
| 0 | 2012-07-09T05:42:38Z | [
"python",
"linux",
"unix"
] |
how to split a string matching a pattern in python | 1,713,876 | <p>I have string looking like this:</p>
<pre><code>'Toy Story..(II) (1995)'
</code></pre>
<p>I want to split the line into two parts like this:</p>
<pre><code>['Toy Story..(II)','1995']
</code></pre>
<p>How can I do it? Thanks.</p>
| 1 | 2009-11-11T08:46:46Z | 1,713,887 | <p>You could use regular expressions for that. See here: <a href="http://www.amk.ca/python/howto/regex/" rel="nofollow">http://www.amk.ca/python/howto/regex/</a></p>
<p>Or you could use the split function and then manyally remove the parenthesis or other non desired characters. See here: <a href="http://www.python.org... | 0 | 2009-11-11T08:48:55Z | [
"python",
"string",
"split"
] |
how to split a string matching a pattern in python | 1,713,876 | <p>I have string looking like this:</p>
<pre><code>'Toy Story..(II) (1995)'
</code></pre>
<p>I want to split the line into two parts like this:</p>
<pre><code>['Toy Story..(II)','1995']
</code></pre>
<p>How can I do it? Thanks.</p>
| 1 | 2009-11-11T08:46:46Z | 1,713,889 | <pre><code>l[:-1].split("(")
</code></pre>
| 0 | 2009-11-11T08:49:57Z | [
"python",
"string",
"split"
] |
how to split a string matching a pattern in python | 1,713,876 | <p>I have string looking like this:</p>
<pre><code>'Toy Story..(II) (1995)'
</code></pre>
<p>I want to split the line into two parts like this:</p>
<pre><code>['Toy Story..(II)','1995']
</code></pre>
<p>How can I do it? Thanks.</p>
| 1 | 2009-11-11T08:46:46Z | 1,713,896 | <p>This code will get you started:</p>
<pre><code>'Toy Stroy..(II) (1995)'.rstrip(')').rsplit('(',1)
</code></pre>
<p>Other than that, you can use <code>r'\s*[(]\d{4}[)]\s*$'</code> to match a four-digit number in parentheses at the end of the string. If you find it, you can chop it off:</p>
<pre><code>s = ''
l = [s... | 4 | 2009-11-11T08:52:23Z | [
"python",
"string",
"split"
] |
how to split a string matching a pattern in python | 1,713,876 | <p>I have string looking like this:</p>
<pre><code>'Toy Story..(II) (1995)'
</code></pre>
<p>I want to split the line into two parts like this:</p>
<pre><code>['Toy Story..(II)','1995']
</code></pre>
<p>How can I do it? Thanks.</p>
| 1 | 2009-11-11T08:46:46Z | 1,713,906 | <p>One way is this:</p>
<pre><code>s = 'Toy Stroy..(II) (1995)'
print s[:s.rfind('(')].strip()
print s[s.rfind('('):].strip("()")
</code></pre>
<p>Output:</p>
<pre><code>Toy Stroy..(II)
1995
>>>
</code></pre>
| 1 | 2009-11-11T08:56:31Z | [
"python",
"string",
"split"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,090 | <p>No need to iterate over the version tuples. The built in comparison operator on lists and tuples already works exactly like you want it. You'll just need to zero extend the version lists to the corresponding length. With python 2.6 you can use izip_longest to pad the sequences. </p>
<pre><code>from itertools import... | 12 | 2009-11-11T09:34:04Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,132 | <p>This is a little more compact than your suggestion. Rather than filling the shorter version with zeros, I'm removing trailing zeros from the version lists after splitting.</p>
<pre><code>def normalize_version(v):
parts = [int(x) for x in v.split(".")]
while parts[-1] == 0:
parts.pop()
return pa... | 9 | 2009-11-11T09:45:50Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,190 | <p>Remove the uninteresting part of the string (trailing zeroes and dots), and then compare the lists of numbers.</p>
<pre><code>import re
def mycmp(version1, version2):
def normalize(v):
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
return cmp(normalize(version1), normalize(version2))... | 27 | 2009-11-11T09:59:36Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,274 | <p>Remove trailing .0 and .00 with regex, split and use cmp function which compares arrays correctly.</p>
<pre><code>def mycmp(v1,v2):
c1=map(int,re.sub('(\.0+)+\Z','',v1).split('.'))
c2=map(int,re.sub('(\.0+)+\Z','',v2).split('.'))
return cmp(c1,c2)
</code></pre>
<p>and of course you can convert it to a one-liner... | 6 | 2009-11-11T10:17:51Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,276 | <pre><code>def compare_version(v1, v2):
return cmp(*tuple(zip(*map(lambda x, y: (x or 0, y or 0),
[int(x) for x in v1.split('.')], [int(y) for y in v2.split('.')]))))
</code></pre>
<p>It's a one liner (split for legability). Not sure about readable...</p>
| 0 | 2009-11-11T10:18:30Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,378 | <p>Is <em>reuse</em> considered elegance in this instance? :)</p>
<pre><code># pkg_resources is in setuptools
# See http://peak.telecommunity.com/DevCenter/PkgResources#parsing-utilities
def mycmp(a, b):
from pkg_resources import parse_version as V
return cmp(V(a),V(b))
</code></pre>
| 21 | 2009-11-11T10:40:04Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,490 | <p>The most difficult to read solution, but a one-liner nevertheless! and using iterators to be fast.</p>
<pre><code>next((c for c in imap(lambda x,y:cmp(int(x or 0),int(y or 0)),
v1.split('.'),v2.split('.')) if c), 0)
</code></pre>
<p>that is for Python2.6 and 3.+ btw, Python 2.5 and older need to catch ... | 1 | 2009-11-11T11:06:38Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 1,714,536 | <p>My preferred solution:</p>
<p>Padding the string with extra zeroes and just using the four first is easy to understand,
doesn't require any regex and the lambda is more or less readable. I use two lines for readability, for me elegance is short and simple. </p>
<pre><code>def mycmp(version1,version2):
tup = lamb... | -1 | 2009-11-11T11:16:18Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 6,972,866 | <p>How about using Python's <code>distutils.version.StrictVersion</code>?</p>
<pre><code>>>> from distutils.version import StrictVersion
>>> StrictVersion('10.4.10') > StrictVersion('10.4.9')
True
</code></pre>
<p>So for your <code>cmp</code> function:</p>
<pre><code>>>> cmp = lambda x,... | 185 | 2011-08-07T12:38:16Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 8,617,392 | <p>This is my solution (written in C, sorry). I hope you'll find it useful</p>
<pre><code>int compare_versions(const char *s1, const char *s2) {
while(*s1 && *s2) {
if(isdigit(*s1) && isdigit(*s2)) {
/* compare as two decimal integers */
int s1_i = strtol(s1, &s1... | -1 | 2011-12-23T14:54:02Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 11,991,841 | <p>Lists are comparable in python, so if one converts the strings representing the numbers in to integers, the basic python comparison can be used with success. </p>
<p>I however needed to extend a bit this approach, first cause I use python3x where <strong>cmp</strong> function does not exist any-more I had to emulat... | 1 | 2012-08-16T16:43:37Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 12,923,860 | <p>In case you don't want to pull in an external dependency here is an attempt of mine (written for python 3.x). "rc", "rel" (and possibly one could add "c") are regarded as "release candidate" and devide the version number into two parts and if missing the value of the second part is high (999). Else letters produce a... | 2 | 2012-10-16T21:39:58Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 33,622,659 | <pre><code>from distutils.version import StrictVersion
def version_compare(v1, v2, op=None):
_map = {
'<': [-1],
'lt': [-1],
'<=': [-1, 0],
'le': [-1, 0],
'>': [1],
'gt': [1],
'>=': [1, 0],
'ge': [1, 0],
'==': [0],
'eq': [0]... | 2 | 2015-11-10T04:02:19Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 37,422,085 | <p>Another solution:</p>
<pre><code>def mycmp(v1, v2):
import itertools as it
f = lambda v: list(it.dropwhile(lambda x: x == 0, map(int, v.split('.'))[::-1]))[::-1]
return cmp(f(v1), f(v2))
</code></pre>
<p>One can use like this too:</p>
<pre><code>import itertools as it
f = lambda v: list(it.dropwhile(l... | 0 | 2016-05-24T19:18:49Z | [
"python"
] |
Version number comparison | 1,714,027 | <p>Python must have a more elegant solution to this ... maybe one of you can help:</p>
<p>I want to write a <code>cmp</code>-like function returning -1, 0 or 1 for version numbers, allowing for an arbitrary number of subsections. </p>
<p>Each subsection is supposed to be interpreted as a number, therefore 1.10 > 1.1.... | 57 | 2009-11-11T09:21:59Z | 39,595,525 | <p>Did this in order to be able to parse and compare the debian package version string. Please notice that it is not strict with the character validation.</p>
<p>This might be helpful as well.</p>
<pre><code>#!/usr/bin/env python
# Read <https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version&g... | 0 | 2016-09-20T13:30:51Z | [
"python"
] |
Strange behavior with python import | 1,714,111 | <p>So I am trying to import a module "foo" that contains directories "bar" and "wiz". "bar" contains python files a.py, b.py, and c.py. "wiz" contains python files x.py, y.py and z.py.</p>
<pre><code>$ ls foo
__init__.py bar wiz
$ ls foo/bar
__init__.py a.py b.py c.py
$ ls foo/wiz
__init__.py... | 0 | 2009-11-11T09:40:04Z | 1,714,149 | <p>You haven't imported "z" (x was probably imported in some other module):</p>
<pre><code>Python 2.4.3 (#1, Jan 14 2008, 18:31:21)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> foo.wiz
Traceback (most recen... | 1 | 2009-11-11T09:50:14Z | [
"python",
"import",
"module"
] |
Strange behavior with python import | 1,714,111 | <p>So I am trying to import a module "foo" that contains directories "bar" and "wiz". "bar" contains python files a.py, b.py, and c.py. "wiz" contains python files x.py, y.py and z.py.</p>
<pre><code>$ ls foo
__init__.py bar wiz
$ ls foo/bar
__init__.py a.py b.py c.py
$ ls foo/wiz
__init__.py... | 0 | 2009-11-11T09:40:04Z | 1,714,193 | <p>When importing <code>foo</code>, Python will just load <code>foo/__init__.py</code>, it will not (automatically) load <code>foo.bar</code> or <code>foo.wiz</code>. Therefore, trying to access those without explicitely importing them will raise a <code>AttributeError</code>.</p>
<p>If some module imports sub-modules... | 2 | 2009-11-11T10:01:11Z | [
"python",
"import",
"module"
] |
Supervisord RPC - UNKNOWN_METHOD on any request | 1,714,174 | <p>I've configured (almost default) supervisord.conf and started supervisord. Tasks launched and xmlrpc interfaces are up, but gives
<code>xmlrpclib.Fault: <Fault 1: 'UNKNOWN_METHOD'></code> on evey xmlrpc request, even when launching supervisorctl itself.</p>
<p>There is a same message in the log:</p>
<pre><co... | 2 | 2009-11-11T09:57:11Z | 1,718,041 | <p>I suspect you removed these lines from the supervisord.conf config file:</p>
<pre><code>; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rp... | 5 | 2009-11-11T21:01:44Z | [
"python",
"xml-rpc",
"supervisord"
] |
Strange error in google app engine | 1,714,200 | <p>I would like to mention before hand that I am a novice to python and with that to python platform of GAE. I have been finding this very strange error/fault when I am trying to get an entity using its key ID...
Here's what I do,</p>
<p>I am querying the datastore entity model UserDetails for the key corresponding to... | 0 | 2009-11-11T10:01:39Z | 1,714,401 | <p>You're getting this error because 'accounts' is a list rather than a single instance. Based on your code, I can't see why this would be the case, but try doing the following:</p>
<pre><code>src_key = db.GqlQuery('SELECT __key__ FROM UserDetails WHERE user_name = :uname', uname = src_username).get()
if src_key:
ac... | 1 | 2009-11-11T10:44:44Z | [
"python",
"google-app-engine"
] |
Can't use a data obj with timeit.Time module in python | 1,714,352 | <p>I'm trying to measure how long it takes read then encrypt some data (independently). But I can't seem to access the a pre-created data obj within timeit (as it runs in its own virtual environment)</p>
<p>This works fine (timing file read operation):</p>
<pre><code>t = timeit.Timer("""
openFile = open('mytestfile.b... | 1 | 2009-11-11T10:35:53Z | 1,714,429 | <p><a href="http://docs.python.org/library/timeit.html#timeit.Timer" rel="nofollow">timeit</a> takes a setup argument that only runs once</p>
<p>from the docs:</p>
<blockquote>
<p>setup: statement to be executed once
initially (default 'pass')</p>
</blockquote>
<p>for example:</p>
<pre><code>setup = """
from Cr... | 1 | 2009-11-11T10:51:27Z | [
"python",
"performance",
"timeit"
] |
Can't use a data obj with timeit.Time module in python | 1,714,352 | <p>I'm trying to measure how long it takes read then encrypt some data (independently). But I can't seem to access the a pre-created data obj within timeit (as it runs in its own virtual environment)</p>
<p>This works fine (timing file read operation):</p>
<pre><code>t = timeit.Timer("""
openFile = open('mytestfile.b... | 1 | 2009-11-11T10:35:53Z | 1,714,462 | <p>you can use the <code>setup</code> parameter of the <code>timeit.Timer</code> class like so:</p>
<pre><code>tt = timeit.Timer("""
from Crypto.Cipher import AES
import os
newFile = []
key = os.urandom(32)
cipher = AES.new(key, AES.MODE_CFB)
for lines in fileData:
newFile = cipher.encrypt(lines)""",
setup = "fileD... | 0 | 2009-11-11T10:59:00Z | [
"python",
"performance",
"timeit"
] |
Check String for / against Characters in Python | 1,714,569 | <p>I need to be able to tell the <em>difference</em> between a string that can contain <strong>letters and numbers</strong>, and a string that can contain <strong>numbers, colons and hyphens</strong>.</p>
<pre><code>>>> def checkString(s):
... pattern = r'[-:0-9]'
... if re.search(pattern,s):
... prin... | 1 | 2009-11-11T11:24:30Z | 1,714,598 | <pre><code>pattern = r'\A([^-:0-9]+|[A-Za-z0-9])\Z'
</code></pre>
| 0 | 2009-11-11T11:28:14Z | [
"python",
"regex"
] |
Check String for / against Characters in Python | 1,714,569 | <p>I need to be able to tell the <em>difference</em> between a string that can contain <strong>letters and numbers</strong>, and a string that can contain <strong>numbers, colons and hyphens</strong>.</p>
<pre><code>>>> def checkString(s):
... pattern = r'[-:0-9]'
... if re.search(pattern,s):
... prin... | 1 | 2009-11-11T11:24:30Z | 1,714,601 | <p>you need to match the whole string, not a single character as you do at the moment:</p>
<pre><code>>>> re.search('^[-:0-9]+$', "12:24:-14")
<_sre.SRE_Match object at 0x01013758>
>>> re.search('^[-:0-9]+$', "hello")
>>> re.search('^[-:0-9]+$', "hello2")
</code></pre>
<p>To explain r... | 5 | 2009-11-11T11:28:24Z | [
"python",
"regex"
] |
Check String for / against Characters in Python | 1,714,569 | <p>I need to be able to tell the <em>difference</em> between a string that can contain <strong>letters and numbers</strong>, and a string that can contain <strong>numbers, colons and hyphens</strong>.</p>
<pre><code>>>> def checkString(s):
... pattern = r'[-:0-9]'
... if re.search(pattern,s):
... prin... | 1 | 2009-11-11T11:24:30Z | 1,714,793 | <p>Your regular expression is almost fine; you just need to make it match the whole string. Also, as a commenter pointed out, you don't really need a raw string (the <code>r</code> prefix on the string) in this case. Voila:</p>
<pre><code>def checkString(s):
if re.match('[-:0-9]+$', s):
print "Matches pattern.... | 0 | 2009-11-11T12:08:41Z | [
"python",
"regex"
] |
Check String for / against Characters in Python | 1,714,569 | <p>I need to be able to tell the <em>difference</em> between a string that can contain <strong>letters and numbers</strong>, and a string that can contain <strong>numbers, colons and hyphens</strong>.</p>
<pre><code>>>> def checkString(s):
... pattern = r'[-:0-9]'
... if re.search(pattern,s):
... prin... | 1 | 2009-11-11T11:24:30Z | 1,714,819 | <p>SilentGhost's answer is pretty good, but take note that it would also match strings like <code>"---::::"</code> with no digits at all.</p>
<p>I think you're looking for something like this:</p>
<pre><code>'^(-?\d+:)*-?\d+$'
</code></pre>
<ul>
<li><code>^</code> Matches the beginning of the line.</li>
<li><code>(-... | 1 | 2009-11-11T12:14:55Z | [
"python",
"regex"
] |
Is there any library to deserialize with python which is serialized with java | 1,714,624 | <p>Is there any library to deserialize with python which is serialized with java?</p>
| 7 | 2009-11-11T11:33:19Z | 1,714,638 | <p>Java serialisation is a representation of the class/data structures and tightly tied to the virtual machine. Consequently that's going to be difficult to translate to the Python world.</p>
<ol>
<li>Your Java program can serialise/deserialise in XML, which would be translatable. Check out <a href="http://java.sun.co... | 5 | 2009-11-11T11:36:10Z | [
"java",
"python",
"serialization"
] |
Is there any library to deserialize with python which is serialized with java | 1,714,624 | <p>Is there any library to deserialize with python which is serialized with java?</p>
| 7 | 2009-11-11T11:33:19Z | 1,714,644 | <p>Java binary serialization is really designed to be used with Java. To do it in Python you'd have to have all the relevant Java classes available for inspection, and create Python objects appropriately - it would be pretty hideous and fragile.</p>
<p>You're better off using a cross-platform serialization format such... | 4 | 2009-11-11T11:37:07Z | [
"java",
"python",
"serialization"
] |
Is there any library to deserialize with python which is serialized with java | 1,714,624 | <p>Is there any library to deserialize with python which is serialized with java?</p>
| 7 | 2009-11-11T11:33:19Z | 1,714,693 | <p>If I were you, I'd read the data with <a href="http://www.jython.org/" rel="nofollow">Jython</a>, and either reserialize it with <code>pickle</code> ( so that you can read it from Python ), or in a language neutral format, like XML.</p>
| 0 | 2009-11-11T11:47:35Z | [
"java",
"python",
"serialization"
] |
Is there any library to deserialize with python which is serialized with java | 1,714,624 | <p>Is there any library to deserialize with python which is serialized with java?</p>
| 7 | 2009-11-11T11:33:19Z | 1,714,862 | <p>If you are using Java classes, then I don't even know what it would mean to deserialize a Java class in a Python environment. If you are only using simple primitives (ints, floats, strings), then it probably wouldn't be too hard to build a Python library that could deserialize the Java format.</p>
<p>But as others... | 0 | 2009-11-11T12:23:58Z | [
"java",
"python",
"serialization"
] |
Is there any library to deserialize with python which is serialized with java | 1,714,624 | <p>Is there any library to deserialize with python which is serialized with java?</p>
| 7 | 2009-11-11T11:33:19Z | 1,714,957 | <p>You don't say whether you have control over the serialization of the data or not, but if you do, <a href="http://json.org/" rel="nofollow">JSON</a> seems to be a nice format which is cross platform and has a good balance between human readable and machine readable. <a href="http://json.org/java/" rel="nofollow">For... | 1 | 2009-11-11T12:41:50Z | [
"java",
"python",
"serialization"
] |
Is there any library to deserialize with python which is serialized with java | 1,714,624 | <p>Is there any library to deserialize with python which is serialized with java?</p>
| 7 | 2009-11-11T11:33:19Z | 1,716,180 | <p>An other option is to use <a href="http://twistedmatrix.com/projects/core/documentation/howto/pb-intro.html" rel="nofollow">Perspective Broker</a> from <a href="http://twistedmatrix.com/trac/" rel="nofollow">Twisted</a>. Their's a <a href="http://itamarst.org/software/twistedjava/" rel="nofollow">Java implementation... | -1 | 2009-11-11T16:04:17Z | [
"java",
"python",
"serialization"
] |
Is there any library to deserialize with python which is serialized with java | 1,714,624 | <p>Is there any library to deserialize with python which is serialized with java?</p>
| 7 | 2009-11-11T11:33:19Z | 16,470,856 | <p>Here's a very, very, rough implementation that doesn't require any imports. The tricky thing here is some classes have custom serializers which require the original code to deserialize. Also, my particular file was gzip'd though I didn't include code for that. I used these two pages for reference:</p>
<p><a href="h... | 6 | 2013-05-09T20:48:37Z | [
"java",
"python",
"serialization"
] |
Python code comments | 1,714,633 | <p>In C# and through Visual Studio, it is possible to comment your functions, so you can tell whoever is using your class what the input arguments should be, what it is supposed to return, etc. Is there anything remotely similar in python?</p>
| 2 | 2009-11-11T11:34:58Z | 1,714,637 | <p>In Python you use <a href="http://www.python.org/dev/peps/pep-0257/" rel="nofollow">docstrings</a> like this:</p>
<pre><code>def foo():
""" Here is the docstring """
</code></pre>
<p>Basically you need to have a triple quoted string be on the first line of a function, class, or module to be considered a docstr... | 9 | 2009-11-11T11:36:09Z | [
"python"
] |
Python code comments | 1,714,633 | <p>In C# and through Visual Studio, it is possible to comment your functions, so you can tell whoever is using your class what the input arguments should be, what it is supposed to return, etc. Is there anything remotely similar in python?</p>
| 2 | 2009-11-11T11:34:58Z | 1,714,643 | <p>Just put a string anywhere you like. If there is a string as the first thing in a method, Python will put it in the special field <code>__doc__</code>:</p>
<pre><code>def f():
"""This is the documentation"""
pass
"""But you can have as many comments as you like."""
print f.__doc__
</code></pre>
| 2 | 2009-11-11T11:37:05Z | [
"python"
] |
Python code comments | 1,714,633 | <p>In C# and through Visual Studio, it is possible to comment your functions, so you can tell whoever is using your class what the input arguments should be, what it is supposed to return, etc. Is there anything remotely similar in python?</p>
| 2 | 2009-11-11T11:34:58Z | 1,714,715 | <p>As mentioned in other answers, a string at the very top of the function serves as documentation, like this:</p>
<pre><code>>>> def fact(n):
... """Calculate the factorial of a number.
...
... Return the factorial for any non-negative integer.
... It is the responsibility of the caller not to p... | 5 | 2009-11-11T11:50:59Z | [
"python"
] |
Python code comments | 1,714,633 | <p>In C# and through Visual Studio, it is possible to comment your functions, so you can tell whoever is using your class what the input arguments should be, what it is supposed to return, etc. Is there anything remotely similar in python?</p>
| 2 | 2009-11-11T11:34:58Z | 1,714,794 | <p>I think what you are getting at is that C# has a strong cultural convention for the formatting of code comments, and Visual Studio provides tools that collect those comments together, format them according to agreed markup, and so on. Java is similar, with its Javadoc.</p>
<p>Python has some conventions like this,... | 7 | 2009-11-11T12:09:08Z | [
"python"
] |
How to wrap built-in methods in Python? (or 'how to pass them by reference') | 1,714,725 | <p>I want to wrap the default open method with a wrapper that should also catch exceptions. Here's a test example that <strong>works</strong>:</p>
<pre><code>truemethod = open
def fn(*args, **kwargs):
try:
return truemethod(*args, **kwargs)
except (IOError, OSError):
sys.exit('Can\'t open \'{0}... | 3 | 2009-11-11T11:54:18Z | 1,714,750 | <p>Try adding <code>global open</code>. In the general case, you might want to look at <a href="http://docs.python.org/library/%5F%5Fbuiltin%5F%5F.html" rel="nofollow">this section of the manual</a>:</p>
<blockquote>
<p>This module provides direct access to all âbuilt-inâ identifiers of Python; for example, <co... | 2 | 2009-11-11T11:58:07Z | [
"python",
"exception-handling",
"wrapper"
] |
How to wrap built-in methods in Python? (or 'how to pass them by reference') | 1,714,725 | <p>I want to wrap the default open method with a wrapper that should also catch exceptions. Here's a test example that <strong>works</strong>:</p>
<pre><code>truemethod = open
def fn(*args, **kwargs):
try:
return truemethod(*args, **kwargs)
except (IOError, OSError):
sys.exit('Can\'t open \'{0}... | 3 | 2009-11-11T11:54:18Z | 1,714,775 | <p>you can just add <code>return fn</code> at the end of your <code>wrap</code> function and then do:</p>
<pre><code>>>> open = wrap(open)
>>> open('bhla')
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
open('bhla')
File "<pyshell#18>", line 7, i... | 1 | 2009-11-11T12:04:36Z | [
"python",
"exception-handling",
"wrapper"
] |
How to wrap built-in methods in Python? (or 'how to pass them by reference') | 1,714,725 | <p>I want to wrap the default open method with a wrapper that should also catch exceptions. Here's a test example that <strong>works</strong>:</p>
<pre><code>truemethod = open
def fn(*args, **kwargs):
try:
return truemethod(*args, **kwargs)
except (IOError, OSError):
sys.exit('Can\'t open \'{0}... | 3 | 2009-11-11T11:54:18Z | 1,714,779 | <p>The problem with your code is that inside <code>wrap</code>, your <code>method = fn</code> statement is simply changing the local value of <code>method</code>, it isn't changing the larger value of <code>open</code>. You'll have to assign to those names yourself:</p>
<pre><code>def wrap(method, exceptions = (OSErr... | 3 | 2009-11-11T12:05:04Z | [
"python",
"exception-handling",
"wrapper"
] |
Inline editing of ManyToMany relation in Django | 1,714,995 | <p>After working through the Django tutorial I'm now trying to build a very simple invoicing application.</p>
<p>I want to add several Products to an Invoice, and to specify the quantity of each product in the Invoice form in the Django admin. Now I've to create a new Product object if I've got different quantites of ... | 4 | 2009-11-11T12:49:49Z | 1,715,204 | <p>You need to change your model structure a bit. As you recognise, the quantity doesn't belong on the Product model - it belongs on the <em>relationship</em> between Product and Invoice. </p>
<p>To do this in Django, you can use a <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to... | 9 | 2009-11-11T13:37:59Z | [
"python",
"django",
"django-admin",
"inline-editing"
] |
Couple of questions regarding PyQt | 1,715,098 | <p>I have a couple of questions.</p>
<p>I have an algorithm that will generate a couple of pictures in python that must be displayed on a form. I am using PyGt for this. My question is: where should I run my code? Right from the initializer? In that case from what I tested, the form won't show up. </p>
<ul>
<li>Shoul... | 1 | 2009-11-11T13:12:26Z | 1,715,113 | <p>You can run the algorithm in a separate thread, placing the data into a Queue when finished. The main thread (GUI) will periodically sample the queue and display the data when it arrives.</p>
| 1 | 2009-11-11T13:16:06Z | [
"python",
"pyqt",
"pyqt4"
] |
Couple of questions regarding PyQt | 1,715,098 | <p>I have a couple of questions.</p>
<p>I have an algorithm that will generate a couple of pictures in python that must be displayed on a form. I am using PyGt for this. My question is: where should I run my code? Right from the initializer? In that case from what I tested, the form won't show up. </p>
<ul>
<li>Shoul... | 1 | 2009-11-11T13:12:26Z | 1,715,135 | <p>You might want to check the <a href="http://doc.trolltech.com/4.5/threads-mandelbrot.html" rel="nofollow">Mandelbrot example</a>.</p>
<p>Basically the idea is to use a worker thread to do the heavy computations (I'd suggest a QThread to ease the communication to the main thread by using signals/slots), then once th... | 4 | 2009-11-11T13:20:39Z | [
"python",
"pyqt",
"pyqt4"
] |
Exception message (Python 2.6) | 1,715,198 | <p>In Python, if I open a binary file that doesn't exist, the program exits with an error and prints:</p>
<pre><code>Traceback (most recent call last):
File "C:\Python_tests\Exception_Handling\src\exception_handling.py",
line 4, in <module>
pkl_file = open('monitor.dat', 'rb')
IOError: [Errno 2] No such... | 29 | 2009-11-11T13:35:37Z | 1,715,206 | <p>This prints the exception message:</p>
<pre><code>except Exception, e:
print "Couldn't do it: %s" % e
</code></pre>
<p>This will show the whole traceback:</p>
<pre><code>import traceback
# ...
except Exception, e:
traceback.print_exc()
</code></pre>
<p>But you might not want to catch Exception. The na... | 81 | 2009-11-11T13:38:16Z | [
"python",
"exception-handling",
"message"
] |
Exception message (Python 2.6) | 1,715,198 | <p>In Python, if I open a binary file that doesn't exist, the program exits with an error and prints:</p>
<pre><code>Traceback (most recent call last):
File "C:\Python_tests\Exception_Handling\src\exception_handling.py",
line 4, in <module>
pkl_file = open('monitor.dat', 'rb')
IOError: [Errno 2] No such... | 29 | 2009-11-11T13:35:37Z | 1,715,222 | <p>Python has the <a href="http://docs.python.org/library/traceback.html">traceback</a> module.</p>
<pre><code>import traceback
try:
pkl_file = open('monitor.dat', 'rb')
monitoring_pickle = pickle.load(pkl_file)
pkl_file.close()
except IOError:
traceback.print_exc()
</code></pre>
| 9 | 2009-11-11T13:39:48Z | [
"python",
"exception-handling",
"message"
] |
Exception message (Python 2.6) | 1,715,198 | <p>In Python, if I open a binary file that doesn't exist, the program exits with an error and prints:</p>
<pre><code>Traceback (most recent call last):
File "C:\Python_tests\Exception_Handling\src\exception_handling.py",
line 4, in <module>
pkl_file = open('monitor.dat', 'rb')
IOError: [Errno 2] No such... | 29 | 2009-11-11T13:35:37Z | 1,715,326 | <p>Thanks for all.</p>
<p>That's, what I needed :)</p>
<pre><code>import traceback
try:
# boom
except Exception:
print traceback.format_exc()
</code></pre>
| 4 | 2009-11-11T13:57:15Z | [
"python",
"exception-handling",
"message"
] |
Exception message (Python 2.6) | 1,715,198 | <p>In Python, if I open a binary file that doesn't exist, the program exits with an error and prints:</p>
<pre><code>Traceback (most recent call last):
File "C:\Python_tests\Exception_Handling\src\exception_handling.py",
line 4, in <module>
pkl_file = open('monitor.dat', 'rb')
IOError: [Errno 2] No such... | 29 | 2009-11-11T13:35:37Z | 1,715,424 | <p>If you want to capture the exception object passed by the Exception, it's best to start using the NEW format introduced in Python 2.6 (which currently supports both) because it will be the only way to do it into Python 3.</p>
<p>And that is:</p>
<pre><code>try:
...
except IOError as e:
...
</code></pre>
<... | 20 | 2009-11-11T14:15:49Z | [
"python",
"exception-handling",
"message"
] |
TypeError when trying to upload Pictures from Google App Engine to Picasa with the GData API | 1,715,574 | <p>I'm trying to write a small tool to upload Pictures from Google App Engine to Picasa. Fetching the image works, but when i try to upload it i get the error "<em>TypeError: stat() argument 1 must be (encoded string without NULL bytes), not str</em>" </p>
<p>The Code basically looks like this:</p>
<pre><code>def get... | 2 | 2009-11-11T14:38:24Z | 1,725,028 | <p>The Solution to this problem was using StringIO :-)</p>
<p>( <a href="http://docs.python.org/library/stringio.html">http://docs.python.org/library/stringio.html</a> )</p>
<p>adding</p>
<pre><code>pic = StringIO.StringIO(pic)
</code></pre>
<p>converts the result.content from urlfetch into a file-like format gdata... | 5 | 2009-11-12T20:07:55Z | [
"python",
"google-app-engine",
"gdata-api",
"typeerror",
"picasa"
] |
Best way to decode unknown unicoding encoding in Python 2.5 | 1,715,772 | <p>Have I got that all the right way round? Anyway, I am parsing a lot of html, but I don't always know what encoding it's meant to be (a surprising number lie about it). The code below easily shows what I've been doing so far, but I'm sure there's a better way. Your suggestions would be much appreciated.</p>
<pre><co... | 3 | 2009-11-11T15:06:57Z | 1,715,827 | <p>Since you are using Python, you might try <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Beautiful%20Soup%20Gives%20You%20Unicode,%20Dammit" rel="nofollow"><code>UnicodeDammit</code></a>. It is part of <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>... | 1 | 2009-11-11T15:14:26Z | [
"python",
"html",
"unicode",
"encoding",
"character-encoding"
] |
Best way to decode unknown unicoding encoding in Python 2.5 | 1,715,772 | <p>Have I got that all the right way round? Anyway, I am parsing a lot of html, but I don't always know what encoding it's meant to be (a surprising number lie about it). The code below easily shows what I've been doing so far, but I'm sure there's a better way. Your suggestions would be much appreciated.</p>
<pre><co... | 3 | 2009-11-11T15:06:57Z | 1,715,833 | <p>I've tackled the same problem and found that there's no way to determine a content's encoding type without metadata about the content. That's why I ended up with the same approach you're trying here.</p>
<p>My only additional advice to what you've done is, rather than ordering the list of possible encoding in most-... | 2 | 2009-11-11T15:15:17Z | [
"python",
"html",
"unicode",
"encoding",
"character-encoding"
] |
Best way to decode unknown unicoding encoding in Python 2.5 | 1,715,772 | <p>Have I got that all the right way round? Anyway, I am parsing a lot of html, but I don't always know what encoding it's meant to be (a surprising number lie about it). The code below easily shows what I've been doing so far, but I'm sure there's a better way. Your suggestions would be much appreciated.</p>
<pre><co... | 3 | 2009-11-11T15:06:57Z | 1,715,913 | <p>There are two general purpose libraries for detecting unknown encodings:</p>
<ul>
<li>chardet, part of <a href="http://feedparser.org">Universal Feed Parser</a></li>
<li>UnicodeDammit, part of <a href="http://www.crummy.com/software/BeautifulSoup/">Beautiful Soup</a></li>
</ul>
<p>chardet is supposed to be a port ... | 8 | 2009-11-11T15:25:52Z | [
"python",
"html",
"unicode",
"encoding",
"character-encoding"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.