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 |
|---|---|---|---|---|---|---|---|---|---|
Django: Dynamic LOGIN_URL variable | 1,088,913 | <p>Currently, in my <code>settings</code> module I have this:</p>
<pre><code>LOGIN_URL = '/login'
</code></pre>
<p>If I ever decide to change the login URL in <code>urls.py</code>, I'll have to change it here as well. Is there any more dynamic way of doing this?</p>
| 6 | 2009-07-06T19:55:02Z | 1,088,929 | <p>Settings <em>IS</em> where you are setting your dynamic login url. Make sure to import <code>LOGIN_URL</code> from <code>settings.py</code> in your <code>urls.py</code> and use that instead.</p>
<pre><code>from projectname.settings import LOGIN_URL
</code></pre>
| 7 | 2009-07-06T19:58:53Z | [
"python",
"django",
"django-urls"
] |
Django: Dynamic LOGIN_URL variable | 1,088,913 | <p>Currently, in my <code>settings</code> module I have this:</p>
<pre><code>LOGIN_URL = '/login'
</code></pre>
<p>If I ever decide to change the login URL in <code>urls.py</code>, I'll have to change it here as well. Is there any more dynamic way of doing this?</p>
| 6 | 2009-07-06T19:55:02Z | 1,089,677 | <p>This works for me ... with LOGIN_URL = '/accounts/login'</p>
<p><strong>If the problem is</strong> that settings.py has ...</p>
<pre><code>LOGIN_URL = '/login/' # <-- remember trailing slash!
</code></pre>
<p>... but, urls.py wants ... </p>
<pre><code>url(r'^login/$',
auth_views.login, {'template_name... | 4 | 2009-07-06T23:31:31Z | [
"python",
"django",
"django-urls"
] |
Decorator to mark a method to be executed no more than once even if called several times | 1,089,023 | <p>I will go straight to the example:</p>
<pre><code>class Foo:
@execonce
def initialize(self):
print 'Called'
>>> f1 = Foo()
>>> f1.initialize()
Called
>>> f1.initialize()
>>> f2 = Foo()
>>> f2.initialize()
Called
>>> f2.initialize()
>>>
</code><... | 4 | 2009-07-06T20:18:27Z | 1,089,052 | <pre><code>import functools
def execonce(f):
@functools.wraps(f)
def donothing(*a, **k):
pass
@functools.wraps(f)
def doit(self, *a, **k):
try:
return f(self, *a, **k)
finally:
setattr(self, f.__name__, donothing)
return doit
</code></pre>
| 6 | 2009-07-06T20:25:13Z | [
"python",
"class",
"methods",
"decorator"
] |
Decorator to mark a method to be executed no more than once even if called several times | 1,089,023 | <p>I will go straight to the example:</p>
<pre><code>class Foo:
@execonce
def initialize(self):
print 'Called'
>>> f1 = Foo()
>>> f1.initialize()
Called
>>> f1.initialize()
>>> f2 = Foo()
>>> f2.initialize()
Called
>>> f2.initialize()
>>>
</code><... | 4 | 2009-07-06T20:18:27Z | 1,089,057 | <p>You could do something like this:</p>
<pre><code>class Foo:
def __init__(self):
self.initialize_called = False
def initialize(self):
if self.initalize_called:
return
self.initialize_called = True
print 'Called'
</code></pre>
<p>This is straightforward and easy to read. There is another ... | 0 | 2009-07-06T20:26:35Z | [
"python",
"class",
"methods",
"decorator"
] |
Decorator to mark a method to be executed no more than once even if called several times | 1,089,023 | <p>I will go straight to the example:</p>
<pre><code>class Foo:
@execonce
def initialize(self):
print 'Called'
>>> f1 = Foo()
>>> f1.initialize()
Called
>>> f1.initialize()
>>> f2 = Foo()
>>> f2.initialize()
Called
>>> f2.initialize()
>>>
</code><... | 4 | 2009-07-06T20:18:27Z | 1,089,060 | <p>try something similar to this</p>
<pre><code>def foo():
try:
foo.called
except:
print "called"
foo.called = True
</code></pre>
<p>methods and functions are objects. you can add methods and attributes on them. This can be useful for your case. If you want a decorator... | 0 | 2009-07-06T20:27:08Z | [
"python",
"class",
"methods",
"decorator"
] |
Pythonic way to log specific things to a file? | 1,089,269 | <p>I understand that Python loggers cannot be instantiated directly, as the documentation suggests:</p>
<blockquote>
<p>Note that Loggers are never
instantiated directly, but always
through the module-level function
<code>logging.getLogger(name)</code></p>
</blockquote>
<p>.. which is reasonable, as you are e... | 0 | 2009-07-06T21:18:58Z | 1,089,292 | <p>Assuming you're calling to <code>setup.py build</code> as a subprocess I think you really just want output redirection, which you can get via the subprocess invocation.</p>
<pre><code>from subprocess import Popen
with open('/var/logs/pypi/django/%s.build.log' % time_str, 'w') as fh:
Popen('python setup.py build... | 0 | 2009-07-06T21:26:42Z | [
"python",
"logging"
] |
Pythonic way to log specific things to a file? | 1,089,269 | <p>I understand that Python loggers cannot be instantiated directly, as the documentation suggests:</p>
<blockquote>
<p>Note that Loggers are never
instantiated directly, but always
through the module-level function
<code>logging.getLogger(name)</code></p>
</blockquote>
<p>.. which is reasonable, as you are e... | 0 | 2009-07-06T21:18:58Z | 1,089,358 | <p>Instead of many loggers, you could use one logger and many handlers. For example:</p>
<pre><code>log = logging.getLogger(name)
while some_condition:
try:
handler = make_handler(filename)
log.addHandler(handler)
# do something and log
finally:
log.removeHandler(handler)
... | 4 | 2009-07-06T21:47:31Z | [
"python",
"logging"
] |
Pythonic way to log specific things to a file? | 1,089,269 | <p>I understand that Python loggers cannot be instantiated directly, as the documentation suggests:</p>
<blockquote>
<p>Note that Loggers are never
instantiated directly, but always
through the module-level function
<code>logging.getLogger(name)</code></p>
</blockquote>
<p>.. which is reasonable, as you are e... | 0 | 2009-07-06T21:18:58Z | 1,089,442 | <p>There are two issues here:</p>
<ol>
<li>Being able to direct output to different log files during different phases of the process.</li>
<li>Being able to redirect stdout/stderr of arbitrary commands to those same log files.</li>
</ol>
<p>For point 1, I would go along with <code>ars</code>'s answer: he's spot on ab... | 1 | 2009-07-06T22:11:42Z | [
"python",
"logging"
] |
How to make custom PhotoEffects in Django Photologue? | 1,089,304 | <p>I'm creating an image gallery in Django using the <a href="http://code.google.com/p/django-photologue/" rel="nofollow">Photologue</a> application. There are a number of <a href="http://code.google.com/p/django-photologue/wiki/PhotoEffect" rel="nofollow">PhotoEffects</a> that come with it. I'd like to extend these ... | 2 | 2009-07-06T21:30:06Z | 1,089,631 | <p>Looks like you could define another preset effect in the utils file, and then import it into models.py. Then you'd want to add it as an option to the PhotoEffect class in models.py. This would of course make your Photologue a bit custom to your needs though.</p>
| 1 | 2009-07-06T23:13:11Z | [
"python",
"django",
"python-imaging-library",
"photologue"
] |
How to make custom PhotoEffects in Django Photologue? | 1,089,304 | <p>I'm creating an image gallery in Django using the <a href="http://code.google.com/p/django-photologue/" rel="nofollow">Photologue</a> application. There are a number of <a href="http://code.google.com/p/django-photologue/wiki/PhotoEffect" rel="nofollow">PhotoEffects</a> that come with it. I'd like to extend these ... | 2 | 2009-07-06T21:30:06Z | 1,089,801 | <p>I'm the developer of Photologue. I would suggest you look at the 3.x branch of Photologue and more specifically, django-imagekit, the new Library it's based on: <a href="http://bitbucket.org/jdriscoll/django-imagekit/wiki/Home" rel="nofollow" title="django-imagekit">http://bitbucket.org/jdriscoll/django-imagekit/wik... | 2 | 2009-07-07T00:16:59Z | [
"python",
"django",
"python-imaging-library",
"photologue"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 1,089,346 | <p>Have you considered using R and the <a href="http://www.quantmod.com/" rel="nofollow">quantmod</a> package? It likely provides exactly what you need.</p>
| 4 | 2009-07-06T21:43:41Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 1,089,435 | <p>You can use Pylab (<code>matplotlib.finance</code>) with Python. Here are some examples: <a href="http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/plotfile%5Fdemo.html">http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo.html</a> . There is some good material specifically on this pro... | 8 | 2009-07-06T22:10:44Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 1,089,511 | <p>Are you free to use JRuby instead of Ruby? That'd let you use JFreeChart, plus your code would still be in Ruby</p>
| 1 | 2009-07-06T22:32:34Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 1,089,512 | <p>You can use <a href="http://matplotlib.sourceforge.net/" rel="nofollow">matplotlib</a> and the the optional <code>bottom</code> parameter of <a href="http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.bar" rel="nofollow">matplotlib.pyplot.bar</a>. You can then use line <code>plot</code> to indic... | 16 | 2009-07-06T22:32:49Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 1,511,267 | <p>Please look at the Open Flash Chart embedding for WHIFF
<a href="http://aaron.oirt.rutgers.edu/myapp/docs/W1100%5F1600.openFlashCharts" rel="nofollow">http://aaron.oirt.rutgers.edu/myapp/docs/W1100_1600.openFlashCharts</a>
An example of a candle chart is right at the top. This would be especially
good for embedding... | 0 | 2009-10-02T19:02:08Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 2,591,495 | <p>Open Flash Chart is nice choice if you like the look of examples. I've moved to JavaScript/Canvas library like <a href="http://code.google.com/p/flot/" rel="nofollow">Flot</a> for HTML embedded charts, as it is more customizable and I get desired effect without much hacking (http://itprolife.worona.eu/2009/08/scatt... | 0 | 2010-04-07T10:08:44Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 5,611,490 | <p>This is the stock chart I draw just days ago using Matplotlib, I've posted the source too, for your reference: <a href="http://bluegene8210.is-programmer.com/posts/25954.html" rel="nofollow">StockChart_Matplotlib</a></p>
| 0 | 2011-04-10T11:37:45Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Financial Charts / Graphs in Ruby or Python | 1,089,307 | <p>What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart.</p>
<p><a href="http://en.wikipedia.org/wiki/Open-high-low-close_chart">http... | 12 | 2009-07-06T21:31:21Z | 6,272,093 | <p>Some examples about financial plots (OHLC) using matplotlib can be found here:</p>
<ul>
<li><p><a href="http://matplotlib.sourceforge.net/examples/pylab_examples/finance_demo.html" rel="nofollow">finance demo</a></p>
<pre><code>#!/usr/bin/env python
from pylab import *
from matplotlib.dates import DateFormatter, ... | 4 | 2011-06-07T21:58:38Z | [
"python",
"ruby",
"charts",
"graph",
"financial"
] |
Python remove all lines which have common value in fields | 1,089,550 | <p>I have lines of data comprising of 4 fields </p>
<pre><code>aaaa bbb1 cccc dddd
aaaa bbb2 cccc dddd
aaaa bbb3 cccc eeee
aaaa bbb4 cccc ffff
aaaa bbb5 cccc gggg
aaaa bbb6 cccc dddd
</code></pre>
<p>Please bear with me.</p>
<p>The first and third field is always the same - but I don't need them, the 4th ... | 1 | 2009-07-06T22:46:13Z | 1,089,563 | <p>Here you go:</p>
<pre><code>from collections import defaultdict
LINES = """\
aaaa bbb1 cccc dddd
aaaa bbb2 cccc dddd
aaaa bbb3 cccc eeee
aaaa bbb4 cccc ffff
aaaa bbb5 cccc gggg
aaaa bbb6 cccc dddd""".split('\n')
# Count how many lines each unique value of the fourth field appears in.
d_counts = defaultdict(int)
f... | 6 | 2009-07-06T22:50:32Z | [
"python",
"duplicate-removal"
] |
Python remove all lines which have common value in fields | 1,089,550 | <p>I have lines of data comprising of 4 fields </p>
<pre><code>aaaa bbb1 cccc dddd
aaaa bbb2 cccc dddd
aaaa bbb3 cccc eeee
aaaa bbb4 cccc ffff
aaaa bbb5 cccc gggg
aaaa bbb6 cccc dddd
</code></pre>
<p>Please bear with me.</p>
<p>The first and third field is always the same - but I don't need them, the 4th ... | 1 | 2009-07-06T22:46:13Z | 1,090,462 | <p>For your amplified requirement, you can avoid reading the file twice or saving it in a list:</p>
<pre><code>LINES = """\
aaaa bbb1 cccc dddd
aaaa bbb2 cccc dddd
aaaa bbb3 cccc eeee
aaaa bbb4 cccc ffff
aaaa bbb5 cccc gggg
aaaa bbb6 cccc dddd""".split('\n')
import collections
adict = collections.defaultdict(list)
fo... | 0 | 2009-07-07T05:16:01Z | [
"python",
"duplicate-removal"
] |
Sending an email from Pylons | 1,089,576 | <p>I am using Pylons to develop an application and I want my controller actions to send emails to certain addresses. Is there a built in Pylons feature for sending email?</p>
| 4 | 2009-07-06T22:55:20Z | 1,089,588 | <p>Can't you just use standard Python library modules, <code>email</code> to prepare the mail and <code>smtp</code> to send it? What extra value beyond that are you looking for from the "built-in feature"?</p>
| 2 | 2009-07-06T22:59:13Z | [
"python",
"pylons"
] |
Sending an email from Pylons | 1,089,576 | <p>I am using Pylons to develop an application and I want my controller actions to send emails to certain addresses. Is there a built in Pylons feature for sending email?</p>
| 4 | 2009-07-06T22:55:20Z | 1,089,592 | <p>Try this: <a href="http://jjinux.blogspot.com/2009/02/python-logging-to-email-in-pylons.html" rel="nofollow">http://jjinux.blogspot.com/2009/02/python-logging-to-email-in-pylons.html</a></p>
| 2 | 2009-07-06T23:00:07Z | [
"python",
"pylons"
] |
Sending an email from Pylons | 1,089,576 | <p>I am using Pylons to develop an application and I want my controller actions to send emails to certain addresses. Is there a built in Pylons feature for sending email?</p>
| 4 | 2009-07-06T22:55:20Z | 1,224,696 | <p>What you want is <a href="http://www.python-turbomail.org/" rel="nofollow">turbomail</a>. In documentation you have an entry where is explains how to integrate it with Pylons.</p>
| 5 | 2009-08-03T21:20:25Z | [
"python",
"pylons"
] |
Python: Inflate and Deflate implementations | 1,089,662 | <p>I am interfacing with a server that requires that data sent to it is compressed with <em>Deflate</em> algorithm (Huffman encoding + LZ77) and also sends data that I need to <em>Inflate</em>. </p>
<p>I know that Python includes Zlib, and that the C libraries in Zlib support calls to <em>Inflate</em> and <em>Deflate... | 32 | 2009-07-06T23:24:10Z | 1,089,787 | <p>You can still use the <a href="https://docs.python.org/2/library/zlib.html"><code>zlib</code></a> module to inflate/deflate data. The <a href="https://docs.python.org/2/library/gzip.html"><code>gzip</code></a> module uses it internally, but adds a file-header to make it into a gzip-file. Looking at the <a href="http... | 16 | 2009-07-07T00:12:26Z | [
"c#",
"python",
"compression",
"zlib"
] |
Python: Inflate and Deflate implementations | 1,089,662 | <p>I am interfacing with a server that requires that data sent to it is compressed with <em>Deflate</em> algorithm (Huffman encoding + LZ77) and also sends data that I need to <em>Inflate</em>. </p>
<p>I know that Python includes Zlib, and that the C libraries in Zlib support calls to <em>Inflate</em> and <em>Deflate... | 32 | 2009-07-06T23:24:10Z | 1,090,361 | <p>This is an add-on to MizardX's answer, giving some explanation and background.</p>
<p>See <a href="http://www.chiramattel.com/george/blog/2007/09/09/deflatestream-block-length-does-not-match.html" rel="nofollow">http://www.chiramattel.com/george/blog/2007/09/09/deflatestream-block-length-does-not-match.html</a></p>... | 13 | 2009-07-07T04:31:48Z | [
"c#",
"python",
"compression",
"zlib"
] |
Is & faster than % when checking for odd numbers? | 1,089,936 | <p>To check for odd and even integer, is the lowest bit checking more efficient than using the modulo?</p>
<pre><code>>>> def isodd(num):
return num & 1 and True or False
>>> isodd(10)
False
>>> isodd(9)
True
</code></pre>
| 23 | 2009-07-07T01:26:42Z | 1,089,945 | <p>Yep. The <code>timeit</code> module in the standard library is how you check on those things. E.g:</p>
<pre><code>AmAir:stko aleax$ python -mtimeit -s'def isodd(x): x & 1' 'isodd(9)'
1000000 loops, best of 3: 0.446 usec per loop
AmAir:stko aleax$ python -mtimeit -s'def isodd(x): x & 1' 'isodd(10)'
1000000 ... | 53 | 2009-07-07T01:28:58Z | [
"python",
"performance",
"bit-manipulation",
"modulo"
] |
Is & faster than % when checking for odd numbers? | 1,089,936 | <p>To check for odd and even integer, is the lowest bit checking more efficient than using the modulo?</p>
<pre><code>>>> def isodd(num):
return num & 1 and True or False
>>> isodd(10)
False
>>> isodd(9)
True
</code></pre>
| 23 | 2009-07-07T01:26:42Z | 1,089,949 | <p>To be totally honest, <strong>I don't think it matters.</strong></p>
<p>The first issue is readability. What makes more sense to other developers? I, personally, would expect a modulo when checking the evenness/oddness of a number. I would expect that most other developers would expect the same thing. By introducin... | 23 | 2009-07-07T01:30:52Z | [
"python",
"performance",
"bit-manipulation",
"modulo"
] |
Is & faster than % when checking for odd numbers? | 1,089,936 | <p>To check for odd and even integer, is the lowest bit checking more efficient than using the modulo?</p>
<pre><code>>>> def isodd(num):
return num & 1 and True or False
>>> isodd(10)
False
>>> isodd(9)
True
</code></pre>
| 23 | 2009-07-07T01:26:42Z | 1,089,970 | <p>"return num & 1 and True or False" ? Wah! If you're speed-crazy (1) "return num & 1" (2) inline it: <code>if somenumber % 2 == 1</code> is legible AND beats <code>isodd(somenumber)</code> because it avoids the Python function call.</p>
| 4 | 2009-07-07T01:37:53Z | [
"python",
"performance",
"bit-manipulation",
"modulo"
] |
Is & faster than % when checking for odd numbers? | 1,089,936 | <p>To check for odd and even integer, is the lowest bit checking more efficient than using the modulo?</p>
<pre><code>>>> def isodd(num):
return num & 1 and True or False
>>> isodd(10)
False
>>> isodd(9)
True
</code></pre>
| 23 | 2009-07-07T01:26:42Z | 1,090,020 | <p>John brings up a good point. The real overhead is in the function call:</p>
<pre><code>me@localhost ~> python -mtimeit -s'9 % 2'
10000000 loops, best of 3: 0.0271 usec per loop
me@localhost ~> python -mtimeit -s'10 % 2'
10000000 loops, best of 3: 0.0271 usec per loop
me@localhost ~> python -mtimeit -s'9 &... | 3 | 2009-07-07T01:56:27Z | [
"python",
"performance",
"bit-manipulation",
"modulo"
] |
Is & faster than % when checking for odd numbers? | 1,089,936 | <p>To check for odd and even integer, is the lowest bit checking more efficient than using the modulo?</p>
<pre><code>>>> def isodd(num):
return num & 1 and True or False
>>> isodd(10)
False
>>> isodd(9)
True
</code></pre>
| 23 | 2009-07-07T01:26:42Z | 1,090,027 | <p>The best optimization you can get is to <em>not</em> put the test into a function. '<code>number % 2</code>' and 'number & 1' are very common ways of checking odd/evenness, experienced programmers will recognize the pattern instantly, and you can always throw in a comment such as '# if number is odd, then blah b... | 10 | 2009-07-07T02:00:48Z | [
"python",
"performance",
"bit-manipulation",
"modulo"
] |
Is & faster than % when checking for odd numbers? | 1,089,936 | <p>To check for odd and even integer, is the lowest bit checking more efficient than using the modulo?</p>
<pre><code>>>> def isodd(num):
return num & 1 and True or False
>>> isodd(10)
False
>>> isodd(9)
True
</code></pre>
| 23 | 2009-07-07T01:26:42Z | 1,954,646 | <p>Apart from the evil optimization, it takes away the very idiomatic "var % 2 == 0" that every coder understands without looking twice. So this is violates pythons zen as well for very little gain.</p>
<p>Furthermore a = b and True or False has been superseded for better readability by </p>
<p>return True if num &am... | 1 | 2009-12-23T18:51:02Z | [
"python",
"performance",
"bit-manipulation",
"modulo"
] |
Is & faster than % when checking for odd numbers? | 1,089,936 | <p>To check for odd and even integer, is the lowest bit checking more efficient than using the modulo?</p>
<pre><code>>>> def isodd(num):
return num & 1 and True or False
>>> isodd(10)
False
>>> isodd(9)
True
</code></pre>
| 23 | 2009-07-07T01:26:42Z | 5,153,295 | <p>Was really surprised none of the above answers did both variable setup (timing literal is different story) and no function invocation (which obviously hides "lower terms"). Stuck on that timing from ipython's timeit, where I got clear winner x&1 - better for ~18% using python2.6 (~12% using python3.1).</p>
<p>O... | 0 | 2011-03-01T10:33:20Z | [
"python",
"performance",
"bit-manipulation",
"modulo"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,035 | <p>Integers are more efficient from a storage and performance perspective. However, if there is a remote chance that alpha characters may be introduced, then you should use a string. In my opinion, the efficiency and performance benefits are likely to be negligible, whereas the time it takes to modify your code may n... | 0 | 2009-07-07T02:04:15Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,048 | <p>I'm not sure how good databases are at comparing whether one string is greater than another, like it can with integers. Try a query like this:</p>
<pre><code>SELECT * FROM my_table WHERE integer_as_string > '100';
</code></pre>
| 1 | 2009-07-07T02:07:35Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,057 | <p>It really depends on what kind of id you are talking about. If it's a code like a phone number it would actually be better to use a varchar for the id and then have your own id to be a serial for the db and use for primary key. In a case where the integer have no numerical value, varchars are generally prefered. <... | 3 | 2009-07-07T02:09:18Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,065 | <p>Unless you really need the features of an integer (that is, the ability to do arithmetic), then it is probably better for you to store the product IDs as strings. You will never need to do anything like add two product IDs together, or compute the average of a group of product IDs, so there is no need for an actual ... | 23 | 2009-07-07T02:12:26Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,071 | <p>As answered in <a href="http://stackoverflow.com/questions/747802/integer-vs-string-in-database">Integer vs String in database</a></p>
<p>In my country, post-codes are also always 4 digits. But the first digit can be zero.</p>
<blockquote>
<p>If you store "0700" as an integer, you can get a lot of problems:</p>
... | 0 | 2009-07-07T02:14:22Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,100 | <p>Do NOT consider performance. Consider meaning.</p>
<p>ID "numbers" are not numeric except that they are written with an alphabet of all digits.</p>
<p>If I have part number 12 and part number 14, what is the difference between the two? Is part number 2 or -2 meaningful? No.</p>
<p>Part numbers (and anything t... | 12 | 2009-07-07T02:28:35Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,132 | <p>The space an integer would take up would me much less than a string. For example 2^32-1 = 4,294,967,295. This would take 10 bytes to store, where as the integer would take 4 bytes to store. For a single entry this is not very much space, but when you start in the millions... As many other posts suggest there are... | 1 | 2009-07-07T02:42:17Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,390 | <p>I've just spent the last year dealing with a database that has almost all IDs as strings, some with digits only, and others mixed. These are the problems:</p>
<ol>
<li>Grossly restricted ID space. A 4 char (digit-only) ID has capacity for 10,000 unique values. A 4 byte numeric has capacity for over 4 billion.</li>
... | 3 | 2009-07-07T04:45:21Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,708 | <ol>
<li>You won't be able to do comparisons correctly. "... where x > 500" is not same as ".. where x > '500'" because "500" > "100000"</li>
<li>Performance wise string it would be a hit especially if you use indexes as integer indexes are much faster than string indexes.</li>
</ol>
<p>On the other hand it really dep... | 1 | 2009-07-07T06:41:48Z | [
"python",
"mysql",
"database",
"database-design"
] |
Any drawbacks to storing an integer as a string in a database? | 1,090,022 | <p>I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string.</p>
<p>Are there performance or other disadvantages to saving the value... | 13 | 2009-07-07T01:58:05Z | 1,090,924 | <p>Better use independent ID and add string ID if necessary: if there's a business indicator you need to include, why make it system ID?</p>
<p>Main drawbacks:</p>
<ol>
<li><p>Integer operations and indexing always show better performance on large scales of data (more than 1k rows in a table, not to speak of connecte... | 0 | 2009-07-07T07:58:05Z | [
"python",
"mysql",
"database",
"database-design"
] |
How does Python store lists internally? | 1,090,104 | <p>How are lists in python stored internally? Is it an array? A linked list? Something else?</p>
<p>Or does the interpreter guess at the right structure for each instance based on length, etc.</p>
<p>If the question is implementation dependent, what about the classic CPython?</p>
| 9 | 2009-07-07T02:31:01Z | 1,090,117 | <p>from <a href="http://www.pycon.it/media/stuff/slides/core-python-containers-under-hood.ppt">Core Python Containers: Under the Hood</a><br>
List Implementation:<br>
Fixed-length array of pointers<br>
* When the array grows or shrinks, calls realloc() and, if necessary, copies all of the items to the new space<br>
sou... | 21 | 2009-07-07T02:35:40Z | [
"python",
"data-structures"
] |
How can I parse marked up text for further processing? | 1,090,280 | <p><strong>See updated input and output data at Edit-1.</strong></p>
<p>What I am trying to accomplish is turning</p>
<pre>
+ 1
+ 1.1
+ 1.1.1
- 1.1.1.1
- 1.1.1.2
+ 1.2
- 1.2.1
- 1.2.2
- 1.3
+ 2
- 3
</pre>
<p>into a python data structure such as </p>
<pre><code>[{'1': [{'1.1': {'1.1.1': ['1.1.1.1', '1... | 4 | 2009-07-07T03:47:13Z | 1,090,424 | <p>Since you're dealing with an outline situation, you can simplify things by using a stack. Basically, you want to create a stack that has <code>dict</code>s corresponding to the depth of the outline. When you parse a new line and the depth of the outline has increased, you push a new <code>dict</code> onto the stac... | 1 | 2009-07-07T04:59:28Z | [
"python",
"parsing",
"markdown",
"markup",
"lexer"
] |
How can I parse marked up text for further processing? | 1,090,280 | <p><strong>See updated input and output data at Edit-1.</strong></p>
<p>What I am trying to accomplish is turning</p>
<pre>
+ 1
+ 1.1
+ 1.1.1
- 1.1.1.1
- 1.1.1.2
+ 1.2
- 1.2.1
- 1.2.2
- 1.3
+ 2
- 3
</pre>
<p>into a python data structure such as </p>
<pre><code>[{'1': [{'1.1': {'1.1.1': ['1.1.1.1', '1... | 4 | 2009-07-07T03:47:13Z | 1,090,463 | <p><strong>Edit</strong>: thanks to the clarification and change in the spec I've edited my code, still using an explicit <code>Node</code> class as an intermediate step for clarity -- the logic is to turn the list of lines into a list of nodes, then turn that list of nodes into a tree (by using their indent attribute ... | 6 | 2009-07-07T05:16:12Z | [
"python",
"parsing",
"markdown",
"markup",
"lexer"
] |
How can I parse marked up text for further processing? | 1,090,280 | <p><strong>See updated input and output data at Edit-1.</strong></p>
<p>What I am trying to accomplish is turning</p>
<pre>
+ 1
+ 1.1
+ 1.1.1
- 1.1.1.1
- 1.1.1.2
+ 1.2
- 1.2.1
- 1.2.2
- 1.3
+ 2
- 3
</pre>
<p>into a python data structure such as </p>
<pre><code>[{'1': [{'1.1': {'1.1.1': ['1.1.1.1', '1... | 4 | 2009-07-07T03:47:13Z | 1,091,364 | <p>Stacks are a really useful datastructure when parsing trees. You just keep the path from the last added node up to the root on the stack at all times so you can find the correct parent by the length of the indent. Something like this should work for parsing your last example:</p>
<pre><code>import re
line_tokens = ... | 1 | 2009-07-07T09:47:20Z | [
"python",
"parsing",
"markdown",
"markup",
"lexer"
] |
How can I parse marked up text for further processing? | 1,090,280 | <p><strong>See updated input and output data at Edit-1.</strong></p>
<p>What I am trying to accomplish is turning</p>
<pre>
+ 1
+ 1.1
+ 1.1.1
- 1.1.1.1
- 1.1.1.2
+ 1.2
- 1.2.1
- 1.2.2
- 1.3
+ 2
- 3
</pre>
<p>into a python data structure such as </p>
<pre><code>[{'1': [{'1.1': {'1.1.1': ['1.1.1.1', '1... | 4 | 2009-07-07T03:47:13Z | 1,159,300 | <p>The syntax you`re using is <em>very</em> similar to Yaml. It has some differences, but itâs quite easy to learn â itâs main focus is to be human readable (and writable). </p>
<p>Take look at Yaml website. There are some python bindings, documentation and other stuff there.</p>
<ul>
<li><a href="http://www.ya... | 0 | 2009-07-21T13:45:08Z | [
"python",
"parsing",
"markdown",
"markup",
"lexer"
] |
Using Python to call Mencoder with some arguments | 1,090,503 | <p>I'll start by saying that I am very, very new to Python.</p>
<p>I used to have a Windows/Dos batch file in order to launch Mencoder with the right set of parameters, without having to type them each time.</p>
<p>Things got messy when I tried to improve my script, and I decided that it would be a good opportunity t... | 1 | 2009-07-07T05:28:54Z | 1,090,541 | <p>Python have two types of quotes, " and ' and they are completely equal. So easiest way to get quotes in a string is to say '"C:\Program Files\MPlayer-1.0rc2\mencoder.exe"'.</p>
<p>Using the raw prefix (ie r'"C:\Program Files\MPlayer-1.0rc2\mencoder.exe"') is a good idea, but that is not the error here, as none of t... | 4 | 2009-07-07T05:38:10Z | [
"python",
"windows",
"mencoder"
] |
Using Python to call Mencoder with some arguments | 1,090,503 | <p>I'll start by saying that I am very, very new to Python.</p>
<p>I used to have a Windows/Dos batch file in order to launch Mencoder with the right set of parameters, without having to type them each time.</p>
<p>Things got messy when I tried to improve my script, and I decided that it would be a good opportunity t... | 1 | 2009-07-07T05:28:54Z | 2,015,918 | <p>use two quotes instead of one if you are doing on windows. </p>
<pre><code>"\\"
</code></pre>
| 1 | 2010-01-06T20:20:54Z | [
"python",
"windows",
"mencoder"
] |
Using Python to call Mencoder with some arguments | 1,090,503 | <p>I'll start by saying that I am very, very new to Python.</p>
<p>I used to have a Windows/Dos batch file in order to launch Mencoder with the right set of parameters, without having to type them each time.</p>
<p>Things got messy when I tried to improve my script, and I decided that it would be a good opportunity t... | 1 | 2009-07-07T05:28:54Z | 2,679,562 | <p>You can even put the mencoder.exe into a directory which doesn't have a space char inside it's name (opposed to Program Files).</p>
| 0 | 2010-04-21T00:14:30Z | [
"python",
"windows",
"mencoder"
] |
Using Python to call Mencoder with some arguments | 1,090,503 | <p>I'll start by saying that I am very, very new to Python.</p>
<p>I used to have a Windows/Dos batch file in order to launch Mencoder with the right set of parameters, without having to type them each time.</p>
<p>Things got messy when I tried to improve my script, and I decided that it would be a good opportunity t... | 1 | 2009-07-07T05:28:54Z | 8,200,180 | <p>I'm new to Python but I know when ever I see that problem, to fix it, the file (executable or argument) must be in quotes. Just add <strong>\"</strong> before and after any file that contains a space in it to differentiate between the command-line arguments. So, that applies to your outfile variable as well. The cod... | 1 | 2011-11-20T07:55:05Z | [
"python",
"windows",
"mencoder"
] |
Search a folder for files like "/*tmp*.log" in Python | 1,090,651 | <p>As the title says, I'm using Linux, and the folder could contain more than one file, I want to get the one its name contain <code>*tmp*.log</code> (<code>*</code> means anything of course!). Just like what I do using Linux command line.</p>
| 3 | 2009-07-07T06:17:18Z | 1,090,656 | <p>Use the <a href="http://docs.python.org/library/glob.html"><code>glob</code></a> module.</p>
<pre><code>>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']
</code></pre>
| 12 | 2009-07-07T06:18:58Z | [
"python",
"linux",
"file",
"folders"
] |
Search a folder for files like "/*tmp*.log" in Python | 1,090,651 | <p>As the title says, I'm using Linux, and the folder could contain more than one file, I want to get the one its name contain <code>*tmp*.log</code> (<code>*</code> means anything of course!). Just like what I do using Linux command line.</p>
| 3 | 2009-07-07T06:17:18Z | 1,094,073 | <p>The glob answer is easier, but for the sake of completeness: You could also use os.listdir and a regular expression check:</p>
<pre><code>import os
import re
dirEntries = os.listdir(path/to/dir)
for entry in dirEntries:
if re.match(".*tmp.*\.log", entry):
print entry
</code></pre>
| 2 | 2009-07-07T18:43:59Z | [
"python",
"linux",
"file",
"folders"
] |
Search a folder for files like "/*tmp*.log" in Python | 1,090,651 | <p>As the title says, I'm using Linux, and the folder could contain more than one file, I want to get the one its name contain <code>*tmp*.log</code> (<code>*</code> means anything of course!). Just like what I do using Linux command line.</p>
| 3 | 2009-07-07T06:17:18Z | 12,544,486 | <p>The code below expands on previous answers by showing a more complicated search case. </p>
<p>I had an application that was heavily controlled by a configuration file. In fact there were many versions of the configuration each with different tradeoffs. So one configuration set would result in a thorough work but wo... | 0 | 2012-09-22T14:11:44Z | [
"python",
"linux",
"file",
"folders"
] |
Handling Multiple Network Interfaces in Python | 1,090,731 | <p>How can I do the following things in python:</p>
<ol>
<li>List all the IP interfaces on the current machine.</li>
<li>Receive updates about changes in network interfaces (goes up, goes down, changes IP address).</li>
</ol>
<p>Any python package available in Ubuntu Hardy will do.</p>
| 2 | 2009-07-07T06:48:38Z | 1,090,766 | <p>I think the best way to do this is via <a href="http://dbus.freedesktop.org/releases/dbus-python/" rel="nofollow">dbus-python</a>.</p>
<p>The <a href="http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html" rel="nofollow">tutorial</a> touches on network interfaces a little bit:</p>
<pre><code>import dbus
bu... | 3 | 2009-07-07T07:02:55Z | [
"python",
"linux",
"networking",
"ip"
] |
Handling Multiple Network Interfaces in Python | 1,090,731 | <p>How can I do the following things in python:</p>
<ol>
<li>List all the IP interfaces on the current machine.</li>
<li>Receive updates about changes in network interfaces (goes up, goes down, changes IP address).</li>
</ol>
<p>Any python package available in Ubuntu Hardy will do.</p>
| 2 | 2009-07-07T06:48:38Z | 14,047,551 | <p>I have been using the following code,</p>
<pre><code>temp = str(os.system("ifconfig -a | awk '$2~/^Link/{_1=$1;getline;if($2~/^addr/){print _1" "}}'"))
</code></pre>
<p>it will give the 'up' network interfaces</p>
<p>e.g. eth0, eth2, wlan0</p>
| 0 | 2012-12-26T23:27:31Z | [
"python",
"linux",
"networking",
"ip"
] |
Handling Multiple Network Interfaces in Python | 1,090,731 | <p>How can I do the following things in python:</p>
<ol>
<li>List all the IP interfaces on the current machine.</li>
<li>Receive updates about changes in network interfaces (goes up, goes down, changes IP address).</li>
</ol>
<p>Any python package available in Ubuntu Hardy will do.</p>
| 2 | 2009-07-07T06:48:38Z | 14,048,341 | <p>No, no... You don't need to bother os.system() or dbus API.</p>
<p>What you really need is to use netlink API to implement this. Either use <a href="http://www.infradead.org/~tgr/libnl/doc/" rel="nofollow">libnl</a> interface (netlink.route.link) or handle netlink messages by yourself. Take a look at <a href="http:... | 0 | 2012-12-27T01:27:57Z | [
"python",
"linux",
"networking",
"ip"
] |
How to communicate between Python and C# using XML-RPC? | 1,090,792 | <p>Assume I have simple XML-RPC service that is implemented with Python:</p>
<pre><code>from SimpleXMLRPCServer import SimpleXMLRPCServer
def getTest():
return 'test message'
if __name__ == '__main__' :
server = SimpleThreadedXMLRPCServer(('localhost', 8888))
server.register_fuction(g... | 5 | 2009-07-07T07:13:05Z | 1,090,839 | <p>In order to call the getTest method from c# you will need an XML-RPC client library. <a href="http://www.xml-rpc.net/" rel="nofollow">XML-RPC</a> is an example of such a library.</p>
| 2 | 2009-07-07T07:30:34Z | [
"c#",
"python",
"xml-rpc"
] |
How to communicate between Python and C# using XML-RPC? | 1,090,792 | <p>Assume I have simple XML-RPC service that is implemented with Python:</p>
<pre><code>from SimpleXMLRPCServer import SimpleXMLRPCServer
def getTest():
return 'test message'
if __name__ == '__main__' :
server = SimpleThreadedXMLRPCServer(('localhost', 8888))
server.register_fuction(g... | 5 | 2009-07-07T07:13:05Z | 1,090,843 | <p>Not to toot my own horn, but: <a href="http://liboxide.svn.sourceforge.net/viewvc/liboxide/trunk/Oxide.Net/Rpc/" rel="nofollow">http://liboxide.svn.sourceforge.net/viewvc/liboxide/trunk/Oxide.Net/Rpc/</a></p>
<pre><code>class XmlRpcTest : XmlRpcClient
{
private static Uri remoteHost = new Uri("http://localhost:... | 3 | 2009-07-07T07:31:21Z | [
"c#",
"python",
"xml-rpc"
] |
How to communicate between Python and C# using XML-RPC? | 1,090,792 | <p>Assume I have simple XML-RPC service that is implemented with Python:</p>
<pre><code>from SimpleXMLRPCServer import SimpleXMLRPCServer
def getTest():
return 'test message'
if __name__ == '__main__' :
server = SimpleThreadedXMLRPCServer(('localhost', 8888))
server.register_fuction(g... | 5 | 2009-07-07T07:13:05Z | 1,090,995 | <p>Thank you for answer, I try xml-rpc library from darin link. I can call getTest function with following code</p>
<pre><code>using CookComputing.XmlRpc;
...
namespace Hello
{
/* proxy interface */
[XmlRpcUrl("http://localhost:8888")]
public interface IStateName : IXmlRpcProxy
... | 3 | 2009-07-07T08:19:15Z | [
"c#",
"python",
"xml-rpc"
] |
Python operators | 1,090,863 | <p>I am learning Python for the past few days and I have written this piece of code to evaluate a postfix expression.</p>
<pre><code>postfix_expression = "34*34*+"
stack = []
for char in postfix_expression :
try :
char = int(char);
stack.append(char);
except ValueError:
if char == '+' :
... | 7 | 2009-07-07T07:37:49Z | 1,090,886 | <p>The <a href="http://docs.python.org/library/operator.html" rel="nofollow"><code>operator</code></a> module has functions that implement the standard arithmetic operators. With that, you can set up a mapping like:</p>
<pre><code>OperatorFunctions = {
'+': operator.add,
'-': operator.sub,
'*': operator.mu... | 15 | 2009-07-07T07:43:50Z | [
"python",
"operators"
] |
Python operators | 1,090,863 | <p>I am learning Python for the past few days and I have written this piece of code to evaluate a postfix expression.</p>
<pre><code>postfix_expression = "34*34*+"
stack = []
for char in postfix_expression :
try :
char = int(char);
stack.append(char);
except ValueError:
if char == '+' :
... | 7 | 2009-07-07T07:37:49Z | 1,090,891 | <p>Just use <a href="http://docs.python.org/library/functions.html#eval" rel="nofollow">eval</a> along with string generation:</p>
<pre><code>postfix_expression = "34*34*+"
stack = []
for char in postfix_expression:
if char in '+-*/':
expression = '%d%s%d' % (stack.pop(), char, stack.pop())
stack.a... | 0 | 2009-07-07T07:46:37Z | [
"python",
"operators"
] |
Python operators | 1,090,863 | <p>I am learning Python for the past few days and I have written this piece of code to evaluate a postfix expression.</p>
<pre><code>postfix_expression = "34*34*+"
stack = []
for char in postfix_expression :
try :
char = int(char);
stack.append(char);
except ValueError:
if char == '+' :
... | 7 | 2009-07-07T07:37:49Z | 1,090,908 | <pre><code>[untested]
from operator import add, sub, mul, div
# read the docs; this is a tiny part of the operator module
despatcher = {
'+': add,
'-': sub,
# etc
}
opfunc = despatcher[op_char]
operand2 = stack.pop()
# your - and / are bassackwards
stack[-1] = opfunc(stack[-1], operand2)
</code></pre>... | 0 | 2009-07-07T07:52:48Z | [
"python",
"operators"
] |
How to test if a class attribute is an instance method | 1,091,259 | <p>In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object.</p>
<p>hasattr returns true regardless of whether the attribute is an instance method or not.</p>
<p>Any sugg... | 2 | 2009-07-07T09:23:23Z | 1,091,281 | <pre><code>import types
print isinstance(getattr(your_object, "your_attribute"), types.MethodType)
</code></pre>
| 3 | 2009-07-07T09:32:10Z | [
"python",
"methods",
"attributes",
"instance"
] |
How to test if a class attribute is an instance method | 1,091,259 | <p>In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object.</p>
<p>hasattr returns true regardless of whether the attribute is an instance method or not.</p>
<p>Any sugg... | 2 | 2009-07-07T09:23:23Z | 1,091,288 | <pre><code>def hasmethod(obj, name):
return hasattr(obj, name) and type(getattr(obj, name)) == types.MethodType
</code></pre>
| 8 | 2009-07-07T09:33:55Z | [
"python",
"methods",
"attributes",
"instance"
] |
How to test if a class attribute is an instance method | 1,091,259 | <p>In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object.</p>
<p>hasattr returns true regardless of whether the attribute is an instance method or not.</p>
<p>Any sugg... | 2 | 2009-07-07T09:23:23Z | 1,091,297 | <p>You can use the <code>inspect</code> module:</p>
<pre><code>class A(object):
def method_name(self):
pass
import inspect
print inspect.ismethod(getattr(A, 'method_name')) # prints True
a = A()
print inspect.ismethod(getattr(a, 'method_name')) # prints True
</code></pre>
| 3 | 2009-07-07T09:35:20Z | [
"python",
"methods",
"attributes",
"instance"
] |
How to test if a class attribute is an instance method | 1,091,259 | <p>In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object.</p>
<p>hasattr returns true regardless of whether the attribute is an instance method or not.</p>
<p>Any sugg... | 2 | 2009-07-07T09:23:23Z | 1,091,300 | <p>This function checks if the attribute exists and then checks if the attribute is a method using the <code>inspect</code> module.</p>
<pre><code>import inspect
def ismethod(obj, name):
if hasattr(obj, name):
if inspect.ismethod(getattr(obj, name)):
return True
return False
class Foo:
... | 1 | 2009-07-07T09:35:49Z | [
"python",
"methods",
"attributes",
"instance"
] |
how do I get the process list in Python? | 1,091,327 | <p>How do I get a process list of all running processes from Python, on Unix, containing then name of the command/process and process id, so I can filter and kill processes. </p>
| 7 | 2009-07-07T09:41:39Z | 1,091,353 | <p>Why Python?<br />
You can directly use <a href="http://manpages.ubuntu.com/manpages/karmic/man1/killall.1.html" rel="nofollow"><code>killall</code></a> on the process name.</p>
| -1 | 2009-07-07T09:45:20Z | [
"python",
"unix",
"kill",
"ps",
"processlist"
] |
how do I get the process list in Python? | 1,091,327 | <p>How do I get a process list of all running processes from Python, on Unix, containing then name of the command/process and process id, so I can filter and kill processes. </p>
| 7 | 2009-07-07T09:41:39Z | 1,091,426 | <p>On linux, the easiest solution is probably to use the external <code>ps</code> command:</p>
<pre><code>>>> import os
>>> data = [(int(p), c) for p, c in [x.rstrip('\n').split(' ', 1) \
... for x in os.popen('ps h -eo pid:1,command')]]
</code></pre>
<p>On other systems you might have to cha... | 2 | 2009-07-07T10:01:45Z | [
"python",
"unix",
"kill",
"ps",
"processlist"
] |
how do I get the process list in Python? | 1,091,327 | <p>How do I get a process list of all running processes from Python, on Unix, containing then name of the command/process and process id, so I can filter and kill processes. </p>
| 7 | 2009-07-07T09:41:39Z | 1,091,428 | <p>On Linux, with a suitably recent Python which includes the <code>subprocess</code> module:</p>
<pre><code>from subprocess import Popen, PIPE
process = Popen(['ps', '-eo' ,'pid,args'], stdout=PIPE, stderr=PIPE)
stdout, notused = process.communicate()
for line in stdout.splitlines():
pid, cmdline = line.split(' ... | 6 | 2009-07-07T10:02:17Z | [
"python",
"unix",
"kill",
"ps",
"processlist"
] |
Python composite pattern exception handling & pylint | 1,091,337 | <p>I'm implementig a Composite pattern in <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">this way</a>:</p>
<p>1) the "abstract" component is:</p>
<pre><code>class Component(object):
"""Basic Component Abstraction"""
def __init__(self, *args, **kw):
raise NotImplementedError("m... | 1 | 2009-07-07T09:42:31Z | 1,091,390 | <p>Abstract initializers are a bad idea. Your code might evolve so that you want to do some initialization in the root component. And even if you don't why require the implementation of the initializer. For some subclasses an empty initializer would be an acceptable choice.</p>
<p>If you don't want any instances of th... | 4 | 2009-07-07T09:52:05Z | [
"python",
"composite",
"pylint"
] |
Python composite pattern exception handling & pylint | 1,091,337 | <p>I'm implementig a Composite pattern in <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">this way</a>:</p>
<p>1) the "abstract" component is:</p>
<pre><code>class Component(object):
"""Basic Component Abstraction"""
def __init__(self, *args, **kw):
raise NotImplementedError("m... | 1 | 2009-07-07T09:42:31Z | 1,091,452 | <p>You want to guarantee, that the base class Component is not instanciated. This is a noble guesture common in other programming languages like C++ (where you can make the constructors private or so to prevent direct usage).</p>
<p>But it is not supported in Python. Python does not support all programming notions and... | 1 | 2009-07-07T10:07:28Z | [
"python",
"composite",
"pylint"
] |
Python composite pattern exception handling & pylint | 1,091,337 | <p>I'm implementig a Composite pattern in <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">this way</a>:</p>
<p>1) the "abstract" component is:</p>
<pre><code>class Component(object):
"""Basic Component Abstraction"""
def __init__(self, *args, **kw):
raise NotImplementedError("m... | 1 | 2009-07-07T09:42:31Z | 1,091,524 | <p>Not bad coding as such, but the <code>__init__</code> of the component is simply not needed. If you want it, you can ignore pylint, but it's a better idea to simply remove the <code>__init__</code> from Component.</p>
<p>Embrace the dynamicism!</p>
| 1 | 2009-07-07T10:21:46Z | [
"python",
"composite",
"pylint"
] |
Python composite pattern exception handling & pylint | 1,091,337 | <p>I'm implementig a Composite pattern in <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">this way</a>:</p>
<p>1) the "abstract" component is:</p>
<pre><code>class Component(object):
"""Basic Component Abstraction"""
def __init__(self, *args, **kw):
raise NotImplementedError("m... | 1 | 2009-07-07T09:42:31Z | 1,091,528 | <p>Another suggestion to complement the idea of Markus:</p>
<p>If you really must, I suggest that you use __new __ and check for the given object type. When it is "Component" you could fire your exception:</p>
<pre><code>class Component(object):
"""Basic Component Abstraction"""
def __new__(objType, *args, **kwargs)... | 2 | 2009-07-07T10:22:43Z | [
"python",
"composite",
"pylint"
] |
Python composite pattern exception handling & pylint | 1,091,337 | <p>I'm implementig a Composite pattern in <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">this way</a>:</p>
<p>1) the "abstract" component is:</p>
<pre><code>class Component(object):
"""Basic Component Abstraction"""
def __init__(self, *args, **kw):
raise NotImplementedError("m... | 1 | 2009-07-07T09:42:31Z | 2,341,833 | <p>Renaming your class Component to AbstractComponent should help. And don't provide an <code>__init__</code> method in your base class if it's not supposed to be called by subclasses. </p>
| 2 | 2010-02-26T13:21:51Z | [
"python",
"composite",
"pylint"
] |
TeamCity for Python/Django continuous integration | 1,091,465 | <p>I've set up <a href="http://en.wikipedia.org/wiki/TeamCity">TeamCity</a> on a Linux (Ubuntu) box and would like to use it for some of Python/Django projects.</p>
<p>The problem is that I don't really see what to do next - I tried searching for a Python specific build agent for TeamCity but without much of the succe... | 9 | 2009-07-07T10:09:26Z | 1,102,217 | <p>Ok, so there's how to get it working with proper TeamCity integration:</p>
<p>Presuming you have TeamCity installed with at least 1 build agent available</p>
<p>1) Configure your build agent to execute </p>
<pre><code>manage.py test
</code></pre>
<p>2) Download and install this plugin for TC <a href="http://pypi... | 21 | 2009-07-09T06:51:57Z | [
"python",
"django",
"continuous-integration",
"teamcity"
] |
TeamCity for Python/Django continuous integration | 1,091,465 | <p>I've set up <a href="http://en.wikipedia.org/wiki/TeamCity">TeamCity</a> on a Linux (Ubuntu) box and would like to use it for some of Python/Django projects.</p>
<p>The problem is that I don't really see what to do next - I tried searching for a Python specific build agent for TeamCity but without much of the succe... | 9 | 2009-07-07T10:09:26Z | 14,136,986 | <p>I have added feature request to TeamCity issue tracker, to make full-featured python support. This is the link: <a href="http://youtrack.jetbrains.com/issue/TW-25141" rel="nofollow">http://youtrack.jetbrains.com/issue/TW-25141</a>. If you interested, you can vote for it, and that may force JetBrains to improve pytho... | 1 | 2013-01-03T10:26:41Z | [
"python",
"django",
"continuous-integration",
"teamcity"
] |
Dropdown menus in forms containing database primary keys | 1,091,668 | <p>In a framework like Django or Pylons you can set up function to handle form submissions. If your form involves a dropdown menu (i.e. a select tag) populated with objects from a database you can set the values equal to the primary key for the record like:</p>
<pre><code><select>
<option value="1">Volv... | 0 | 2009-07-07T10:58:13Z | 1,091,728 | <p>Using the primary key is fine. What exactly are you concerned with? This is an implementation detail that won't show up to the user in the actual rendered page.</p>
| 3 | 2009-07-07T11:09:22Z | [
"python",
"django",
"pylons"
] |
Programmatic control of python optimization? | 1,092,243 | <p>I've been playing with <a href="http://www.pyglet.org/index.html" rel="nofollow">pyglet</a>. It's very nice. However, if I run my code, which is in an executable file (call it game.py) prefixed with the usual</p>
<pre><code>#!/usr/bin/env python
</code></pre>
<p>by doing</p>
<pre><code>./game.py
</code></pre>
... | 5 | 2009-07-07T13:06:14Z | 1,092,266 | <p><strong>"On Linux I can easily provide a ./game script to run the file for end users:"</strong></p>
<p>Correct.</p>
<p><strong>"but that's not very cross-platform."</strong></p>
<p>Half-correct. There are exactly two shell languages that matter. Standard Linux "sh" and Non-standard Windows "bat" (a/k/a cmd.exe... | 14 | 2009-07-07T13:11:41Z | [
"python",
"optimization",
"pyglet",
"multiplatform"
] |
Programmatic control of python optimization? | 1,092,243 | <p>I've been playing with <a href="http://www.pyglet.org/index.html" rel="nofollow">pyglet</a>. It's very nice. However, if I run my code, which is in an executable file (call it game.py) prefixed with the usual</p>
<pre><code>#!/usr/bin/env python
</code></pre>
<p>by doing</p>
<pre><code>./game.py
</code></pre>
... | 5 | 2009-07-07T13:06:14Z | 1,097,256 | <p>Answering your question (as opposing to fixing your problem, which S. Lott did perfectly), I think a lot of the time people who distribute Python code don't worry about this, because it's rare for the optimisation flag to have any effect. I believe Pyglet is the only exception I've heard of in years of using Python.... | 2 | 2009-07-08T10:25:15Z | [
"python",
"optimization",
"pyglet",
"multiplatform"
] |
What is the correct way to "pipe" Maven's output in Python to the screen when used in a Python shell script? | 1,092,299 | <p>My Python utility script contains UNIX system calls such as </p>
<pre><code>status, output = commands.getstatusoutput("ls -ltr")
print "Output: ", output
print "Status: ", status
</code></pre>
<p>Which work fine and print the output to the console but as soon as I run Maven from the same script,</p>
<pre><code>st... | 0 | 2009-07-07T13:21:56Z | 1,092,345 | <p>Are you sure that <code>${PWD}</code> is properly expanded? If not, try:</p>
<pre><code>status, output = commands.getstatusoutput("mvn clean install -s./../../foo/bar/settings.xml -Dportal -Dmain.dir=%s/../.. -o" % os.getcwd ())
</code></pre>
| 0 | 2009-07-07T13:29:45Z | [
"python",
"unix",
"shell",
"maven-2"
] |
want to get mac address of remote PC | 1,092,379 | <p>I have my web page in python, i am able to get the ip address of the user, who will be accessing our web page, we want to get the mac address of the user's PC, is it possible in python, we are using linux PC, we want to get it on linux.</p>
| 1 | 2009-07-07T13:35:37Z | 1,092,392 | <p>All you can access is what the user sends to you.</p>
<p>MAC address is not part of that data.</p>
| 1 | 2009-07-07T13:38:25Z | [
"python",
"python-3.x"
] |
want to get mac address of remote PC | 1,092,379 | <p>I have my web page in python, i am able to get the ip address of the user, who will be accessing our web page, we want to get the mac address of the user's PC, is it possible in python, we are using linux PC, we want to get it on linux.</p>
| 1 | 2009-07-07T13:35:37Z | 1,092,395 | <p><a href="http://code.activestate.com/recipes/347812/" rel="nofollow">from Active code</a> </p>
<pre><code>#!/usr/bin/env python
import ctypes
import socket
import struct
def get_macaddress(host):
""" Returns the MAC address of a network host, requires >= WIN2K. """
# Check for api availability
try... | 2 | 2009-07-07T13:39:04Z | [
"python",
"python-3.x"
] |
want to get mac address of remote PC | 1,092,379 | <p>I have my web page in python, i am able to get the ip address of the user, who will be accessing our web page, we want to get the mac address of the user's PC, is it possible in python, we are using linux PC, we want to get it on linux.</p>
| 1 | 2009-07-07T13:35:37Z | 1,092,409 | <p>I have a small, signed Java Applet, which requires Java 6 runtime on the remote computer to do this. It uses the <a href="http://java.sun.com/javase/6/docs/api/java/net/NetworkInterface.html#getHardwareAddress%28%29" rel="nofollow">getHardwareAddress()</a> method on <a href="http://java.sun.com/javase/6/docs/api/ja... | 5 | 2009-07-07T13:41:33Z | [
"python",
"python-3.x"
] |
want to get mac address of remote PC | 1,092,379 | <p>I have my web page in python, i am able to get the ip address of the user, who will be accessing our web page, we want to get the mac address of the user's PC, is it possible in python, we are using linux PC, we want to get it on linux.</p>
| 1 | 2009-07-07T13:35:37Z | 1,092,454 | <p>The <a href="http://code.google.com/p/dpkt/" rel="nofollow">dpkt</a> package was <a href="http://stackoverflow.com/questions/85577/search-for-host-with-mac-address-using-python/85632">already mentioned</a> on SO. It allows for parsing TCP/IP packets. I have not yet used it for your case, though.</p>
| 0 | 2009-07-07T13:48:37Z | [
"python",
"python-3.x"
] |
Where do I find the Python Crypto package when installing Paramiko on windows? | 1,092,402 | <p>I am trying to SFTP from Python running on windows and installed Paramiko as was recommended here. Unfortunately, it asks for Crypto.Util.randpool so I need to install the Crypto package. I found RPMS for Linux, but can't find anything or source code for windows.</p>
<p>The readme for Paramiko states:
pycrypto comp... | 3 | 2009-07-07T13:40:06Z | 1,092,441 | <p>See <a href="http://www.voidspace.org.uk/python/modules.shtml#pycrypto" rel="nofollow">here</a> for Win32 binaries for Python 2.2 through to 2.7</p>
| 6 | 2009-07-07T13:46:05Z | [
"python",
"paramiko"
] |
Windows XP - mute/unmute audio in programmatically in Python | 1,092,466 | <p>My machine has two audio inputs: a mic in that I use for gaming, and a line in that I use for guitar. When using one it's important that the other be muted to remove hiss/static, so I was hoping to write a small script that would toggle which one was muted (it's fairly inconvenient to click through the tray icon, sw... | 1 | 2009-07-07T13:50:58Z | 1,093,445 | <p><strong><em>Disclaimer:</strong> I'm not a windows programming guru by any means...but here's my best guess</em></p>
<p>Per the <a href="http://python.net/crew/mhammond/win32/FAQ.html" rel="nofollow">pywin32 FAQ</a>:</p>
<blockquote>
<p><strong>How do I use the exposed Win32 functions to do xyz?</strong></p>
... | 4 | 2009-07-07T16:42:40Z | [
"python",
"windows",
"winapi",
"audio",
"pywin32"
] |
Windows XP - mute/unmute audio in programmatically in Python | 1,092,466 | <p>My machine has two audio inputs: a mic in that I use for gaming, and a line in that I use for guitar. When using one it's important that the other be muted to remove hiss/static, so I was hoping to write a small script that would toggle which one was muted (it's fairly inconvenient to click through the tray icon, sw... | 1 | 2009-07-07T13:50:58Z | 1,093,624 | <p>You are probably better off using <code>ctypes</code> - <code>pywin32</code> is good if you are using one of the already included APIs, but I think you'll be out of luck with the sound APIs. Together with the example code from the C# link provided by <code>tgray</code>, use <code>ctypes</code> and <code>winmm.dll</c... | 1 | 2009-07-07T17:22:31Z | [
"python",
"windows",
"winapi",
"audio",
"pywin32"
] |
Windows XP - mute/unmute audio in programmatically in Python | 1,092,466 | <p>My machine has two audio inputs: a mic in that I use for gaming, and a line in that I use for guitar. When using one it's important that the other be muted to remove hiss/static, so I was hoping to write a small script that would toggle which one was muted (it's fairly inconvenient to click through the tray icon, sw... | 1 | 2009-07-07T13:50:58Z | 1,093,683 | <p><strong>tgray</strong> seems to have pointed you in the right direction, but once you find out the right Win32 APIs to deal with, you have a couple of options:</p>
<p>1) Try using pywin32...but it may or may not wrap the functionality you need (it probably doesn't). So you probably only want to do this if you need... | 0 | 2009-07-07T17:32:31Z | [
"python",
"windows",
"winapi",
"audio",
"pywin32"
] |
Windows XP - mute/unmute audio in programmatically in Python | 1,092,466 | <p>My machine has two audio inputs: a mic in that I use for gaming, and a line in that I use for guitar. When using one it's important that the other be muted to remove hiss/static, so I was hoping to write a small script that would toggle which one was muted (it's fairly inconvenient to click through the tray icon, sw... | 1 | 2009-07-07T13:50:58Z | 1,094,204 | <p>I had a similar problem and couldn't figure out how to use Windows API's to do what I wanted. I ended up just automating the GUI with AutoIt. I think that will be the fastest and easiest solution (albeit a "hacky" one). As I <a href="http://stackoverflow.com/questions/1084514/make-your-program-use-a-gui/1092401#1... | 2 | 2009-07-07T19:11:01Z | [
"python",
"windows",
"winapi",
"audio",
"pywin32"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 1,092,617 | <p>I use <a href="http://pypi.python.org/pypi/zope.event" rel="nofollow">zope.event</a>. It's the most bare bones you can imagine. :-)
In fact, here is the complete source code:</p>
<pre><code>subscribers = []
def notify(event):
for subscriber in subscribers:
subscriber(event)
</code></pre>
<p>Note that ... | 10 | 2009-07-07T14:19:39Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 1,092,860 | <p>If I do code in pyQt I use QT sockets/signals paradigm, same is for django</p>
<p>If I'm doing async I/O I use native select module</p>
<p>If I'm usign a SAX python parser I'm using event API provided by SAX. So it looks like I'm victim of underlying API :-)</p>
<p>Maybe you should ask yourself what do you expect... | 1 | 2009-07-07T15:02:48Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 1,094,423 | <p>We use an EventHook as suggested from Michael Foord in his <a href="http://www.voidspace.org.uk/python/weblog/arch_d7_2007_02_03.shtml#e616">Event Pattern</a>:</p>
<p>Just add EventHooks to your classes with:</p>
<pre><code>class MyBroadcaster()
def __init__():
self.onChange = EventHook()
theBroadcast... | 58 | 2009-07-07T19:46:51Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 1,096,614 | <p>I found this small script on <a href="http://www.valuedlessons.com/2008/04/events-in-python.html">Valued Lessons</a>. It seems to have just the right simplicity/power ratio I'm after. Peter Thatcher is the author of following code (no licensing is mentioned).</p>
<pre><code>class Event:
def __init__(self):
... | 8 | 2009-07-08T07:32:24Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 1,097,401 | <p>Here's another <a href="http://home.gna.org/py-notify/" rel="nofollow">module</a> for consideration. It seems a viable choice for more demanding applications.</p>
<blockquote>
<p>Py-notify is a Python package
providing tools for implementing
Observer programming pattern. These
tools include signals, conditi... | 1 | 2009-07-08T11:10:07Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 2,022,629 | <p>I've been doing it this way:</p>
<pre><code>class Event(list):
"""Event subscription.
A list of callable objects. Calling an instance of this will cause a
call to each item in the list in ascending order by index.
Example Usage:
>>> def f(x):
... print 'f(%s)' % x
>>... | 53 | 2010-01-07T18:28:47Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 16,192,256 | <p>Wrapping up the various event systems that are mentioned in the answers here:</p>
<p>The most basic style of event system is the 'bag of handler methods', which is a simple implementation of the <a href="http://en.wikipedia.org/wiki/Observer_pattern">Observer pattern</a>. Basically, the handler methods (callables)... | 59 | 2013-04-24T12:38:55Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 20,807,692 | <p>I created an <code>EventManager</code> class (code at the end). The syntax is the following:</p>
<pre><code>#Create an event with no listeners assigned to it
EventManager.addEvent( eventName = [] )
#Create an event with listeners assigned to it
EventManager.addEvent( eventName = [fun1, fun2,...] )
#Create any num... | 2 | 2013-12-27T20:53:42Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 28,479,007 | <p>Here is a minimal design that should work fine. What you have to do is to simply inherit <code>Observer</code> in a class and afterwards use <code>observe(event_name, callback_fn)</code> to listen for a specific event. Whenever that specific event is fired anywhere in the code (ie. <code>Event('USB connected')</code... | 2 | 2015-02-12T13:43:22Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Event system in Python | 1,092,531 | <p>What event system for Python do you use? I'm already aware of <a href="http://pydispatcher.sourceforge.net/">pydispatcher</a>, but I was wondering what else can be found, or is commonly used?</p>
<p>I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution th... | 111 | 2009-07-07T14:00:51Z | 29,059,561 | <p>You may have a look at <a href="https://github.com/riga/pymitter" rel="nofollow">pymitter</a> (<a href="https://pypi.python.org/pypi/pymitter" rel="nofollow">pypi</a>). Its a small single-file (~250 loc) approach
"providing namespaces, wildcards and TTL".</p>
<p>Here's a basic example:</p>
<pre><code>from pymitter... | 3 | 2015-03-15T10:23:32Z | [
"python",
"events",
"event-handling",
"dispatcher"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.