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 |
|---|---|---|---|---|---|---|---|---|---|
How to make a completely unshared copy of a complicated list? (Deep copy is not enough) | 1,601,269 | <p>Have a look at this Python code:</p>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
c = [[a, b], [b, a]] # [[[1, 2, 3], [4, 5, 6]], [[4, 5, 6], [1, 2, 3]]]
c[0][0].append(99) # [[[1, 2, 3, 99], [4, 5, 6]], [[4, 5, 6], [1, 2, 3, 99]]]
</code></pre>
<p>Notice how modifying one element of <code>c</code> modifies that every... | 5 | 2009-10-21T14:38:27Z | 1,601,304 | <p>Depending on you situation, you might want to work against a <a href="http://docs.python.org/library/copy.html" rel="nofollow">deep copy</a> of this list.</p>
| 5 | 2009-10-21T14:42:59Z | [
"python",
"list",
"copy"
] |
How to make a completely unshared copy of a complicated list? (Deep copy is not enough) | 1,601,269 | <p>Have a look at this Python code:</p>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
c = [[a, b], [b, a]] # [[[1, 2, 3], [4, 5, 6]], [[4, 5, 6], [1, 2, 3]]]
c[0][0].append(99) # [[[1, 2, 3, 99], [4, 5, 6]], [[4, 5, 6], [1, 2, 3, 99]]]
</code></pre>
<p>Notice how modifying one element of <code>c</code> modifies that every... | 5 | 2009-10-21T14:38:27Z | 1,601,334 | <p>When you want a copy, you explicitly make a copy - the cryptical <code>[:]</code> "slice it all" form is idiomatic, but my favorite is the much-more-readable approach of explicitly calling <code>list</code>.</p>
<p>If <code>c</code> is constructed in the wrong way (with references instead of shallow copies to lists... | 7 | 2009-10-21T14:47:25Z | [
"python",
"list",
"copy"
] |
How to make a completely unshared copy of a complicated list? (Deep copy is not enough) | 1,601,269 | <p>Have a look at this Python code:</p>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
c = [[a, b], [b, a]] # [[[1, 2, 3], [4, 5, 6]], [[4, 5, 6], [1, 2, 3]]]
c[0][0].append(99) # [[[1, 2, 3, 99], [4, 5, 6]], [[4, 5, 6], [1, 2, 3, 99]]]
</code></pre>
<p>Notice how modifying one element of <code>c</code> modifies that every... | 5 | 2009-10-21T14:38:27Z | 1,601,335 | <p>To see Stephan's suggestion at work, compare the two outputs below:</p>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
c = [[a, b], [b, a]]
c[0][0].append(99)
print c
print "-------------------"
a = [1, 2, 3]
b = [4, 5, 6]
c = [[a[:], b[:]], [b[:], a[:]]]
c[0][0].append(99)
print c
</code></pre>
<p>The output is as follow... | 1 | 2009-10-21T14:47:28Z | [
"python",
"list",
"copy"
] |
How to make a completely unshared copy of a complicated list? (Deep copy is not enough) | 1,601,269 | <p>Have a look at this Python code:</p>
<pre><code>a = [1, 2, 3]
b = [4, 5, 6]
c = [[a, b], [b, a]] # [[[1, 2, 3], [4, 5, 6]], [[4, 5, 6], [1, 2, 3]]]
c[0][0].append(99) # [[[1, 2, 3, 99], [4, 5, 6]], [[4, 5, 6], [1, 2, 3, 99]]]
</code></pre>
<p>Notice how modifying one element of <code>c</code> modifies that every... | 5 | 2009-10-21T14:38:27Z | 1,601,774 | <p>To convert an existing list of lists to one where nothing is shared, you could recursively copy the list.</p>
<p><code>deepcopy</code> will not be sufficient, as it will copy the structure as-is, keeping <em>internal</em> references as references, not copies.</p>
<pre><code>def unshared_copy(inList):
if isinst... | 7 | 2009-10-21T15:49:41Z | [
"python",
"list",
"copy"
] |
Is there a way to tell whether a function is getting executed in a unittest? | 1,601,308 | <p>I'm using a config file to get the info for my database. It always gets the hostname and then figures out what database options to use from this config file. I want to be able to tell if I'm inside a unittest here and use the in memory sqlite database instead. Is there a way to tell at that point whether I'm insi... | 1 | 2009-10-21T14:43:36Z | 1,601,322 | <p>Inject your database dependency into your class using IoC. This should be done by handing it a repository object in the constructor of your class. Note that you don't necessarily need an IoC container to do this. You just need a repository interface and two implementations of your repository.</p>
<p>Note: In Py... | 3 | 2009-10-21T14:45:48Z | [
"python",
"unit-testing",
"sqlite"
] |
Is there a way to tell whether a function is getting executed in a unittest? | 1,601,308 | <p>I'm using a config file to get the info for my database. It always gets the hostname and then figures out what database options to use from this config file. I want to be able to tell if I'm inside a unittest here and use the in memory sqlite database instead. Is there a way to tell at that point whether I'm insi... | 1 | 2009-10-21T14:43:36Z | 1,601,336 | <p>This is kind of brute force but it works. Have an environmental variable UNIT_TEST that your code checks, and set it inside your unit test driver.</p>
| 0 | 2009-10-21T14:47:29Z | [
"python",
"unit-testing",
"sqlite"
] |
Is there a way to tell whether a function is getting executed in a unittest? | 1,601,308 | <p>I'm using a config file to get the info for my database. It always gets the hostname and then figures out what database options to use from this config file. I want to be able to tell if I'm inside a unittest here and use the in memory sqlite database instead. Is there a way to tell at that point whether I'm insi... | 1 | 2009-10-21T14:43:36Z | 1,601,338 | <p>Use some sort of database configuration and configure which database to use, and configure the in-memory database during unit tests.</p>
| 1 | 2009-10-21T14:47:36Z | [
"python",
"unit-testing",
"sqlite"
] |
Is there a way to tell whether a function is getting executed in a unittest? | 1,601,308 | <p>I'm using a config file to get the info for my database. It always gets the hostname and then figures out what database options to use from this config file. I want to be able to tell if I'm inside a unittest here and use the in memory sqlite database instead. Is there a way to tell at that point whether I'm insi... | 1 | 2009-10-21T14:43:36Z | 1,601,351 | <p>As Robert Harvey points out, it would be better if you could hand the settings to the component instead of having the component looking it up itself. This allows you to swap the settings simply by providing another object, i.e</p>
<pre><code>TestComponent(TestSettings())
</code></pre>
<p>instead of</p>
<pre><code... | 0 | 2009-10-21T14:49:29Z | [
"python",
"unit-testing",
"sqlite"
] |
Is there a way to tell whether a function is getting executed in a unittest? | 1,601,308 | <p>I'm using a config file to get the info for my database. It always gets the hostname and then figures out what database options to use from this config file. I want to be able to tell if I'm inside a unittest here and use the in memory sqlite database instead. Is there a way to tell at that point whether I'm insi... | 1 | 2009-10-21T14:43:36Z | 1,601,370 | <p>I recommend using a mocking library such as <a href="http://labix.org/mocker" rel="nofollow">mocker</a>. And FYI, writing your code to check and see if you're in a unit test is a <em>bad</em> code smell. Your unit tests should be executing the code that's being tested as you wrote it.</p>
| 0 | 2009-10-21T14:52:21Z | [
"python",
"unit-testing",
"sqlite"
] |
Foreign key needs a value from the key's table to match a column in another table | 1,601,586 | <p>Pardon the excessive amount of code, but I'm not sure if I can explain my question otherwise</p>
<p>I have a Django project that I am working on which has the following:</p>
<pre><code>class Project(models.Model):
name = models.CharField(max_length=100, unique=True)
dir = models.CharField(max_length=300, blank=... | 0 | 2009-10-21T15:21:24Z | 1,601,795 | <p>I'm sure you could do it at the PostgreSQL level with a <a href="http://www.postgresql.org/docs/8.4/interactive/triggers.html" rel="nofollow">trigger</a>, which you could add to a <a href="http://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data" rel="nofollow">Django initial-SQL file</a> ... | 1 | 2009-10-21T15:54:42Z | [
"python",
"database",
"django"
] |
Foreign key needs a value from the key's table to match a column in another table | 1,601,586 | <p>Pardon the excessive amount of code, but I'm not sure if I can explain my question otherwise</p>
<p>I have a Django project that I am working on which has the following:</p>
<pre><code>class Project(models.Model):
name = models.CharField(max_length=100, unique=True)
dir = models.CharField(max_length=300, blank=... | 0 | 2009-10-21T15:21:24Z | 1,602,490 | <p>You could use the <code>pre_save</code> signal and raise an error if they do no match... The effect would be similar to overridding save (it gets called before save)</p>
<p>The problem is creating/deleting/updating the many-to-many relation will not trigger save (or consequentially <code>pre_save</code> or <code>po... | 2 | 2009-10-21T17:59:06Z | [
"python",
"database",
"django"
] |
python contour for binary 2D matrix | 1,601,613 | <p>I want to calculate a convex hull around a shape in a binary NxM matrix. The convex hull algorithm expects a list of coordinates, so I take numpy.argwhere(im) to have all shape point coordinates. However, most of those points are not contributing to the convex hull (they lie on the inside of the shape). Because conv... | 4 | 2009-10-21T15:25:55Z | 1,602,285 | <p>This assignment seems to accomplish the same thing as your last two steps:</p>
<pre><code>outline = np.array(dict(reversed(coords)).items() + dict(coords).items())
</code></pre>
<p>Don't know if it's any faster, however.</p>
| 0 | 2009-10-21T17:22:54Z | [
"python",
"algorithm",
"numpy",
"contour"
] |
python contour for binary 2D matrix | 1,601,613 | <p>I want to calculate a convex hull around a shape in a binary NxM matrix. The convex hull algorithm expects a list of coordinates, so I take numpy.argwhere(im) to have all shape point coordinates. However, most of those points are not contributing to the convex hull (they lie on the inside of the shape). Because conv... | 4 | 2009-10-21T15:25:55Z | 1,603,760 | <p>For more general solution, you could use somekind of edge detection method to find only the edge points. I believe (Google..) that NumPy has built-in sobel filter, which will do that.</p>
| 0 | 2009-10-21T21:24:00Z | [
"python",
"algorithm",
"numpy",
"contour"
] |
python contour for binary 2D matrix | 1,601,613 | <p>I want to calculate a convex hull around a shape in a binary NxM matrix. The convex hull algorithm expects a list of coordinates, so I take numpy.argwhere(im) to have all shape point coordinates. However, most of those points are not contributing to the convex hull (they lie on the inside of the shape). Because conv... | 4 | 2009-10-21T15:25:55Z | 1,721,641 | <p>In the absence of an acceptable answer I post my best working code as the solution.</p>
<pre><code>def outline(im):
''' Input binary 2D (NxM) image. Ouput array (2xK) of K (y,x) coordinates
where 0 <= K <= 2*M.
'''
topbottom = np.empty((1,2*im.shape[1]), dtype=np.uint16)
topbottom[0,0:... | 1 | 2009-11-12T11:41:43Z | [
"python",
"algorithm",
"numpy",
"contour"
] |
Python Cherrypy Access Log Rotation | 1,601,665 | <p>If I want the access log for Cherrypy to only get to a fixed size, how would I go about using rotating log files?</p>
<p>I've already tried <a href="http://www.cherrypy.org/wiki/Logging" rel="nofollow">http://www.cherrypy.org/wiki/Logging</a>, which seems out of date, or has information missing.</p>
| 3 | 2009-10-21T15:33:14Z | 1,601,679 | <p>Look at <a href="http://docs.python.org/library/logging.html" rel="nofollow">http://docs.python.org/library/logging.html</a>.</p>
<p>You probably want to configure a RotatingFileHandler</p>
<p><a href="http://docs.python.org/library/logging.html#rotatingfilehandler" rel="nofollow">http://docs.python.org/library/lo... | 4 | 2009-10-21T15:35:47Z | [
"python",
"cherrypy",
"logging"
] |
Python Cherrypy Access Log Rotation | 1,601,665 | <p>If I want the access log for Cherrypy to only get to a fixed size, how would I go about using rotating log files?</p>
<p>I've already tried <a href="http://www.cherrypy.org/wiki/Logging" rel="nofollow">http://www.cherrypy.org/wiki/Logging</a>, which seems out of date, or has information missing.</p>
| 3 | 2009-10-21T15:33:14Z | 1,601,705 | <p>Cherrypy does its logging using the standard Python logging module. You will need to change it to use a <a href="http://docs.python.org/library/logging.html#rotatingfilehandler" rel="nofollow">RotatingFileHandler</a>. This handler will take care of everything for you including rotating the log when it reaches a set ... | 2 | 2009-10-21T15:40:21Z | [
"python",
"cherrypy",
"logging"
] |
Python Cherrypy Access Log Rotation | 1,601,665 | <p>If I want the access log for Cherrypy to only get to a fixed size, how would I go about using rotating log files?</p>
<p>I've already tried <a href="http://www.cherrypy.org/wiki/Logging" rel="nofollow">http://www.cherrypy.org/wiki/Logging</a>, which seems out of date, or has information missing.</p>
| 3 | 2009-10-21T15:33:14Z | 2,093,163 | <blockquote>
<p>I've already tried <a href="http://www.cherrypy.org/wiki/Logging" rel="nofollow">http://www.cherrypy.org/wiki/Logging</a>, which seems
out of date, or has information missing.</p>
</blockquote>
<p>Try adding:</p>
<pre><code>import logging
import logging.handlers
import cherrypy # you might have i... | 3 | 2010-01-19T11:44:54Z | [
"python",
"cherrypy",
"logging"
] |
Python Cherrypy Access Log Rotation | 1,601,665 | <p>If I want the access log for Cherrypy to only get to a fixed size, how would I go about using rotating log files?</p>
<p>I've already tried <a href="http://www.cherrypy.org/wiki/Logging" rel="nofollow">http://www.cherrypy.org/wiki/Logging</a>, which seems out of date, or has information missing.</p>
| 3 | 2009-10-21T15:33:14Z | 26,975,707 | <p>The CherryPy documentation of the <a href="http://cherrypy.readthedocs.org/en/latest/pkg/cherrypy.html#custom-handlers" rel="nofollow">custom log handlers</a> shows this very example.</p>
<p>Here is the slightly modified version that I use on my app:</p>
<pre><code>import logging
from logging import handlers
def ... | 2 | 2014-11-17T15:11:52Z | [
"python",
"cherrypy",
"logging"
] |
Recursion - Python, return value question | 1,601,757 | <p>I realize that this may sound like a silly question, but the last time I programmed it was in assembler so my thinking may be off:</p>
<p>A recursive function as so:</p>
<pre><code>def fac(n):
if n == 0:
return 1
else:
return n * fac(n - 1)
</code></pre>
<p>Why is it that when the function... | 3 | 2009-10-21T15:46:44Z | 1,601,786 | <p>It <strong>does</strong> return 1 when n == 0. That return value is popped off the stack from the calling site, which was the invocation at <code>n * fac(n - 1)</code>. That <code>1</code> is multiplied by <code>n</code> and returned, etc.</p>
| 1 | 2009-10-21T15:52:45Z | [
"python",
"recursion",
"stack"
] |
Recursion - Python, return value question | 1,601,757 | <p>I realize that this may sound like a silly question, but the last time I programmed it was in assembler so my thinking may be off:</p>
<p>A recursive function as so:</p>
<pre><code>def fac(n):
if n == 0:
return 1
else:
return n * fac(n - 1)
</code></pre>
<p>Why is it that when the function... | 3 | 2009-10-21T15:46:44Z | 1,601,799 | <p>Think about like this, for <code>fac(5)</code> for example:</p>
<pre><code>return 5 * fac(4)
return 4 * fac(3)
return 3 * fac(2)
return 2 * fac(1)
return 1 * fac(0)
... | 12 | 2009-10-21T15:55:19Z | [
"python",
"recursion",
"stack"
] |
Recursion - Python, return value question | 1,601,757 | <p>I realize that this may sound like a silly question, but the last time I programmed it was in assembler so my thinking may be off:</p>
<p>A recursive function as so:</p>
<pre><code>def fac(n):
if n == 0:
return 1
else:
return n * fac(n - 1)
</code></pre>
<p>Why is it that when the function... | 3 | 2009-10-21T15:46:44Z | 1,601,802 | <p>If you call fac(0) it will return 1 (not 0, but I suppose that's just a typo in your question). If you call fac(1), it will go in the else clause, and there it will call <code>fac(0)</code>. This will return 1. It will then calculate n*1, which is 1, and return that. If you call <code>fac(2)</code> it will also go i... | 0 | 2009-10-21T15:55:41Z | [
"python",
"recursion",
"stack"
] |
Recursion - Python, return value question | 1,601,757 | <p>I realize that this may sound like a silly question, but the last time I programmed it was in assembler so my thinking may be off:</p>
<p>A recursive function as so:</p>
<pre><code>def fac(n):
if n == 0:
return 1
else:
return n * fac(n - 1)
</code></pre>
<p>Why is it that when the function... | 3 | 2009-10-21T15:46:44Z | 1,601,814 | <p>Nothing's being implicitely returned - when n=0, the function is entering the if statement, and returning 1 directly from the <code>return 1</code> statement.
However, this isn't the point at which the "answer which is the factorial" is returned to the user. Instead, it may be returning this value to the
<em>callin... | 0 | 2009-10-21T15:57:56Z | [
"python",
"recursion",
"stack"
] |
Recursion - Python, return value question | 1,601,757 | <p>I realize that this may sound like a silly question, but the last time I programmed it was in assembler so my thinking may be off:</p>
<p>A recursive function as so:</p>
<pre><code>def fac(n):
if n == 0:
return 1
else:
return n * fac(n - 1)
</code></pre>
<p>Why is it that when the function... | 3 | 2009-10-21T15:46:44Z | 1,601,885 | <p>James, when the final call to your function (when n==0) returns it's just one of several instances of fac(n) on the call stack. If you say print(fac(4)), the stack is essentially:</p>
<pre><code>fac(0)
fac(1)
fac(2)
fac(3)
fac(4)
print()
</code></pre>
<p>The final call to fac(0) appropriately returns 1, however in... | 0 | 2009-10-21T16:08:40Z | [
"python",
"recursion",
"stack"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,601,907 | <p>Because embedded devices mostly have limited resources where it is not welcome to have luxury such as automatic garbage collector. C/C++ allows you to work on quite low levels and program close to machine so that you get effective code as very much needed on those devices.</p>
<p>One more area where high-level lang... | 14 | 2009-10-21T16:12:50Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,601,917 | <p>You can do robotics with Java on the Mindstorm robots and MS has a push for doing robotics, but to a large extent C/C++ is used due to limited resources, and LISP is used for AI because for a long time this was an area of research and researchers were the main users of LISP, so they used the language they knew.</p>
... | 11 | 2009-10-21T16:15:14Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,601,985 | <blockquote>
<p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications?</p>
</blockquote>
<p>I presume it's about space requirements, performance and reliability. </p>
<blockquote>
<p>For e... | 1 | 2009-10-21T16:27:48Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,602,031 | <p>My guess is that C/C++ are used because they are closer to the hardware and allow for resource-aware programming. This is generally true for all embedded projects, not just robotics.</p>
<p>Then I guess that LISP is often chosen, because it still seems the predominant language in artificial intelligence research. L... | 5 | 2009-10-21T16:36:55Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,602,139 | <p>I once built a robot based on Java. It garbage collected right into a wall. </p>
<p>If you're going to have processes running that you can't micromanage (eg, a Linux based system) then they must know to yield to certain high priority processes like motion control. So either you do it yourself in a low level languag... | 45 | 2009-10-21T16:54:20Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,602,365 | <p>Most commercial and industrial robots are programmed in C or C++. There maybe another language that the user interacts with. For example The industrial robot company I work for uses C running in a VxWork OS, but the applications programmers like me work with a proprietary language for commanding the robot. Both C an... | 0 | 2009-10-21T17:35:45Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,602,386 | <p>The main reason for the prevalence of C and C++ is that the runtime is deterministic for both due to the lack of garbage collection requirements. This makes it a good choice when you have to provide runtime guarantees. Not too mention that C has been considered the "higher level assembly language" of choice for ma... | 2 | 2009-10-21T17:40:51Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,602,575 | <p>Having worked with robotics, my answer is efficiency. Yes, you can run a Java Virtual Machine on cell phones. But how efficient will it be? I was on a team that wanted to run a Java Virtual Machine on a full Windows XP machine on a robot, running multiple realtime monitoring applications in Matlab. Needless to say, ... | 0 | 2009-10-21T18:11:58Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,602,925 | <ul>
<li><p>As others have pointed out already, C and C++ are used because they are low-level. Another reason for C's popularity is that just about every architecture gets a C compiler targeted for it. This is good enough for a lot of people, so extra effort isn't often put into other languages. This is sort of like... | 27 | 2009-10-21T19:04:03Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,604,222 | <p>Lisp is/was used in some research and some commercial robots. iRobot for example uses it. Here is an older article about their Common Lisp variant called <a href="http://www.cs.cmu.edu/~chuck/pubpg/LUV-1995.html" rel="nofollow">L</a> (<- Link).</p>
<p>Lisp is used when there is need for special higher level libr... | 2 | 2009-10-21T23:30:30Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,608,682 | <p>In 20 years in embedded systems (including 8 years on a commercial robotics project), I have never seen Lisp used anywhere and would not regard it as 'prevalent'. I seen far more Ada for example. I would say that it is a niche, but if you happen to be working in that niche, it might <em>look</em> prevalent to you.<... | 12 | 2009-10-22T17:17:42Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,608,712 | <ul>
<li><p>Embedded system needs a bare minimum OS and simple (not always) Application, since most OS-es are "C" its a natural choice</p></li>
<li><p>Scarcity of Processing/Memory resource force optimization from very low-level. C (edge over C++) has a great scope of Optimization</p></li>
</ul>
| 0 | 2009-10-22T17:24:27Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,624,375 | <p>I just read some introductory Erlang materials and one of the first things they said was that Erlang was suitable for "Soft" real-time control. This is not something that I would want in any robot near me. </p>
<p>In addition I would say that robots (as in industrial) currently have no real need for hot swapped c... | 1 | 2009-10-26T11:52:27Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 1,776,810 | <p>I once fell over this interesting snippet on using Lisp at NASA: <a href="http://www.flownet.com/gat/jpl-lisp.html">http://www.flownet.com/gat/jpl-lisp.html</a></p>
<blockquote>
<p>In 1994 JPL started working on the
Remote Agent (RA), an autonomous
spacecraft control system. RA was
written entirely in Comm... | 10 | 2009-11-21T21:15:06Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
Why are C, C++, and LISP so prevalent in embedded devices and robots? | 1,601,893 | <p>It seems that the software language skills most sought for embedded devices and robots are C, C++, and LISP. Why haven't more recent languages made inroads into these applications? </p>
<p>For example, <a href="http://www.erlang.org/">Erlang</a> would seem particularly well-suited to robotic applications, since it... | 18 | 2009-10-21T16:10:20Z | 2,790,905 | <p>Java made another milestone this year when it became <a href="http://labs.oracle.com/spotlight/2010/2010-01-26_javaonfirst.html" rel="nofollow">a programming option for the FIRST Robotics Competition</a>. FRC is an impressive competition involving over 77,000 high-school students, mentors, and volunteers from around... | 0 | 2010-05-07T18:44:43Z | [
"python",
"embedded",
"erlang",
"lisp",
"robotics"
] |
In python's tkinter, how can I make a Label such that you can select the text with the mouse? | 1,602,106 | <p>In python's tkinter interface, is there a configuration option that will change a Label such that you can select the text in the Label and then copy it to the clipboard?</p>
<p>EDIT:</p>
<p>How would you modify this "hello world" app to provide such functionality?</p>
<pre><code>from Tkinter import *
master = Tk... | 3 | 2009-10-21T16:49:13Z | 1,602,312 | <p>The easiest way is to use a disabled text widget with a height of 1 line:</p>
<pre><code>from Tkinter import *
master = Tk()
w = Text(master, height=1, borderwidth=0)
w.insert(1.0, "Hello, world!")
w.pack()
w.configure(state="disabled")
# if tkinter is 8.5 or above you'll want the selection background
# to app... | 6 | 2009-10-21T17:26:49Z | [
"python",
"tkinter"
] |
In python's tkinter, how can I make a Label such that you can select the text with the mouse? | 1,602,106 | <p>In python's tkinter interface, is there a configuration option that will change a Label such that you can select the text in the Label and then copy it to the clipboard?</p>
<p>EDIT:</p>
<p>How would you modify this "hello world" app to provide such functionality?</p>
<pre><code>from Tkinter import *
master = Tk... | 3 | 2009-10-21T16:49:13Z | 3,799,914 | <p>Made some changes to the above code:</p>
<pre><code>from tkinter import *
master = Tk()
w = Text(master, height=1)
w.insert(1.0, "Hello, world!")
w.pack()
# if tkinter is 8.5 or above you'll want the selection background
# to appear like it does when the widget is activated
# comment this out for older version... | 4 | 2010-09-26T21:33:59Z | [
"python",
"tkinter"
] |
Casting vs. coercion in Python | 1,602,122 | <p>In the Python documentation and on mailing lists I see that values are sometimes "cast", and sometimes "coerced". What is the difference? </p>
| 23 | 2009-10-21T16:51:30Z | 1,602,151 | <p>I think "casting" shouldn't be used for Python; there are only type conversion, but no casts (in the C sense). A type conversion is done e.g. through <code>int(o)</code> where the object o is converted into an integer (actually, an integer object is constructed out of o). Coercion happens in the case of binary opera... | 26 | 2009-10-21T16:55:57Z | [
"python",
"casting",
"types",
"coercion"
] |
Casting vs. coercion in Python | 1,602,122 | <p>In the Python documentation and on mailing lists I see that values are sometimes "cast", and sometimes "coerced". What is the difference? </p>
| 23 | 2009-10-21T16:51:30Z | 1,602,216 | <p>Cast is explicit. Coerce is implicit.</p>
<p>The examples in Python would be:</p>
<pre><code>cast(2, POINTER(c_float)) #cast
1.0 + 2 #coerce
1.0 + float(2) #conversion
</code></pre>
<p>Cast really only comes up in the C FFI. What is typically called casting in C or Java is referred to as conversion in python, ... | 34 | 2009-10-21T17:11:03Z | [
"python",
"casting",
"types",
"coercion"
] |
Python compute cluster | 1,602,177 | <p>Would it be possible to make a python cluster, by writing a telnet server, then telnet-ing the commands and output back-and-forth? Has anyone got a better idea for a python compute cluster?
PS. Preferably for python 3.x, if anyone knows how.</p>
| 5 | 2009-10-21T17:00:33Z | 1,602,212 | <p>What kind of stuff do you want to do? You might want to check out <a href="http://hadoop.apache.org/" rel="nofollow">hadoop</a>. The backend, heavy lifting is done in java, but has a python interface, so you can write python scripts create and send the input, as well as process the results. </p>
| 4 | 2009-10-21T17:10:05Z | [
"python",
"python-3.x",
"parallel-processing",
"cluster-computing"
] |
Python compute cluster | 1,602,177 | <p>Would it be possible to make a python cluster, by writing a telnet server, then telnet-ing the commands and output back-and-forth? Has anyone got a better idea for a python compute cluster?
PS. Preferably for python 3.x, if anyone knows how.</p>
| 5 | 2009-10-21T17:00:33Z | 1,602,240 | <p>Look into these</p>
<p><a href="http://www.parallelpython.com/" rel="nofollow">http://www.parallelpython.com/</a></p>
<p><a href="http://pyro.sourceforge.net/" rel="nofollow">http://pyro.sourceforge.net/</a></p>
<p>I have used both and both are exellent for distributed computing<br />
for more detailed list of o... | 4 | 2009-10-21T17:14:26Z | [
"python",
"python-3.x",
"parallel-processing",
"cluster-computing"
] |
Python compute cluster | 1,602,177 | <p>Would it be possible to make a python cluster, by writing a telnet server, then telnet-ing the commands and output back-and-forth? Has anyone got a better idea for a python compute cluster?
PS. Preferably for python 3.x, if anyone knows how.</p>
| 5 | 2009-10-21T17:00:33Z | 1,602,251 | <p>The Python wiki hosts a very comprehensive list of <a href="http://wiki.python.org/moin/ParallelProcessing">Python cluster computing libraries and tools</a>. You might be especially interested in <a href="http://www.parallelpython.com/">Parallel Python</a>.</p>
<p><strong>Edit:</strong> There is a new library that ... | 13 | 2009-10-21T17:16:17Z | [
"python",
"python-3.x",
"parallel-processing",
"cluster-computing"
] |
Python compute cluster | 1,602,177 | <p>Would it be possible to make a python cluster, by writing a telnet server, then telnet-ing the commands and output back-and-forth? Has anyone got a better idea for a python compute cluster?
PS. Preferably for python 3.x, if anyone knows how.</p>
| 5 | 2009-10-21T17:00:33Z | 1,602,252 | <p>You can see most of the third-party packages available for Python 3 listed <a href="http://pypi.python.org/pypi?%3Aaction=browse&c=533&show=all">here</a>; relevant to cluster computation is <a href="http://pypi.python.org/pypi/mpi4py/1.1.0">mpi4py</a> -- most other distributed computing tools such as pyro ar... | 11 | 2009-10-21T17:16:21Z | [
"python",
"python-3.x",
"parallel-processing",
"cluster-computing"
] |
Python compute cluster | 1,602,177 | <p>Would it be possible to make a python cluster, by writing a telnet server, then telnet-ing the commands and output back-and-forth? Has anyone got a better idea for a python compute cluster?
PS. Preferably for python 3.x, if anyone knows how.</p>
| 5 | 2009-10-21T17:00:33Z | 1,602,353 | <p>"Would it be possible to make a python cluster"</p>
<p>Yes.</p>
<p>I love yes/no questions. Anything else you want to know?</p>
<p>(Note that Python 3 has few third-party libraries yet, so you may wanna stay with Python 2 at the moment.)</p>
| -2 | 2009-10-21T17:33:21Z | [
"python",
"python-3.x",
"parallel-processing",
"cluster-computing"
] |
Python compute cluster | 1,602,177 | <p>Would it be possible to make a python cluster, by writing a telnet server, then telnet-ing the commands and output back-and-forth? Has anyone got a better idea for a python compute cluster?
PS. Preferably for python 3.x, if anyone knows how.</p>
| 5 | 2009-10-21T17:00:33Z | 6,598,078 | <p>If you need to write administrative scripts, take a look at the <a href="http://clustershell.sourceforge.net" rel="nofollow">ClusterShell</a> Python library too, or/and its parallel shell <strong>clush</strong>. It's useful when dealing with node sets also (<em>man nodeset</em>).</p>
| 1 | 2011-07-06T14:29:51Z | [
"python",
"python-3.x",
"parallel-processing",
"cluster-computing"
] |
Python compute cluster | 1,602,177 | <p>Would it be possible to make a python cluster, by writing a telnet server, then telnet-ing the commands and output back-and-forth? Has anyone got a better idea for a python compute cluster?
PS. Preferably for python 3.x, if anyone knows how.</p>
| 5 | 2009-10-21T17:00:33Z | 19,551,897 | <p>I think <a href="http://ipython.org/ipython-doc/dev/parallel/index.html" rel="nofollow">IPython.parallel</a> is the way to go. I've been using it extensively for the last year and a half. It allows you to work interactively with as many worker nodes as you want. If you are on AWS, <a href="http://star.mit.edu/cluste... | 0 | 2013-10-23T20:43:17Z | [
"python",
"python-3.x",
"parallel-processing",
"cluster-computing"
] |
I want to create a "CGI script" in python that stays resident in memory and services multiple requests | 1,602,516 | <p>I have a website that right now, runs by creating static html pages from a cron job that runs nightly. </p>
<p>I'd like to add some search and filtering features using a CGI type script, but my script will have enough of a startup time (maybe a few seconds?) that I'd like it to stay resident and serve multiple requ... | 2 | 2009-10-21T18:03:05Z | 1,602,537 | <p>That's exactly what <a href="http://www.wsgi.org/wsgi/WsgiStart" rel="nofollow">WSGI</a> is for ;)</p>
<p>I don't know off hand what the simplest way to turn a CGI script into a WSGI application is, though (I've always had that managed by a framework). It shouldn't be too tricky, though.</p>
<p>That said, <a href=... | 4 | 2009-10-21T18:06:19Z | [
"python",
"frameworks",
"cgi",
"pylons"
] |
I want to create a "CGI script" in python that stays resident in memory and services multiple requests | 1,602,516 | <p>I have a website that right now, runs by creating static html pages from a cron job that runs nightly. </p>
<p>I'd like to add some search and filtering features using a CGI type script, but my script will have enough of a startup time (maybe a few seconds?) that I'd like it to stay resident and serve multiple requ... | 2 | 2009-10-21T18:03:05Z | 1,603,021 | <p>maybe you should direct your search towards inter process commmunication and make a search process that returns the results to the web server. This search process will be running all the time assuming you have your own server.</p>
| -1 | 2009-10-21T19:21:42Z | [
"python",
"frameworks",
"cgi",
"pylons"
] |
Problems scripting Unison with Python | 1,602,529 | <p>I am trying to make a simple script to automate and log synchronization via Unison. I am also using subprocess.Popen rather than the usual os.system call as it's deprecated. I've spent the past 2 days looking at docs and such trying to figure out what I'm doing wrong, but for some reason if I call unison from a term... | 1 | 2009-10-21T18:05:15Z | 1,602,583 | <p>The most likely culprit is that unison is sending some output to stderr instead of just stdout. Popen takes an additional <code>stderr</code> argument so you can try capturing that instead of (or in addition to) stdout).</p>
<p>For a quick reference on <a href="http://en.wikipedia.org/wiki/Standard%5Fstreams" rel=... | 1 | 2009-10-21T18:12:51Z | [
"python",
"unison"
] |
Problems scripting Unison with Python | 1,602,529 | <p>I am trying to make a simple script to automate and log synchronization via Unison. I am also using subprocess.Popen rather than the usual os.system call as it's deprecated. I've spent the past 2 days looking at docs and such trying to figure out what I'm doing wrong, but for some reason if I call unison from a term... | 1 | 2009-10-21T18:05:15Z | 1,602,760 | <p>Changed ["unison", "sync"] to simply ["unison sync"]...appears to be working without need for user interaction now, not sure why that would be any different...but works for me.</p>
| 0 | 2009-10-21T18:40:29Z | [
"python",
"unison"
] |
Django raw id field lookup has the wrong link | 1,602,607 | <p>I have a django app, and on the backend I've got a many to many field that I've set in the '<code>raw_id_fields</code>' property in the ModelAdmin class. When running it locally, everything is fine, but when I test on the live site, the link to the lookup popout window doesnt work.</p>
<p>The django app resides at... | 1 | 2009-10-21T18:16:24Z | 1,602,962 | <p>This sounds like a bug in Django, I've seen a few of this kind. I'm pretty sure it has to do with the fact that you placed your admin at example.com/djangoapp/admin/ instead of example.com/admin/ which is the default. I have a hunch that if you change the admin url, it will work.</p>
| 1 | 2009-10-21T19:10:18Z | [
"python",
"django",
"django-admin"
] |
Exit a process while threads are sleeping | 1,602,743 | <p>In a python script, I started a bunch of threads, each of which pulls some resource at an interval using time.sleep(interval). I have another thread running, which uses the cmd module to monitor user inputs. When the user enters 'q', I call</p>
<pre><code>sys.exit(0)
</code></pre>
<p>However, when the script is ru... | 0 | 2009-10-21T18:38:19Z | 1,603,009 | <p>sys.exit will only stop the thread it executes from. If you have other non-daemon thread in your program they will continue to execute. <a href="http://docs.python.org/library/threading.html#thread-objects" rel="nofollow">Section 17.2.1</a> of the Python library docs contains:</p>
<blockquote>
<p>A thread can be ... | 4 | 2009-10-21T19:19:56Z | [
"python",
"multithreading"
] |
How do I wrangle python lookups: make.up.a.dot.separated.name.and.use.it.until.destroyed = 777 | 1,602,745 | <p>I'm a Python newbie with a very particular itch to experiment with Python's dot-name-lookup process. How do I code either a class or function in "make.py" so that these assignment statements work succesfully?</p>
<pre><code>import make
make.a.dot.separated.name = 666
make.something.else.up = 123
make.anything.i.w... | 3 | 2009-10-21T18:38:38Z | 1,602,855 | <pre><code>#!/usr/bin/env python
class Make:
def __getattr__(self, name):
self.__dict__[name] = Make()
return self.__dict__[name]
make = Make()
make.a.dot.separated.name = 666
make.anything.i.want = 777
print make.a.dot.separated.name
print make.anything.i.want
</code></pre>
<p>The special <cod... | 11 | 2009-10-21T18:55:25Z | [
"python",
"namespaces",
"lookup"
] |
Python Sphinx Documentation | 1,602,800 | <p>How can you use Sphinx for Python 3.x documentation?
<a href="http://doc.python.org/3.1/" rel="nofollow">http://doc.python.org/3.1</a> seem to have managed it.</p>
| 3 | 2009-10-21T18:46:24Z | 1,603,018 | <p>The documentation is in reStructuredText as you can see in their <a href="http://svn.python.org/view/python/tags/r311/Doc/" rel="nofollow">SVN repository</a> (they also mention it in the <a href="http://docs.python.org/3.1/about.html" rel="nofollow">documentation</a>). Obviously other tools are involved to help buil... | 3 | 2009-10-21T19:21:11Z | [
"python",
"documentation",
"python-sphinx"
] |
Python problem executing popen in cron | 1,602,830 | <p>I use <code>popen</code> to execute commands in a Python script, and I call it via cron.<br />
Cron calls out this script but the behavior isn't the same if I call it by hand.</p>
<h3>Source:</h3>
<pre><code>from subprocess import Popen, PIPE
pp = Popen('/usr/bin/which iptables', shell=True, stdout=PIPE)
data = ... | 7 | 2009-10-21T18:51:01Z | 1,602,848 | <p>Normally when processes are run from cron, the <code>PATH</code> is set to a very restrictive value (the man page for my crontab says <code>/usr/bin:/bin</code>). You may need to add:</p>
<pre>
PATH=/usr/bin:/bin:/sbin
</pre>
<p>to the top of your crontab file.</p>
| 18 | 2009-10-21T18:54:24Z | [
"python",
"console",
"cron"
] |
Setting value for a node in XML document in Python | 1,602,919 | <p>I have a XML document "abc.xml": </p>
<p>I need to write a function replace(name, newvalue) which can replace the value node with tag 'name' with the new value and write it back to the disk. Is this possible in python? How should I do this?</p>
| 0 | 2009-10-21T19:02:52Z | 1,603,011 | <p>Sure it is possible.
The xml.etree.ElementTree module will help you with parsing XML, finding tags and replacing values.</p>
<p>If you know a little bit more about the XML file you want to change, you can probably make the task a bit easier than if you need to write a generic function that will handle any XML file... | 2 | 2009-10-21T19:20:20Z | [
"python",
"xml",
"python-3.x"
] |
Setting value for a node in XML document in Python | 1,602,919 | <p>I have a XML document "abc.xml": </p>
<p>I need to write a function replace(name, newvalue) which can replace the value node with tag 'name' with the new value and write it back to the disk. Is this possible in python? How should I do this?</p>
| 0 | 2009-10-21T19:02:52Z | 1,603,080 | <pre><code>import xml.dom.minidom
filename='abc.xml'
doc = xml.dom.minidom.parse(filename)
print doc.toxml()
c = doc.getElementsByTagName("c")
print c[0].toxml()
c[0].childNodes[0].nodeValue = 'zip'
print doc.toxml()
def replace(tagname, newvalue):
'''doc is global, first occurrence of tagname gets it!'''
doc.get... | 1 | 2009-10-21T19:31:49Z | [
"python",
"xml",
"python-3.x"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 1,602,944 | <p>You don't have to call keys:</p>
<pre><code>if 'key1' in dict:
print "blah"
else:
print "boo"
</code></pre>
<p>That will be much faster as it uses the dictionary's hashing as opposed to doing a linear search, which calling keys would do.</p>
| 600 | 2009-10-21T19:06:30Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 1,602,945 | <p>You can shorten this:</p>
<pre><code>if 'key1' in dict:
...
</code></pre>
<p>However, this is at best a cosmetic improvement. Why do you believe this is not the best way?</p>
| 42 | 2009-10-21T19:06:40Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 1,602,950 | <p>I would recommend using the <code>setdefault</code> method instead. It sounds like it will do everything you want.</p>
<pre><code>>>> d = {'foo':'bar'}
>>> q = d.setdefault('foo','baz') #Do not override the existing key
>>> print q #The value takes what was originally in the dictionary
b... | 28 | 2009-10-21T19:07:28Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 1,602,964 | <p><code>in</code> is the intended way to test for the existence of a key in a <code>dict</code>.</p>
<pre><code>d = dict()
for i in xrange(100):
key = i % 10
if key in d:
d[key] += 1
else:
d[key] = 1
</code></pre>
<p>If you wanted a default, you can always use <code>dict.get()</code>:</p... | 1,258 | 2009-10-21T19:10:21Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 1,602,990 | <p>You can test for the presence of a key in a dictionary, using the <b>in</b> keyword:</p>
<pre><code>d = {'a': 1, 'b': 2}
'a' in d # <== evaluates to True
'c' in d # <== evaluates to False
</code></pre>
<p>A common use for checking the existence of a key in a dictionary before mutating it is to default-initia... | 180 | 2009-10-21T19:16:46Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 16,459,431 | <p><strong>You can use the has_key() method:</strong></p>
<pre><code>if dict.has_key('xyz')==1:
#update the value for the key
else:
pass
</code></pre>
<p><strong>Or the <code>dict.get</code> method to set a default value if not found:</strong></p>
<pre><code>mydict = {"a": 5}
print mydict["a"] #p... | 6 | 2013-05-09T10:17:15Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 16,637,874 | <p>Just an FYI adding to Chris. B (best answer):</p>
<pre><code>d = defaultdict(int)
</code></pre>
<p>Works as well; the reason is that calling <code>int()</code> returns <code>0</code> which is what <code>defaultdict</code> does behind the scenes (when constructing a dictionary), hence the name "Factory Function" in... | 9 | 2013-05-19T18:12:35Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 21,608,048 | <p>What about using EAFP (easier to ask forgiveness than permission):</p>
<pre><code>try:
blah = dict["mykey"]
# key exists in dict
except:
# key doesn't exist in dict
</code></pre>
<p>See other SO posts:</p>
<p><a href="http://stackoverflow.com/questions/1835756/using-try-vs-if-in-python">Using try vs if i... | 5 | 2014-02-06T16:08:34Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 30,527,984 | <p>For additional info on speed execution of the accepted answer's proposed methods (10m loops):</p>
<ul>
<li><code>'key' in mydict</code> elapsed time 1.07 sec</li>
<li><code>mydict.get('key')</code> elapsed time 1.84 sec</li>
<li><code>mydefaultdict['key']</code> elapsed time 1.07 sec</li>
</ul>
<p>Therefore using ... | 13 | 2015-05-29T11:06:44Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 31,438,780 | <p><code>print dict.get('key1', 'blah')</code></p>
<p>Won't print boo for the values in the dict, but accomplishes the goal by printing the value of key1 to confirm it's existence instead.</p>
| 3 | 2015-07-15T18:55:45Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 32,509,350 | <p>For checking you can use <code>has_key()</code> method </p>
<pre><code>if dict.has_key('key1'):
print "it is there"
</code></pre>
<p>If you want a value then you can use <code>get()</code> method</p>
<pre><code>a = dict.get('key1', expeced_type)
</code></pre>
<p>If you want a tuple or list or dictionary or an... | 6 | 2015-09-10T18:37:27Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 34,483,480 | <p>I Think the simplest one is like this</p>
<pre><code> # Sample dict for matching, we just use the key for validating
successful_response_dict = {
"username": "abc29",
"email": "abc29@gmail.com",
"first_name": "abc",
"last_name": "kecap 4",
"referral_code": "Kj5"
}
... | -4 | 2015-12-27T18:27:35Z | [
"python",
"dictionary"
] |
Check if a given key already exists in a dictionary | 1,602,934 | <p>I wanted to test if a key exists in a dictionary before updating the value for the key.
I wrote the following code:</p>
<pre><code>if 'key1' in dict.keys():
print "blah"
else:
print "boo"
</code></pre>
<p>I think this is not the best way to accomplish this task. Is there a better way to test for a key in the d... | 1,211 | 2009-10-21T19:05:09Z | 37,782,534 | <p>Easiest one is if you know which key(key name) is to look for:</p>
<pre><code># suppose your dictionary is
my_dict = {'foo': 1, 'bar': 2}
# check if a key is there
if 'key' in my_dict.keys(): # it will evaluates to true if that key is present otherwise false.
# do something
</code></pre>
<p>or you can also d... | 0 | 2016-06-13T05:44:35Z | [
"python",
"dictionary"
] |
How to trim the longest match from beginning of a string (using python) | 1,603,076 | <p>In recent bash versions, I can do this:</p>
<pre><code>$ string="Universe.World.Country.State.City.Street"
$ echo $string
Universe.World.Country.State.City.Street
$ newString="${string##*.}"
$ echo $newString
Street
</code></pre>
<p>Using Python, what is a succinct way to doing the same?
I am interested in the las... | 0 | 2009-10-21T19:31:43Z | 1,603,102 | <p>How about</p>
<pre><code>x[x.rfind('.') + 1 : ]
</code></pre>
<p>To me, that expresses what you're interested in (find the last dot, then take everything after it) more simply than a pattern or the concept of a "longest match".</p>
| 3 | 2009-10-21T19:35:20Z | [
"python",
"string"
] |
How to trim the longest match from beginning of a string (using python) | 1,603,076 | <p>In recent bash versions, I can do this:</p>
<pre><code>$ string="Universe.World.Country.State.City.Street"
$ echo $string
Universe.World.Country.State.City.Street
$ newString="${string##*.}"
$ echo $newString
Street
</code></pre>
<p>Using Python, what is a succinct way to doing the same?
I am interested in the las... | 0 | 2009-10-21T19:31:43Z | 1,603,106 | <p>Maybe:</p>
<pre><code>re.search(r"\.([^.]*)$", s).groups()[0]
</code></pre>
<p>EDIT: First version was bad :)</p>
| 0 | 2009-10-21T19:36:13Z | [
"python",
"string"
] |
How to trim the longest match from beginning of a string (using python) | 1,603,076 | <p>In recent bash versions, I can do this:</p>
<pre><code>$ string="Universe.World.Country.State.City.Street"
$ echo $string
Universe.World.Country.State.City.Street
$ newString="${string##*.}"
$ echo $newString
Street
</code></pre>
<p>Using Python, what is a succinct way to doing the same?
I am interested in the las... | 0 | 2009-10-21T19:31:43Z | 1,603,182 | <p>If you know its always going to be the last element and a full stop you can't beat</p>
<pre><code>"Universe.World.Country.State.City.Street".split(".")[-1]
</code></pre>
| 0 | 2009-10-21T19:51:00Z | [
"python",
"string"
] |
How to trim the longest match from beginning of a string (using python) | 1,603,076 | <p>In recent bash versions, I can do this:</p>
<pre><code>$ string="Universe.World.Country.State.City.Street"
$ echo $string
Universe.World.Country.State.City.Street
$ newString="${string##*.}"
$ echo $newString
Street
</code></pre>
<p>Using Python, what is a succinct way to doing the same?
I am interested in the las... | 0 | 2009-10-21T19:31:43Z | 1,603,574 | <pre><code>>>> "Universe.World.Country.State.City.Street".rsplit('.',1)[1]
'Street'
</code></pre>
<p>Edit: rpartition as suggested by SilentGhost seems to be the most efficient</p>
<pre><code># rpartition
$ python -m timeit -r100 -n100 -s 'x="Universe.World.Country.State.City.Street"' 'x.rpartition(".")[-1]'... | 1 | 2009-10-21T20:57:26Z | [
"python",
"string"
] |
How to trim the longest match from beginning of a string (using python) | 1,603,076 | <p>In recent bash versions, I can do this:</p>
<pre><code>$ string="Universe.World.Country.State.City.Street"
$ echo $string
Universe.World.Country.State.City.Street
$ newString="${string##*.}"
$ echo $newString
Street
</code></pre>
<p>Using Python, what is a succinct way to doing the same?
I am interested in the las... | 0 | 2009-10-21T19:31:43Z | 1,603,633 | <pre><code>>>> 'Universe.World.Country.State.City.Street'.rpartition('.')[2]
'Street'
</code></pre>
| 3 | 2009-10-21T21:05:20Z | [
"python",
"string"
] |
How to trim the longest match from beginning of a string (using python) | 1,603,076 | <p>In recent bash versions, I can do this:</p>
<pre><code>$ string="Universe.World.Country.State.City.Street"
$ echo $string
Universe.World.Country.State.City.Street
$ newString="${string##*.}"
$ echo $newString
Street
</code></pre>
<p>Using Python, what is a succinct way to doing the same?
I am interested in the las... | 0 | 2009-10-21T19:31:43Z | 6,576,942 | <p><code>string.rsplit('.', 1)[-1]</code> with maxsplit=1 returns only the rightmost '.', so it also only matches once.</p>
<p>Looks like a tossup with <code>string.rpartition('.')[-1]</code></p>
<p>PS: gnibbler actually timed rsplit and it was slightly slower than rpartition, rfind.</p>
| 0 | 2011-07-04T23:53:16Z | [
"python",
"string"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 1,603,138 | <p>You have two options here.</p>
<ol>
<li><p>Make a proper <strong>cron job</strong> that calls your script. Cron is a common name for a GNU/Linux daemon that periodically launches scripts according to a schedule you set. You add your script into a crontab or place a symlink to it into a special directory and the d... | 65 | 2009-10-21T19:43:06Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 1,603,141 | <p>You should use the <a href="http://pypi.python.org/pypi/python-daemon/" rel="nofollow">python-daemon</a> library, it takes care of everything.</p>
<p>From PyPI: <em>Library to implement a well-behaved Unix daemon process.</em></p>
| 33 | 2009-10-21T19:43:45Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 1,603,146 | <p>First, read up on mail aliases. A mail alias will do this inside the mail system without you having to fool around with daemons or services or anything of the sort.</p>
<p>You can write a simple script that will be executed by sendmail each time a mail message is sent to a specific mailbox.</p>
<p>See <a href="ht... | 3 | 2009-10-21T19:44:22Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 1,603,152 | <p>You can use fork() to detach your script from the tty and have it continue to run, like so:</p>
<pre><code>import os, sys
fpid = os.fork()
if fpid!=0:
# Running as daemon now. PID is fpid
sys.exit(0)
</code></pre>
<p>Of course you also need to implement an endless loop, like</p>
<pre><code>while 1:
do_your_... | 27 | 2009-10-21T19:45:12Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 1,603,166 | <p><a href="http://code.activestate.com/recipes/278731/" rel="nofollow">Recipe 278731: Creating a daemon the Python way </a></p>
| 3 | 2009-10-21T19:49:01Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 6,374,881 | <p>Here's a nice class that is taken from <a href="https://web.archive.org/web/20160305151936/http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/" rel="nofollow">here</a>: </p>
<pre><code>#!/usr/bin/env python
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
... | 43 | 2011-06-16T15:58:40Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 8,956,634 | <p>how about using <code>$nohup</code> command on linux?</p>
<p>I use it for running my commands on my Bluehost server.</p>
<p>Please advice if I am wrong.</p>
| 6 | 2012-01-21T21:00:02Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 19,514,587 | <p>You can also make the python script run as a service using a shell script. First create a shell script to run the python script like this (scriptname arbitary name)</p>
<pre><code>#!/bin/sh
script='/home/.. full path to script'
/usr/bin/python $script &
</code></pre>
<p>now make a file in /etc/init.d/scriptna... | 10 | 2013-10-22T09:56:08Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 19,515,492 | <p><code>cron</code> is clearly a great choice for many purposes. However it doesn't create a service or daemon as you requested in the OP. <code>cron</code> just runs jobs periodically (meaning the job starts and stops), and no more often than once / minute. There are issues with <code>cron</code> -- for example, i... | 3 | 2013-10-22T10:36:53Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 20,908,406 | <p>Use whatever service manager your system offers - for example under Ubuntu use <strong>upstart</strong>. This will handle all the details for you such as start on boot, restart on crash, etc.</p>
| 1 | 2014-01-03T16:36:35Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 27,716,630 | <p>Had similar problem, the link below worked for me well:
<a href="http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/#footnote_0_1077" rel="nofollow">http://werxltd.com/wp/2012/01/05/simple-init-d-script-template/#footnote_0_1077</a></p>
<p>It uses nothing specific to any distributive, if <strong>chkconf... | 0 | 2014-12-31T05:36:22Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 30,122,400 | <p>I would recommend this solution. You need to inherit and override method <code>run</code>.</p>
<pre><code>import sys
import os
from signal import SIGTERM
from abc import ABCMeta, abstractmethod
class Daemon(object):
__metaclass__ = ABCMeta
def __init__(self, pidfile):
self._pidfile = pidfile
... | 0 | 2015-05-08T11:12:15Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 35,008,431 | <p>If you are using terminal(ssh or something) and you want to keep a long-time script working after you log out from the terminal, you can try this:</p>
<p><code>screen</code></p>
<p><code>apt-get install screen</code></p>
<p>create a virtual terminal inside( namely abc): <code>screen -dmS abc</code></p>
<p>now we... | 0 | 2016-01-26T06:59:40Z | [
"python",
"linux",
"scripting",
"daemons"
] |
How to make a Python script run like a service or daemon in Linux | 1,603,109 | <p>I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re exe... | 96 | 2009-10-21T19:36:34Z | 36,384,704 | <p>A simple and <a href="https://pypi.python.org/pypi/daemonize" rel="nofollow">supported</a> version is Deamonize
Install it from Python Package Index (PyPI):</p>
<pre><code>$ pip install daemonize
</code></pre>
<p>and then use like:</p>
<pre><code>...
import os
from daemonize import Daemonize
...
def main()
... | 1 | 2016-04-03T11:08:46Z | [
"python",
"linux",
"scripting",
"daemons"
] |
Why can I not import the Python module 'signal' using Jython, in Linux? | 1,603,189 | <p>I can't find any reference to the 'signal' class being left out in Jython. Using Jython 2.1.</p>
<p>Thanks</p>
| 2 | 2009-10-21T19:52:23Z | 1,603,283 | <p>I would imagine Unix-style signals are difficult to do on the JVM, since the JVM has no notion of signals, and it is likely some JNI magic would be required to get this to work.</p>
<p>In Jython 2.5, the module exists, but seems to throw <code>NotImplementedError</code> for most functions.</p>
| 2 | 2009-10-21T20:07:04Z | [
"python",
"jython",
"signals"
] |
Wait for an event, but don't take it off the queue | 1,603,537 | <p>Is there any way to make the program sleep until an event occurs, but to not take it off the queue?</p>
<p>Similarly to <a href="http://www.pygame.org/docs/ref/event.html#pygame.event.wait" rel="nofollow">http://www.pygame.org/docs/ref/event.html#pygame.event.wait</a></p>
<p>Or will I need to use pygame.event.wait... | 0 | 2009-10-21T20:51:43Z | 1,606,257 | <p>You will need to do what you suggest and post it back onto the queue. If the ordering is important (which it often is), then just keep your own queue of already retrieved events, and whenever you want to start processing events normally, just handle your own list first before draining pygame's queue.</p>
<p>I'm at ... | 1 | 2009-10-22T10:12:49Z | [
"python",
"event-handling",
"pygame"
] |
Is there a good diagramming library for Python? | 1,603,567 | <p>I should say I'm looking for something interactive, equivalent to what Nevron offers in it's .NET Diagram product, where a user can create nodes, interact with them by dragging them around, etc. I know there's GraphViz, but as far as I know it's static, and just renders a graph/diagram, there is no interaction with ... | 6 | 2009-10-21T20:56:49Z | 1,603,867 | <p><a href="http://ubietylab.net/ubigraph/" rel="nofollow">Ubigraph</a> is probably not what you want, but is still really excellent.</p>
| 2 | 2009-10-21T21:51:35Z | [
"python",
"graph",
"diagram"
] |
Is there a good diagramming library for Python? | 1,603,567 | <p>I should say I'm looking for something interactive, equivalent to what Nevron offers in it's .NET Diagram product, where a user can create nodes, interact with them by dragging them around, etc. I know there's GraphViz, but as far as I know it's static, and just renders a graph/diagram, there is no interaction with ... | 6 | 2009-10-21T20:56:49Z | 1,603,884 | <p>Writing graphviz dot files is a good way to go. Google for graphviz and see <a href="http://code.google.com/p/pydot/" rel="nofollow">http://code.google.com/p/pydot/</a> for a python wrapper.</p>
| 0 | 2009-10-21T21:54:45Z | [
"python",
"graph",
"diagram"
] |
Python idiom for 'Try until no exception is raised' | 1,603,578 | <p>I want my code to automatically try multiple ways to create a database connection. As soon as one works, the code needs to move on (i.e. it shouldn't try to other ways anymore). If they all fail well, then the script can just blow up.</p>
<p>So in - what I thought was, but most likely isn't - a stroke of genius I t... | 7 | 2009-10-21T20:58:03Z | 1,603,615 | <p>Approximately:</p>
<pre><code>attempts = [
{ 'database'='postgres', 'user'='pgsql', ...},
{ 'database'='postgres', 'user'='postgres', 'host'='localhost', 'password'=getpass()},
...
]
conn = None
for attempt in attempts:
try:
conn = psycopg2.connect(**attempt)
break
except psycopg... | 14 | 2009-10-21T21:02:53Z | [
"python"
] |
Python idiom for 'Try until no exception is raised' | 1,603,578 | <p>I want my code to automatically try multiple ways to create a database connection. As soon as one works, the code needs to move on (i.e. it shouldn't try to other ways anymore). If they all fail well, then the script can just blow up.</p>
<p>So in - what I thought was, but most likely isn't - a stroke of genius I t... | 7 | 2009-10-21T20:58:03Z | 1,603,729 | <p>You're close. Probably the best thing to do in this case is nesting the second and subsequent attempts in the except block. Thus the critical part of your code would look like:</p>
<pre><code>if not CURSOR:
# try to connect and get a cursor
try:
# first try the bog standard way: db postgres, user ... | -1 | 2009-10-21T21:18:41Z | [
"python"
] |
kill subprocess when python process is killed? | 1,603,658 | <p>I am writing a python program that lauches a subprocess (using Popen).
I am reading stdout of the subprocess, doing some filtering, and writing to
stdout of main process.</p>
<p>When I kill the main process (cntl-C) the subprocess keeps running.
How do I kill the subprocess too? The subprocess is likey to run a lon... | 7 | 2009-10-21T21:08:21Z | 1,603,780 | <p>Windows doesn't have signals, so you can't use the signal module. However, you can still catch the KeyboardInterrupt exception when Ctrl-C is pressed.</p>
<p>Something like this should get you going:</p>
<pre><code>import subprocess
try:
child = subprocess.Popen(blah)
child.wait()
except KeyboardInterru... | 5 | 2009-10-21T21:29:27Z | [
"python",
"windows",
"process"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.