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 |
|---|---|---|---|---|---|---|---|---|---|
Is there an API for Aardvark? | 2,441,803 | <p>Is there an API for Aardvark (http://vark.com)? How can I programmatically ask questions and get answers?</p>
| 2 | 2010-03-14T10:15:31Z | 2,446,436 | <p>Since their website do not seems to provide an API, you'll have to rely upon the old, brutal and nevertheless efficient (as long as the site do not change) html scanning of pages.</p>
<p>Using java platform, i would suggest you to use Groovy goodness, like <a href="http://groovy.codehaus.org/Reading+XML+using+Groov... | 1 | 2010-03-15T10:39:15Z | [
"java",
"php",
"python"
] |
GetAuthSubToken returns None | 2,441,813 | <p>Hey guys, I am a little lost on how to get the auth token. Here is the code I am using on the return from authorizing my app:</p>
<pre><code>client = gdata.service.GDataService()
gdata.alt.appengine.run_on_appengine(client)
sessionToken = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
client.UpgradeT... | 0 | 2010-03-14T10:20:48Z | 2,452,203 | <p>To answer my own question:</p>
<p>When you get the Token just call:</p>
<pre><code>client.token_store.add_token(sessionToken)
</code></pre>
<p>and App Engine will store it in a new entity type for you. Then when making calls to the calendar service just dont set the authsubtoken as it will take care of that for ... | 0 | 2010-03-16T04:55:11Z | [
"python",
"google-app-engine",
"gdata-api",
"gdata"
] |
matplotlib: how to refresh figure.canvas | 2,441,906 | <p>I can't understand how to refresh FigureCanvasWxAgg instance. Here is the example:</p>
<pre><code>
import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame._... | 10 | 2010-03-14T11:00:53Z | 2,463,844 | <p>As I said in the comments, I don't think that the figure canvas refresh is your problem, in fact I think it's doing exactly what it's supposed to (redrawing itself based on it's last state [ie as it was in your subplot]). I think your problem is more that the wxFrame is not refreshing.</p>
<p>The easiest way to fi... | 7 | 2010-03-17T16:05:58Z | [
"python",
"wxpython",
"matplotlib"
] |
How to find out the exact RSS XML path of a website? | 2,441,954 | <p>How do I get the exact feed.xml/rss.xml/atom.xml path of a website?</p>
<p>For example, I supplied "http://www.example.com/news/today/this_is_a_news", but the rss is pointing to "http://www.example.com/rss/feed.xml", most modern browsers have this features already and I'm curious how did they get them.</p>
<p>Can ... | 0 | 2010-03-14T11:20:43Z | 2,444,277 | <p>Something like this in Ruby will work...</p>
<pre>
require 'rubygems'
require 'nokogiri'
require 'open-uri'
html = Nokogiri::HTML(open('http://stackoverflow.com/questions/2441954/how-to-find-out-the-exact-rss-xml-path-of-a-website'))
puts html.css('link[type="application/atom+xml"]').first.attr('href')
# => "/fee... | 2 | 2010-03-14T23:28:41Z | [
"python",
"xml",
"ruby",
"bash",
"rss"
] |
How to find out the exact RSS XML path of a website? | 2,441,954 | <p>How do I get the exact feed.xml/rss.xml/atom.xml path of a website?</p>
<p>For example, I supplied "http://www.example.com/news/today/this_is_a_news", but the rss is pointing to "http://www.example.com/rss/feed.xml", most modern browsers have this features already and I'm curious how did they get them.</p>
<p>Can ... | 0 | 2010-03-14T11:20:43Z | 5,330,681 | <p>You may also use a command line tool like xmlstarlet (together with HTML tidy):</p>
<pre><code># version 1
curl -s http://stackoverflow.com/questions/2441954/how-to-find-out-the-exact-rss-xml-path-of-a-website |
tidy -q -c -wrap 0 -numeric -asxml -utf8 --merge-divs yes --merge-spans yes 2>/dev/null |
xmlstarlet... | 1 | 2011-03-16T19:27:36Z | [
"python",
"xml",
"ruby",
"bash",
"rss"
] |
How to find out the exact RSS XML path of a website? | 2,441,954 | <p>How do I get the exact feed.xml/rss.xml/atom.xml path of a website?</p>
<p>For example, I supplied "http://www.example.com/news/today/this_is_a_news", but the rss is pointing to "http://www.example.com/rss/feed.xml", most modern browsers have this features already and I'm curious how did they get them.</p>
<p>Can ... | 0 | 2010-03-14T11:20:43Z | 19,213,178 | <p>In python use this classic solution: <a href="http://www.aaronsw.com/2002/feedfinder/" rel="nofollow">http://www.aaronsw.com/2002/feedfinder/</a></p>
| 0 | 2013-10-06T19:47:53Z | [
"python",
"xml",
"ruby",
"bash",
"rss"
] |
Accessing Class Variables from a List in a nice way in Python | 2,442,000 | <p>Suppose I have a list X = [a, b, c] where a, b, c are instances of the same class C.
Now, all these instances a,b,c, have a variable called v, a.v, b.v, c.v ...
I simply want a list Y = [a.v, b.v, c.v]</p>
<p>Is there a nice command to do this?
The best way I can think of is:</p>
<pre><code>Y = []
for i i... | 1 | 2010-03-14T11:35:22Z | 2,442,013 | <p>That should work:</p>
<pre><code>Y = [x.v for x in X]
</code></pre>
| 11 | 2010-03-14T11:38:18Z | [
"python",
"class",
"list",
"map",
"methods"
] |
Accessing Class Variables from a List in a nice way in Python | 2,442,000 | <p>Suppose I have a list X = [a, b, c] where a, b, c are instances of the same class C.
Now, all these instances a,b,c, have a variable called v, a.v, b.v, c.v ...
I simply want a list Y = [a.v, b.v, c.v]</p>
<p>Is there a nice command to do this?
The best way I can think of is:</p>
<pre><code>Y = []
for i i... | 1 | 2010-03-14T11:35:22Z | 2,442,016 | <p>I would do a list comprehension:</p>
<pre><code>Y = [ i.v for i in X ]
</code></pre>
<p>It is shorter and more conveniant.</p>
| 2 | 2010-03-14T11:39:34Z | [
"python",
"class",
"list",
"map",
"methods"
] |
Accessing Class Variables from a List in a nice way in Python | 2,442,000 | <p>Suppose I have a list X = [a, b, c] where a, b, c are instances of the same class C.
Now, all these instances a,b,c, have a variable called v, a.v, b.v, c.v ...
I simply want a list Y = [a.v, b.v, c.v]</p>
<p>Is there a nice command to do this?
The best way I can think of is:</p>
<pre><code>Y = []
for i i... | 1 | 2010-03-14T11:35:22Z | 2,442,060 | <p>The list comprehension is the way to go. </p>
<p>But you also said you don't know how to use map to do it. Now, I would not <em>recommend</em> to use <code>map</code> for this at all, but it can be done:</p>
<pre><code>map( lambda x: x.v, X)
</code></pre>
<p>that is, you create an anonymous function (a lambda) to... | 5 | 2010-03-14T11:57:28Z | [
"python",
"class",
"list",
"map",
"methods"
] |
Python, SWIG and other strange things | 2,442,042 | <p>I have a firmware for an USB module I can already control by visual C. Now I want to port this to python. for this I need the octopus library which is written in c. I found a file called octopus_wrap which was created by SWIG!</p>
<p>then I found a makefile which says:</p>
<blockquote>
<p>python2.5:
swig ... | 1 | 2010-03-14T11:46:37Z | 2,442,094 | <p>You should link and compile for the python2.6 <strong>-lpython26</strong>.
Also the file extension for windows is .pyd no .so</p>
| 0 | 2010-03-14T12:13:48Z | [
"python",
"usb",
"wrapper",
"swig"
] |
how to search for file's has a known file extension like .py? | 2,442,243 | <p>how to search for file's has a known file extension like .py ??</p>
<pre><code>fext = raw_input("Put file extension to search: ")
dir = raw_input("Dir to search in: ")
##Search for the file and get the right one's
</code></pre>
| 1 | 2010-03-14T13:19:10Z | 2,442,270 | <p>I believe you want to do something like similar to this: <code>/dir/to/search/*.extension</code>?</p>
<p>This is called glob and here is how to use it:</p>
<pre><code>import glob
files = glob.glob('/path/*.extension')
</code></pre>
<p>Edit: and here is the documentation: <a href="http://docs.python.org/library/gl... | 4 | 2010-03-14T13:24:44Z | [
"python",
"file",
"search"
] |
how to search for file's has a known file extension like .py? | 2,442,243 | <p>how to search for file's has a known file extension like .py ??</p>
<pre><code>fext = raw_input("Put file extension to search: ")
dir = raw_input("Dir to search in: ")
##Search for the file and get the right one's
</code></pre>
| 1 | 2010-03-14T13:19:10Z | 2,442,279 | <p>Non-recursive:</p>
<pre><code>for x in os.listdir(dir):
if x.endswith(fext):
filename = os.path.join(dir, x)
# do your stuff here
</code></pre>
| 0 | 2010-03-14T13:25:57Z | [
"python",
"file",
"search"
] |
how to search for file's has a known file extension like .py? | 2,442,243 | <p>how to search for file's has a known file extension like .py ??</p>
<pre><code>fext = raw_input("Put file extension to search: ")
dir = raw_input("Dir to search in: ")
##Search for the file and get the right one's
</code></pre>
| 1 | 2010-03-14T13:19:10Z | 2,442,320 | <pre><code>import os
root="/home"
ext = raw_input("Put file extension to search: ")
path = raw_input("Dir to search in: ")
for r,d,f in os.walk(path):
for files in f:
if files.endswith(ext):
print "found: ",os.path.join(r,files)
</code></pre>
| 1 | 2010-03-14T13:39:30Z | [
"python",
"file",
"search"
] |
how to search for file's has a known file extension like .py? | 2,442,243 | <p>how to search for file's has a known file extension like .py ??</p>
<pre><code>fext = raw_input("Put file extension to search: ")
dir = raw_input("Dir to search in: ")
##Search for the file and get the right one's
</code></pre>
| 1 | 2010-03-14T13:19:10Z | 2,442,560 | <p>You can write is as simple as:</p>
<pre><code>import os
ext = raw_input("Put file extension to search: ")
path = raw_input("Dir to search in: ")
matching_files = [os.path.join(path, x) for x in os.listdir(path) if x.endswith(ext)]
</code></pre>
| -1 | 2010-03-14T15:06:47Z | [
"python",
"file",
"search"
] |
Python: Removing tuples from a list of lists | 2,442,580 | <p>I have a list of lists containing tuples:</p>
<pre><code>[[(1L,)], [(2L,)], [(3L,)], [(4L,)], [(5L,)]
</code></pre>
<p>how do i edit the list so the list looks like:</p>
<pre><code>l = [[1][2][3][4][5]]
</code></pre>
| 1 | 2010-03-14T15:13:33Z | 2,442,589 | <pre><code>>>> a
[[(1L,)], [(2L,)], [(3L,)], [(4L,)], [(5L,)]]
>>> a = [[x[0][0]] for x in a]
>>> a
[[1L], [2L], [3L], [4L], [5L]]
</code></pre>
| 6 | 2010-03-14T15:15:51Z | [
"python",
"list",
"tuples"
] |
How to delete an element from a list while iterating it in Python? | 2,442,651 | <p>Suppose I have a list of numbers:</p>
<pre><code>L = [1, 2, 3, 4, 5]
</code></pre>
<p>How do I delete an element, let's say 3, from the list while I iterate it?</p>
<p>I tried the following code but it didn't do it:</p>
<pre><code>for el in L:
if el == 3:
del el
</code></pre>
<p>Any ideas?</p>
<p>Thanks,... | 2 | 2010-03-14T15:36:38Z | 2,442,655 | <p>Best is usually to proceed constructively -- build the new list of the items you want instead of removing those you don't. E.g.:</p>
<pre><code>L[:] = [el for el in L if el != 3]
</code></pre>
<p>the list comprehension builds the desired list and the assignment to the "whole-list slice", <code>L[:]</code>, ensure... | 11 | 2010-03-14T15:37:48Z | [
"python"
] |
How to delete an element from a list while iterating it in Python? | 2,442,651 | <p>Suppose I have a list of numbers:</p>
<pre><code>L = [1, 2, 3, 4, 5]
</code></pre>
<p>How do I delete an element, let's say 3, from the list while I iterate it?</p>
<p>I tried the following code but it didn't do it:</p>
<pre><code>for el in L:
if el == 3:
del el
</code></pre>
<p>Any ideas?</p>
<p>Thanks,... | 2 | 2010-03-14T15:36:38Z | 2,442,663 | <pre><code>for el in L:
if el == 2:
del L[el]
</code></pre>
| -4 | 2010-03-14T15:39:59Z | [
"python"
] |
Calculating Hebrew date in Python | 2,442,674 | <p>I'd like to calculate Hebrew dates (primarily the current Hebrew date) in Python. Which library is mature, easy to use, and documented? I note these. There may be others.</p>
<ul>
<li>Python Date Utilities Library as discussed <a href="http://www.ziporah-greve.net/prog/jewish-python.html" rel="nofollow">here</a></... | 4 | 2010-03-14T15:44:22Z | 2,442,991 | <p>The Python Date Utilities library (available on <a href="http://sourceforge.net/projects/pythondateutil/" rel="nofollow">sourceforge</a>) seems to be fine to do what you want, for more specific usage with hebrew dates you could have a look <a href="http://www.ziporah-greve.net/prog/jewish-python.html" rel="nofollow"... | 2 | 2010-03-14T17:14:18Z | [
"python",
"datetime",
"date",
"calendar",
"hebrew"
] |
python send/receive hex data via TCP socket | 2,442,704 | <p>I have a ethenet access control device that is said to be able to communicate via TCP.
<br>
<b>How can i send a pachet by entering the HEX data</b>, since this is what i have from their manual (a standard format for the communication packets sent and received after each command)<br>
Can you please show some example ... | 0 | 2010-03-14T15:53:26Z | 2,442,712 | <p>Just encode the hex data in a string:</p>
<pre><code>'\x34\x82\xf6'
</code></pre>
| 6 | 2010-03-14T15:55:11Z | [
"python",
"sockets",
"tcp",
"access-control"
] |
python send/receive hex data via TCP socket | 2,442,704 | <p>I have a ethenet access control device that is said to be able to communicate via TCP.
<br>
<b>How can i send a pachet by entering the HEX data</b>, since this is what i have from their manual (a standard format for the communication packets sent and received after each command)<br>
Can you please show some example ... | 0 | 2010-03-14T15:53:26Z | 2,442,733 | <p>I'd use <a href="http://docs.python.org/library/struct.html?highlight=struct.pack#struct.pack" rel="nofollow">struct.pack</a> to prepare the string of bytes to send, from the data you want to send. Be sure to start the packing format with <code>></code> to mean you want big-endian ordering and standard sizes, si... | 4 | 2010-03-14T16:06:29Z | [
"python",
"sockets",
"tcp",
"access-control"
] |
numpy.equal with string values | 2,442,799 | <p>The numpy.equal function does not work if a list or array contains strings:</p>
<pre><code>>>> import numpy
>>> index = numpy.equal([1,2,'a'],None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function not supported for these types, and can't coer... | 0 | 2010-03-14T16:22:44Z | 2,442,817 | <p>What's wrong with a stock list comprehension?</p>
<pre><code>index = [x is None for x in L]
</code></pre>
| 1 | 2010-03-14T16:26:46Z | [
"python",
"numpy"
] |
numpy.equal with string values | 2,442,799 | <p>The numpy.equal function does not work if a list or array contains strings:</p>
<pre><code>>>> import numpy
>>> index = numpy.equal([1,2,'a'],None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function not supported for these types, and can't coer... | 0 | 2010-03-14T16:22:44Z | 2,443,036 | <p>If you really need to use numpy, be more careful about what you pass in and it can work:</p>
<pre><code>>>> import numpy
>>> a = numpy.array([1, 2, 'a'], dtype=object) # makes type of array what you need
>>> numpy.equal(a, None)
array([False, False, False], dtype=bool)
</code></pre>
<p>S... | 2 | 2010-03-14T17:28:56Z | [
"python",
"numpy"
] |
Setting package-wide variables during python setup.py install | 2,442,821 | <p>Is there a way that when a user types</p>
<pre><code>python setup.py install
</code></pre>
<p>to install a Python package, <code>setup.py</code> can be made to set specific variables at the base of the pacakge? A common example would be to basically set <code>mypackage.__revision__</code> to be the svn revision of... | 2 | 2010-03-14T16:27:53Z | 2,442,899 | <p>The SVN version can be set by SVN. You don't need to use setup.py to mess with that.</p>
<p>Simply include the <code>$Revision$</code> flag in the text somewhere and tell SVN to do replacements.</p>
<p>Global options are usually handled by configuration files. Why mess with it at install time? It's much easier (... | 0 | 2010-03-14T16:49:31Z | [
"python"
] |
PyYAML parse into arbitary object | 2,442,933 | <p>I have the following Python 2.6 program and YAML definition (using <a href="http://pyyaml.org/wiki/PyYAML" rel="nofollow">PyYAML</a>):</p>
<pre><code>import yaml
x = yaml.load(
"""
product:
name : 'Product X'
sku : 123
features :
- size : '10x3... | 3 | 2010-03-14T16:58:19Z | 2,442,999 | <p>So you have a dictionary with string keys and values that can be numbers, nested dictionaries, lists, and you'd like to wrap that into an instance which lets you use attribute access in lieu of dict indexing, and "call with an index" in lieu of list indexing -- not sure what "strongly typed" has to do with this, or ... | 6 | 2010-03-14T17:17:13Z | [
"python",
"yaml",
"pyyaml"
] |
Python - Check if numbers in list are factors of a number | 2,442,972 | <p>I have a <code>list</code> of numbers (<code>integers</code>) (say, from 1 to 10). </p>
<p>They're not necessarily consecutive, but they are in ascending order. </p>
<p>I've prompted the user multiple times to enter a choice of the available numbers. When that number is entered, it is removed from the list along w... | 0 | 2010-03-14T17:09:58Z | 2,443,003 | <p>For the first problem, you could use list comprehensions to build a new list where each element is not the number selected and not a factor of the number selected (see code). Compare this with your original list.</p>
<pre><code>$ python
>>> selected_number = 6
>>> [x for x in range(1,11) if select... | 2 | 2010-03-14T17:18:03Z | [
"python",
"list",
"python-3.x",
"factors"
] |
Python - Check if numbers in list are factors of a number | 2,442,972 | <p>I have a <code>list</code> of numbers (<code>integers</code>) (say, from 1 to 10). </p>
<p>They're not necessarily consecutive, but they are in ascending order. </p>
<p>I've prompted the user multiple times to enter a choice of the available numbers. When that number is entered, it is removed from the list along w... | 0 | 2010-03-14T17:09:58Z | 2,443,042 | <p>If L is a list of non-zero numbers, the list of those which are factors of a number N is:</p>
<pre><code>factors = [x for x in L if N % x == 0]
</code></pre>
<p>The list will simply be empty if N has no factors in L, of course.</p>
<p>I'm not sure what you mean by "numbers without factors", unless you mean "prime... | 1 | 2010-03-14T17:31:15Z | [
"python",
"list",
"python-3.x",
"factors"
] |
Python - Check if numbers in list are factors of a number | 2,442,972 | <p>I have a <code>list</code> of numbers (<code>integers</code>) (say, from 1 to 10). </p>
<p>They're not necessarily consecutive, but they are in ascending order. </p>
<p>I've prompted the user multiple times to enter a choice of the available numbers. When that number is entered, it is removed from the list along w... | 0 | 2010-03-14T17:09:58Z | 2,443,056 | <p>To check if there are any factors of the number <code>guess</code> remaining you can use <a href="http://docs.python.org/library/functions.html#any" rel="nofollow"><code>any()</code></a>:</p>
<pre><code>hasfactors = any(guess % n == 0 for n in numbers)
</code></pre>
<p>To check if all the remaining numbers are pri... | 3 | 2010-03-14T17:37:37Z | [
"python",
"list",
"python-3.x",
"factors"
] |
Make Python Socket Server More Efficient | 2,443,226 | <p>I have very little experience working with sockets and multithreaded programming so to learn more I decided to see if I could hack together a little python socket server to power a chat room. I ended up getting it working pretty well but then I noticed my server's CPU usage spiked up over 100% when I had it running ... | 1 | 2010-03-14T18:31:12Z | 2,443,296 | <p>There are several possible race conditions in your code, but they would threaten correctness rather than performance: fixing them e.g. by locking would definitely not improve performance.</p>
<p>Rather, I'd focus on what good you think those threads are doing, at all -- since the core of your code is a <code>select... | 6 | 2010-03-14T18:49:58Z | [
"python",
"multithreading",
"sockets"
] |
Concatenate generator and item | 2,443,252 | <p>I have a generator (numbers) and a value (number). I would like to iterate over these as if they were one sequence:</p>
<pre><code>i for i in tuple(my_generator) + (my_value,)
</code></pre>
<p>The problem is, as far as I undestand, this creates 3 tuples only to immediately discard them and also copies items in "my... | 25 | 2010-03-14T18:39:25Z | 2,443,253 | <p><a href="http://docs.python.org/library/itertools.html#itertools.chain"><code>itertools.chain()</code></a></p>
| 6 | 2010-03-14T18:40:13Z | [
"python",
"iterator",
"generator",
"list-comprehension"
] |
Concatenate generator and item | 2,443,252 | <p>I have a generator (numbers) and a value (number). I would like to iterate over these as if they were one sequence:</p>
<pre><code>i for i in tuple(my_generator) + (my_value,)
</code></pre>
<p>The problem is, as far as I undestand, this creates 3 tuples only to immediately discard them and also copies items in "my... | 25 | 2010-03-14T18:39:25Z | 2,443,260 | <p><a href="http://docs.python.org/library/itertools.html#itertools.chain"><code>itertools.chain</code></a> treats several sequences as a single sequence.</p>
<p>So you could use it as:</p>
<pre><code>import itertools
def my_generator():
yield 1
yield 2
for i in itertools.chain(my_generator(), [5]):
pri... | 36 | 2010-03-14T18:41:00Z | [
"python",
"iterator",
"generator",
"list-comprehension"
] |
Concatenate generator and item | 2,443,252 | <p>I have a generator (numbers) and a value (number). I would like to iterate over these as if they were one sequence:</p>
<pre><code>i for i in tuple(my_generator) + (my_value,)
</code></pre>
<p>The problem is, as far as I undestand, this creates 3 tuples only to immediately discard them and also copies items in "my... | 25 | 2010-03-14T18:39:25Z | 2,443,262 | <p>Try <code>itertools.chain(*iterables)</code>. Docs here: <a href="http://docs.python.org/library/itertools.html#itertools.chain" rel="nofollow">http://docs.python.org/library/itertools.html#itertools.chain</a></p>
| 4 | 2010-03-14T18:41:46Z | [
"python",
"iterator",
"generator",
"list-comprehension"
] |
passing self data into a recursive function | 2,443,264 | <p>I'm trying to set a function to do something like this</p>
<pre><code> def __binaryTreeInsert(self, toInsert, currentNode=getRoot(), parentNode=None):
</code></pre>
<p>where current node starts as root, and then we change it to a different node in the method and recursivly call it again.</p>
<p>However, i canno... | 1 | 2010-03-14T18:42:57Z | 2,443,272 | <p>You can do</p>
<pre><code>def __binaryTreeInsert(self, toInsert, currentNode=None, parentNode=None):
if currentNode is None:
currentNode = self.getRoot()
...
</code></pre>
| 0 | 2010-03-14T18:44:49Z | [
"python",
"recursion",
"self"
] |
passing self data into a recursive function | 2,443,264 | <p>I'm trying to set a function to do something like this</p>
<pre><code> def __binaryTreeInsert(self, toInsert, currentNode=getRoot(), parentNode=None):
</code></pre>
<p>where current node starts as root, and then we change it to a different node in the method and recursivly call it again.</p>
<p>However, i canno... | 1 | 2010-03-14T18:42:57Z | 2,443,277 | <pre><code>def __binaryTreeInsert(self, toInsert, currentNode=0, parentNode=None):
if not currentNode:
currentNode = self.getRoot()
</code></pre>
| -1 | 2010-03-14T18:46:04Z | [
"python",
"recursion",
"self"
] |
passing self data into a recursive function | 2,443,264 | <p>I'm trying to set a function to do something like this</p>
<pre><code> def __binaryTreeInsert(self, toInsert, currentNode=getRoot(), parentNode=None):
</code></pre>
<p>where current node starts as root, and then we change it to a different node in the method and recursivly call it again.</p>
<p>However, i canno... | 1 | 2010-03-14T18:42:57Z | 2,443,323 | <p>While <code>arg=None</code> is the idiomatic Python sentinel value for an non-supplied argument, it doesn't <em>have</em> to be <code>None</code>. In Lua, for instance, the idiomatic non-supplied argument is an empty table. We can actually apply that to this case:</p>
<pre><code>class Foo:
sentinel = {}
d... | 2 | 2010-03-14T18:57:18Z | [
"python",
"recursion",
"self"
] |
passing self data into a recursive function | 2,443,264 | <p>I'm trying to set a function to do something like this</p>
<pre><code> def __binaryTreeInsert(self, toInsert, currentNode=getRoot(), parentNode=None):
</code></pre>
<p>where current node starts as root, and then we change it to a different node in the method and recursivly call it again.</p>
<p>However, i canno... | 1 | 2010-03-14T18:42:57Z | 2,443,339 | <p>When a function or method is defined, the <code>def</code> line is evaluated immediately, including any keyword arguments. For this reason, things like function calls and mutable objects are usually not appropriate for default arguments.</p>
<p>The solution is instead to use a sentinel value. <code>None</code> is m... | 0 | 2010-03-14T19:00:57Z | [
"python",
"recursion",
"self"
] |
How to make socket.recv(500) not stop a while loop | 2,443,383 | <p>I made an IRC bot which uses a while true loop to receive whatever is said.<br>
To receive I use recv(500), but that stops the loop if there isn't anything to receive, but i need the loop to continue even if there isn't anything to receive.<br>
I need a makeshift timer to continue running.</p>
<p>Example code:</p>
... | 1 | 2010-03-14T19:13:18Z | 2,443,391 | <p>This is going to prove a bad way to design a network application. I recommend looking into <a href="http://twistedmatrix.com/" rel="nofollow">twisted</a>, a networking library with an excellent implementation of the IRC protocol for making a client (like your bot) in <code>twisted.words.protocols.irc</code>.</p>
<p... | 1 | 2010-03-14T19:15:14Z | [
"python",
"sockets",
"while-loop"
] |
How to make socket.recv(500) not stop a while loop | 2,443,383 | <p>I made an IRC bot which uses a while true loop to receive whatever is said.<br>
To receive I use recv(500), but that stops the loop if there isn't anything to receive, but i need the loop to continue even if there isn't anything to receive.<br>
I need a makeshift timer to continue running.</p>
<p>Example code:</p>
... | 1 | 2010-03-14T19:13:18Z | 2,443,396 | <p>You can <a href="http://docs.python.org/library/socket.html?highlight=socket.send#socket.socket.settimeout" rel="nofollow">settimeout</a> on the socket so that the call returns promptly (with a suitable <a href="http://docs.python.org/library/socket.html?highlight=socket.send#socket.timeout" rel="nofollow">exception... | 2 | 2010-03-14T19:16:56Z | [
"python",
"sockets",
"while-loop"
] |
How to make socket.recv(500) not stop a while loop | 2,443,383 | <p>I made an IRC bot which uses a while true loop to receive whatever is said.<br>
To receive I use recv(500), but that stops the loop if there isn't anything to receive, but i need the loop to continue even if there isn't anything to receive.<br>
I need a makeshift timer to continue running.</p>
<p>Example code:</p>
... | 1 | 2010-03-14T19:13:18Z | 2,443,398 | <p>I usually use <a href="http://python-irclib.sourceforge.net/" rel="nofollow"><code>irclib</code></a> which takes care of this sort of detail for you.</p>
| 1 | 2010-03-14T19:17:38Z | [
"python",
"sockets",
"while-loop"
] |
How to make socket.recv(500) not stop a while loop | 2,443,383 | <p>I made an IRC bot which uses a while true loop to receive whatever is said.<br>
To receive I use recv(500), but that stops the loop if there isn't anything to receive, but i need the loop to continue even if there isn't anything to receive.<br>
I need a makeshift timer to continue running.</p>
<p>Example code:</p>
... | 1 | 2010-03-14T19:13:18Z | 2,443,406 | <p>If you want to do this with low-level python, consider using the <code>ready_sockets = select.select([s.fileno()], [], [], 0.1)</code> -- this will test the socket <code>s</code> for readability. If your socket's file number is not returned in <code>ready_sockets</code>, then there is no data to read.</p>
<p>Be ca... | 1 | 2010-03-14T19:20:18Z | [
"python",
"sockets",
"while-loop"
] |
Convert PPT to PNG via python | 2,443,464 | <p>I want to convert PPT to png, or other image formats using Python.</p>
<p>This question has been asked on SO, but essentially recommends running OpenOffice in headless X server, which was an absolute pain last time I used it. (Mostly due to hard to replicate bugs due to OO crashing.)</p>
<p>Is there any other way,... | 4 | 2010-03-14T19:37:06Z | 2,445,618 | <p>A basic workflow : </p>
<ul>
<li><p>convert your ppt to pdf by using a pdf printer from PowerPoint or OpenOffice's built in PDF converter</p></li>
<li><p>use ghostscript to convert the pdf to png or other image format (something along the line of <code>gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r100 -sOutputFile... | 2 | 2010-03-15T07:27:31Z | [
"python",
"powerpoint",
"file-conversion"
] |
Quicker way than "try" and "except" ? - Python | 2,443,489 | <p>I'm often having code written as follows</p>
<pre><code>try:
self.title = item.title().content.string
except AttributeError, e:
self.title = None
</code></pre>
<hr>
<p>Is there a quicker way of dealing with this? a one-liner?</p>
| 3 | 2010-03-14T19:43:09Z | 2,443,559 | <p>What exceptions are you getting from <code>item.title()</code>? The bare <code>except</code> (horrible practice!) doesn't tell us. If it's an AttributeError (where <code>item</code> doesn't have a <code>title</code> method, for example),</p>
<pre><code>self.title = getattr(item, 'title', lambda: None)()
</code></... | 6 | 2010-03-14T20:04:11Z | [
"python",
"beautifulsoup"
] |
Quicker way than "try" and "except" ? - Python | 2,443,489 | <p>I'm often having code written as follows</p>
<pre><code>try:
self.title = item.title().content.string
except AttributeError, e:
self.title = None
</code></pre>
<hr>
<p>Is there a quicker way of dealing with this? a one-liner?</p>
| 3 | 2010-03-14T19:43:09Z | 2,443,604 | <ul>
<li><p>You should know ahead of time whether or not an object has a given attribute. It is a bad sign when you have an object but do not know what it is.</p></li>
<li><p>You retrieve three attributes in your try block. A try block should contain as little code as possible. You could let an error pass silently if a... | 0 | 2010-03-14T20:17:57Z | [
"python",
"beautifulsoup"
] |
Quicker way than "try" and "except" ? - Python | 2,443,489 | <p>I'm often having code written as follows</p>
<pre><code>try:
self.title = item.title().content.string
except AttributeError, e:
self.title = None
</code></pre>
<hr>
<p>Is there a quicker way of dealing with this? a one-liner?</p>
| 3 | 2010-03-14T19:43:09Z | 2,443,629 | <p>In one line, although Iâd only recommend this in 5% of all use cases.</p>
<pre><code>self.title = item.title().content.string if hasattr(item, 'title') else None
</code></pre>
| 2 | 2010-03-14T20:27:27Z | [
"python",
"beautifulsoup"
] |
Quicker way than "try" and "except" ? - Python | 2,443,489 | <p>I'm often having code written as follows</p>
<pre><code>try:
self.title = item.title().content.string
except AttributeError, e:
self.title = None
</code></pre>
<hr>
<p>Is there a quicker way of dealing with this? a one-liner?</p>
| 3 | 2010-03-14T19:43:09Z | 2,443,771 | <p>Your question focuses on the speed of this operation. First, why do you think this operation is slow? Second, there isn't a faster way to access the attributes. Even trying to avoid the catch by checking for the attribute first will likely be slower, simply because of the Python conditionals needed to check if the ... | 0 | 2010-03-14T21:00:55Z | [
"python",
"beautifulsoup"
] |
Quicker way than "try" and "except" ? - Python | 2,443,489 | <p>I'm often having code written as follows</p>
<pre><code>try:
self.title = item.title().content.string
except AttributeError, e:
self.title = None
</code></pre>
<hr>
<p>Is there a quicker way of dealing with this? a one-liner?</p>
| 3 | 2010-03-14T19:43:09Z | 2,450,991 | <p>How about a two-liner?</p>
<pre><code>try: self.title = item.title().content.string
except AttributeError, e: self.title = None
</code></pre>
<p>Denser, less readable, but you really save two keypresses!</p>
| 0 | 2010-03-15T22:43:26Z | [
"python",
"beautifulsoup"
] |
Quicker way than "try" and "except" ? - Python | 2,443,489 | <p>I'm often having code written as follows</p>
<pre><code>try:
self.title = item.title().content.string
except AttributeError, e:
self.title = None
</code></pre>
<hr>
<p>Is there a quicker way of dealing with this? a one-liner?</p>
| 3 | 2010-03-14T19:43:09Z | 2,451,771 | <p>Assuming the AttributeError happens on <code>string</code>:</p>
<pre><code>self.title = getattr(item.title().content, 'string', None)
</code></pre>
| 2 | 2010-03-16T02:36:01Z | [
"python",
"beautifulsoup"
] |
Implementing the factory design pattern using metaclasses in python | 2,443,648 | <p>I found a lot of links on metaclasses, and most of them mention that they are useful for implementing factory methods. Can you show me an example of using metaclasses to implement the design pattern?</p>
| 5 | 2010-03-14T20:31:07Z | 2,443,666 | <p>There's no need. You can <a href="http://www.python.org/download/releases/2.2.1/descrintro/#__new__" rel="nofollow">override a class's <code>__new__()</code> method</a> in order to return a completely different object type.</p>
| 0 | 2010-03-14T20:35:51Z | [
"python",
"factory",
"metaclass"
] |
Implementing the factory design pattern using metaclasses in python | 2,443,648 | <p>I found a lot of links on metaclasses, and most of them mention that they are useful for implementing factory methods. Can you show me an example of using metaclasses to implement the design pattern?</p>
| 5 | 2010-03-14T20:31:07Z | 2,443,681 | <p>You can find some helpful examples at <a href="http://en.wikibooks.org/wiki/Python_Programming/MetaClasses" rel="nofollow">wikibooks/python</a>, <a href="http://onlamp.com/pub/a/python/2003/04/17/metaclasses.html" rel="nofollow">here</a> and <a href="http://www.ibm.com/developerworks/linux/library/l-pymeta.html" rel... | 2 | 2010-03-14T20:39:17Z | [
"python",
"factory",
"metaclass"
] |
Implementing the factory design pattern using metaclasses in python | 2,443,648 | <p>I found a lot of links on metaclasses, and most of them mention that they are useful for implementing factory methods. Can you show me an example of using metaclasses to implement the design pattern?</p>
| 5 | 2010-03-14T20:31:07Z | 2,443,770 | <p>I'd love to hear people's comments on this, but I think this is an example of what you want to do</p>
<pre><code>class FactoryMetaclassObject(type):
def __init__(cls, name, bases, attrs):
"""__init__ will happen when the metaclass is constructed:
the class object itself (not the instance of the... | 1 | 2010-03-14T21:00:51Z | [
"python",
"factory",
"metaclass"
] |
Why can't I pass self as a named argument to an instance method in Python? | 2,443,673 | <p>This works:</p>
<pre><code>>>> def bar(x, y):
... print x, y
...
>>> bar(y=3, x=1)
1 3
</code></pre>
<p>And this works:</p>
<pre><code>>>> class Foo(object):
... def bar(self, x, y):
... print x, y
...
>>> z = Foo()
>>> z.bar(y=3, x=1)
1 3
</code></... | 5 | 2010-03-14T20:38:01Z | 2,443,700 | <p><code>z.bar</code> is a <em>bound</em> method -- it already has an <code>im_self</code> attribute that becomes the first argument (conventionally named <code>self</code>) to the underlying function object, the bound method's <code>im_func</code> attribute. To override that you obviously need to re-bind <code>im_sel... | 6 | 2010-03-14T20:43:29Z | [
"python",
"methods",
"metaprogramming",
"language-lawyer"
] |
Piping EOF problems with stdio and C++/Python | 2,443,701 | <p>I got some problems with EOF and stdio in a communication pipeline between a python process and a C++ program. I have no idea what I am doing wrong. When I see an EOF in my program I clear the stdin and next round I try to read in a new line. The problem is: for some reason the getline function immediatly (from the ... | 0 | 2010-03-14T20:43:31Z | 2,443,748 | <p><code>communicate</code> in python is a one shot function. It sends the given input to a process, closes the input stream, and reads the output streams, waiting for the process to terminate.</p>
<p>There is no way you can 'restart' the pipe with the same process after "communicating".</p>
<p>Conversely, on the oth... | 1 | 2010-03-14T20:56:11Z | [
"c++",
"python",
"pipe",
"stdin",
"iostream"
] |
Problem running python/matplotlib in background after ending ssh session | 2,443,702 | <p>I have to VPN and then ssh from home to my work server and want to run a python script in the background, then log out of the ssh session. My script makes several histogram plots using matplotlib, and as long as I keep the connection open everything is fine, but if I log out I keep getting an error message in the lo... | 15 | 2010-03-14T20:43:33Z | 2,443,823 | <p>If you are running on a *nix OS the problem is your session is terminated and all processes requiring a session are also terminated when you disconnect. More specifically all your processes are sent a SIGHUP (signal hang-up). The default handling of SITHUP is to terminate the process. If you want you script to cont... | 0 | 2010-03-14T21:16:20Z | [
"python",
"ssh",
"background",
"matplotlib",
"tkinter"
] |
Problem running python/matplotlib in background after ending ssh session | 2,443,702 | <p>I have to VPN and then ssh from home to my work server and want to run a python script in the background, then log out of the ssh session. My script makes several histogram plots using matplotlib, and as long as I keep the connection open everything is fine, but if I log out I keep getting an error message in the lo... | 15 | 2010-03-14T20:43:33Z | 2,443,957 | <p>I believe your matplotlib backend requires X11. Look in your matplotlibrc file to determine what your default is (from the error, I'm betting TkAgg). To run without X11, use the Agg backend. Either set it globally in the matplotlibrc file or on a script by script by adding this to the python program:</p>
<pre><c... | 13 | 2010-03-14T22:04:47Z | [
"python",
"ssh",
"background",
"matplotlib",
"tkinter"
] |
Problem running python/matplotlib in background after ending ssh session | 2,443,702 | <p>I have to VPN and then ssh from home to my work server and want to run a python script in the background, then log out of the ssh session. My script makes several histogram plots using matplotlib, and as long as I keep the connection open everything is fine, but if I log out I keep getting an error message in the lo... | 15 | 2010-03-14T20:43:33Z | 2,444,609 | <p>Sorry if this is a stupid answer, but if you're just running a console session, would 'screen' not suffice? Detachable sessions, etc.</p>
| 2 | 2010-03-15T01:43:09Z | [
"python",
"ssh",
"background",
"matplotlib",
"tkinter"
] |
Problem running python/matplotlib in background after ending ssh session | 2,443,702 | <p>I have to VPN and then ssh from home to my work server and want to run a python script in the background, then log out of the ssh session. My script makes several histogram plots using matplotlib, and as long as I keep the connection open everything is fine, but if I log out I keep getting an error message in the lo... | 15 | 2010-03-14T20:43:33Z | 2,444,638 | <p>It looks like you're running in interactive mode by default, so matplotlib wants to plot everything to the screen first, which of course it can't do.</p>
<p>Try putting</p>
<pre><code>ioff()
</code></pre>
<p>at the top of your script, along with making the backend change.</p>
<p>reference: <a href="http://matplo... | 9 | 2010-03-15T01:53:49Z | [
"python",
"ssh",
"background",
"matplotlib",
"tkinter"
] |
Python 2.6 and 3.1.1, earlier version compatibility | 2,443,746 | <p>I ordered three books to start teaching myself Python - a beginning programming book, a computer science book that uses Python for all of its code references, and a book on Python network programming. Unfortunately, I was a little too quick on ordering them, because I hadn't noticed the version differences. The begi... | 1 | 2010-03-14T20:56:02Z | 2,443,769 | <p>99.8% of 2.3 code is valid in 2.6. The 3.x book <em>should</em> be able to backfill the 2.x knowledge from 2.4 on, assuming it actually touches upon the relevant subjects. See the various <a href="http://docs.python.org/whatsnew/" rel="nofollow">"What's New"</a> documentation to see, well, what's new.</p>
| 4 | 2010-03-14T21:00:34Z | [
"python",
"version",
"compatibility"
] |
calling a cdef in a cdef class | 2,444,000 | <p>is their any way to make this work, without sacrificing the cdef in cdef caller? (no use of cpdef either)</p>
<pre><code>from array import *
from numpy import *
cdef class Agents:
cdef public caller(self):
print "caller"
A[1].called()
cdef called(self):
print "called"
A = [Agents(... | 2 | 2010-03-14T22:16:44Z | 5,197,887 | <p>For Cython A[1] will be a python object. If you want to be able to still use cdef, use automatic cast in your caller :</p>
<pre><code>cdef public caller(self):
cdef Agents agent
print "caller"
agent = A[1]
agent.called()
</code></pre>
<p>You can check with the -a mode in cython to know if you are u... | 3 | 2011-03-04T18:39:17Z | [
"python",
"cython"
] |
Good way to flatten a multiple file python program for distribution? | 2,444,165 | <p>I am writing a console application in python that will consist of a handful of modules, each with a couple hundred lines of code.</p>
<p>For development it would be nice to modularize the program, but for distribution I like the idea of being able to post the program as a single python script.</p>
<p>Are there any... | 3 | 2010-03-14T22:56:12Z | 2,444,202 | <p>A zipfile (with just the <code>.pyc</code> or <code>.pyo</code> files in it, ideally) would suffice, especially if you're distributing code supporting a specific <code>X.Y</code> version of Python (any Z in <code>X.Y.Z</code> will do, i.e., if you support Python 2.6, that will work in 2.6.1, 2.6.2, and so on). Just... | 4 | 2010-03-14T23:07:05Z | [
"python",
"distribution"
] |
Good way to flatten a multiple file python program for distribution? | 2,444,165 | <p>I am writing a console application in python that will consist of a handful of modules, each with a couple hundred lines of code.</p>
<p>For development it would be nice to modularize the program, but for distribution I like the idea of being able to post the program as a single python script.</p>
<p>Are there any... | 3 | 2010-03-14T22:56:12Z | 2,596,282 | <p>No code to do this seems to exist.</p>
| 0 | 2010-04-07T22:09:18Z | [
"python",
"distribution"
] |
How to make socket.listen(1) work for some time and then continue rest of code? | 2,444,178 | <p>I'm making server that make a tcp socket and work over port range, with each port it will listen on that port for some time, then continue the rest of the code.</p>
<p>like this::</p>
<pre><code>import socket
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.setsockopt(socket.SOL_SOCKET, socket.SO_REUSE... | 2 | 2010-03-14T22:59:56Z | 2,444,219 | <p>You can <a href="http://docs.python.org/library/socket.html?highlight=socket.send#socket.socket.settimeout">settimeout</a> on the socket to the maximum amount of time you want to wait on it each time (call it again before every <code>listen</code> to the time you want to wait <em>this</em> time around) -- you'll get... | 12 | 2010-03-14T23:10:58Z | [
"python",
"sockets",
"ports"
] |
how to use cherrpy built in data storage | 2,444,270 | <p>Ok I have been reading the cherrypy documents for sometime and have not found a simple example yet. Let say I have a simple hello world site, how do I store data? Lets say I want to store a = 1, and b =2 to a dictionary using cherrypy. The config files are confusing as hell. Anyone have very simple example of st... | 1 | 2010-03-14T23:26:38Z | 2,444,291 | <p>You configure cherrypy to use sessions and store them to a file, e.g. in this way:</p>
<pre><code> cherrypy.config.update({'tools.sessions.on': True,
'tools.sessions.storage_type': "file",
'tools.sessions.storage_path': "/tmp/cherrypy_mysessions",
'tools.sessions.timeout': 60})
</code></pre>
<p>(or ... | 1 | 2010-03-14T23:31:38Z | [
"python",
"cherrypy"
] |
how to use cherrpy built in data storage | 2,444,270 | <p>Ok I have been reading the cherrypy documents for sometime and have not found a simple example yet. Let say I have a simple hello world site, how do I store data? Lets say I want to store a = 1, and b =2 to a dictionary using cherrypy. The config files are confusing as hell. Anyone have very simple example of st... | 1 | 2010-03-14T23:26:38Z | 2,444,295 | <p>Edit your config file:</p>
<pre><code>[/]
tools.sessions.on = True
tools.sessions.storage_type = "file" # leave blank for in-memory
tools.sessions.storage_path = "/home/site/sessions"
tools.sessions.timeout = 60
</code></pre>
<p>Setting data on a session:</p>
<pre><code>cherrypy.session['fieldname'] = 'fieldvalue... | 2 | 2010-03-14T23:33:04Z | [
"python",
"cherrypy"
] |
Problem with for-loop in python | 2,444,337 | <p>This code is supposed to be able to sort the items in self.array based upon the order of the characters in self.order. The method sort runs properly until the third iteration, unil for some reason the for loop seems to repeat indefinitely. What is going on here?</p>
<p>Edit: I'm making my own sort function because ... | 1 | 2010-03-14T23:50:03Z | 2,444,383 | <p>During the third pass of your loop you are appending new elements to the list you are iterating over therefore you can never leave the loop:<br>
<code>self.arrayt = self.leave</code> - this assignment leads to the fact that <code>self.leave.append(arrayi)</code> will append elements to the list <code>self.arrayt</co... | 2 | 2010-03-15T00:07:38Z | [
"python",
"class",
"for-loop"
] |
Problem with for-loop in python | 2,444,337 | <p>This code is supposed to be able to sort the items in self.array based upon the order of the characters in self.order. The method sort runs properly until the third iteration, unil for some reason the for loop seems to repeat indefinitely. What is going on here?</p>
<p>Edit: I'm making my own sort function because ... | 1 | 2010-03-14T23:50:03Z | 2,444,384 | <p>You have <code>self.arrayt = self.leave</code> which makes <code>arrayt</code> refer to exactly the same array as <code>leave</code> (it's <strong>not</strong> a copy of the contents!!!), then in the loop <code>for arrayi in self.arrayt:</code> you perpetrate a <code>self.leave.append(arrayi)</code> -- which lenghte... | 2 | 2010-03-15T00:07:50Z | [
"python",
"class",
"for-loop"
] |
Problem with for-loop in python | 2,444,337 | <p>This code is supposed to be able to sort the items in self.array based upon the order of the characters in self.order. The method sort runs properly until the third iteration, unil for some reason the for loop seems to repeat indefinitely. What is going on here?</p>
<p>Edit: I'm making my own sort function because ... | 1 | 2010-03-14T23:50:03Z | 2,444,399 | <p>The key-extractor Alex mentions is trivial enough to put in a lambda function</p>
<pre><code>>>> array = ['ca', 'bd', 'ac', 'ab']
>>> order = ['a', 'b', 'c', 'd']
>>> sorted(array, key=lambda v:map(order.index,v))
['ab', 'ac', 'bd', 'ca']
>>> order = ['b', 'a', 'c', 'd']
>>... | 2 | 2010-03-15T00:14:48Z | [
"python",
"class",
"for-loop"
] |
PyQt4 Custom Widgets | 2,444,452 | <p>Are there any good PyQt4 custom widgets like at <a href="http://www.qt-apps.org/index.php?xcontentmode=4298&PHPSESSID=fe445ee4c63f527a6ac528a3312f66e6" rel="nofollow">Qt-Apps.org</a>?</p>
<p>I would like to start making PyQt custom widgets but online resources that I find don't seem to be clear</p>
<p>For exam... | 2 | 2010-03-15T00:34:29Z | 2,445,944 | <p>There should be PyQt examples of all C++ Qt examples in your PyQt4 distribution. I have them here: <code>/usr/share/doc/python-qt4-doc/examples</code>. Theye are quite good for the start. When you understand them, it should also be fairly easy for you to port some C++ examples to PyQt code or turn C++ custom widgets... | 1 | 2010-03-15T09:00:25Z | [
"python",
"widget",
"pyqt4"
] |
PyQt4 Custom Widgets | 2,444,452 | <p>Are there any good PyQt4 custom widgets like at <a href="http://www.qt-apps.org/index.php?xcontentmode=4298&PHPSESSID=fe445ee4c63f527a6ac528a3312f66e6" rel="nofollow">Qt-Apps.org</a>?</p>
<p>I would like to start making PyQt custom widgets but online resources that I find don't seem to be clear</p>
<p>For exam... | 2 | 2010-03-15T00:34:29Z | 2,446,861 | <p>online resources about PyQt aren't really that rampant, so any information/projects would be welcomed. Don't hesitate to post links to your upcoming widgets or anything else.</p>
<p>I would be really glad to work on that with you as i'm learning more about pyqt as well.</p>
| 0 | 2010-03-15T12:00:03Z | [
"python",
"widget",
"pyqt4"
] |
PyQt4 Custom Widgets | 2,444,452 | <p>Are there any good PyQt4 custom widgets like at <a href="http://www.qt-apps.org/index.php?xcontentmode=4298&PHPSESSID=fe445ee4c63f527a6ac528a3312f66e6" rel="nofollow">Qt-Apps.org</a>?</p>
<p>I would like to start making PyQt custom widgets but online resources that I find don't seem to be clear</p>
<p>For exam... | 2 | 2010-03-15T00:34:29Z | 11,744,413 | <p>Are you looking for tutorials on making custom PyQt widgets, or looking for a library of them?</p>
<p>I've been developing a library of reusable custom widgets if that's what you're looking for - at somepoint will be getting to the tutorials, but they aren't there yet.</p>
<p>Check out projexsoftware.com, specific... | 1 | 2012-07-31T16:07:18Z | [
"python",
"widget",
"pyqt4"
] |
Python sock.listen(...) | 2,444,459 | <p>All the examples I've seen of <code>sock.listen(5)</code> in the python documentation suggest I should set the max backlog number to be <code>5</code>. This is causing a problem for my app since I'm expecting some very high volume (many concurrent connections). I set it to 200 and haven't seen any problems on my sys... | 4 | 2010-03-15T00:38:14Z | 2,444,483 | <p>The doc say this</p>
<blockquote>
<p><code>socket.listen(backlog)</code> Listen for
connections made to the socket. The
backlog argument specifies the maximum
number of queued connections and
should be at least 1; the maximum
value is system-dependent (usually 5).</p>
</blockquote>
<p>Obviously the sys... | 7 | 2010-03-15T00:45:18Z | [
"python",
"concurrency",
"sockets",
"multithreading"
] |
Python sock.listen(...) | 2,444,459 | <p>All the examples I've seen of <code>sock.listen(5)</code> in the python documentation suggest I should set the max backlog number to be <code>5</code>. This is causing a problem for my app since I'm expecting some very high volume (many concurrent connections). I set it to 200 and haven't seen any problems on my sys... | 4 | 2010-03-15T00:38:14Z | 2,444,491 | <p>You don't need to adjust the parameter to <code>listen()</code> to a larger number than 5.</p>
<p>The parameter controls how many non-<code>accept()</code>-ed connections are allowed to be outstanding. The <code>listen()</code> parameter has no bearing on the number of concurrently connected sockets, only on the n... | 12 | 2010-03-15T00:49:41Z | [
"python",
"concurrency",
"sockets",
"multithreading"
] |
Go to a specific line in Python? | 2,444,538 | <p>I want to go to line 34 in a .txt file and read it. How would you do that in Python?</p>
| 20 | 2010-03-15T01:11:25Z | 2,444,547 | <p>You could just read all the lines and index the line your after.</p>
<pre><code>line = open('filename').readlines()[33]
</code></pre>
| 1 | 2010-03-15T01:15:05Z | [
"python"
] |
Go to a specific line in Python? | 2,444,538 | <p>I want to go to line 34 in a .txt file and read it. How would you do that in Python?</p>
| 20 | 2010-03-15T01:11:25Z | 2,444,557 | <p>There's two ways:</p>
<ol>
<li>Read the file, line by line, stop when you've gotten to the line you want</li>
<li>Use <code>f.readlines()</code> which will read the entire file into memory, and return it as a list of lines, then extract the 34th item from that list.</li>
</ol>
<h2>Solution 1</h2>
<p>Benefit: You ... | 1 | 2010-03-15T01:20:52Z | [
"python"
] |
Go to a specific line in Python? | 2,444,538 | <p>I want to go to line 34 in a .txt file and read it. How would you do that in Python?</p>
| 20 | 2010-03-15T01:11:25Z | 2,444,559 | <p>Use Python Standard Library's <a href="http://docs.python.org/library/linecache.html?highlight=linecache#module-linecache">linecache</a> module:</p>
<pre><code>line = linecache.getline(thefilename, 33)
</code></pre>
<p>should do exactly what you want. You don't even need to open the file -- <code>linecache</code>... | 56 | 2010-03-15T01:21:35Z | [
"python"
] |
Go to a specific line in Python? | 2,444,538 | <p>I want to go to line 34 in a .txt file and read it. How would you do that in Python?</p>
| 20 | 2010-03-15T01:11:25Z | 2,444,574 | <pre><code>for linenum,line in enumerate(open("file")):
if linenum+1==34: print line.rstrip()
</code></pre>
| 1 | 2010-03-15T01:24:56Z | [
"python"
] |
Go to a specific line in Python? | 2,444,538 | <p>I want to go to line 34 in a .txt file and read it. How would you do that in Python?</p>
| 20 | 2010-03-15T01:11:25Z | 2,444,763 | <p>A solution that will not read more of the file than necessary is</p>
<pre><code>from itertools import islice
line_number = 34
with open(filename) as f:
# Adjust index since Python/islice indexes from 0 and the first
# line of a file is line 1
line = next(islice(f, line_number - 1, line_number))
</code... | 3 | 2010-03-15T02:32:29Z | [
"python"
] |
Go to a specific line in Python? | 2,444,538 | <p>I want to go to line 34 in a .txt file and read it. How would you do that in Python?</p>
| 20 | 2010-03-15T01:11:25Z | 8,046,389 | <p>This code will open the file, read the line and print it.</p>
<pre><code># Open and read file into buffer
f = open(file,"r")
lines = f.readlines()
# If we need to read line 33, and assign it to some variable
x = lines[33]
print(x)
</code></pre>
| 3 | 2011-11-08T05:38:20Z | [
"python"
] |
How to control a subthread process in python? | 2,444,616 | <p>Code first:</p>
<pre><code>'''this is main structure of my program'''
from twisted.web import http
from twisted.protocols import basic
import threading
threadstop = False #thread trigger,to be done
class MyThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.st... | 1 | 2010-03-15T01:48:31Z | 2,444,689 | <p>Use the <a href="http://docs.python.org/library/atexit.html?highlight=atexit#module-atexit" rel="nofollow">atexit</a> module to register (in the main thread) a function that set the global <code>threadstop</code> to <code>True</code>, or, more simply, set the <a href="http://docs.python.org/library/threading.html?hi... | 2 | 2010-03-15T02:09:50Z | [
"python",
"multithreading",
"twisted"
] |
How to control a subthread process in python? | 2,444,616 | <p>Code first:</p>
<pre><code>'''this is main structure of my program'''
from twisted.web import http
from twisted.protocols import basic
import threading
threadstop = False #thread trigger,to be done
class MyThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.st... | 1 | 2010-03-15T01:48:31Z | 2,445,745 | <p>This is not a direct answer to your question and Alex has already addressed your query, but here's a thought.</p>
<p>I see you're using python's <code>threading</code>. Did you try using <code>twisted.internet.threads</code> ?</p>
<p>When I find myself using threads in a <code>twisted</code> application, I go to <... | 2 | 2010-03-15T08:03:22Z | [
"python",
"multithreading",
"twisted"
] |
Dynamically expanding Django forms | 2,444,656 | <p>I would like to create a form where a user can enter an arbitrary # of items in separate textboxes. The user could add (and potentially remove) fields as needed. Something like this:
<img src="http://www.eggdrop.ch/downloads/dynamicforms/dynamicforms.png" alt="alt text"></p>
<p>I found the following different solut... | 1 | 2010-03-15T01:58:33Z | 2,444,672 | <p>I know this is a <a href="http://djangoadvent.com/1.2/jquery-admin/#new-features" rel="nofollow">new feature</a> in the admin in Django 1.2. </p>
<p>Maybe you can take a look at the way they implemented it there.</p>
| 2 | 2010-03-15T02:02:20Z | [
"python",
"django"
] |
Is there an alternative to gobject.timeout_add() in Python? | 2,444,665 | <p>I'm using gobject.timeout_add() to display a timer in my project (<a href="http://github.com/flavioamieiro/dojotools" rel="nofollow">dojotools</a>).</p>
<p>I was wondering if there is any other way to achieve the same results, but without the gobject dependency.</p>
<p>The requirement is just calling a method repe... | 0 | 2010-03-15T01:59:51Z | 2,444,922 | <p>You can use a thread with time.sleep(interval) to achieve the same effect.</p>
<pre><code>import thread, time
def timer():
while True:
time.sleep(1)
# do something here
thread.start_new_thread(timer, ())
</code></pre>
| 2 | 2010-03-15T03:26:52Z | [
"python",
"gobject"
] |
Is there an alternative to gobject.timeout_add() in Python? | 2,444,665 | <p>I'm using gobject.timeout_add() to display a timer in my project (<a href="http://github.com/flavioamieiro/dojotools" rel="nofollow">dojotools</a>).</p>
<p>I was wondering if there is any other way to achieve the same results, but without the gobject dependency.</p>
<p>The requirement is just calling a method repe... | 0 | 2010-03-15T01:59:51Z | 4,697,581 | <p>If you are OK with using TkInter, which should be available on all Pythons (except cell phones and maybe some tablets), you can use TkInter's <code>after()</code> function.<br>
That would avoid the blocking that sleep causes.</p>
| 1 | 2011-01-15T01:38:28Z | [
"python",
"gobject"
] |
SQLAlchemy custom query column | 2,444,679 | <p>I have a declarative table defined like this:</p>
<pre><code>class Transaction(Base):
__tablename__ = "transactions"
id = Column(Integer, primary_key=True)
account_id = Column(Integer)
transfer_account_id = Column(Integer)
amount = Column(Numeric(12, 2))
...
</code></pre>
<p>The query shoul... | 3 | 2010-03-15T02:07:13Z | 2,444,704 | <p>The construct you are looking for is called <code>column_property</code>. You could use a secondary mapper to actually replace the amount column. Are you sure you are not making things too difficult for yourself by not just storing the negative values in the database directly or giving the "corrected" column a diffe... | 1 | 2010-03-15T02:15:09Z | [
"python",
"sqlalchemy",
"declarative"
] |
SQLAlchemy custom query column | 2,444,679 | <p>I have a declarative table defined like this:</p>
<pre><code>class Transaction(Base):
__tablename__ = "transactions"
id = Column(Integer, primary_key=True)
account_id = Column(Integer)
transfer_account_id = Column(Integer)
amount = Column(Numeric(12, 2))
...
</code></pre>
<p>The query shoul... | 3 | 2010-03-15T02:07:13Z | 2,449,126 | <p>Any query you do will not replace original <code>amount</code> column. But you can load another column using following query:</p>
<pre><code>q = session.query(Transaction,
case([(Transaction.transfer_account_id==1, -1*Transaction.amount)], else_=Transaction.amount).label('special_amount')
... | 1 | 2010-03-15T17:30:08Z | [
"python",
"sqlalchemy",
"declarative"
] |
Generating two thumbnails from the same image in Django | 2,444,691 | <p>this seems like quite an easy problem but I can't figure out what is going on here.
Basically, what I'd like to do is create two different thumbnails from one image on a Django model. What ends up happening is that it seems to be looping and recreating the same image (while appending an underscore to it each time) u... | 0 | 2010-03-15T02:10:29Z | 2,444,773 | <p>Generally I like to give thumbnailing capabilities to the template author as much as possible. That way they can adjust the size of the things in the template. Whereas building it into the business logic layer is more fixed. You might have a reason though.</p>
<p>This template filter should generate the file on fir... | 3 | 2010-03-15T02:36:03Z | [
"python",
"django",
"python-imaging-library",
"thumbnails"
] |
Python 2 dict_items.sort() in Python 3 | 2,444,697 | <p>I'm porting some code from Python 2 to 3. This is valid code in Python 2 syntax:</p>
<pre><code>def print_sorted_dictionary(dictionary):
items=dictionary.items()
items.sort()
</code></pre>
<p>In Python 3, the dict_items have no method 'sort' - how can I make a workaround for this in Python 3?</p>
| 1 | 2010-03-15T02:13:45Z | 2,444,715 | <p>Use <code>items = sorted(dictionary.items())</code>, it works great in both Python 2 <em>and</em> Python 3.</p>
| 7 | 2010-03-15T02:16:48Z | [
"python",
"python-3.x"
] |
Python 2 dict_items.sort() in Python 3 | 2,444,697 | <p>I'm porting some code from Python 2 to 3. This is valid code in Python 2 syntax:</p>
<pre><code>def print_sorted_dictionary(dictionary):
items=dictionary.items()
items.sort()
</code></pre>
<p>In Python 3, the dict_items have no method 'sort' - how can I make a workaround for this in Python 3?</p>
| 1 | 2010-03-15T02:13:45Z | 2,444,721 | <p><code>dict.items</code> returns a view instead of a list in Python 3 (somewhat similarly to the <code>iteritems</code> method in Python 2.x). To get a sorted list of the items use</p>
<pre><code>sorted_items = sorted(d.items())
</code></pre>
<p>The <code>sorted</code> builtin takes an iterable and returns a new li... | 2 | 2010-03-15T02:17:34Z | [
"python",
"python-3.x"
] |
Distribute pre-compiled python extension module with distutils | 2,444,701 | <p>Quick one today: I'm learning the in's and out's of Pythons distutils library, and I would like to include a python extension module (.pyd) with my package. I know of course that the recommended way is to have distutils compile the extension at the time the package is created, but this is a fairly complex extension ... | 10 | 2010-03-15T02:14:42Z | 2,444,884 | <p>Try a manifest template:</p>
<p><a href="http://docs.python.org/distutils/sourcedist.html#specifying-the-files-to-distribute" rel="nofollow">http://docs.python.org/distutils/sourcedist.html#specifying-the-files-to-distribute</a></p>
| 5 | 2010-03-15T03:13:47Z | [
"python",
"python-3.x",
"distutils"
] |
Distribute pre-compiled python extension module with distutils | 2,444,701 | <p>Quick one today: I'm learning the in's and out's of Pythons distutils library, and I would like to include a python extension module (.pyd) with my package. I know of course that the recommended way is to have distutils compile the extension at the time the package is created, but this is a fairly complex extension ... | 10 | 2010-03-15T02:14:42Z | 7,715,429 | <p>Try using package_data: <a href="http://docs.python.org/distutils/setupscript#installing-package-data" rel="nofollow">http://docs.python.org/distutils/setupscript#installing-package-data</a></p>
| 0 | 2011-10-10T15:53:01Z | [
"python",
"python-3.x",
"distutils"
] |
Distribute pre-compiled python extension module with distutils | 2,444,701 | <p>Quick one today: I'm learning the in's and out's of Pythons distutils library, and I would like to include a python extension module (.pyd) with my package. I know of course that the recommended way is to have distutils compile the extension at the time the package is created, but this is a fairly complex extension ... | 10 | 2010-03-15T02:14:42Z | 12,012,086 | <p>I solved this by overriding Extension.build_extension:</p>
<pre><code>setup_args = { ... }
if platform.system() == 'Windows':
class my_build_ext(build_ext):
def build_extension(self, ext):
''' Copies the already-compiled pyd
'''
import shutil
import os.pat... | 1 | 2012-08-17T19:33:55Z | [
"python",
"python-3.x",
"distutils"
] |
Can a CLSID be different for the same program installed on two different machines? | 2,444,897 | <p>I am using comtypes to generate wrappers for a certain com library. I am having certain issues with a few things, that are not being generated properly. I can get around this by doing the missing work, manually. However can i depend on the fact that CLSID's will not change?</p>
<p>Lets say:</p>
<p>I install a prog... | 0 | 2010-03-15T03:19:23Z | 2,444,939 | <p>The CLSID is at least supposed not to change. Naturally a program can do a lot many stupid things breaking regulations. But: AS the CLSID is how the class is loaded, a changed CLSID would mean the USING program of a class would also have to use the changed CLSID.</p>
<p>Su, yous assumption is right - if the same pr... | 1 | 2010-03-15T03:34:17Z | [
"python",
"com"
] |
Can a CLSID be different for the same program installed on two different machines? | 2,444,897 | <p>I am using comtypes to generate wrappers for a certain com library. I am having certain issues with a few things, that are not being generated properly. I can get around this by doing the missing work, manually. However can i depend on the fact that CLSID's will not change?</p>
<p>Lets say:</p>
<p>I install a prog... | 0 | 2010-03-15T03:19:23Z | 2,444,964 | <p>Disclaimer: Done a lot of COM, but never with python.</p>
<p>The UUID for a COM interface is part of the definition of the interface. It should be the same on every machine, and for all time.</p>
<p>Also, in ATL COM land, classes have CLSIDs, interfaces have IIDs. They both have UUIDs (or possibly GUIDs). Not sure... | 1 | 2010-03-15T03:42:43Z | [
"python",
"com"
] |
Unpacking tuples/arrays/lists as indices for Numpy Arrays | 2,444,923 | <p>I would love to be able to do</p>
<pre><code>>>> A = numpy.array(((1,2),(3,4)))
>>> idx = (0,0)
>>> A[*idx]
</code></pre>
<p>and get</p>
<pre><code>1
</code></pre>
<p>however this is not valid syntax. Is there a way of doing this without explicitly writing out</p>
<pre><code>>>&... | 8 | 2010-03-15T03:26:57Z | 2,444,929 | <p>Try</p>
<pre><code>A[tuple(idx)]
</code></pre>
<p>Unless you have a more complex use case that's not as simple as this example, the above should work for all arrays.</p>
| 8 | 2010-03-15T03:30:37Z | [
"python",
"numpy"
] |
Unpacking tuples/arrays/lists as indices for Numpy Arrays | 2,444,923 | <p>I would love to be able to do</p>
<pre><code>>>> A = numpy.array(((1,2),(3,4)))
>>> idx = (0,0)
>>> A[*idx]
</code></pre>
<p>and get</p>
<pre><code>1
</code></pre>
<p>however this is not valid syntax. Is there a way of doing this without explicitly writing out</p>
<pre><code>>>&... | 8 | 2010-03-15T03:26:57Z | 2,444,930 | <p>Indexing an object calls:</p>
<pre><code>object.__getitem__(index)
</code></pre>
<p>When you do A[1, 2], it's the equivalent of:</p>
<pre><code>A.__getitem__((1, 2))
</code></pre>
<p>So when you do:</p>
<pre><code>b = (1, 2)
A[1, 2] == A[b]
A[1, 2] == A[(1, 2)]
</code></pre>
<p>Both statements will evaluate t... | 2 | 2010-03-15T03:30:42Z | [
"python",
"numpy"
] |
Unpacking tuples/arrays/lists as indices for Numpy Arrays | 2,444,923 | <p>I would love to be able to do</p>
<pre><code>>>> A = numpy.array(((1,2),(3,4)))
>>> idx = (0,0)
>>> A[*idx]
</code></pre>
<p>and get</p>
<pre><code>1
</code></pre>
<p>however this is not valid syntax. Is there a way of doing this without explicitly writing out</p>
<pre><code>>>&... | 8 | 2010-03-15T03:26:57Z | 2,444,935 | <p><em>No unpacking is necessary</em>âwhen you have a comma between <code>[</code> and <code>]</code>, you are making a tuple, not passing arguments. <code>foo[bar, baz]</code> is equivalent to <code>foo[(bar, baz)]</code>. So if you have a tuple <code>t = bar, baz</code> you would simply say <code>foo[t]</code>.</p>... | 2 | 2010-03-15T03:32:27Z | [
"python",
"numpy"
] |
Unpacking tuples/arrays/lists as indices for Numpy Arrays | 2,444,923 | <p>I would love to be able to do</p>
<pre><code>>>> A = numpy.array(((1,2),(3,4)))
>>> idx = (0,0)
>>> A[*idx]
</code></pre>
<p>and get</p>
<pre><code>1
</code></pre>
<p>however this is not valid syntax. Is there a way of doing this without explicitly writing out</p>
<pre><code>>>&... | 8 | 2010-03-15T03:26:57Z | 2,444,942 | <p>It's easier than you think:</p>
<pre><code>>>> import numpy
>>> A = numpy.array(((1,2),(3,4)))
>>> idx = (0,0)
>>> A[idx]
1
</code></pre>
| 9 | 2010-03-15T03:35:13Z | [
"python",
"numpy"
] |
Python beginner having trouble running code | 2,445,093 | <p>For some reason this code will not seem to run in the interpreter. When I hit F5 nothing happens, not even the debugger seems to recognize it. I assume it has something to do with the class, as when removed the interpreter seems to recognize the rest of the code. Please tell me what I am doing wrong.
Edit: I have re... | -1 | 2010-03-15T04:33:24Z | 2,445,103 | <p>The source highlighting should give you a hint. You either need to switch to double quotes, or escape the <code>'</code> in <code>won't</code>.</p>
<p>Change</p>
<pre><code>print ('Why won't this work?')
</code></pre>
<p>to</p>
<pre><code>print ('Why won\'t this work?')
</code></pre>
| 2 | 2010-03-15T04:35:36Z | [
"python"
] |
Python beginner having trouble running code | 2,445,093 | <p>For some reason this code will not seem to run in the interpreter. When I hit F5 nothing happens, not even the debugger seems to recognize it. I assume it has something to do with the class, as when removed the interpreter seems to recognize the rest of the code. Please tell me what I am doing wrong.
Edit: I have re... | -1 | 2010-03-15T04:33:24Z | 2,445,161 | <p>Seems that you have a problem with your indentation</p>
<pre><code>... my = sorting_class()
File "<stdin>", line 45
my = sorting_class()
^
IndentationError: unindent does not match any outer indentation level
>>> x = ['ac', 'bc' ,'ab', 'da']
File "<stdin>"... | 0 | 2010-03-15T04:54:42Z | [
"python"
] |
Python beginner having trouble running code | 2,445,093 | <p>For some reason this code will not seem to run in the interpreter. When I hit F5 nothing happens, not even the debugger seems to recognize it. I assume it has something to do with the class, as when removed the interpreter seems to recognize the rest of the code. Please tell me what I am doing wrong.
Edit: I have re... | -1 | 2010-03-15T04:33:24Z | 2,445,163 | <p>You're <code>my = sorting_class()</code> is defined inside the class. Take it out the class definition and you should be all set.</p>
| 0 | 2010-03-15T04:54:53Z | [
"python"
] |
Python beginner having trouble running code | 2,445,093 | <p>For some reason this code will not seem to run in the interpreter. When I hit F5 nothing happens, not even the debugger seems to recognize it. I assume it has something to do with the class, as when removed the interpreter seems to recognize the rest of the code. Please tell me what I am doing wrong.
Edit: I have re... | -1 | 2010-03-15T04:33:24Z | 2,445,188 | <p>You reference <code>my</code> within your class methods when they are clearly not in scope anywhere. I'm not sure what this should even be referring to.</p>
<p>Also, it's indented one level too far.</p>
| 0 | 2010-03-15T05:03:57Z | [
"python"
] |
Python beginner having trouble running code | 2,445,093 | <p>For some reason this code will not seem to run in the interpreter. When I hit F5 nothing happens, not even the debugger seems to recognize it. I assume it has something to do with the class, as when removed the interpreter seems to recognize the rest of the code. Please tell me what I am doing wrong.
Edit: I have re... | -1 | 2010-03-15T04:33:24Z | 2,445,247 | <p>I got the following error message when running your code:</p>
<pre><code> File "sss.py", line 44
carry, leave += my.sort(arrayt)
SyntaxError: illegal expression for augmented assignment
</code></pre>
<p>You should get similar error messages too. BTW, I am using python 2.6.4 for testing.</p>
| 2 | 2010-03-15T05:18:12Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.