title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How do I find the shortest overlapping match using regular expressions? | 2,148,700 | <p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p>
<pre><code>import re
string = "A|B|A|B|C|D|E|F|G"
my_pattern = 'a.*?b.*?c'
my_regex = re.compile(my_p... | 12 | 2010-01-27T16:49:34Z | 2,148,815 | <p>I do not think that this task can be accomplished by a single regular expression. I have no proof that this is the case, but there are quite a lot of things that can't be done with regexes and I expected this problem to be one of them. Some good examples of the limitations of regexes are given in <a href="http://blo... | 0 | 2010-01-27T17:04:30Z | [
"python",
"regex"
] |
How do I find the shortest overlapping match using regular expressions? | 2,148,700 | <p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p>
<pre><code>import re
string = "A|B|A|B|C|D|E|F|G"
my_pattern = 'a.*?b.*?c'
my_regex = re.compile(my_p... | 12 | 2010-01-27T16:49:34Z | 2,149,345 | <p>This might be a useful application of <a href="http://www.perlmonks.org/index.pl?node=sexeger" rel="nofollow">sexegers</a>. Regular-expression matching is biased toward the longest, leftmost choice. Using non-greedy quantifiers such as in <code>.*?</code> skirts the longest part, and reversing both the input and pat... | 0 | 2010-01-27T18:25:39Z | [
"python",
"regex"
] |
How do I find the shortest overlapping match using regular expressions? | 2,148,700 | <p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p>
<pre><code>import re
string = "A|B|A|B|C|D|E|F|G"
my_pattern = 'a.*?b.*?c'
my_regex = re.compile(my_p... | 12 | 2010-01-27T16:49:34Z | 2,149,385 | <p>You might be able to write the regex in such a way that it can't contain smaller matches.</p>
<p>For your regex:</p>
<pre><code>a.*?b.*?c
</code></pre>
<p>I think you can write this:</p>
<pre><code>a[^ab]*b[^c]*c
</code></pre>
<p>It's tricky to get that correct, and I don't see any more general or more obviousl... | 0 | 2010-01-27T18:31:57Z | [
"python",
"regex"
] |
How do I find the shortest overlapping match using regular expressions? | 2,148,700 | <p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p>
<pre><code>import re
string = "A|B|A|B|C|D|E|F|G"
my_pattern = 'a.*?b.*?c'
my_regex = re.compile(my_p... | 12 | 2010-01-27T16:49:34Z | 2,149,839 | <p>A Python loop to look for the shortest match, by brute force testing each substring from left to right, picking the shortest:</p>
<pre><code>shortest = None
for i in range(len(string)):
m = my_regex.match(string[i:])
if m:
mstr = m.group()
if shortest is None or len(mstr) < len(shortest)... | 0 | 2010-01-27T19:53:55Z | [
"python",
"regex"
] |
How do I find the shortest overlapping match using regular expressions? | 2,148,700 | <p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p>
<pre><code>import re
string = "A|B|A|B|C|D|E|F|G"
my_pattern = 'a.*?b.*?c'
my_regex = re.compile(my_p... | 12 | 2010-01-27T16:49:34Z | 2,151,596 | <p>No, there isn't in the Python regular expression engine.</p>
<p>My take for a custom function, though:</p>
<pre><code>import re, itertools
# directly from itertools recipes
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = itertools.tee(iterable)
for elem in b:
break
... | 0 | 2010-01-28T01:03:59Z | [
"python",
"regex"
] |
How do I find the shortest overlapping match using regular expressions? | 2,148,700 | <p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p>
<pre><code>import re
string = "A|B|A|B|C|D|E|F|G"
my_pattern = 'a.*?b.*?c'
my_regex = re.compile(my_p... | 12 | 2010-01-27T16:49:34Z | 7,554,237 | <p>Another regex solution; it finds only the last occurence of .*a.*b.*c:</p>
<pre><code>my_pattern = 'a(?!.*a.*b.*c).*b[^c]*c'
</code></pre>
<p><code>a(?!.*a.*?b.*?c)</code> ensures that there is no <code>'a.*?b.*?c'</code> after first 'A'
strings like A|A|B|C or A|B|A|B|C or A|B|C|A|B|C in results are eliminated</p... | 1 | 2011-09-26T11:14:52Z | [
"python",
"regex"
] |
How do I find the shortest overlapping match using regular expressions? | 2,148,700 | <p>I'm still relatively new to regex. I'm trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a substring of a larger match. For example:</p>
<pre><code>import re
string = "A|B|A|B|C|D|E|F|G"
my_pattern = 'a.*?b.*?c'
my_regex = re.compile(my_p... | 12 | 2010-01-27T16:49:34Z | 7,554,619 | <p>Contrary to most other answers here, this <em>can</em> be done in a single regex using a <a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow">positive lookahead assertion</a> with a <a href="http://www.regular-expressions.info/brackets.html" rel="nofollow">capturing group</a>:</p>
<pre><code... | 9 | 2011-09-26T11:49:10Z | [
"python",
"regex"
] |
Boost::Python, static factories, and inheritance | 2,148,777 | <p>So I may have a rather unique use case here, but I'm thinking it should work- But it's not working correctly.</p>
<p>Basically, I have a class that uses a static factory method ( create ) that returns a shared_ptr to the newly created
instance of the class. This class also has a virtual function that I'd like to ov... | 4 | 2010-01-27T16:59:48Z | 2,159,991 | <p>I ended up rethinking my design using intrusive_ptrs. There was a little more work to be done with the wrappers than using shared_ptr, but it worked out fairly well. Thanks to everyone for their time.</p>
| 1 | 2010-01-29T05:07:57Z | [
"c++",
"python",
"boost"
] |
Python - Trap all signals | 2,148,888 | <p>In python 2.6 under Linux, I can use the following to handle a TERM signal:</p>
<pre><code>import signal
def handleSigTERM():
shutdown()
signal.signal(signal.SIGTERM, handleSigTERM)
</code></pre>
<p>Is there any way to setup a handler for all signals received by the process, other than just setting them up... | 16 | 2010-01-27T17:16:29Z | 2,148,925 | <p>You could just loop through the signals in the signal module and set them up.</p>
<pre><code>for i in [x for x in dir(signal) if x.startswith("SIG")]:
try:
signum = getattr(signal,i)
signal.signal(signum,sighandler)
except RuntimeError,m:
print "Skipping %s"%i
</code></pre>
| 18 | 2010-01-27T17:24:03Z | [
"python",
"linux",
"signal-handling"
] |
Python - Trap all signals | 2,148,888 | <p>In python 2.6 under Linux, I can use the following to handle a TERM signal:</p>
<pre><code>import signal
def handleSigTERM():
shutdown()
signal.signal(signal.SIGTERM, handleSigTERM)
</code></pre>
<p>Is there any way to setup a handler for all signals received by the process, other than just setting them up... | 16 | 2010-01-27T17:16:29Z | 5,669,030 | <p>If you want to get rid of the try, just ignore signals that cannot be caught.</p>
<pre><code>def receive_signal(signum, stack):
if signum in [1,2,3,15]:
print 'Caught signal %s, exiting.' %(str(signum))
sys.exit()
else:
print 'Caught signal %s, ignoring.' %(str(signum))
def main():
... | 9 | 2011-04-14T20:06:35Z | [
"python",
"linux",
"signal-handling"
] |
Python - Trap all signals | 2,148,888 | <p>In python 2.6 under Linux, I can use the following to handle a TERM signal:</p>
<pre><code>import signal
def handleSigTERM():
shutdown()
signal.signal(signal.SIGTERM, handleSigTERM)
</code></pre>
<p>Is there any way to setup a handler for all signals received by the process, other than just setting them up... | 16 | 2010-01-27T17:16:29Z | 28,999,277 | <p>That code won't work in the current version of python. There are many variables starting with SIG with the same value. For instance, SIGHUP and SIG_UNBLOCK are both 1. The only way I could think of to get a list of <em>actual signals</em> was to just make it myself.</p>
<pre><code>from signal import *
signals =... | 0 | 2015-03-11T23:24:14Z | [
"python",
"linux",
"signal-handling"
] |
Python - Trap all signals | 2,148,888 | <p>In python 2.6 under Linux, I can use the following to handle a TERM signal:</p>
<pre><code>import signal
def handleSigTERM():
shutdown()
signal.signal(signal.SIGTERM, handleSigTERM)
</code></pre>
<p>Is there any way to setup a handler for all signals received by the process, other than just setting them up... | 16 | 2010-01-27T17:16:29Z | 34,568,177 | <p>As of Python 3.5, the signal constants are <a href="https://docs.python.org/3/library/signal.html#module-contents" rel="nofollow">defined as an enum</a>, enabling a nicer approach:</p>
<pre><code>import signal
catchable_sigs = set(signal.Signals) - {signal.SIGKILL, signal.SIGSTOP}
for sig in catchable_sigs:
si... | 3 | 2016-01-02T16:40:04Z | [
"python",
"linux",
"signal-handling"
] |
Running a Django test server under twisted web | 2,148,890 | <p>As I'm writing an application which uses twisted web for serving async requests and Django for normal content delivery, I thought it would have been nice to have both run under the same twisted reactor through the WSGI interface of Django.</p>
<p>I also wanted to test my app using the nice test server facility that... | 4 | 2010-01-27T17:16:38Z | 2,152,342 | <p>This might be exactly what you are looking for: <a href="http://github.com/clemesha/twisted-wsgi-django" rel="nofollow">http://github.com/clemesha/twisted-wsgi-django</a></p>
| 2 | 2010-01-28T04:44:28Z | [
"python",
"django",
"integration",
"twisted",
"asynchronous"
] |
When running a python script in IDLE, is there a way to pass in command line arguments (args)? | 2,148,994 | <p>I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.</p>
<p>I'm running Windows.</p>
| 28 | 2010-01-27T17:33:20Z | 2,149,029 | <p>It doesn't seem like IDLE provides a way to do this through the GUI, but you could do something like:</p>
<pre><code>idle.py -r scriptname.py arg1 arg2 arg3
</code></pre>
<p>You can also set <code>sys.argv</code> manually, like:</p>
<pre><code>try:
__file__
except:
sys.argv = [sys.argv[0], 'argument1', 'a... | 23 | 2010-01-27T17:37:14Z | [
"python",
"command-line-arguments",
"python-idle"
] |
When running a python script in IDLE, is there a way to pass in command line arguments (args)? | 2,148,994 | <p>I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.</p>
<p>I'm running Windows.</p>
| 28 | 2010-01-27T17:33:20Z | 2,149,047 | <p>Here are a couple of ways that I can think of: </p>
<p>1) You can call your "main" function directly on the IDLE console with arguments if you want. </p>
<p>2) You can add a test line in front of your main function call which supplies an array of arguments (or create a unit test which does the same thing), or set ... | 4 | 2010-01-27T17:38:54Z | [
"python",
"command-line-arguments",
"python-idle"
] |
When running a python script in IDLE, is there a way to pass in command line arguments (args)? | 2,148,994 | <p>I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.</p>
<p>I'm running Windows.</p>
| 28 | 2010-01-27T17:33:20Z | 14,978,078 | <p>This code works great for me, I can use "F5" in IDLE and then call again from the interactive prompt:</p>
<pre><code>def mainf(*m_args):
# Overrides argv when testing (interactive or below)
if m_args:
sys.argv = ["testing mainf"] + list(m_args)
</code></pre>
<p>...</p>
<pre><code>if __name__ == "_... | 0 | 2013-02-20T10:54:45Z | [
"python",
"command-line-arguments",
"python-idle"
] |
When running a python script in IDLE, is there a way to pass in command line arguments (args)? | 2,148,994 | <p>I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.</p>
<p>I'm running Windows.</p>
| 28 | 2010-01-27T17:33:20Z | 24,236,886 | <p>In a pinch, Seth's #2 worked....</p>
<blockquote>
<p>2) You can add a test line in front of your main function call which
supplies an array of arguments (or create a unit test which does the
same thing), or set sys.argv directly.</p>
</blockquote>
<p>For example... </p>
<pre><code>sys.argv = ["wordcount.py"... | 6 | 2014-06-16T05:00:50Z | [
"python",
"command-line-arguments",
"python-idle"
] |
When running a python script in IDLE, is there a way to pass in command line arguments (args)? | 2,148,994 | <p>I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.</p>
<p>I'm running Windows.</p>
| 28 | 2010-01-27T17:33:20Z | 33,057,011 | <p>Visual Studio 2015 has an addon for Python. You can supply arguments with that. VS 2015 is now free.</p>
| 0 | 2015-10-10T17:38:28Z | [
"python",
"command-line-arguments",
"python-idle"
] |
When running a python script in IDLE, is there a way to pass in command line arguments (args)? | 2,148,994 | <p>I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.</p>
<p>I'm running Windows.</p>
| 28 | 2010-01-27T17:33:20Z | 37,769,286 | <p>Based on the post by danben, here is my solution that works in IDLE:</p>
<pre><code>try:
sys.argv = ['fibo3_5.py', '30']
fibonacci(int(sys.argv[1]))
except:
print(str('Then try some other way.'))
</code></pre>
| 0 | 2016-06-11T23:12:20Z | [
"python",
"command-line-arguments",
"python-idle"
] |
RPX, OpenID - How to write a proper SignIn Handler for AppEngine | 2,149,240 | <p>Ive spent days searching the web and im drawing a blank -im new to python too! I simply want to integrate RPX (janrain) into Appengine - loads of code for the script inserts and the return of the openid token - that's all great - but other than that no-one seems to take it any further as in actually creating an open... | 1 | 2010-01-27T18:08:25Z | 2,157,733 | <p>there is a GAE recipe that should help</p>
<p><a href="http://appengine-cookbook.appspot.com/recipe/accept-google-aol-yahoo-myspace-facebook-and-openid-logins/" rel="nofollow">http://appengine-cookbook.appspot.com/recipe/accept-google-aol-yahoo-myspace-facebook-and-openid-logins/</a></p>
| 0 | 2010-01-28T20:31:08Z | [
"python",
"google-app-engine",
"openid",
"rpx"
] |
RPX, OpenID - How to write a proper SignIn Handler for AppEngine | 2,149,240 | <p>Ive spent days searching the web and im drawing a blank -im new to python too! I simply want to integrate RPX (janrain) into Appengine - loads of code for the script inserts and the return of the openid token - that's all great - but other than that no-one seems to take it any further as in actually creating an open... | 1 | 2010-01-27T18:08:25Z | 2,157,750 | <p>GAE gives you access to a database, right? Generate a secure token and store it with the user URL returned by RPX in the database. Set the secure token as a cookie so that you get it on every request - look the token up in the database and then do the rest from there.</p>
<p>While I'm worried about performance it a... | 1 | 2010-01-28T20:34:10Z | [
"python",
"google-app-engine",
"openid",
"rpx"
] |
Python asyncore & dbus | 2,149,358 | <p>Is it possible to integrate <code>asyncore</code> with <code>dbus</code> through the same <code>main loop</code>? </p>
<p>Usually, DBus integration is done through <code>glib</code> main loop: is it possible to have either <code>asyncore</code> integrate this main loop <em>or</em> have dbus use <code>asyncore</code... | 5 | 2010-01-27T18:27:49Z | 2,149,387 | <p><code>asyncore</code> sucks. <code>glib</code> already provides async stuff, so just use <code>glib</code>'s mainloop to do everything.</p>
| 7 | 2010-01-27T18:32:13Z | [
"python",
"dbus",
"asyncore"
] |
Python asyncore & dbus | 2,149,358 | <p>Is it possible to integrate <code>asyncore</code> with <code>dbus</code> through the same <code>main loop</code>? </p>
<p>Usually, DBus integration is done through <code>glib</code> main loop: is it possible to have either <code>asyncore</code> integrate this main loop <em>or</em> have dbus use <code>asyncore</code... | 5 | 2010-01-27T18:27:49Z | 2,154,293 | <p>Although you got what is probably a perfectly reasonable answer, there is another approach - you don't need to use asyncore's loop per se. Just call asyncore.loop with a zero timeout and a count of 1, which stops it iterating (and thus makes the function name completely misleading) and polls the sockets just once. C... | 0 | 2010-01-28T12:02:26Z | [
"python",
"dbus",
"asyncore"
] |
Python asyncore & dbus | 2,149,358 | <p>Is it possible to integrate <code>asyncore</code> with <code>dbus</code> through the same <code>main loop</code>? </p>
<p>Usually, DBus integration is done through <code>glib</code> main loop: is it possible to have either <code>asyncore</code> integrate this main loop <em>or</em> have dbus use <code>asyncore</code... | 5 | 2010-01-27T18:27:49Z | 4,689,617 | <p>I wrote a trivial <a href="http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html#g-source-new" rel="nofollow"><code>GSource</code></a> wrapper for one of <a href="http://code.google.com/u/anacrolix/" rel="nofollow">my own projects</a> called <a href="http://code.google.com/p/lanshare/source/browse... | 1 | 2011-01-14T09:29:48Z | [
"python",
"dbus",
"asyncore"
] |
Downloading a File Protected by NTLM/SSPI Without Prompting For Credentials Using Python on Win32? | 2,149,496 | <p>I need to download a file on a corporate Sharepoint site using CPython. Existing codebase prevents me from using Ironpython without porting the code, so .NET's <code>WebClient</code> library is out. I also want to download the file without prompting the user to save and without prompting the user for network credent... | 6 | 2010-01-27T18:49:27Z | 2,156,711 | <p>I ended up finding <a href="http://support.microsoft.com/kb/244757" rel="nofollow">some VB code from a Microsoft support page</a> that uses a function from <code>urlmon.dll</code> I replicated it with a single line of <code>ctypes</code> code and it accomplished exactly what I needed it to do.</p>
<pre><code>ctypes... | 4 | 2010-01-28T18:00:42Z | [
"python",
"winapi",
"curl",
"pywin32"
] |
How to fix "can't adapt error" when saving binary data using python psycopg2 | 2,149,515 | <p>I ran across this bug three times today in one of our projects. Putting the problem and solution online for future reference.</p>
<pre><code>impost psycopg2
con = connect(...)
def save(long_blob):
cur = con.cursor()
long_data = struct.unpack('<L', long_blob)
cur.execute('insert into blob_recor... | 4 | 2010-01-27T18:53:28Z | 2,149,516 | <p>The problem is struct.unpack returns a tuple result, even if there is only one value to unpack. You need to make sure you grab the first item from the tuple, even if there is only one item. Otherwise psycopg2 sql argument parsing will fail trying to convert the tuple to a string giving the "can't adapt" error mess... | 3 | 2010-01-27T18:53:41Z | [
"python",
"postgresql",
"psycopg2",
"unpack",
"iterable-unpacking"
] |
How to fix "can't adapt error" when saving binary data using python psycopg2 | 2,149,515 | <p>I ran across this bug three times today in one of our projects. Putting the problem and solution online for future reference.</p>
<pre><code>impost psycopg2
con = connect(...)
def save(long_blob):
cur = con.cursor()
long_data = struct.unpack('<L', long_blob)
cur.execute('insert into blob_recor... | 4 | 2010-01-27T18:53:28Z | 2,272,191 | <p>"Can't adapt" is raised when psycopg doesn't know the type of your <code>long_blob</code> variable. What type is it?</p>
<p>You can easily <a href="http://initd.org/psycopg/docs/advanced.html#adapting-new-types" rel="nofollow">register an adapter</a> to tell psycopg how to convert the value for the database.</p>
<... | 1 | 2010-02-16T10:40:24Z | [
"python",
"postgresql",
"psycopg2",
"unpack",
"iterable-unpacking"
] |
What's the difference between OneToOne and Subclassing a model in Django | 2,149,567 | <p>For example:</p>
<pre><code>class Subdomain(Site):
#fields here
</code></pre>
<p>and </p>
<pre><code>class Subdomain(models.Model):
site = models.OneToOne(Site)
#fields here
</code></pre>
| 2 | 2010-01-27T19:01:51Z | 2,149,577 | <p>Models with a <code>OneToOne</code> have an independent PK; submodels always use the PK of their supermodel.</p>
| 5 | 2010-01-27T19:03:09Z | [
"python",
"django",
"django-models"
] |
possible in sqlalchemy to join table based on a column value? | 2,149,659 | <p>I am trying to create a table to hold user actions on my web app. Take a simple case where a user adds a new story, and comments on it. This will add two entries to the user_action table. In the user_action table I would like to store the module name associated with each action and the items id. In this cause I woul... | 1 | 2010-01-27T19:19:17Z | 2,152,041 | <p>What you want are polymorphic models. Read SQLAlchemy docs about this topic or Google them.</p>
| 1 | 2010-01-28T03:11:26Z | [
"python",
"sqlalchemy"
] |
django - inlineformset_factory with more than one ForeignKey | 2,149,697 | <p>Im trying to do a formset with the following models (boost is the primary):</p>
<pre>
class boost(models.Model):
creator = models.ForeignKey(userInfo)
game = models.ForeignKey(gameInfo)
name = models.CharField(max_length=200)
desc = models.CharField(max_length=500)
rules = models.CharField(max_len... | 4 | 2010-01-27T19:28:33Z | 2,150,942 | <p>If I understand you correctly:</p>
<p>To change what is displayed set the model's <code>__unicode__</code> function</p>
<pre><code>class userInfo(models.Model):
#model fields
def __unicode__(self):
return self.auth.username
</code></pre>
| 1 | 2010-01-27T22:54:46Z | [
"python",
"django"
] |
Python-MySQLdb problem: wrong ELF class: ELFCLASS32 | 2,149,782 | <p>As part of trying out django CMS (http://www.django-cms.org/), I'm struggling with getting Python-MySQLdb to work (http://pypi.python.org/pypi/MySQL-python/).</p>
<ul>
<li>I have installed Django CMS and all of its dependencies (Python 2.5, Django, django-south, MySQL server)</li>
<li>I'm trying out the example cod... | 1 | 2010-01-27T19:44:11Z | 2,149,812 | <p>Yes, the bit difference is what's causing this. Find or build a 64-bit version of MySQLdb.</p>
<p><code>ELF</code> is the <a href="http://en.wikipedia.org/wiki/Executable_and_Linkable_Format">Executable and Linkable Format</a>. <code>ELFCLASS32</code> means that it's a 32-bit ELF file.</p>
| 8 | 2010-01-27T19:48:41Z | [
"python",
"linux",
"django",
"mysql",
"django-cms"
] |
Customary To Inherit Metaclasses From type? | 2,149,846 | <p>I have been trying to understand python metaclasses, and so have been going through some sample code. As far as I understand it, a Python metaclass can be any callable. So, I can have my metaclass like</p>
<pre><code>def metacls(clsName, bases, atts):
....
return type(clsName, bases, atts)
</code></pre>
<p... | 21 | 2010-01-27T19:55:12Z | 2,150,336 | <p>There are subtle differences, mostly relating to inheritance. When using a
function as a metaclass, the resulting class is really an instance of <code>type</code>,
and can be inherited from without restriction; however, the metaclass function
will never be called for such subclasses. When using a subclass of <code... | 33 | 2010-01-27T21:21:58Z | [
"python",
"metaclass"
] |
"NOTICE AUTH" notifications when connecting to IRC server | 2,149,895 | <p>As a learning exercise, I'm writing a Python program to connect to a channel on an IRC network, so I can output messages in the channel to stdout. I'm using asynchat and manually sending the protocol messages, rather than using something like Twisted or existing bot code from the net - again, it's a more useful lear... | 2 | 2010-01-27T20:06:16Z | 2,149,950 | <p>There's no RFC requirement to do this, it's just a common thing that servers in the wild do. Observe that they're plain old NOTICE commands (i.e. just messages). Just treat them as messages sent to a psuedo-user "AUTH" (since the server doesn't have a better name for you yet). You're not required to wait for them, a... | 3 | 2010-01-27T20:16:34Z | [
"python",
"irc",
"rfc"
] |
Python: How does regex re.compile(r'^[-\w]+$') search? Or, how does regex work in this context? | 2,149,898 | <p>By reading the documentation <a href="http://docs.python.org/library/re.html#search-vs-match" rel="nofollow">here</a> it seems to me that</p>
<pre><code>re.compile(r'^[-\w]+$')
</code></pre>
<p>would just search whether there was any character that is alphanumeric, an underscore, or a hyphen. But really this retur... | 2 | 2010-01-27T20:07:20Z | 2,149,910 | <p>The <code>^</code> and <code>$</code> anchor the regex at the beginning and ending of the string, therefore <em>all</em> characters would have to match the pattern in between.</p>
| 3 | 2010-01-27T20:09:37Z | [
"python",
"regex"
] |
Python: How does regex re.compile(r'^[-\w]+$') search? Or, how does regex work in this context? | 2,149,898 | <p>By reading the documentation <a href="http://docs.python.org/library/re.html#search-vs-match" rel="nofollow">here</a> it seems to me that</p>
<pre><code>re.compile(r'^[-\w]+$')
</code></pre>
<p>would just search whether there was any character that is alphanumeric, an underscore, or a hyphen. But really this retur... | 2 | 2010-01-27T20:07:20Z | 2,149,915 | <p>The two characters <code>^</code> and <code>$</code> mark the start and the end of the string respectively. So <code>^[-\w]+$</code> will only match if there are only one or more word characters or a hyphen (<code>[-\w]+</code>) between the start (<code>^</code>) and the end of the string (<code>$</code>).</p>
| 4 | 2010-01-27T20:11:22Z | [
"python",
"regex"
] |
Python: How does regex re.compile(r'^[-\w]+$') search? Or, how does regex work in this context? | 2,149,898 | <p>By reading the documentation <a href="http://docs.python.org/library/re.html#search-vs-match" rel="nofollow">here</a> it seems to me that</p>
<pre><code>re.compile(r'^[-\w]+$')
</code></pre>
<p>would just search whether there was any character that is alphanumeric, an underscore, or a hyphen. But really this retur... | 2 | 2010-01-27T20:07:20Z | 2,149,981 | <p>just as per answers above, ^ and $ enclose all charactes in between and they represent line start and end respectively. If in doubt re any expression try debug mode, that usually explains a lot:</p>
<pre><code>>>> p = re.compile("^[-\w]+$", re.DEBUG)
at at_beginning
max_repeat 1 65535
in
literal 45
... | 2 | 2010-01-27T20:23:20Z | [
"python",
"regex"
] |
How to download a file behind a HTTPS login? | 2,149,980 | <p>How would you go about downloading a webpage file behind an HTTPS login via a language such as python? More specifically I am talking about the page behind the login from <a href="http://www.cnbtn.com" rel="nofollow">http://www.cnbtn.com</a>.</p>
| 0 | 2010-01-27T20:23:01Z | 2,150,018 | <p>https will not matter. HTTPS just says that the data going over the wire is securely encrypted. Rather you need to learn more about how the login actually works. For instance is it Basic Auth (where a popup shows up for user/pass)? you can then make a request like <a href="https://user:pass@foo.com/my_file.gif" rel=... | 2 | 2010-01-27T20:29:08Z | [
"python",
"https"
] |
Setting an Excel Range with an Array using Python and comtypes? | 2,150,017 | <p>Using <a href="http://starship.python.net/crew/theller/comtypes/" rel="nofollow"><code>comtypes</code></a> to drive Python, it seems some magic is happening behind the scenes that is not converting tuples and lists to <code>VARIANT</code> types:</p>
<pre><code># RANGE(âC14:D21â) has values
# Setting the Value o... | 3 | 2010-01-27T20:29:07Z | 2,150,140 | <p>Try <code>sheet.Range("C14", "D21").Value = vals</code>. I'm not quite sure how the API is structured, but it works for me.</p>
<p>(Also, <code>tuple([(x,y) for x,y in zip('abcdefgh',xrange(8))])</code> can be replaced with a generator expression <code>tuple((x, y) for x, y in zip('abcdefgh', xrange(8)))</code>, wh... | 1 | 2010-01-27T20:48:50Z | [
"python",
"arrays",
"excel",
"com",
"range"
] |
Setting an Excel Range with an Array using Python and comtypes? | 2,150,017 | <p>Using <a href="http://starship.python.net/crew/theller/comtypes/" rel="nofollow"><code>comtypes</code></a> to drive Python, it seems some magic is happening behind the scenes that is not converting tuples and lists to <code>VARIANT</code> types:</p>
<pre><code># RANGE(âC14:D21â) has values
# Setting the Value o... | 3 | 2010-01-27T20:29:07Z | 5,237,491 | <p>I've spent a lot of time trying to figure out a solution to this problem to be able to fully substitute python for matlab, reading on various different forums with no real direct answer. </p>
<p>Here is my robust solution that works very well. I have to write daily/weekly/monthly/quarterly reports that write to xls... | 4 | 2011-03-08T19:50:25Z | [
"python",
"arrays",
"excel",
"com",
"range"
] |
What to put for a commonName when making an OpenSSL key? | 2,150,048 | <p>I have an application application framework that works in a peer-to-peer manner between unnamed hosts on a network. I want to have the traffic be encrypted, so I've implemented a setup with M2Crypto, but I've run into a snag. I have no idea what to put down for 'commonName' when creating the cert. It seems to want a... | 1 | 2010-01-27T20:34:33Z | 2,150,499 | <p>In your use case the default host name checking is not appropriate. You might want to try just doing certificate fingerprint checking. First, get the fingerprints of each certificate (openssl x509 -fingerprint). Let's say you have peer A and peer B, with fingerprint A and fingerprint B, respectively.</p>
<p>On peer... | 1 | 2010-01-27T21:46:54Z | [
"python",
"ssl",
"m2crypto"
] |
What to put for a commonName when making an OpenSSL key? | 2,150,048 | <p>I have an application application framework that works in a peer-to-peer manner between unnamed hosts on a network. I want to have the traffic be encrypted, so I've implemented a setup with M2Crypto, but I've run into a snag. I have no idea what to put down for 'commonName' when creating the cert. It seems to want a... | 1 | 2010-01-27T20:34:33Z | 2,151,725 | <p>So based on your comment to my first answer I decided to offer another solution that might work for your case. Create your own CA cert and key. Then in your peers tell M2Crypto to accept only certificates that were signed by this CA (see this older stackoverflow question for APIs to use: <a href="http://stackoverflo... | 1 | 2010-01-28T01:39:23Z | [
"python",
"ssl",
"m2crypto"
] |
Finding Signed Angle Between Vectors | 2,150,050 | <p>How would you find the signed angle theta from vector a to b?</p>
<p>And yes, I know that theta = arccos((a.b)/(|a||b|)).</p>
<p>However, this does not contain a sign (i.e. it doesn't distinguish between a clockwise or counterclockwise rotation).</p>
<p>I need something that can tell me the minimum angle to rotat... | 23 | 2010-01-27T20:34:51Z | 2,150,111 | <p>If you have an atan2() function in your math library of choice:</p>
<pre><code>signed_angle = atan2(b.y,b.x) - atan2(a.y,a.x)
</code></pre>
| 27 | 2010-01-27T20:44:34Z | [
"java",
"python",
"math",
"trigonometry",
"angle"
] |
Finding Signed Angle Between Vectors | 2,150,050 | <p>How would you find the signed angle theta from vector a to b?</p>
<p>And yes, I know that theta = arccos((a.b)/(|a||b|)).</p>
<p>However, this does not contain a sign (i.e. it doesn't distinguish between a clockwise or counterclockwise rotation).</p>
<p>I need something that can tell me the minimum angle to rotat... | 23 | 2010-01-27T20:34:51Z | 2,150,475 | <p>What you want to use is often called the âperp dot productâ, that is, find the vector perpendicular to one of the vectors, and then find the dot product with the other vector.</p>
<pre><code>if(a.x*b.y - a.y*b.x < 0)
angle = -angle;
</code></pre>
<p>You can also do this:</p>
<pre><code>angle = atan2( a... | 44 | 2010-01-27T21:44:38Z | [
"java",
"python",
"math",
"trigonometry",
"angle"
] |
best way to build time series server using python | 2,150,095 | <p>I'm interested to build a fast server that serves queries on time series. For example, say I have 1000 time series identified by category name x. The server will take a query submitted by a client process and immediately return the last value associated with a particular timestamp.</p>
<p>For example on the client ... | 0 | 2010-01-27T20:42:26Z | 2,150,304 | <p>As far as communication goes, do you have a protocol in mind? HTTP? raw TCP?</p>
<p>I would personally recommend an HTTP server using <a href="http://docs.python.org/library/wsgiref.html" rel="nofollow">http://docs.python.org/library/wsgiref.html</a> , although there's a chance that even that is not fast enough.</p... | 1 | 2010-01-27T21:16:52Z | [
"python"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 2,150,125 | <p>A <a href="http://docs.python.org/library/collections.html#deque-objects"><code>collections.deque</code></a> is optimized for pulling and pushing on both ends. They even have a dedicated <code>rotate()</code> method. </p>
<pre><code>from collections import deque
items = deque([1, 2])
items.append(3) # deque == [1, ... | 123 | 2010-01-27T20:46:27Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 2,150,130 | <p>If efficiency is your goal, (cycles? memory?) you may be better off looking at the array module: <a href="http://docs.python.org/library/array.html" rel="nofollow">http://docs.python.org/library/array.html</a></p>
<p>Arrays do not have the overhead of lists. </p>
<p>As far as pure lists go though, what you have i... | 2 | 2010-01-27T20:47:07Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 2,150,512 | <p>It depends on what you want to have happen when you do this:</p>
<pre><code>>>> shift([1,2,3], 14)
</code></pre>
<p>You might want to change your:</p>
<pre><code>def shift(seq, n):
return seq[n:]+seq[:n]
</code></pre>
<p>to:</p>
<pre><code>def shift(seq, n):
n = n % len(seq)
return seq[n:] ... | 21 | 2010-01-27T21:48:40Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 2,150,592 | <p>Possibly a ringbuffer is more suitable. It is not a list, although it is likely that it can behave enough like a list for your purposes.</p>
<p>The problem is that the efficiency of a shift on a list is O(n), which becomes significant for large enough lists.</p>
<p>Shifting in a ringbuffer is simply updating the h... | 3 | 2010-01-27T21:59:31Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 2,151,035 | <p>This also depends on if you want to shift the list in place (mutating it), or if you want the function to return a new list. Because, according to my tests, something like this is at least twenty times faster than your implementation that adds two lists:</p>
<pre><code>def shiftInPlace(l, n):
n = n % len(l)
... | 9 | 2010-01-27T23:10:59Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 8,391,327 | <p>What about just using <a href="https://docs.python.org/3/tutorial/datastructures.html#more-on-lists"><code>pop(0)</code></a>?</p>
<blockquote>
<p><code>list.pop([i])</code></p>
<p>Remove the item at the given position in the list, and return it. If
no index is specified, <code>a.pop()</code> removes and re... | 47 | 2011-12-05T20:20:52Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 9,386,361 | <p>I take this cost model as a reference:</p>
<p><a href="http://scripts.mit.edu/~6.006/fall07/wiki/index.php?title=Python_Cost_Model" rel="nofollow">http://scripts.mit.edu/~6.006/fall07/wiki/index.php?title=Python_Cost_Model</a></p>
<p>Your method of slicing the list and concatenating two sub-lists are linear-time o... | 1 | 2012-02-21T22:32:00Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 9,448,385 | <p>For an immutable implementation, you could use something like this:</p>
<pre><code>def shift(seq, n):
shifted_seq = []
for i in range(len(seq)):
shifted_seq.append(seq[(i-n) % len(seq)])
return shifted_seq
print shift([1, 2, 3, 4], 1)
</code></pre>
| 2 | 2012-02-25T21:49:10Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 12,775,964 | <p>for similar functionality as shift in other languages:</p>
<pre><code>def shift(l):
x = l[0]
del(l[0])
return x
</code></pre>
| -3 | 2012-10-08T05:47:19Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 12,872,433 | <p>Numpy can do this using the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.roll.html#numpy.roll"><code>roll</code></a> command:</p>
<pre><code>>>> import numpy
>>> a=numpy.arange(1,10) #Generate some data
>>> numpy.roll(a,1)
array([9, 1, 2, 3, 4, 5, 6, 7, 8])
>>&... | 15 | 2012-10-13T10:57:20Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 13,124,747 | <p>If you just want to iterate over these sets of elements rather than construct a separate data structure, consider using iterators to construct a generator expression:</p>
<pre><code>def shift(l,n):
return itertools.islice(itertools.cycle(l),n,n+len(l))
>>> list(shift([1,2,3],1))
[2, 3, 1]
</code></pre... | 9 | 2012-10-29T15:34:10Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 16,614,364 | <p>I don't know if this is 'efficient', but it also works:</p>
<pre><code>x = [1,2,3,4]
x.insert(0,x.pop())
</code></pre>
<p>EDIT: Hello again, I just found a big problem with this solution!
Consider the following code:</p>
<pre><code>class MyClass():
def __init__(self):
self.classlist = []
def shif... | 1 | 2013-05-17T16:57:29Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 22,630,708 | <p>I think you are looking for this:</p>
<pre><code>a.insert(0, x)
</code></pre>
| 4 | 2014-03-25T09:46:01Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 24,631,654 | <p>Simplest way I can think of: </p>
<pre><code>a.append(a.pop(0))
</code></pre>
| 4 | 2014-07-08T12:15:54Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 30,780,615 | <p>The following method is O(n) in place with constant auxiliary memory:</p>
<pre><code>def rotate(arr, shift):
pivot = shift % len(arr)
dst = 0
src = pivot
while (dst != src):
arr[dst], arr[src] = arr[src], arr[dst]
dst += 1
src += 1
if src == len(arr):
src = pivot
elif dst == pivot:... | 0 | 2015-06-11T12:19:52Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 34,774,171 | <p>I have similar thing. For example, to shift by two...</p>
<pre><code>def Shift(*args):
return args[len(args)-2:]+args[:len(args)-2]
</code></pre>
| 0 | 2016-01-13T18:19:35Z | [
"python",
"list"
] |
Efficient way to shift a list in python | 2,150,108 | <p>What is the most efficient way to shift a list in python?
Right now I have something like this:</p>
<pre><code>>>> def shift(l, n):
... return l[n:] + l[:n]
...
>>> l = [1,2,3,4]
>>> shift(l,1)
[2, 3, 4, 1]
>>> shift(l,2)
[3, 4, 1, 2]
>>> shift(l,0)
[1, 2, 3, 4]
&g... | 122 | 2010-01-27T20:44:07Z | 36,520,053 | <p>Another alternative:</p>
<pre><code>def move(arr, n):
return [arr[(idx-n) % len(arr)] for idx,_ in enumerate(arr)]
</code></pre>
| 0 | 2016-04-09T17:05:08Z | [
"python",
"list"
] |
pygtk: invert colors of a textview Widget | 2,150,142 | <p>I finally managed to change the background of a textview widget in pygtk. Turns out I needed to use the <code>widget.modify_base(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0, 0))</code> That results in the desired black background.</p>
<p>Now, the rest of the problem... Now I want to change the text color to white.</p>
... | 4 | 2010-01-27T20:49:13Z | 2,150,301 | <p>Found the answer. It is much simpler than I was going.</p>
<pre><code># Textview with inverted colors
import gtk
tv = gtk.TextView()
tv.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))
tv.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse('white'))
</code></pre>
<p>That's all!!!</p>
| 5 | 2010-01-27T21:16:35Z | [
"python",
"colors",
"pygtk",
"textview"
] |
Is python a serious option for concurrent programming | 2,150,144 | <p>just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:</p>
<p>I have read about GIL and the consensus seems to be if you require concurren... | 4 | 2010-01-27T20:49:54Z | 2,150,156 | <p>In my limited experience, the "context switch cost" is overrated as a performance limitation.</p>
<p>I/O bandwidth and memory are the most common limiting factors. Python's I/O is comparable to many other languages, since it simply uses the standard C libraries pretty directly.</p>
<p>Your actual problem may not ... | 1 | 2010-01-27T20:52:33Z | [
"python",
"multithreading"
] |
Is python a serious option for concurrent programming | 2,150,144 | <p>just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:</p>
<p>I have read about GIL and the consensus seems to be if you require concurren... | 4 | 2010-01-27T20:49:54Z | 2,150,166 | <p><a href="http://docs.python.org/library/multiprocessing.html"><code>multiprocessing</code></a> can get around the GIL, but it introduces its own issues such as communication between the processes.</p>
| 11 | 2010-01-27T20:54:11Z | [
"python",
"multithreading"
] |
Is python a serious option for concurrent programming | 2,150,144 | <p>just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:</p>
<p>I have read about GIL and the consensus seems to be if you require concurren... | 4 | 2010-01-27T20:49:54Z | 2,150,247 | <p>If you're considering learning Python for addressing this problem, I might suggest taking a look at Erlang instead. It has excellent support for very lightweight processes, and built-in primitives for IPC.</p>
<p>Not to discourage you from learning Python, of course, just suggesting there might be a better tool fo... | 1 | 2010-01-27T21:07:26Z | [
"python",
"multithreading"
] |
Is python a serious option for concurrent programming | 2,150,144 | <p>just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:</p>
<p>I have read about GIL and the consensus seems to be if you require concurren... | 4 | 2010-01-27T20:49:54Z | 2,150,315 | <p>Python is not very good for CPU-bound concurrent programming. The GIL will (in many cases) make your program run as if it was running on a single core - or even worse. Even Unladen Swallow will (probably) not solve that problem (quote from their <a href="http://code.google.com/p/unladen-swallow/wiki/ProjectPlan">pro... | 7 | 2010-01-27T21:18:12Z | [
"python",
"multithreading"
] |
Is python a serious option for concurrent programming | 2,150,144 | <p>just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:</p>
<p>I have read about GIL and the consensus seems to be if you require concurren... | 4 | 2010-01-27T20:49:54Z | 2,150,370 | <p>Also if you are looking at object sharing between the python processes, i suggest you look at the answer by Alex in <a href="http://stackoverflow.com/questions/1268252/python-possible-to-share-in-memory-data-between-2-separate-processes/1269055#1269055">this question</a></p>
| 1 | 2010-01-27T21:27:13Z | [
"python",
"multithreading"
] |
Is python a serious option for concurrent programming | 2,150,144 | <p>just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:</p>
<p>I have read about GIL and the consensus seems to be if you require concurren... | 4 | 2010-01-27T20:49:54Z | 8,353,250 | <p>writing codes for multiple process is not an easy task. </p>
<p>But if you start thinking to this way first, eventually, it is easier to scale if one machine isn't enough...Threads can't be used across machines...</p>
| 0 | 2011-12-02T07:49:51Z | [
"python",
"multithreading"
] |
Is python a serious option for concurrent programming | 2,150,144 | <p>just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:</p>
<p>I have read about GIL and the consensus seems to be if you require concurren... | 4 | 2010-01-27T20:49:54Z | 18,595,947 | <p>A very glib one-word response: Golang.</p>
| 0 | 2013-09-03T15:22:20Z | [
"python",
"multithreading"
] |
pygtk: determine key is a modifier | 2,150,159 | <p>I've got key-press-event handler and i need to determine which kind of key was pressed: modifier or not?</p>
<p>It's not in event.state, because this field works only when modifier was pressed with something else, but i need this for single key (i.e. simply pressing control or alt, ...).</p>
| 6 | 2010-01-27T20:53:03Z | 2,150,337 | <p>You'll find what you're looking for in event.keyval. For example, the following code works for me:</p>
<pre><code>def key_press_event(widget, event):
keyname = gtk.gdk.keyval_name(event.keyval)
if "Control" in keyname or "Alt" in keyname:
print "You pressed a modifier!"
</code></pre>
| 2 | 2010-01-27T21:22:00Z | [
"python",
"user-interface",
"gtk",
"pygtk"
] |
pygtk: determine key is a modifier | 2,150,159 | <p>I've got key-press-event handler and i need to determine which kind of key was pressed: modifier or not?</p>
<p>It's not in event.state, because this field works only when modifier was pressed with something else, but i need this for single key (i.e. simply pressing control or alt, ...).</p>
| 6 | 2010-01-27T20:53:03Z | 2,155,406 | <p>If your version of GTK+/PyGTK is recent enough, key events have a <code><a href="http://library.gnome.org/devel/gdk/stable/gdk-Event-Structures.html#GdkEventKey.is-modifier" rel="nofollow">is_modifier</a></code> attribute. It's not documented in the PyGTK reference, but it's in the GDK API documentation and is expos... | 4 | 2010-01-28T15:02:40Z | [
"python",
"user-interface",
"gtk",
"pygtk"
] |
Parsing All Mail from Mailbox File in Python | 2,150,177 | <p>Maybe I'm going about this the wrong way, but I want to parse a single "catch all" email inbox via Python. I see the <a href="http://docs.python.org/library/email.parser.html" rel="nofollow">email</a> module and I can make it parse an individual email, but what I want to do is open (for example) /var/spool/mail/catc... | 0 | 2010-01-27T20:55:04Z | 2,150,200 | <p>You'll want to use <a href="http://docs.python.org/library/mailbox.html" rel="nofollow"><code>mailbox</code></a> to actually go through the mailbox.</p>
| 2 | 2010-01-27T20:59:38Z | [
"python",
"email",
"parsing"
] |
Can somebody explain a money regex that just checks if the value matches some pattern? | 2,150,205 | <p><strong>There are multiple posts on here that capture value</strong>, but I'm just looking to check to see if the value is something. More vaguely put; I'm looking to understand the difference between checking a value, and "capturing" a value. In the current case the value would be the following acceptable money for... | 2 | 2010-01-27T21:00:30Z | 2,150,234 | <p>I believe the following regex will meet your needs:</p>
<pre><code>/^\$?(\d*(\.\d\d?)?|\d+)$/
</code></pre>
<p>It allows for an optional '$'. It allows for an optional decimal, but requires at least one but not more than two digits after the decimal if the decimal is present.</p>
<p><strong>Edit:</strong> The out... | 3 | 2010-01-27T21:04:24Z | [
"python",
"regex",
"money"
] |
Can somebody explain a money regex that just checks if the value matches some pattern? | 2,150,205 | <p><strong>There are multiple posts on here that capture value</strong>, but I'm just looking to check to see if the value is something. More vaguely put; I'm looking to understand the difference between checking a value, and "capturing" a value. In the current case the value would be the following acceptable money for... | 2 | 2010-01-27T21:00:30Z | 2,150,250 | <blockquote>
<p>Also understanding out to get a normalized version (only digits and a the optional decimal point) out of it that strips the dollar sign.</p>
</blockquote>
<p>This is also known as "capturing" the value ;)</p>
<p>Working off Aaron's base example:</p>
<pre><code>/^\$?(\d+(?:\.\d{1,2})?)$/
</code></pr... | 2 | 2010-01-27T21:07:39Z | [
"python",
"regex",
"money"
] |
Can somebody explain a money regex that just checks if the value matches some pattern? | 2,150,205 | <p><strong>There are multiple posts on here that capture value</strong>, but I'm just looking to check to see if the value is something. More vaguely put; I'm looking to understand the difference between checking a value, and "capturing" a value. In the current case the value would be the following acceptable money for... | 2 | 2010-01-27T21:00:30Z | 2,150,417 | <p>Here's a regex you can use:</p>
<pre><code>regex = re.compile(r'^\$?(\d*(\d\.?|\.\d{1,2}))$')
</code></pre>
<p>Here's a test-bed I used to test it. I've included all your tests, plus some of my own. I've also included some negative tests, as making sure that it doesn't match when it shouldn't is just as important ... | 5 | 2010-01-27T21:34:00Z | [
"python",
"regex",
"money"
] |
Can somebody explain a money regex that just checks if the value matches some pattern? | 2,150,205 | <p><strong>There are multiple posts on here that capture value</strong>, but I'm just looking to check to see if the value is something. More vaguely put; I'm looking to understand the difference between checking a value, and "capturing" a value. In the current case the value would be the following acceptable money for... | 2 | 2010-01-27T21:00:30Z | 2,150,465 | <p>Assuming you want to allow <code>$5.</code> but not <code>5.</code>, the following will accept your language:</p>
<pre><code>money = re.compile('|'.join([
r'^\$?(\d*\.\d{1,2})$', # e.g., $.50, .50, $1.50, $.5, .5
r'^\$?(\d+)$', # e.g., $500, $5, 500, 5
r'^\$(\d+\.?)$', # e.g., $5.
]))
</cod... | 8 | 2010-01-27T21:43:10Z | [
"python",
"regex",
"money"
] |
How can I get a total count of a model's related objects and the model's children's related objects? | 2,150,644 | <p>In Django, I've got a Checkout model, which is a ticket for somebody checking out equipment. I've also got an OrganizationalUnit model that the Checkout model relates to (via ForeignKey), as the person on the checkout belongs to an OrganizationalUnit on our campus.</p>
<p>The OrganizationalUnit has a self relation,... | 3 | 2010-01-27T22:07:38Z | 2,152,034 | <p>I'm not sure how does SQL perform on this one but what you want to do is exactly what you explained.</p>
<p>Get all OU and it's parents with While loop and then count Checkouts and sum them. </p>
<p>ORM brings you dynamic operations over SQL but kill performance:)</p>
| 0 | 2010-01-28T03:09:46Z | [
"python",
"django",
"many-to-many",
"models",
"django-select-related"
] |
How can I get a total count of a model's related objects and the model's children's related objects? | 2,150,644 | <p>In Django, I've got a Checkout model, which is a ticket for somebody checking out equipment. I've also got an OrganizationalUnit model that the Checkout model relates to (via ForeignKey), as the person on the checkout belongs to an OrganizationalUnit on our campus.</p>
<p>The OrganizationalUnit has a self relation,... | 3 | 2010-01-27T22:07:38Z | 2,164,027 | <p>What you need is a recursive function that traverse OrganizationalUnit relation tree and gets number of related Checkouts for each OrganizationalUnit. So your code will look like this:</p>
<pre><code>def count_checkouts(ou):
checkout_count = ou.checkouts.count()
for kid in ou.children.all():
checkout_c... | 3 | 2010-01-29T18:03:16Z | [
"python",
"django",
"many-to-many",
"models",
"django-select-related"
] |
How can I get a total count of a model's related objects and the model's children's related objects? | 2,150,644 | <p>In Django, I've got a Checkout model, which is a ticket for somebody checking out equipment. I've also got an OrganizationalUnit model that the Checkout model relates to (via ForeignKey), as the person on the checkout belongs to an OrganizationalUnit on our campus.</p>
<p>The OrganizationalUnit has a self relation,... | 3 | 2010-01-27T22:07:38Z | 2,212,460 | <p>I think the most efficient way of calculating this is at write time. You should modify OrganizationalUnit like this:</p>
<pre><code>class OrganizationalUnit(models.Model):
name = models.CharField(max_length=100)
parent = models.ForeignKey(
'self',
blank=True, null=True,
related_name=... | 3 | 2010-02-06T07:54:57Z | [
"python",
"django",
"many-to-many",
"models",
"django-select-related"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 2,151,151 | <p>You'll need to use <code>os.stat</code> to get the file creation time and a combination of <code>time.strftime</code> and <code>time.timezone</code> for formatting:</p>
<pre><code>>>> import time
>>> import os
>>> t = os.stat('C:/Path/To/File.txt').st_ctime
>>> t = time.localtime... | 9 | 2010-01-27T23:31:08Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 2,995,858 | <p>Correct me if I'm wrong (I'm not), but the offset from UTC changes with daylight saving time. So you should use</p>
<pre><code>tz = str.format('{0:+06.2f}', float(time.altzone) / 3600)
</code></pre>
<p>I also belive, that the sign should be different</p>
<pre><code>tz = str.format('{0:+06.2f}', -float(time.altzon... | 4 | 2010-06-08T08:45:57Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 4,036,669 | <p>I agree with Jarek, and I furthermore note that the ISO offset separator character is a colon, so I think the final answer should be:</p>
<pre><code>isodate.datetime_isoformat(datetime.datetime.now()) + str.format('{0:+06.2f}', -float(time.timezone) / 3600).replace('.', ':')
</code></pre>
| 2 | 2010-10-27T18:58:49Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 4,462,893 | <p><strong>ISO 8601 Time Representation</strong></p>
<p>The international standard ISO 8601 describes a string representation for dates and times. Two simple examples of this format are </p>
<pre><code>2010-12-16 17:22:15
20101216T172215
</code></pre>
<p>(which both stand for the 16 of December 2010) but the format ... | 25 | 2010-12-16T16:20:25Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 12,184,436 | <pre><code>import datetime, time
def convert_enddate_to_seconds(self, ts):
"""Takes ISO 8601 format(string) and converts into epoch time."""
dt = datetime.datetime.strptime(ts[:-7],'%Y-%m-%dT%H:%M:%S.%f')+\
datetime.timedelta(hours=int(ts[-5:-3]),
minutes=int(ts[-2:]))*int(t... | -4 | 2012-08-29T18:39:57Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 15,142,736 | <p>I found the datetime.isoformat in the <a href="http://docs.python.org/2/library/datetime.html">doc</a>; seems to do what you want :</p>
<pre><code>datetime.isoformat([sep])
Return a string representing the date and time in ISO 8601 format, YYYY-MM-DDTHH:MM:SS.mmmmmm or, if microsecond is 0, YYYY-MM-DDTHH:MM:SS
If... | 36 | 2013-02-28T18:19:18Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 28,147,286 | <p>Local to ISO-8601:</p>
<pre><code>import datetime
datetime.datetime.now().isoformat()
</code></pre>
<p>UTC to ISO-8601:</p>
<pre><code>import datetime
datetime.datetime.utcnow().isoformat()
</code></pre>
| 59 | 2015-01-26T09:14:36Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 33,970,813 | <p><a href="http://tools.ietf.org/html/rfc3339#page-12">ISO8601 time format</a> does not store a time zone name, only the corresponding utc offset is preserved.</p>
<p>To convert a file ctime to an ISO 8601 time string while preserving the utc offset in Python 3:</p>
<pre><code>>>> import os
>>> fro... | 8 | 2015-11-28T11:31:31Z | [
"python",
"datetime",
"iso8601"
] |
ISO Time (ISO 8601) in Python? | 2,150,739 | <p>I have a file. In Python, I would like to take its creation time, and convert it to an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO time (ISO 8601) string</a> <strong>while preserving the fact that it was created in the Eastern Time Zone</strong>.</p>
<p>How do I take the file's ctime and convert it to an IS... | 58 | 2010-01-27T22:22:36Z | 34,006,019 | <p>Here is what I use to convert to XSD datetime format:</p>
<pre><code>from datetime import datetime
datetime.now().replace(microsecond=0).isoformat()
# You get your iso string
</code></pre>
<p>I came across this question when looking for XSD date time format. I needed to remove the microseconds from <code>isofo... | 4 | 2015-11-30T19:04:53Z | [
"python",
"datetime",
"iso8601"
] |
replacing node text using lxml.objectify while preserving attributes | 2,150,838 | <p>Using <code>lxml.objectify</code> like so:</p>
<pre><code>from lxml import objectify
o = objectify.fromstring("<a><b atr='someatr'>oldtext</b></a>")
o.b = 'newtext'
</code></pre>
<p>results in <code><a><b>newtext</b></a></code>, losing the node attribute. It seems ... | 4 | 2010-01-27T22:37:21Z | 2,151,303 | <pre><code>>>> type(o.b)
<type 'lxml.objectify.StringElement'>
</code></pre>
<p>You are replacing an element with a plain string. You need to replace it with a new string element.</p>
<pre><code>>>> o.b = objectify.E.b('newtext', atr='someatr')
</code></pre>
<p>For some reason you can't just ... | 8 | 2010-01-27T23:55:10Z | [
"python",
"xml",
"lxml"
] |
Buildout: Including another Python project via mercurial? | 2,150,887 | <p>I have a project called Foo/ that has buildout.cfg and setup.py. Now there is another project called Bar/ .. which too has buildout.cfg and setup.py. Since Bar/ depends on various Python modules, it has <code>install_requires=['lxml', 'SQLAlchemy']</code> in its setup.py. Foo/ depends on Bar/.</p>
<p>But Bar/ does ... | 2 | 2010-01-27T22:44:30Z | 2,151,229 | <p>If you can check out/clone the repository, then you can develop the python module as usual:</p>
<pre><code>[buildout]
...
develop = src/Bar
eggs = Bar
</code></pre>
| 0 | 2010-01-27T23:43:45Z | [
"python",
"mercurial",
"buildout"
] |
Buildout: Including another Python project via mercurial? | 2,150,887 | <p>I have a project called Foo/ that has buildout.cfg and setup.py. Now there is another project called Bar/ .. which too has buildout.cfg and setup.py. Since Bar/ depends on various Python modules, it has <code>install_requires=['lxml', 'SQLAlchemy']</code> in its setup.py. Foo/ depends on Bar/.</p>
<p>But Bar/ does ... | 2 | 2010-01-27T22:44:30Z | 2,153,453 | <p>You're using mercurial recipe to make a mercurial checkout of the mercurial recipe that you want to use as a development egg.... There's a huge circular dependency in there.</p>
<p>Buildout needs the mercurial recipe to run the "mr" part. So it grabs the recipe from pypi. It doesn't yet know that the recipe will ac... | -1 | 2010-01-28T09:28:57Z | [
"python",
"mercurial",
"buildout"
] |
Buildout: Including another Python project via mercurial? | 2,150,887 | <p>I have a project called Foo/ that has buildout.cfg and setup.py. Now there is another project called Bar/ .. which too has buildout.cfg and setup.py. Since Bar/ depends on various Python modules, it has <code>install_requires=['lxml', 'SQLAlchemy']</code> in its setup.py. Foo/ depends on Bar/.</p>
<p>But Bar/ does ... | 2 | 2010-01-27T22:44:30Z | 4,855,055 | <p>The only way I found to go around this issue is by adding extra-paths to buildout :</p>
<pre><code>[buildout]
parts = ... pyrtm ...
develop = . parts/pyrtm
eggs = pyrtm
extra-paths = parts/pyrtm/src
# or wherever your pyrtm folder
# could as well be extra-paths = pyrtm/
# if you your code is on same path as buil... | 1 | 2011-01-31T19:21:06Z | [
"python",
"mercurial",
"buildout"
] |
Making a Python/GTK CheckMenuItem, when clicked, not close the menu | 2,150,899 | <p>Using Python and PyGTK I've got a GtkMenu with various GtkCheckMenuItems in it. When the user clicks one of the checkboxes the menu closes. I'd like for the user to be able to check a series of checkboxes without the menu closing each time.</p>
<p>I've looked at using the activate callback to show the menu but thi... | 5 | 2010-01-27T22:46:14Z | 2,152,012 | <p>Try digging into source and it's documentation. I have found this to be the easiest way and best shortcut.</p>
| 0 | 2010-01-28T03:04:22Z | [
"python",
"menu",
"gtk",
"pygtk"
] |
Making a Python/GTK CheckMenuItem, when clicked, not close the menu | 2,150,899 | <p>Using Python and PyGTK I've got a GtkMenu with various GtkCheckMenuItems in it. When the user clicks one of the checkboxes the menu closes. I'd like for the user to be able to check a series of checkboxes without the menu closing each time.</p>
<p>I've looked at using the activate callback to show the menu but thi... | 5 | 2010-01-27T22:46:14Z | 2,152,162 | <p>I see the problem here, the <a href="http://library.gnome.org/devel/pygtk/stable/class-gtkmenuitem.html#signal-gtkmenuitem--activate" rel="nofollow"><code>"activate"</code> signal</a> does not allow you to return a boolean as to whether you wish the signal to propagate onwards. It sounds like you may need to poke ar... | 2 | 2010-01-28T03:44:08Z | [
"python",
"menu",
"gtk",
"pygtk"
] |
Is PHP the only choice re: massive and rapid uptake of a re-deployable, extensible web application? | 2,150,947 | <p>My own answer to this question is YES, but I'd like to hear from others. Put another way the question could be: Would the success of 1-click-install WordPress (not WordPress.com, which is SaaS) be possible if it weren't written in PHP, all other things being equal?</p>
<p>The critical associated requirements I bel... | 3 | 2010-01-27T22:55:26Z | 2,150,982 | <p>As far as points #1 and #2 go, you are probably right. No other platform is so widely, easily and cheaply available in terms of hosting companies and packages like the LAMP stack. Plus, most incompatibilities that can occur when deploying an application to a completely unknown web space are well documented, their nu... | 3 | 2010-01-27T23:01:25Z | [
"php",
"python",
"wordpress",
"deployment",
"hosting"
] |
Depth-First search in Python | 2,151,354 | <p>Okay so basically I'm trying to do a depth-first search for a mini-peg solitaire game. For those unfamiliar with the game it's pretty simple.</p>
<p>There's a board with 10 holes and 9 pegs, a peg is represented by a 1 and an empty spot by a 0. You can move a peg backwards or forwards two holes at a time (but you... | 1 | 2010-01-28T00:06:59Z | 2,151,408 | <p>I haven't decyphered your succ() function, but assuming it works then the rest of the program indeed does depth-first search. I take it that the code doesn't terminate? If succ can return a state that was previously encountered then you might have an infinite decision tree and depth-first search could get stuck goin... | 1 | 2010-01-28T00:20:50Z | [
"python"
] |
Depth-First search in Python | 2,151,354 | <p>Okay so basically I'm trying to do a depth-first search for a mini-peg solitaire game. For those unfamiliar with the game it's pretty simple.</p>
<p>There's a board with 10 holes and 9 pegs, a peg is represented by a 1 and an empty spot by a 0. You can move a peg backwards or forwards two holes at a time (but you... | 1 | 2010-01-28T00:06:59Z | 2,151,572 | <p>Since you are allowed to jump over empty holes, you'll have to keep track of any nodes you have already visited. Otherwise you will have an infinite loop.</p>
<p>You also need to not shortcircuit the for loop unless you have found a goal</p>
<pre><code>tested_nodes=set()
def solve_board(dfs_obj, node):
if goal... | 2 | 2010-01-28T00:57:58Z | [
"python"
] |
How can I use BeautifulSoup to find all the links in a page pointing to a specific domain? | 2,151,365 | <p>How can I use BeautifulSoup to find all the links in a page pointing to a specific domain?</p>
| 4 | 2010-01-28T00:10:46Z | 2,151,427 | <p>Use SoupStrainer,</p>
<pre><code>from BeautifulSoup import BeautifulSoup, SoupStrainer
import re
# Find all links
links = SoupStrainer('a')
[tag for tag in BeautifulSoup(doc, parseOnlyThese=links)]
linkstodomain = SoupStrainer('a', href=re.compile('example.com/'))
</code></pre>
<p>Edit: Modified example from off... | 7 | 2010-01-28T00:23:30Z | [
"python",
"beautifulsoup"
] |
Google Appengine and Python exceptions | 2,151,472 | <p>In my Google Appengine application I have defined a custom exception InvalidUrlException(Exception) in the module 'gvu'. Somewhere in my code I do:</p>
<pre><code>try:
results = gvu.article_parser.parse(source_url)
except gvu.InvalidUrlException as e:
self.redirect('/home?message='+str(e))
...
</code></pre>... | 1 | 2010-01-28T00:34:50Z | 2,151,510 | <p>You probably have an older Python version on your server. <code>except ExceptionType as varname:</code> is a newer syntax. Previously you needed to simply use a comma: <code>except ExceptionType, varname:</code>.</p>
| 5 | 2010-01-28T00:42:43Z | [
"python",
"google-app-engine",
"exception"
] |
Google Appengine and Python exceptions | 2,151,472 | <p>In my Google Appengine application I have defined a custom exception InvalidUrlException(Exception) in the module 'gvu'. Somewhere in my code I do:</p>
<pre><code>try:
results = gvu.article_parser.parse(source_url)
except gvu.InvalidUrlException as e:
self.redirect('/home?message='+str(e))
...
</code></pre>... | 1 | 2010-01-28T00:34:50Z | 2,444,422 | <p>Just FYI, another possible cause for this error - especially if the line referenced is early in the script (like line 2) is line ending differences between Unix and Windows.</p>
<p>I was running Python on Windows from a Cygwin shell and got this error, and was really puzzled. I had created the file with "touch" be... | 0 | 2010-03-15T00:24:15Z | [
"python",
"google-app-engine",
"exception"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.