title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Python TCP stack implementation | 1,581,087 | <p>Is there a python library which implements a standalone TCP stack?</p>
<p>I can't use the usual python socket library because I'm receiving a stream of packets over a socket (they are being tunneled to me over this socket). When I receive a TCP SYN packet addressed to a particular port, I'd like to accept the conn... | 7 | 2009-10-17T00:50:53Z | 1,581,102 | <p>You might be able to use the <a href="http://docs.python.org/library/ctypes.html#module-ctypes" rel="nofollow">ctypes</a> module to import lwip and use it again.</p>
| 0 | 2009-10-17T00:58:34Z | [
"python",
"tcp",
"network-programming",
"network-protocols",
"raw-sockets"
] |
Python TCP stack implementation | 1,581,087 | <p>Is there a python library which implements a standalone TCP stack?</p>
<p>I can't use the usual python socket library because I'm receiving a stream of packets over a socket (they are being tunneled to me over this socket). When I receive a TCP SYN packet addressed to a particular port, I'd like to accept the conn... | 7 | 2009-10-17T00:50:53Z | 1,581,109 | <p>Glancing over <a href="http://www.secdev.org/projects/scapy/doc/introduction.html?highlight=syn" rel="nofollow">Scapy</a>, it looks like it might be able to handle these low-level situations. I haven't used it myself so I can't confirm that it does what you've explained; I've only glanced over the documentation.</p... | 2 | 2009-10-17T01:01:51Z | [
"python",
"tcp",
"network-programming",
"network-protocols",
"raw-sockets"
] |
Python TCP stack implementation | 1,581,087 | <p>Is there a python library which implements a standalone TCP stack?</p>
<p>I can't use the usual python socket library because I'm receiving a stream of packets over a socket (they are being tunneled to me over this socket). When I receive a TCP SYN packet addressed to a particular port, I'd like to accept the conn... | 7 | 2009-10-17T00:50:53Z | 1,581,892 | <p>You don't say which platform you are working on, but if you are working on linux, I'd open a <a href="http://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/Documentation/networking/tuntap.txt" rel="nofollow">tun/tap interface</a> and get the IP packets back into the kernel as a real network interface so th... | 7 | 2009-10-17T10:19:10Z | [
"python",
"tcp",
"network-programming",
"network-protocols",
"raw-sockets"
] |
Python TCP stack implementation | 1,581,087 | <p>Is there a python library which implements a standalone TCP stack?</p>
<p>I can't use the usual python socket library because I'm receiving a stream of packets over a socket (they are being tunneled to me over this socket). When I receive a TCP SYN packet addressed to a particular port, I'd like to accept the conn... | 7 | 2009-10-17T00:50:53Z | 1,582,637 | <p>If you are already committed to the software at the other end of the socket, that is forwarding TCP packets to you, then perhaps TCPWatch will show you how to get at the SYN packets. SCAPY is certainly great for sending exactly the packets that you want, but I'm not sure that it will work as a proxy.</p>
<p><a href... | 0 | 2009-10-17T16:47:41Z | [
"python",
"tcp",
"network-programming",
"network-protocols",
"raw-sockets"
] |
How do I make these relative imports work in Python 3? | 1,581,260 | <p>I have a directory structure that looks like this:</p>
<pre><code>project/
__init__.py
foo/
__init.py__
first.py
second.py
third.py
plum.py
</code></pre>
<p>In <code>project/foo/__init__.py</code> I import classes from <code>first.py</code>, <... | 2 | 2009-10-17T02:46:46Z | 1,581,726 | <p>Edit: I did misunderstand the question: No <code>__all__</code> is not restricted to just modules.</p>
<p>One question is why you want to do a relative import. There is nothing wrong with doing <code>from project.foo import *</code>, here. Secondly, the <code>__all__</code> restriction on foo won't prevent you from... | 3 | 2009-10-17T08:18:59Z | [
"python",
"import",
"python-3.x",
"relative"
] |
How to perform a "Group By" query in Django 1.1? | 1,581,383 | <p>I have seen a lot of talk about 1.1's aggregation, but I am not sure how to use it to perform a simple group by.</p>
<p>I am trying to use Django's sitemap framework to create a sitemap.xml file that Google can crawl to find all the pages of my site. Currently I am passing it all the objects, as in <code>Model.obje... | 3 | 2009-10-17T04:16:42Z | 1,581,449 | <p>Django models are lazy loaded. It will be the same amount of overhead if your code walks across your model relationships as if the sitemap did. The models fields are essentially proxies until you request related models.</p>
| 1 | 2009-10-17T04:54:13Z | [
"python",
"django"
] |
How to perform a "Group By" query in Django 1.1? | 1,581,383 | <p>I have seen a lot of talk about 1.1's aggregation, but I am not sure how to use it to perform a simple group by.</p>
<p>I am trying to use Django's sitemap framework to create a sitemap.xml file that Google can crawl to find all the pages of my site. Currently I am passing it all the objects, as in <code>Model.obje... | 3 | 2009-10-17T04:16:42Z | 1,581,709 | <p>May be Distinct will help you?</p>
<blockquote>
<p>Model.objects.values('name').all().distinct()</p>
</blockquote>
| 1 | 2009-10-17T08:09:15Z | [
"python",
"django"
] |
Installing python-mysql with wamp's mysql | 1,581,431 | <p>(I'm not sure if this should be asked here or SU.. but seeing <a href="http://stackoverflow.com/questions/1458500/need-help-installing-mysql-for-python">this question</a> on SO, I am asking it here...)</p>
<p>I have wamp (mysql-5.1.33) server setup on my vista machine, and I am trying to install python-mysql 1.2.3c... | 3 | 2009-10-17T04:43:33Z | 1,581,670 | <p>It is looking for the Microsoft Visual Studio compiler to take care of some (presumably) C libraries.</p>
<p>You need to install Visual Studio, or perhaps MINGW.</p>
| 0 | 2009-10-17T07:42:37Z | [
"python",
"mysql",
"mysql-python"
] |
Installing python-mysql with wamp's mysql | 1,581,431 | <p>(I'm not sure if this should be asked here or SU.. but seeing <a href="http://stackoverflow.com/questions/1458500/need-help-installing-mysql-for-python">this question</a> on SO, I am asking it here...)</p>
<p>I have wamp (mysql-5.1.33) server setup on my vista machine, and I am trying to install python-mysql 1.2.3c... | 3 | 2009-10-17T04:43:33Z | 3,373,317 | <p>You can use a precompiled binary available at sourceforge page of mysql-python.
The version 1.2.2 has the binary installer for python2.4 and python2.5</p>
<p>If you are searching for python2.6 binaries, find it here - <a href="http://www.codegood.com/archives/4" rel="nofollow">http://www.codegood.com/archives/4</a>... | 0 | 2010-07-30T16:10:43Z | [
"python",
"mysql",
"mysql-python"
] |
Installing python-mysql with wamp's mysql | 1,581,431 | <p>(I'm not sure if this should be asked here or SU.. but seeing <a href="http://stackoverflow.com/questions/1458500/need-help-installing-mysql-for-python">this question</a> on SO, I am asking it here...)</p>
<p>I have wamp (mysql-5.1.33) server setup on my vista machine, and I am trying to install python-mysql 1.2.3c... | 3 | 2009-10-17T04:43:33Z | 4,580,035 | <p>The reason is msvc9compiler.py in Python26\Lib\distutils don't analyse VC version properly. You can check find_vcvarsall(version) in msvc9compiler.py yourself: it always turns version = 9, means VC9(2008) will work, but never VC8(2005). The awkward way to compile something using setup.py with VC8 is make version = 8... | 1 | 2011-01-02T19:19:54Z | [
"python",
"mysql",
"mysql-python"
] |
Reposition a VLC window programmatically | 1,581,782 | <p>I'm sure others have run into this problem too...</p>
<p>I often watch videos in a small VLC window while working on other tasks, but no matter where the window is placed, I eventually need to access something in the GUI behind it, and have to manually reposition the video window first.</p>
<p>This could be solved... | 2 | 2009-10-17T09:04:18Z | 1,581,792 | <p>Here is a windows only solution. You dont need to actually put the mouse over the window. All you need to do is <a href="http://msdn.microsoft.com/en-us/library/ms633499%28VS.85%29.aspx" rel="nofollow">Find the window</a> using its name and <a href="http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx" r... | 1 | 2009-10-17T09:12:19Z | [
"c#",
"python",
"windows",
"cross-platform",
"vlc"
] |
Reposition a VLC window programmatically | 1,581,782 | <p>I'm sure others have run into this problem too...</p>
<p>I often watch videos in a small VLC window while working on other tasks, but no matter where the window is placed, I eventually need to access something in the GUI behind it, and have to manually reposition the video window first.</p>
<p>This could be solved... | 2 | 2009-10-17T09:04:18Z | 1,582,934 | <p>This is a bit OOT, but in Windows 7, shaking the active window will hide others to reveal the desktop (and so will clicking/hovering the rightmost taskbar button). Instead of hiding/moving vlc, you could just temporarily reveal the whole desktop. Shaking the active window again brings everything back.</p>
| 0 | 2009-10-17T18:55:25Z | [
"c#",
"python",
"windows",
"cross-platform",
"vlc"
] |
How to draw a bitmap real quick in python using Tk only? | 1,581,799 | <p>Here is a problem. I want to visualize a specific vector field as a bitmap. It's ok with the representation itself, so I allready have some matrix of RGB lists like [255,255,115], but I have no good idea of how to draw it on screen. So far I make thousands of colored 1px rectangles, but this works too slow. I'm sure... | 3 | 2009-10-17T09:18:39Z | 1,582,896 | <p><strong>ATTEMPT 3 - I swear last one...</strong></p>
<p>I believe this is the fastest pure TK way to do this. Generates 10,000 RGB values in a list of lists, creates a Tkinter.PhotoImage and then puts the pixel values into it.</p>
<pre><code>import Tkinter, random
class App:
def __init__(self, t):
se... | 12 | 2009-10-17T18:34:06Z | [
"python",
"visualization",
"tk"
] |
How to draw a bitmap real quick in python using Tk only? | 1,581,799 | <p>Here is a problem. I want to visualize a specific vector field as a bitmap. It's ok with the representation itself, so I allready have some matrix of RGB lists like [255,255,115], but I have no good idea of how to draw it on screen. So far I make thousands of colored 1px rectangles, but this works too slow. I'm sure... | 3 | 2009-10-17T09:18:39Z | 26,158,702 | <p>There is a faster pure tkinter method:</p>
<pre><code>import Tkinter, random
class App:
def __init__(self, t):
self.i = Tkinter.PhotoImage(width=100,height=100)
colors = ([random.randint(0,255) for i in range(0,3)] for j in range(0,10000))
pixels=" ".join(("{"+" ".join(('#%02x%02x%02x' ... | 3 | 2014-10-02T10:12:58Z | [
"python",
"visualization",
"tk"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 1,581,902 | <p>The way I solved this (actually I did this in Scala, not Python) was to use both a Set and a Queue, only adding links to the queue (and set) if they did not already exist in the set.</p>
<p>Both the set and queue were encapsulated in a single thread, exposing only a queue-like interface to the consumer threads.</p>... | 1 | 2009-10-17T10:26:06Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 1,581,903 | <p>SQLite is so simple to use and would fit perfectly... just a suggestion.</p>
| 2 | 2009-10-17T10:27:08Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 1,581,908 | <p>Also, instead of a set you might try using a dictionary. Operations on sets tend to get rather slow when they're big, whereas a dictionary lookup is nice and quick.</p>
<p>My 2c.</p>
| -3 | 2009-10-17T10:32:23Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 1,581,913 | <p>use:</p>
<pre><code>url in q.queue
</code></pre>
<p>which returns True iff <code>url</code> is in the queue</p>
| 1 | 2009-10-17T10:34:52Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 1,581,920 | <p>Why only use the array (ideally, a dictionary would be even better) to filter things you've already visited? Add things to your array/dictionary as soon as you queue them up, and only add them to the queue if they're not already in the array/dict. Then you have 3 simple separate things:</p>
<ol>
<li>Links not yet s... | 1 | 2009-10-17T10:36:59Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 1,581,937 | <p>If you don't care about the order in which items are processed, I'd try a subclass of <code>Queue</code> that uses <code>set</code> internally:</p>
<pre><code>class SetQueue(Queue):
def _init(self, maxsize):
self.maxsize = maxsize
self.queue = set()
def _put(self, item):
self.queue... | 10 | 2009-10-17T10:46:37Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 1,582,421 | <p>instead of "array of pages already visited" make an "array of pages already added to the queue"</p>
| 0 | 2009-10-17T15:13:21Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 24,183,479 | <p>The put method also needs to be overwritten, if not a join call will block forever
<a href="https://github.com/python/cpython/blob/master/Lib/queue.py#L147" rel="nofollow">https://github.com/python/cpython/blob/master/Lib/queue.py#L147</a> </p>
<pre><code>class UniqueQueue(Queue):
def put(self, item, block=T... | 3 | 2014-06-12T11:42:57Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 26,822,693 | <p><em>Sadly, I have no enouch rating for comment the best Lukáš Lalinskýâs answer.</em></p>
<p>To add support for <code>SetQueue.task_done()</code> and <code>SetQueue.join()</code> for second variant of Lukáš Lalinskýâs SetQueue add else brahch to the if:</p>
<pre><code>def _put(self, item):
if item no... | 0 | 2014-11-08T22:15:46Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 29,691,803 | <p>This is full version of <code>SetQueue</code></p>
<pre><code>import Queue
class SetQueue(Queue.Queue):
def _init(self, maxsize):
Queue.Queue._init(self, maxsize)
self.all_items = set()
def _put(self, item):
if item not in self.all_items:
Queue.Queue._put(self, item)
... | 1 | 2015-04-17T06:23:50Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 34,522,293 | <p>What follows is an improvement over Lukáš Lalinský's latter <a href="https://stackoverflow.com/a/1581937/4117209">solution</a>.
The important difference is that <code>put</code> is overridden in order to ensure <code>unfinished_tasks</code> is accurate and <code>join</code> works as expected.</p>
<pre><code>from... | 1 | 2015-12-30T02:54:15Z | [
"python",
"multithreading",
"queue"
] |
How check if a task is already in python Queue? | 1,581,895 | <p>I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, ... | 10 | 2009-10-17T10:21:43Z | 36,247,735 | <p>I'm agree with @Ben James.Try to use both deque and set. </p>
<p>here are code:</p>
<pre><code>class SetUniqueQueue(Queue):
def _init(self, maxsize):
self.queue = deque()
self.setqueue = set()
def _put(self, item):
if item not in self.setqueue:
self.setqueue.add(item... | 0 | 2016-03-27T13:12:50Z | [
"python",
"multithreading",
"queue"
] |
How to wrap a CLI program in Python (keeping the interactivity)? | 1,582,026 | <p>I'd like to write a wrapper for an interactive CLI Program (the Asterisk CLI).</p>
<p>Basically, I need to keep the interaction with the CLI (including tab-completion) but I want to filter the output of Asterisk, in order to show only lines matching a given pattern.</p>
<p>I tried a select() based approach, using ... | 3 | 2009-10-17T11:44:55Z | 1,582,035 | <p>Pexpect might be useful for you: <a href="http://sourceforge.net/projects/pexpect/">http://sourceforge.net/projects/pexpect/</a></p>
<p>Description from the webpage: "Pexpect is a Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect can be use... | 6 | 2009-10-17T11:53:26Z | [
"python",
"select",
"wrapper",
"command-line-interface",
"interactive"
] |
How to wrap a CLI program in Python (keeping the interactivity)? | 1,582,026 | <p>I'd like to write a wrapper for an interactive CLI Program (the Asterisk CLI).</p>
<p>Basically, I need to keep the interaction with the CLI (including tab-completion) but I want to filter the output of Asterisk, in order to show only lines matching a given pattern.</p>
<p>I tried a select() based approach, using ... | 3 | 2009-10-17T11:44:55Z | 12,582,187 | <p><a href="http://code.google.com/p/py-asterisk/" rel="nofollow">http://code.google.com/p/py-asterisk/</a></p>
<p><strong>Introduction</strong></p>
<p>The Python Asterisk package (codenamed py-Asterisk) is an attempt to produce high quality, well documented Python bindings for the Asterisk Manager API.</p>
<p>The e... | 0 | 2012-09-25T11:40:29Z | [
"python",
"select",
"wrapper",
"command-line-interface",
"interactive"
] |
Dynamic URL with CherryPY MethodDispatcher | 1,582,297 | <p>I need to configure a RESTful style URL that support the following URL scheme:</p>
<ul>
<li>/parent/ </li>
<li>/parent/1 </li>
<li>/parent/1/children</li>
<li>/parent/1/chidren/1</li>
</ul>
<p>I want to use the MethodDispatcher so that each of the above can have GET/POST/PUT/DELETE functions. I have it working ... | 10 | 2009-10-17T14:19:25Z | 1,582,444 | <p><a href="http://tools.cherrypy.org/wiki/RestfulDispatch" rel="nofollow">http://tools.cherrypy.org/wiki/RestfulDispatch</a> might be what you're looking for.</p>
<p>In CherryPy 3.2 (just now coming out of beta), there will be a new <code>_cp_dispatch</code> method you can use in your object tree to do the same thing... | 9 | 2009-10-17T15:27:00Z | [
"python",
"rest",
"cherrypy"
] |
Dynamic URL with CherryPY MethodDispatcher | 1,582,297 | <p>I need to configure a RESTful style URL that support the following URL scheme:</p>
<ul>
<li>/parent/ </li>
<li>/parent/1 </li>
<li>/parent/1/children</li>
<li>/parent/1/chidren/1</li>
</ul>
<p>I want to use the MethodDispatcher so that each of the above can have GET/POST/PUT/DELETE functions. I have it working ... | 10 | 2009-10-17T14:19:25Z | 16,180,835 | <pre><code>#!/usr/bin/env python
import cherrypy
class Items(object):
exposed = True
def __init__(self):
pass
# this line will map the first argument after / to the 'id' parameter
# for example, a GET request to the url:
# http://localhost:8000/items/
# will call GET with id=None
#... | 2 | 2013-04-23T23:23:38Z | [
"python",
"rest",
"cherrypy"
] |
Longest string in numpy object_ array | 1,582,525 | <p>I'm using a numpy object_ array to store variable length strings, e.g.</p>
<pre><code>a = np.array(['hello','world','!'],dtype=np.object_)
</code></pre>
<p>Is there an easy way to find the length of the longest string in the array without looping over all elements?</p>
| 4 | 2009-10-17T16:05:56Z | 1,582,556 | <p>No as the only place the length of each string is known is by the string. So you have to find out from every string what its length is.</p>
| 0 | 2009-10-17T16:15:10Z | [
"python",
"arrays",
"numpy"
] |
Longest string in numpy object_ array | 1,582,525 | <p>I'm using a numpy object_ array to store variable length strings, e.g.</p>
<pre><code>a = np.array(['hello','world','!'],dtype=np.object_)
</code></pre>
<p>Is there an easy way to find the length of the longest string in the array without looping over all elements?</p>
| 4 | 2009-10-17T16:05:56Z | 1,582,665 | <p>If you store the string in a numpy array of dtype object, then you can't get at the size of the objects (strings) without looping. However, if you let np.array decide the dtype, then you can find out the length of the longest string by peeking at the dtype:</p>
<pre><code>In [64]: a = np.array(['hello','world','!',... | 2 | 2009-10-17T16:59:52Z | [
"python",
"arrays",
"numpy"
] |
Longest string in numpy object_ array | 1,582,525 | <p>I'm using a numpy object_ array to store variable length strings, e.g.</p>
<pre><code>a = np.array(['hello','world','!'],dtype=np.object_)
</code></pre>
<p>Is there an easy way to find the length of the longest string in the array without looping over all elements?</p>
| 4 | 2009-10-17T16:05:56Z | 1,582,670 | <p><code>max(a, key=len)</code> gives you the longest string (and <code>len(max(a, key=len))</code> gives you its length) without requiring you to code an explicit loop, but of course <code>max</code> will do its own looping internally, as it couldn't possibly identify "the longest string" in any other way.</p>
| 4 | 2009-10-17T17:01:32Z | [
"python",
"arrays",
"numpy"
] |
Longest string in numpy object_ array | 1,582,525 | <p>I'm using a numpy object_ array to store variable length strings, e.g.</p>
<pre><code>a = np.array(['hello','world','!'],dtype=np.object_)
</code></pre>
<p>Is there an easy way to find the length of the longest string in the array without looping over all elements?</p>
| 4 | 2009-10-17T16:05:56Z | 25,559,451 | <p>Say I want to get the longest string in the second column:</p>
<pre><code>data_array = [['BFNN' 'Forested bog without permafrost or patterning, no internal lawns']
['BONS' 'Nonpatterned, open, shrub-dominated bog']]
def get_max_len_column_value(data_array, column):
return len(max(data_array[:,[co... | 0 | 2014-08-28T23:18:07Z | [
"python",
"arrays",
"numpy"
] |
asyncore not running handle_read | 1,582,558 | <p>I'm trying to just make a simple asyncore example where one socket is the sender and one is the receiver. For some reason, the handle_read() on the receiver is never called so I never get the 'test' data. Anyone know why? This is my first shot at asyncore, so it's probably something extremely simple.</p>
<pre><code... | 0 | 2009-10-17T16:16:06Z | 1,582,565 | <p><code>asyncore.loop</code> does not terminate, so the <code>a.send</code> doesn't happen, since you've coded it to happen in line <em>after</em> the exit of asyncore.loop.</p>
<p>Once this is fixed, you run into the problem that you're running sender and receiver within a single thread and process, so unless you ta... | 1 | 2009-10-17T16:18:42Z | [
"python",
"asyncore"
] |
asyncore not running handle_read | 1,582,558 | <p>I'm trying to just make a simple asyncore example where one socket is the sender and one is the receiver. For some reason, the handle_read() on the receiver is never called so I never get the 'test' data. Anyone know why? This is my first shot at asyncore, so it's probably something extremely simple.</p>
<pre><code... | 0 | 2009-10-17T16:16:06Z | 11,226,559 | <p>A lot late and not solving the issue as Alex points to the causes, but your code shows:</p>
<pre><code>def writable(self):
True
</code></pre>
<p>Shouldn't that be:</p>
<pre><code>def writable(self):
return True
</code></pre>
| 1 | 2012-06-27T12:46:51Z | [
"python",
"asyncore"
] |
Using/Creating Python objects with Jython | 1,582,674 | <p>HI, </p>
<p>lets say I have a Java interface B, something like this. B.java :</p>
<pre><code>public interface B { String FooBar(String s); }
</code></pre>
<p>and I want to use it with a Python class D witch inherits B, like this. D.py :</p>
<pre><code>class D(B):
def FooBar(s)
return s + 'e'
</code><... | 2 | 2009-10-17T17:03:37Z | 1,582,800 | <p>Code for your example above. You also need to change the FooBar implementation to take a self argument since it is not a static method.</p>
<p>You need to have jython.jar on the classpath for this example to compile and run.</p>
<pre><code>import org.python.core.PyObject;
import org.python.core.PyString;
import or... | 3 | 2009-10-17T17:51:28Z | [
"java",
"python",
"jython"
] |
Selenium IDE - can't select "table" tab | 1,582,679 | <p>Can someone tell me why I can't select the "table" tab?</p>
<p>Here is a pic:</p>
<p><img src="http://img110.imageshack.us/img110/935/imgzx.jpg" alt="alt text" /></p>
| 0 | 2009-10-17T17:06:25Z | 1,582,827 | <p>What "Format" are you using? The table is available in HTML only. I think. </p>
<p>Select Options/Format/HTML from the menu and the Table tab should be activated.</p>
| 1 | 2009-10-17T18:05:39Z | [
"python"
] |
Long, slow operation in Django view causes timeout. Any way for Python to speak AJAX instead? | 1,582,708 | <p>I've been programming Python a while, but DJango and web programming in general is new to me.</p>
<p>I have a very long operation performed in a Python view. Since the local() function in my view takes so long to return, there's an HTTP timeout. Fair enough, I understand that part.</p>
<p>What's the best way to gi... | 5 | 2009-10-17T17:19:45Z | 1,582,726 | <p>One way is to submit the task using AJAX/JS or the normal way, start it in background in your view and return immediately. Then use AJAX/JS on client side to periodically check if task is done. If it's done reload the page or provide a link to the client.</p>
<blockquote>
<p>CLIENT "Please start a task using this... | 5 | 2009-10-17T17:26:53Z | [
"python",
"ajax",
"django",
"timeout"
] |
Long, slow operation in Django view causes timeout. Any way for Python to speak AJAX instead? | 1,582,708 | <p>I've been programming Python a while, but DJango and web programming in general is new to me.</p>
<p>I have a very long operation performed in a Python view. Since the local() function in my view takes so long to return, there's an HTTP timeout. Fair enough, I understand that part.</p>
<p>What's the best way to gi... | 5 | 2009-10-17T17:19:45Z | 1,582,971 | <p>Ajax doesn't require any particular technology on the server side. All you need is to return a response in some form that some Javascript on the client side can understand. JSON is an excellent choice here, as it's easy to create in Python (there's a <code>json</code> library in 2.6, and Django has <code>django.util... | 7 | 2009-10-17T19:09:27Z | [
"python",
"ajax",
"django",
"timeout"
] |
Long, slow operation in Django view causes timeout. Any way for Python to speak AJAX instead? | 1,582,708 | <p>I've been programming Python a while, but DJango and web programming in general is new to me.</p>
<p>I have a very long operation performed in a Python view. Since the local() function in my view takes so long to return, there's an HTTP timeout. Fair enough, I understand that part.</p>
<p>What's the best way to gi... | 5 | 2009-10-17T17:19:45Z | 1,583,261 | <p>I'm not sure if this is what you are looking for, but <a href="http://stackoverflow.com/questions/336866/how-to-implement-a-minimal-server-for-ajax-in-python">maybe this question</a> (How to implement a minimal server for AJAX in Python?) is helpful. In my answer I give a minimal example (which is not very well writ... | 1 | 2009-10-17T21:21:46Z | [
"python",
"ajax",
"django",
"timeout"
] |
Best practice for the Python-then-profile-then-C design pattern? | 1,582,718 | <p>A popular software development pattern seems to be:</p>
<ol>
<li>Thrash out the logic and algorithms in Python.</li>
<li>Profile to find out where the slow bits are.</li>
<li>Replace those with C.</li>
<li>Ship code that is the best trade-off between high-level and speedy.</li>
</ol>
<p>I say popular simply becaus... | 4 | 2009-10-17T17:24:41Z | 1,582,784 | <p>Step 3 is wrong. In the modern world, more than half the time "the slow bits" are I/O or network bound, or limited by some other resource outside the process. Rewriting them in anything is only going to introduce bugs.</p>
| 0 | 2009-10-17T17:48:04Z | [
"python",
"c",
"refactoring",
"profiling"
] |
Best practice for the Python-then-profile-then-C design pattern? | 1,582,718 | <p>A popular software development pattern seems to be:</p>
<ol>
<li>Thrash out the logic and algorithms in Python.</li>
<li>Profile to find out where the slow bits are.</li>
<li>Replace those with C.</li>
<li>Ship code that is the best trade-off between high-level and speedy.</li>
</ol>
<p>I say popular simply becaus... | 4 | 2009-10-17T17:24:41Z | 1,582,864 | <p>There are lots of different ways that people approach development. </p>
<p>Sometimes people follow your three steps and discover that the slow bits are due to the external environment, therefore rewriting Python into C does not address the problem. That type of slowness can sometimes be solved on the system side, a... | 3 | 2009-10-17T18:22:20Z | [
"python",
"c",
"refactoring",
"profiling"
] |
Best practice for the Python-then-profile-then-C design pattern? | 1,582,718 | <p>A popular software development pattern seems to be:</p>
<ol>
<li>Thrash out the logic and algorithms in Python.</li>
<li>Profile to find out where the slow bits are.</li>
<li>Replace those with C.</li>
<li>Ship code that is the best trade-off between high-level and speedy.</li>
</ol>
<p>I say popular simply becaus... | 4 | 2009-10-17T17:24:41Z | 1,583,268 | <p>I also thought that way when I started using Python</p>
<p>I've done step 3 twice (that I can recall) in 12 years. Not often enough to call it a design pattern. Usually it's enough to wrap an existing C library. Usually someone else has already written the wrapper.</p>
| 2 | 2009-10-17T21:26:13Z | [
"python",
"c",
"refactoring",
"profiling"
] |
Best practice for the Python-then-profile-then-C design pattern? | 1,582,718 | <p>A popular software development pattern seems to be:</p>
<ol>
<li>Thrash out the logic and algorithms in Python.</li>
<li>Profile to find out where the slow bits are.</li>
<li>Replace those with C.</li>
<li>Ship code that is the best trade-off between high-level and speedy.</li>
</ol>
<p>I say popular simply becaus... | 4 | 2009-10-17T17:24:41Z | 16,521,034 | <p>Mercurial is a good example: it's written in <a href="http://en.wikipedia.org/wiki/Mercurial" rel="nofollow">Python and C</a> and it's about as fast as git, which is mostly written in C.</p>
| 0 | 2013-05-13T11:34:13Z | [
"python",
"c",
"refactoring",
"profiling"
] |
edit text file using Python | 1,582,750 | <p>I need to update a text file whenever my IP address changes, and then run a few commands from the shell afterwards.</p>
<ol>
<li><p>Create variable LASTKNOWN = "212.171.135.53"
This is the ip address we have while writing this script.</p></li>
<li><p>Get the current IP address. It will change on a daily basis.</p>... | 6 | 2009-10-17T17:35:22Z | 1,582,774 | <p>Probably the simplest way would be to open a file using f=open(filename, mode). Then, read all the lines using f.readlines() (this will return a list of strings representing the lines of the program). </p>
<p>You can then search these strings to find the address and replace it with the new one (using standard strin... | 1 | 2009-10-17T17:45:26Z | [
"python",
"text",
"editing"
] |
edit text file using Python | 1,582,750 | <p>I need to update a text file whenever my IP address changes, and then run a few commands from the shell afterwards.</p>
<ol>
<li><p>Create variable LASTKNOWN = "212.171.135.53"
This is the ip address we have while writing this script.</p></li>
<li><p>Get the current IP address. It will change on a daily basis.</p>... | 6 | 2009-10-17T17:35:22Z | 1,582,781 | <p>You're trying to "atomically" update the contents of a file, and there have been many delightful flame wars on the subject. But the general pattern is:</p>
<p>1) Write the new file to a temp file, and make sure you flush and close.</p>
<p>2) Use your operating system's facilities to atomically rename the temp file... | 2 | 2009-10-17T17:47:23Z | [
"python",
"text",
"editing"
] |
edit text file using Python | 1,582,750 | <p>I need to update a text file whenever my IP address changes, and then run a few commands from the shell afterwards.</p>
<ol>
<li><p>Create variable LASTKNOWN = "212.171.135.53"
This is the ip address we have while writing this script.</p></li>
<li><p>Get the current IP address. It will change on a daily basis.</p>... | 6 | 2009-10-17T17:35:22Z | 1,582,903 | <p>After checking the comments and the bit of code that you put on pastebin, here is a working solution. To begin with, the file /tmp/iiiipf.conf contains:</p>
<pre><code>Simply a test file 175.48.204.168
And two times 175.48.204.168 on this line 175.48.204.168
Done.
</code></pre>
<p>After running the code, the fil... | 0 | 2009-10-17T18:37:14Z | [
"python",
"text",
"editing"
] |
edit text file using Python | 1,582,750 | <p>I need to update a text file whenever my IP address changes, and then run a few commands from the shell afterwards.</p>
<ol>
<li><p>Create variable LASTKNOWN = "212.171.135.53"
This is the ip address we have while writing this script.</p></li>
<li><p>Get the current IP address. It will change on a daily basis.</p>... | 6 | 2009-10-17T17:35:22Z | 1,584,198 | <h2>Replace LASTKNOWN by CURRENT in /etc/ipf.conf</h2>
<h3>Replace all at once</h3>
<pre><code>filename = "/etc/ipf.conf"
text = open(filename).read()
open(filename, "w").write(text.replace(LASTKNOWN, CURRENT))
</code></pre>
<h3>Replace line by line</h3>
<pre><code>from __future__ import with_statement
from context... | 3 | 2009-10-18T06:47:31Z | [
"python",
"text",
"editing"
] |
edit text file using Python | 1,582,750 | <p>I need to update a text file whenever my IP address changes, and then run a few commands from the shell afterwards.</p>
<ol>
<li><p>Create variable LASTKNOWN = "212.171.135.53"
This is the ip address we have while writing this script.</p></li>
<li><p>Get the current IP address. It will change on a daily basis.</p>... | 6 | 2009-10-17T17:35:22Z | 2,363,893 | <p>Another way to simply edit files in place is to use the <a href="http://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CC8QFjAA&url=http%3A%2F%2Fdocs.python.org%2Flibrary%2Ffileinput.html&ei=TGeZUPCRHOfP0QXQhIHAAw&usg=AFQjCNEmKT3Z55eqWRpCJIDCDyy1ACOGhg"... | 23 | 2010-03-02T14:43:26Z | [
"python",
"text",
"editing"
] |
pycurl installation on Windows | 1,582,814 | <p>I am not able to install pycurl on Windows on Python2.6. Getting following error:</p>
<pre><code>C:\Documents and Settings\vijayendra\Desktop\Downloads\pycurl-7.19.0>python setup.py install --curl-dir="C:\Documents and Settings\vijayendra\Desktop\Downloads\
curl-7.19.5-win32-ssl\curl-7.19.5"
Using curl directory... | 12 | 2009-10-17T17:57:36Z | 1,582,852 | <p>You install pyCURL on Windows via the provided win32-specific <a href="http://pycurl.sourceforge.net/download/" rel="nofollow">binaries</a>.</p>
| 1 | 2009-10-17T18:17:53Z | [
"python",
"libcurl",
"pycurl"
] |
pycurl installation on Windows | 1,582,814 | <p>I am not able to install pycurl on Windows on Python2.6. Getting following error:</p>
<pre><code>C:\Documents and Settings\vijayendra\Desktop\Downloads\pycurl-7.19.0>python setup.py install --curl-dir="C:\Documents and Settings\vijayendra\Desktop\Downloads\
curl-7.19.5-win32-ssl\curl-7.19.5"
Using curl directory... | 12 | 2009-10-17T17:57:36Z | 1,585,749 | <p>I built pycurl without ssl today for urlgrabber 3.9 and it worked. the dir i used was c:\Pycurl-7.19.0 and same as --curl-dir ,as given CURL_DIR in setup.py, but with fresh compiled libcurl.lib from sources using vc express 08, inside the dir in respective places ie it needs some include files also. try running aft... | 0 | 2009-10-18T19:10:47Z | [
"python",
"libcurl",
"pycurl"
] |
pycurl installation on Windows | 1,582,814 | <p>I am not able to install pycurl on Windows on Python2.6. Getting following error:</p>
<pre><code>C:\Documents and Settings\vijayendra\Desktop\Downloads\pycurl-7.19.0>python setup.py install --curl-dir="C:\Documents and Settings\vijayendra\Desktop\Downloads\
curl-7.19.5-win32-ssl\curl-7.19.5"
Using curl directory... | 12 | 2009-10-17T17:57:36Z | 2,689,993 | <p><a href="http://wiki.woodpecker.org.cn/moin/PyCurl?action=AttachFile&do=view&target=pycurl-7.20.1-bin-win32-py26.zip" rel="nofollow">http://wiki.woodpecker.org.cn/moin/PyCurl?action=AttachFile&do=view&target=pycurl-7.20.1-bin-win32-py26.zip</a></p>
<p>unzip it and copy all to your site-packages
:)</... | 3 | 2010-04-22T10:32:29Z | [
"python",
"libcurl",
"pycurl"
] |
pycurl installation on Windows | 1,582,814 | <p>I am not able to install pycurl on Windows on Python2.6. Getting following error:</p>
<pre><code>C:\Documents and Settings\vijayendra\Desktop\Downloads\pycurl-7.19.0>python setup.py install --curl-dir="C:\Documents and Settings\vijayendra\Desktop\Downloads\
curl-7.19.5-win32-ssl\curl-7.19.5"
Using curl directory... | 12 | 2009-10-17T17:57:36Z | 3,817,095 | <p>Andelf's answer didn't work on my Win 7 x64 machine, but <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">Christoph Gohlke's site</a> has a package that works for me.</p>
| 29 | 2010-09-28T21:12:00Z | [
"python",
"libcurl",
"pycurl"
] |
pycurl installation on Windows | 1,582,814 | <p>I am not able to install pycurl on Windows on Python2.6. Getting following error:</p>
<pre><code>C:\Documents and Settings\vijayendra\Desktop\Downloads\pycurl-7.19.0>python setup.py install --curl-dir="C:\Documents and Settings\vijayendra\Desktop\Downloads\
curl-7.19.5-win32-ssl\curl-7.19.5"
Using curl directory... | 12 | 2009-10-17T17:57:36Z | 17,894,696 | <p>Here is the url,</p>
<p>this sites packages are rocks <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycurl" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycurl</a></p>
| 0 | 2013-07-27T05:45:18Z | [
"python",
"libcurl",
"pycurl"
] |
String matching in python with re | 1,582,895 | <p>I have a file in this structure:</p>
<p><code>009/foo/bar/hi23123/foo/bar231123/foo/bar/yo232131</code></p>
<p>What i need is to find the exact match of a string; e.g. only /foo/bar among /foo/bar/hi and /foo/bar/yo </p>
<p>One solution came up in my mind is like to check for ending "/" for the input string. Beca... | 0 | 2009-10-17T18:34:02Z | 1,582,906 | <p>So you want <code>/foo/bar</code> <strong>not</strong> followed by a <code>/</code>? If so, then you're looking for a "negative lookahead", </p>
<pre><code>r = re.compile(r'/foo/bar(?!/)')
</code></pre>
<p>and then <code>r.search</code> to your heart's content.</p>
| 8 | 2009-10-17T18:37:27Z | [
"python",
"regex",
"string-matching"
] |
XML-RPC C# and Python RPC Server | 1,583,017 | <p>On my server, I'm using the standard example for Python (with an extra Hello World Method) and on the Client side I'm using the XML-RPC.NET Library in C#.
But everytime I run my client I get the exception that the method is not found. Any Ideas how fix that. </p>
<p>thanks!</p>
<p>Python:</p>
<pre><code>from Simp... | 4 | 2009-10-17T19:29:52Z | 1,583,047 | <p>Does it work if you change the declaration to this?</p>
<pre><code>[XmlRpcUrl("http://188.40.xxx.xxx:8000/RPC2")]
</code></pre>
<p>From the <a href="http://docs.python.org/library/simplexmlrpcserver.html">Python docs</a>:</p>
<blockquote>
<p><code>SimpleXMLRPCRequestHandler.rpc_paths</code></p>
<p>An attri... | 5 | 2009-10-17T19:47:08Z | [
"c#",
"python",
"xml-rpc"
] |
Making a C extension to Python that requires another extension | 1,583,077 | <p>I have a couple of Python functions that I use to make game development with Pygame easier. I have them in a file called helper.py in my Python-path, so I can import them from any game I make. I thought, as an exercise to learn about Python extensions, to convert this module to C. My first problem is that I need to ... | 4 | 2009-10-17T20:01:35Z | 1,583,194 | <p>You can import python modules from C code and call things defined in just like you can in python code. It is a bit long winded, but perfectly possible.</p>
<p>When I want to work out how to do something like this I look at the <a href="http://docs.python.org/c-api/index.html" rel="nofollow">C API documentation</a>... | 3 | 2009-10-17T20:59:41Z | [
"python",
"c",
"pygame"
] |
Making a C extension to Python that requires another extension | 1,583,077 | <p>I have a couple of Python functions that I use to make game development with Pygame easier. I have them in a file called helper.py in my Python-path, so I can import them from any game I make. I thought, as an exercise to learn about Python extensions, to convert this module to C. My first problem is that I need to ... | 4 | 2009-10-17T20:01:35Z | 1,583,235 | <pre><code>/* get the sys.modules dictionary */
PyObject* sysmodules PyImport_GetModuleDict();
PyObject* pygame_module;
if(PyMapping_HasKeyString(sysmodules, "pygame")) {
pygame_module = PyMapping_GetItemString(sysmodules, "pygame");
} else {
PyObject* initresult;
pygame_module = PyImport_ImportModule("pyga... | 5 | 2009-10-17T21:15:23Z | [
"python",
"c",
"pygame"
] |
Making a C extension to Python that requires another extension | 1,583,077 | <p>I have a couple of Python functions that I use to make game development with Pygame easier. I have them in a file called helper.py in my Python-path, so I can import them from any game I make. I thought, as an exercise to learn about Python extensions, to convert this module to C. My first problem is that I need to ... | 4 | 2009-10-17T20:01:35Z | 1,584,257 | <p>Most functions in <code>pygame</code> module are just wrappers around SDL functions, that is where you have to look for C version of its functions. <code>pygame.h</code> defines a series of <code>import_pygame_*()</code> functions. Call <code>import_pygame_base()</code> and others once at initialization of extension... | 0 | 2009-10-18T07:31:08Z | [
"python",
"c",
"pygame"
] |
Python: Int not iterable errror | 1,583,148 | <p>I'm attempting to get my feet wet with python on Project Euler, but I'm having an issue with the first problem (find the sum of the multiples of 3 or 5 up to 1,000). I can successfully print out multiples of three and five, but when I attempt to include the sum function I get the following error:</p>
<blockquote>
... | 5 | 2009-10-17T20:42:08Z | 1,583,167 | <p>The <code>sum</code> function expects a list, not a single number.</p>
<p>When you do <code>for numbers in</code>, then the variable <code>numbers</code> has a single integer object. Add a <code>print</code> statement, you'll see that <code>numbers</code> is a single number.</p>
<p>You might want to accumulate al... | 1 | 2009-10-17T20:47:01Z | [
"python"
] |
Python: Int not iterable errror | 1,583,148 | <p>I'm attempting to get my feet wet with python on Project Euler, but I'm having an issue with the first problem (find the sum of the multiples of 3 or 5 up to 1,000). I can successfully print out multiples of three and five, but when I attempt to include the sum function I get the following error:</p>
<blockquote>
... | 5 | 2009-10-17T20:42:08Z | 1,583,168 | <p>numbers needs to be a list or similar when it is passed to sum(). In the code example above, it is an integer - one of the integers from x.</p>
<p>Try something like:</p>
<pre><code>numbers = [num for num in x if num%3==0 and num%5 ==0]
print sum(numbers)
</code></pre>
| 5 | 2009-10-17T20:47:15Z | [
"python"
] |
Python: Int not iterable errror | 1,583,148 | <p>I'm attempting to get my feet wet with python on Project Euler, but I'm having an issue with the first problem (find the sum of the multiples of 3 or 5 up to 1,000). I can successfully print out multiples of three and five, but when I attempt to include the sum function I get the following error:</p>
<blockquote>
... | 5 | 2009-10-17T20:42:08Z | 1,583,171 | <p>I think you want something like what follows.</p>
<pre><code>def numcheck(x):
total = 0
for number in x:
if number % 3 == 0 or and number % 5 == 0:
total += number
print total
</code></pre>
<p>Alternatively, you could append each of the divisible numbers to a list, and then call sum... | 1 | 2009-10-17T20:48:45Z | [
"python"
] |
Python: Int not iterable errror | 1,583,148 | <p>I'm attempting to get my feet wet with python on Project Euler, but I'm having an issue with the first problem (find the sum of the multiples of 3 or 5 up to 1,000). I can successfully print out multiples of three and five, but when I attempt to include the sum function I get the following error:</p>
<blockquote>
... | 5 | 2009-10-17T20:42:08Z | 1,583,183 | <p>help(sum)
Help on built-in function sum in module <strong>builtin</strong>:</p>
<p>sum(...)
sum(sequence[, start]) -> value</p>
<pre><code>Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start' (which defaults to 0). When the sequence is
empty, returns start.
</code></pre>
... | 1 | 2009-10-17T20:54:47Z | [
"python"
] |
Python: Int not iterable errror | 1,583,148 | <p>I'm attempting to get my feet wet with python on Project Euler, but I'm having an issue with the first problem (find the sum of the multiples of 3 or 5 up to 1,000). I can successfully print out multiples of three and five, but when I attempt to include the sum function I get the following error:</p>
<blockquote>
... | 5 | 2009-10-17T20:42:08Z | 1,583,189 | <p>In the for-loop </p>
<pre><code>for numbers in x:
</code></pre>
<p>"numbers" steps through the elements in x one at a time, for each pass through the loop.
It would be perhaps better to name the variable "number" because you are only getting
one number at a time. "numbers" equals an integer each time through the l... | 7 | 2009-10-17T20:56:49Z | [
"python"
] |
Python: Int not iterable errror | 1,583,148 | <p>I'm attempting to get my feet wet with python on Project Euler, but I'm having an issue with the first problem (find the sum of the multiples of 3 or 5 up to 1,000). I can successfully print out multiples of three and five, but when I attempt to include the sum function I get the following error:</p>
<blockquote>
... | 5 | 2009-10-17T20:42:08Z | 1,583,213 | <p>Here is how I would do this:</p>
<pre><code>n = 100
# the next 4 lines are just to confirm that xrange is n numbers starting at 0
junk = xrange(n)
print junk[0] # print first number in sequence
print junk[-1] # print last number in sequence
print "================"
# check to see if numbers are divisable by 3 or... | 1 | 2009-10-17T21:08:29Z | [
"python"
] |
positioning sound with pygame? | 1,583,284 | <p>Is there a way to do panning or 3d sound in Pygame? The only way I've found to control sound playback is to set the volume for both the left and right channels.</p>
| 2 | 2009-10-17T21:32:35Z | 1,583,292 | <p><a href="http://pysonic.sourceforge.net/" rel="nofollow">http://pysonic.sourceforge.net/</a></p>
<p>Try this out, it's a wrapper over the FMOD sound library, it won't disappoint :)</p>
| 0 | 2009-10-17T21:36:22Z | [
"python",
"audio",
"pygame"
] |
positioning sound with pygame? | 1,583,284 | <p>Is there a way to do panning or 3d sound in Pygame? The only way I've found to control sound playback is to set the volume for both the left and right channels.</p>
| 2 | 2009-10-17T21:32:35Z | 1,583,298 | <p>I think setting the separate channel volume is the only way. Pygame doesn't seem to have any notion of world space or positioning for sounds.</p>
| 0 | 2009-10-17T21:38:15Z | [
"python",
"audio",
"pygame"
] |
positioning sound with pygame? | 1,583,284 | <p>Is there a way to do panning or 3d sound in Pygame? The only way I've found to control sound playback is to set the volume for both the left and right channels.</p>
| 2 | 2009-10-17T21:32:35Z | 2,359,462 | <p>You are correct - Pygame itself doesn't have any high-level way to position sound other than manually adjusting channel volumes (and it looks like it only supports stereo).</p>
<p>The best way, to do 3D-audio, especially for games, is to use <a href="http://connect.creativelabs.com/openal/default.aspx" rel="nofollo... | 1 | 2010-03-01T22:11:24Z | [
"python",
"audio",
"pygame"
] |
Using SWIG with pointer to function in C struct | 1,583,293 | <p>I'm trying to write a SWIG wrapper for a C library that uses pointers to functions in its structs. I can't figure out how to handle structs that contain function pointers. A simplified example follows.</p>
<p>test.i:</p>
<pre><code>/* test.i */
%module test
%{
typedef struct {
int (*my_func)(int);
} test_s... | 3 | 2009-10-17T21:36:33Z | 1,583,346 | <p>You forget to "return t;" in init_test():</p>
<pre><code>#include <stdlib.h>
#include <stdio.h>
typedef struct {
int (*my_func)(int);
} test_struct;
int add1(int n) { return n+1; }
test_struct *init_test(){
test_struct *t = (test_struct*) malloc(sizeof(test_struct));
t->my_func = add1;
return t;
}... | 0 | 2009-10-17T22:05:01Z | [
"python",
"c",
"function",
"pointers",
"swig"
] |
Using SWIG with pointer to function in C struct | 1,583,293 | <p>I'm trying to write a SWIG wrapper for a C library that uses pointers to functions in its structs. I can't figure out how to handle structs that contain function pointers. A simplified example follows.</p>
<p>test.i:</p>
<pre><code>/* test.i */
%module test
%{
typedef struct {
int (*my_func)(int);
} test_s... | 3 | 2009-10-17T21:36:33Z | 1,586,452 | <p>I found an answer. If I declare the function pointer as a SWIG "member function", it seems to work as expected:</p>
<pre><code>%module test
%{
typedef struct {
int (*my_func)(int);
} test_struct;
int add1(int n) { return n+1; }
test_struct *init_test()
{
test_struct *t = (test_struct*) malloc(sizeof(test_... | 1 | 2009-10-19T00:31:42Z | [
"python",
"c",
"function",
"pointers",
"swig"
] |
sqlite3 and cursor.description | 1,583,350 | <p>When using the sqlite3 module in python, all elements of cursor.description except the column names are set to None, so this tuple cannot be used to find the column types for a query result (unlike other DB-API compliant modules). Is the only way to get the types of the columns to use <code>pragma table_info(table_n... | 4 | 2009-10-17T22:11:14Z | 1,583,379 | <p>No, it's not the only way. Alternatively, you can also fetch one row, iterate over it, and inspect the individual column Python objects and types. Unless the value is None (in which case the SQL field is NULL), this should give you a fairly precise indication what the database column type was.</p>
<p>sqlite3 only u... | 4 | 2009-10-17T22:29:59Z | [
"python",
"sqlite",
"python-db-api"
] |
sqlite3 and cursor.description | 1,583,350 | <p>When using the sqlite3 module in python, all elements of cursor.description except the column names are set to None, so this tuple cannot be used to find the column types for a query result (unlike other DB-API compliant modules). Is the only way to get the types of the columns to use <code>pragma table_info(table_n... | 4 | 2009-10-17T22:11:14Z | 1,586,168 | <p>I haven't tried this in Python, but you could try something like</p>
<pre><code>SELECT *
FROM sqlite_master
WHERE type = 'table';
</code></pre>
<p>which contains the DDL CREATE statement used to create the table. By parsing the DDL you can get the column type info, such as it is. Remember that SQLITE is rather vag... | 1 | 2009-10-18T22:12:46Z | [
"python",
"sqlite",
"python-db-api"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 1,583,445 | <p>Not sure whether it is any better than the versions you proposed, however...</p>
<p>If predicate is guaranteed to return True/False only, then</p>
<pre><code>sum(map(predicate, seq)) == 1
</code></pre>
<p>will do (although it won't stop at the second element)</p>
| 2 | 2009-10-17T22:59:08Z | [
"python",
"idioms"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 1,583,450 | <p>Perhaps something like this is more to your taste?</p>
<pre><code>def has_one(seq,predicate=bool):
nwanted=1
n=0
for item in seq:
if predicate(item):
n+=1
if n>nwanted:
return False
return n==nwanted
</code></pre>
<p>This is rather like the list c... | 3 | 2009-10-17T23:01:04Z | [
"python",
"idioms"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 1,583,465 | <p>How about calling <a href="http://docs.python.org/3.1/library/functions.html#any" rel="nofollow"><code>any</code></a> twice, on an iterator (Python 2.x and 3.x compatible)?</p>
<pre><code>>>> def has_one(seq, predicate=bool):
... seq = (predicate(e) for e in seq)
... return any(seq) and not any(seq... | 10 | 2009-10-17T23:09:55Z | [
"python",
"idioms"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 1,583,512 | <p>I liked Stephan202's answer, but I like this one a little more, even though it's two lines instead of one. I like it because it's just as crazy but a tiny bit more explicit about how its craziness works:</p>
<pre><code>def has_one(seq):
g = (x for x in seq)
return any(g) and not any(g)
</code></pre>
<p><s... | 3 | 2009-10-17T23:37:36Z | [
"python",
"idioms"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 1,609,321 | <p>How about ...</p>
<pre><code>import functools
import operator
def exactly_one(seq):
"""
Handy for ensuring that exactly one of a bunch of options has been set.
>>> exactly_one((3, None, 'frotz', None))
False
>>> exactly_one((None, None, 'frotz', None))
True
"""
ret... | 1 | 2009-10-22T19:02:25Z | [
"python",
"idioms"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 1,792,927 | <p>Here's modified <a href="http://stackoverflow.com/questions/1583364/idiomatic-python-hasone/1583465#1583465">@Stephan202's answer</a>:</p>
<pre><code>from itertools import imap, repeat
def exactly_n_is_true(iterable, n, predicate=None):
it = iter(iterable) if predicate is None else imap(predicate, iterable)
... | 0 | 2009-11-24T21:08:06Z | [
"python",
"idioms"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 1,793,199 | <p>Look, Ma! No rtfm("itertools"), no dependency on predicate() returning a boolean, minimum evaluation, just works!</p>
<pre><code>Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> def count_in_bounds(seq, predicate=lambda... | 1 | 2009-11-24T21:56:20Z | [
"python",
"idioms"
] |
Idiomatic Python has_one | 1,583,364 | <p>I just invented a stupid little helper function:</p>
<pre><code>def has_one(seq, predicate=bool):
"""Return whether there is exactly one item in `seq` that matches
`predicate`, with a minimum of evaluation (short-circuit).
"""
iterator = (item for item in seq if predicate(item))
try:
ite... | 3 | 2009-10-17T22:23:15Z | 14,392,813 | <p><a href="http://stackoverflow.com/a/1583450/239657">This</a> and <a href="http://stackoverflow.com/a/1793199/239657">this</a> straightforward counting-loop solutions are definitely clearest.</p>
<p>For the sport of it, here is a variation on the <code>any(g) and not any(g)</code> theme that looks less magic on the ... | 0 | 2013-01-18T05:17:22Z | [
"python",
"idioms"
] |
Apparently my app. runs but I don't see anything | 1,583,437 | <p>I'm learning python and Qt to create graphical desktop apps. I designed the UI with Qt Designer and converted the .ui to .py using pyuic, according to the tutorial I'm following, I should be able to run my app. but when I do it, a terminal window opens and it says:</p>
<pre><code>cd '/Users/andresacevedo/' &&am... | 0 | 2009-10-17T22:54:49Z | 1,583,612 | <p>The problem is that your python code is merely defining a class, but has no main program which invokes the class or causes QT to pop up a window. </p>
<p>It seems a little unusual that your Ui_MainWindow class isn't actually a subclass of QMainWindow; it isn't a widget itself, but it merely configures the MainWind... | 1 | 2009-10-18T00:41:15Z | [
"python",
"osx",
"pyqt"
] |
Apparently my app. runs but I don't see anything | 1,583,437 | <p>I'm learning python and Qt to create graphical desktop apps. I designed the UI with Qt Designer and converted the .ui to .py using pyuic, according to the tutorial I'm following, I should be able to run my app. but when I do it, a terminal window opens and it says:</p>
<pre><code>cd '/Users/andresacevedo/' &&am... | 0 | 2009-10-17T22:54:49Z | 1,584,143 | <p>I'm doing very newbie questions, well because I'm a pyqt newbie... what was happening was that I called pyuic without the -x attribute, so the code just creates the UI but not the code for running it, anyway your help was very valuable.</p>
| 1 | 2009-10-18T06:02:17Z | [
"python",
"osx",
"pyqt"
] |
Apparently my app. runs but I don't see anything | 1,583,437 | <p>I'm learning python and Qt to create graphical desktop apps. I designed the UI with Qt Designer and converted the .ui to .py using pyuic, according to the tutorial I'm following, I should be able to run my app. but when I do it, a terminal window opens and it says:</p>
<pre><code>cd '/Users/andresacevedo/' &&am... | 0 | 2009-10-17T22:54:49Z | 1,584,433 | <p>The code you get from Qt Designer is only a class with set of widgets. It is not an application. See the <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#using-qt-designer" rel="nofollow">PyQt manual</a> for info how to use the Designer code in your applications. I'd suggest to read some ... | 0 | 2009-10-18T09:08:14Z | [
"python",
"osx",
"pyqt"
] |
Storing wiki revisions on Google App Engine/Django - Modifying This Existing Code | 1,583,595 | <p>In the past, I created a Django wiki, and it was fairly straightforward to make a Page table for the current wiki entries, and then to store old revisions into a Revision table.</p>
<p>More recently, I decided to set up a website on Google App Engine, and I used some wiki code that another programmer wrote. Because... | 0 | 2009-10-18T00:29:40Z | 1,585,411 | <p>The code in your first snippet is not a model - it's a custom class that uses the low-level datastore module. If you want to extend it, I would recommend throwing it out and replacing it with actual models, along similar lines to the Article model you demonstrated in your second snippet.</p>
<p>Also, they're App En... | 1 | 2009-10-18T16:51:43Z | [
"python",
"django",
"google-app-engine",
"django-models"
] |
Storing wiki revisions on Google App Engine/Django - Modifying This Existing Code | 1,583,595 | <p>In the past, I created a Django wiki, and it was fairly straightforward to make a Page table for the current wiki entries, and then to store old revisions into a Revision table.</p>
<p>More recently, I decided to set up a website on Google App Engine, and I used some wiki code that another programmer wrote. Because... | 0 | 2009-10-18T00:29:40Z | 1,585,978 | <p>I created this model (which mimics the Page class):</p>
<pre><code>class Revision (db.Model):
name = db.StringProperty(required=True)
created = db.DateTimeProperty(required=True)
modified = db.DateTimeProperty(auto_now_add=True)
content = db.TextProperty(required=True)
user = db.UserProperty()
</code></pr... | 0 | 2009-10-18T20:40:32Z | [
"python",
"django",
"google-app-engine",
"django-models"
] |
What does "lambda" mean in Python, and what's the simplest way to use it? | 1,583,617 | <p>Can you give an example and other examples that show when and when not to use Lambda?
My book gives me examples, but they're confusing.</p>
| 10 | 2009-10-18T00:44:25Z | 1,583,629 | <p>I do not know which book you are using, but <a href="http://www.diveintopython.org/power%5Fof%5Fintrospection/lambda%5Ffunctions.html" rel="nofollow"><em>Dive into Python</em> has a section</a> which I think is informative.</p>
| 3 | 2009-10-18T00:50:07Z | [
"python",
"lambda"
] |
What does "lambda" mean in Python, and what's the simplest way to use it? | 1,583,617 | <p>Can you give an example and other examples that show when and when not to use Lambda?
My book gives me examples, but they're confusing.</p>
| 10 | 2009-10-18T00:44:25Z | 1,583,630 | <p>Lambda, which originated from <a href="http://en.wikipedia.org/wiki/Lambda%5Fcalculus">Lambda Calculus</a> and (AFAIK) was first implemented in <a href="http://en.wikipedia.org/wiki/Lisp%5F%28programming%5Flanguage%29">Lisp</a>, is basically an anonymous function - a function which doesn't have a name, and is used i... | 26 | 2009-10-18T00:50:12Z | [
"python",
"lambda"
] |
What does "lambda" mean in Python, and what's the simplest way to use it? | 1,583,617 | <p>Can you give an example and other examples that show when and when not to use Lambda?
My book gives me examples, but they're confusing.</p>
| 10 | 2009-10-18T00:44:25Z | 1,584,145 | <p>Use of lambda is sort of a style thing. When you can get away with a very simple function, and usually where you are just storing it somewhere (in a list of functions perhaps, or in a GUI toolkit data structure, etc.) people feel lambda reduces clutter in their code.</p>
<p>In Python it is only possible to make a ... | 2 | 2009-10-18T06:03:08Z | [
"python",
"lambda"
] |
Possible Data Schemes for Achievements on Google App Engine | 1,583,808 | <p>I'm building a flash game website using Google App Engine. I'm going to put achievements on it, and am scratching my head on how exactly to store this data. I have a (non-google) user model. I need to know how to store each kind of achievement (name, description, picture), as well as link them with users who earn th... | 1 | 2009-10-18T02:12:09Z | 1,583,865 | <p>Unless your users will be adding achievements dynamically (as in something like Kongregate where users can upload their own games, etc), your achievement list will be static. That means you can store the (name, description, picture) list in your main python file, or as an achievements module or something. You can re... | 2 | 2009-10-18T02:58:49Z | [
"python",
"google-app-engine",
"website",
"achievements"
] |
Possible Data Schemes for Achievements on Google App Engine | 1,583,808 | <p>I'm building a flash game website using Google App Engine. I'm going to put achievements on it, and am scratching my head on how exactly to store this data. I have a (non-google) user model. I need to know how to store each kind of achievement (name, description, picture), as well as link them with users who earn th... | 1 | 2009-10-18T02:12:09Z | 3,249,319 | <p>Building on Brandon's answer here.</p>
<p>If you can, it would be MUCH faster to define all the achievements in the Python files, so they are in-memory and require no database fetching. This is also simpler to implement.</p>
<pre><code>class StaticAchievement(object):
"""
An achievement defined in a Python... | 3 | 2010-07-14T18:41:34Z | [
"python",
"google-app-engine",
"website",
"achievements"
] |
activestate pythonwin missing import modules? | 1,583,947 | <p>I'm working my way through DiveIntoPython.com and I'm having trouble getting the import to work. I've installed ActiveState's Pythonwin on a windows xp prof environment. </p>
<p>In the website, there is an exercise which involves 'import odbchelper' and odbchelper.<strong>name</strong></p>
<p><a href="http://ww... | 1 | 2009-10-18T03:46:13Z | 1,583,953 | <p>This module doesn't come packaged with Python2.6 for sure (just tried on my machine). Have you tried googling where this module might be?</p>
<p>Consider this <a href="http://ubuntuforums.org/showthread.php?t=487584" rel="nofollow">post</a>.</p>
| 1 | 2009-10-18T03:50:02Z | [
"python",
"import"
] |
activestate pythonwin missing import modules? | 1,583,947 | <p>I'm working my way through DiveIntoPython.com and I'm having trouble getting the import to work. I've installed ActiveState's Pythonwin on a windows xp prof environment. </p>
<p>In the website, there is an exercise which involves 'import odbchelper' and odbchelper.<strong>name</strong></p>
<p><a href="http://ww... | 1 | 2009-10-18T03:46:13Z | 1,583,961 | <p>figured it out.. </p>
<p>found this: </p>
<pre><code>http://www.faqs.org/docs/diveintopython/odbchelper_divein.html
</code></pre>
<p>downloaded the file and then put it into a folder. c:\temp\python\ in my case with the commands: </p>
<pre><code>>> import sys
>> sys.path.append('c:\\temp\\python\\'... | 1 | 2009-10-18T03:55:25Z | [
"python",
"import"
] |
Python xpath not working? | 1,584,180 | <p>Okay, this is starting to drive me a little bit nuts. I've tried several xml/xpath libraries for Python, and can't figure out a simple way to get a stinkin' "title" element.</p>
<p>The latest attempt looks like this (using Amara):</p>
<pre><code>def view(req, url):
req.content_type = 'text/plain'
doc = ama... | 0 | 2009-10-18T06:35:28Z | 1,584,194 | <p>You probably just have to take into account the namespace of the document which you're dealing with.</p>
<p>I'd suggest looking up how to deal with namespaces in Amara:</p>
<p><a href="http://www.xml3k.org/Amara/Manual#namespaces" rel="nofollow">http://www.xml3k.org/Amara/Manual#namespaces</a></p>
<p>Edit: Using ... | 1 | 2009-10-18T06:46:57Z | [
"python",
"xml",
"xpath",
"xml-namespaces",
"amara"
] |
Python xpath not working? | 1,584,180 | <p>Okay, this is starting to drive me a little bit nuts. I've tried several xml/xpath libraries for Python, and can't figure out a simple way to get a stinkin' "title" element.</p>
<p>The latest attempt looks like this (using Amara):</p>
<pre><code>def view(req, url):
req.content_type = 'text/plain'
doc = ama... | 0 | 2009-10-18T06:35:28Z | 1,584,226 | <p>It is indeed the namespaces. It was a bit tricky to find in the lxml docs, but here's how you do it:</p>
<pre><code>from lxml import etree
doc = etree.parse(open('index.html'))
doc.xpath('//default:title', namespaces={'default':'http://www.w3.org/2005/Atom'})
</code></pre>
<p>You can also do this:</p>
<pre><code>... | 1 | 2009-10-18T07:08:03Z | [
"python",
"xml",
"xpath",
"xml-namespaces",
"amara"
] |
Unit testing a method called during initialization? | 1,584,220 | <p>I have a class like the following:</p>
<pre><code>class Positive(object):
def __init__(self, item):
self._validate_item(item)
self.item = item
def _validate_item(self, item):
if item <= 0:
raise ValueError("item should be positive.")
</code></pre>
<p>I'd like to writ... | 1 | 2009-10-18T07:03:13Z | 1,584,244 | <p>You're not creating an instance of Positive. How about</p>
<pre><code>Positive()._validate_item, 0
</code></pre>
| 1 | 2009-10-18T07:21:02Z | [
"python",
"unit-testing",
"oop",
"testing"
] |
Unit testing a method called during initialization? | 1,584,220 | <p>I have a class like the following:</p>
<pre><code>class Positive(object):
def __init__(self, item):
self._validate_item(item)
self.item = item
def _validate_item(self, item):
if item <= 0:
raise ValueError("item should be positive.")
</code></pre>
<p>I'd like to writ... | 1 | 2009-10-18T07:03:13Z | 1,584,246 | <p>If you're not using self in the method's body, it's a hint that it might not need to be a class member. You can either move the _validate_item function into module scope:</p>
<pre><code>def _validate_item(item):
if item <= 0:
raise ValueError("item should be positive.")
</code></pre>
<p>Or if it re... | 7 | 2009-10-18T07:21:47Z | [
"python",
"unit-testing",
"oop",
"testing"
] |
Unit testing a method called during initialization? | 1,584,220 | <p>I have a class like the following:</p>
<pre><code>class Positive(object):
def __init__(self, item):
self._validate_item(item)
self.item = item
def _validate_item(self, item):
if item <= 0:
raise ValueError("item should be positive.")
</code></pre>
<p>I'd like to writ... | 1 | 2009-10-18T07:03:13Z | 1,584,352 | <p>Well, _validate_item() is tested through the constructor. Invoking it with a null or negative value will raise the ValueError exception.</p>
<p>Taking a step back, that's the goal no ? The "requirement" is that object shall not be created with a zero or negative value. </p>
<p>Now this is a contrived example, so ... | 1 | 2009-10-18T08:21:06Z | [
"python",
"unit-testing",
"oop",
"testing"
] |
google wave OnBlipSubmitted | 1,584,406 | <p>I'm trying to create a wave robot, and I have the basic stuff working. I'm trying to create a new blip with help text when someone types @help but for some reason it doesnt create it. I'm getting no errors in the log console, and I'm seeing the info log 'in @log'</p>
<pre><code>def OnBlipSubmitted(properties, conte... | 1 | 2009-10-18T08:53:41Z | 1,584,416 | <p>Have you tried using <code>Append()</code> instead of <code>SetText()</code>? That's what I'd do in my C# API - I haven't used the Python API, but I'd imagine it's similar. Here's a sample from my demo robot:</p>
<pre><code>protected override void OnBlipSubmitted(IEvent e)
{
if (e.Blip.Document.Text.Contains("r... | 0 | 2009-10-18T08:59:04Z | [
"python",
"google-app-engine",
"google-wave"
] |
google wave OnBlipSubmitted | 1,584,406 | <p>I'm trying to create a wave robot, and I have the basic stuff working. I'm trying to create a new blip with help text when someone types @help but for some reason it doesnt create it. I'm getting no errors in the log console, and I'm seeing the info log 'in @log'</p>
<pre><code>def OnBlipSubmitted(properties, conte... | 1 | 2009-10-18T08:53:41Z | 1,585,179 | <p>For some reason it just started working. I think the google wave is spotty.</p>
| 0 | 2009-10-18T15:35:07Z | [
"python",
"google-app-engine",
"google-wave"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.