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 |
|---|---|---|---|---|---|---|---|---|---|
Chat application using django | 2,093,822 | <p>If i devlop a chat application using django will it have some performance problem?
Can i do server push in django?
I want to have PM and room discussions as well.</p>
| 8 | 2010-01-19T13:37:41Z | 2,094,507 | <p>Basically Django is not the best way to do it.</p>
<p>However, if you are really stick to it and don't want to use to much solutions or/and want to keep it simple you can try with it:</p>
<p><a href="http://popcnt.org/2008/01/django-evserver-asynchronous-server-for.html" rel="nofollow">http://popcnt.org/2008/01/dj... | 1 | 2010-01-19T15:20:20Z | [
"python",
"django",
"performance",
"chat",
"private-messaging"
] |
Chat application using django | 2,093,822 | <p>If i devlop a chat application using django will it have some performance problem?
Can i do server push in django?
I want to have PM and room discussions as well.</p>
| 8 | 2010-01-19T13:37:41Z | 2,094,734 | <p>How about using <a href="http://www.tornadoweb.org" rel="nofollow">tornado</a>? I tried demo chat application of Tornado.
And also Tornado claims to have a good performance than django.</p>
<p>Let me know your thoughts.</p>
| 4 | 2010-01-19T15:47:32Z | [
"python",
"django",
"performance",
"chat",
"private-messaging"
] |
Chat application using django | 2,093,822 | <p>If i devlop a chat application using django will it have some performance problem?
Can i do server push in django?
I want to have PM and room discussions as well.</p>
| 8 | 2010-01-19T13:37:41Z | 2,094,905 | <p>Also <a href="http://twistedmatrix.com/trac/" rel="nofollow">Twisted</a> is worth checking out. I think that you described their tutorial scenario.</p>
| 1 | 2010-01-19T16:11:09Z | [
"python",
"django",
"performance",
"chat",
"private-messaging"
] |
Chat application using django | 2,093,822 | <p>If i devlop a chat application using django will it have some performance problem?
Can i do server push in django?
I want to have PM and room discussions as well.</p>
| 8 | 2010-01-19T13:37:41Z | 8,561,150 | <p>I released a Django app on Pypi and Github that provides a multi-user web chat.
It's based on Gevent: works well in multithreaded environments, but not in pre-forked ones such as gunicorn running more than 1 worker.
I'm just writing the documentation. The repo is: <a href="https://github.com/qubird/django-chatrooms"... | 4 | 2011-12-19T12:10:53Z | [
"python",
"django",
"performance",
"chat",
"private-messaging"
] |
Using Third-Party Modules with Python in an Automator Service | 2,093,837 | <p>I have installed Py-Appscript on my machine and it can be used with the Python installation at <code>/Library/Frameworks/Python.framework/Versions/Current/bin/python</code>.</p>
<p>I am trying to use this installation of Py-Appscript with an Automator service. To do this, I use the <strong>Run Shell Script</strong>... | 2 | 2010-01-19T13:40:13Z | 2,094,638 | <p>When you install modules, you typically install them per Python instance. So in this case you have installed them for the Python in /Library/Frameworks/Python.framework/Versions/Current/bin/python, and it will then be available only for that Python. /usr/bin/python is then apparently another Python installation (I'm... | 0 | 2010-01-19T15:38:01Z | [
"python",
"automator"
] |
Using Third-Party Modules with Python in an Automator Service | 2,093,837 | <p>I have installed Py-Appscript on my machine and it can be used with the Python installation at <code>/Library/Frameworks/Python.framework/Versions/Current/bin/python</code>.</p>
<p>I am trying to use this installation of Py-Appscript with an Automator service. To do this, I use the <strong>Run Shell Script</strong>... | 2 | 2010-01-19T13:40:13Z | 2,095,976 | <p>Okay, I was able to get it working using a hack found at <a href="http://stackoverflow.com/questions/1398591/how-do-i-execute-a-php-shell-script-as-an-automator-action-on-mac-os-x" title="How do I execute a PHP shell script as an Automator action on Mac OS X">How do I execute a PHP shell script as an Automator actio... | 3 | 2010-01-19T18:28:46Z | [
"python",
"automator"
] |
Serializing objects containing django querysets | 2,093,840 | <p>Django provides tools to serialize querysets (django.core.serializers), but what about serializing querysets living inside other objects (like dictionaries)?</p>
<p>I want to serialize the following dictionary:</p>
<pre><code>dictionary = { 'alfa': queryset1, 'beta': queryset2, }
</code></pre>
<p>I decided to do... | 4 | 2010-01-19T13:41:09Z | 2,095,925 | <p>The correct way to do this would be:</p>
<pre><code>from django.utils import simplejson
from django.core import serializers
from django.db.models.query import QuerySet
class HandleQuerySets(simplejson.JSONEncoder):
""" simplejson.JSONEncoder extension: handle querysets """
def default(self, obj):
... | 9 | 2010-01-19T18:23:35Z | [
"python",
"django",
"json"
] |
Why can't Python decorators be chained across definitions? | 2,094,008 | <p>Why arn't the following two scripts equivalent?</p>
<p>(Taken from another question: <a href="http://stackoverflow.com/questions/739654/understanding-python-decorators">Understanding Python Decorators</a>)</p>
<pre><code>def makebold(fn):
def wrapped():
return "<b>" + fn() + "</b>"
retu... | 8 | 2010-01-19T14:09:27Z | 2,094,023 | <p>The reason is because wrapped() inside of makebold doesn't accept any arguments. </p>
<p>When you use the decorator like that it can cause some issues, I'll post an example of how to achieve what you're wanting though, give me just a moment.</p>
<p>Here is a working example of what you need.</p>
<pre><code>def ma... | 1 | 2010-01-19T14:12:30Z | [
"python",
"decorator"
] |
Why can't Python decorators be chained across definitions? | 2,094,008 | <p>Why arn't the following two scripts equivalent?</p>
<p>(Taken from another question: <a href="http://stackoverflow.com/questions/739654/understanding-python-decorators">Understanding Python Decorators</a>)</p>
<pre><code>def makebold(fn):
def wrapped():
return "<b>" + fn() + "</b>"
retu... | 8 | 2010-01-19T14:09:27Z | 2,094,040 | <p>The problem is replacing "makeitalic" (which takes one argument) with the "wrapped"-function in "makebold" which takes zero arguments.</p>
<p>Use <code>*args, **kwargs</code> to pass on arguments further down the chain:</p>
<pre><code>def wrapped(*args, **kwargs):
return "<b>" + fn(*args, **kwargs) + "&l... | 0 | 2010-01-19T14:15:04Z | [
"python",
"decorator"
] |
Why can't Python decorators be chained across definitions? | 2,094,008 | <p>Why arn't the following two scripts equivalent?</p>
<p>(Taken from another question: <a href="http://stackoverflow.com/questions/739654/understanding-python-decorators">Understanding Python Decorators</a>)</p>
<pre><code>def makebold(fn):
def wrapped():
return "<b>" + fn() + "</b>"
retu... | 8 | 2010-01-19T14:09:27Z | 2,094,286 | <p>The problem with the second example is that</p>
<pre><code>@makebold
def makeitalic(fn):
def wrapped():
return "<i>" + fn() + "</i>"
return wrapped
</code></pre>
<p>is trying to decorate <code>makeitalic</code>, the decorator, and not <code>wrapped</code>, the function it returns.</p>
... | 9 | 2010-01-19T14:50:48Z | [
"python",
"decorator"
] |
How can I configure Geany to compile and run my Python programs? | 2,094,105 | <p>Under the Build menu, I can see 'Execute' option, but it is greyed out.</p>
<p>The only option available is 'Set Includes and Arguments'. When I click that both fields are already filled out. What do I have to write there?</p>
<p><img src="http://imgur.com/MXFfW.png" alt="alt text"></p>
| 7 | 2010-01-19T14:27:26Z | 2,094,530 | <p>I don't need to configure anything in geany, I just hit F5 and current module is executed.</p>
<p>Are you sure, that your file is recognized as python source file? Which version of geany are you using (I am using svn version, which is pretty stable, damn, it's rock solid stable ;-))? I have slightly more developed ... | 7 | 2010-01-19T15:23:56Z | [
"python",
"geany"
] |
How can I configure Geany to compile and run my Python programs? | 2,094,105 | <p>Under the Build menu, I can see 'Execute' option, but it is greyed out.</p>
<p>The only option available is 'Set Includes and Arguments'. When I click that both fields are already filled out. What do I have to write there?</p>
<p><img src="http://imgur.com/MXFfW.png" alt="alt text"></p>
| 7 | 2010-01-19T14:27:26Z | 8,891,730 | <p>I had the same problem and found the following solution:</p>
<p>in the 'Build Options' dialogue click on '_Execute' at the bottom of the Dialogue and the _execute options become editable.</p>
<p>I put the full path name to my Python install in there (C:\Python27\python %F) or (C:\Python32\python %F) and it seems t... | 2 | 2012-01-17T08:41:08Z | [
"python",
"geany"
] |
How can I configure Geany to compile and run my Python programs? | 2,094,105 | <p>Under the Build menu, I can see 'Execute' option, but it is greyed out.</p>
<p>The only option available is 'Set Includes and Arguments'. When I click that both fields are already filled out. What do I have to write there?</p>
<p><img src="http://imgur.com/MXFfW.png" alt="alt text"></p>
| 7 | 2010-01-19T14:27:26Z | 9,249,650 | <p>Also Donât forget to set the âKeyBindingâ ie the keyboard Shortcut-key (single or combination) you press to activate âRun, Execute , Compile, Save, Find, Print etc...</p>
<p>To do so;
Edit -> Preference ->Keyboard Shortcuts.
Here you can Choose/Change any Key/s to map to any Action you want.</p>
<p>Why? ... | 1 | 2012-02-12T14:45:01Z | [
"python",
"geany"
] |
How can I configure Geany to compile and run my Python programs? | 2,094,105 | <p>Under the Build menu, I can see 'Execute' option, but it is greyed out.</p>
<p>The only option available is 'Set Includes and Arguments'. When I click that both fields are already filled out. What do I have to write there?</p>
<p><img src="http://imgur.com/MXFfW.png" alt="alt text"></p>
| 7 | 2010-01-19T14:27:26Z | 28,524,309 | <p><em>1></em>
<strong>find the python console path.</strong></p>
<p><strong>2>now set environment variable</strong></p>
| -1 | 2015-02-15T08:31:25Z | [
"python",
"geany"
] |
Is it possible to have an admin inline without original data being shown? | 2,094,140 | <p>In the django admin I have a model with an inline. I would like to be able to only show "add new" lines for the inline, and not show any preexisting, original data in the table belonging to the inline. Is this possible? I have tried every combination of max_num and extra, and it always shows existing table data.</p>... | 3 | 2010-01-19T14:32:26Z | 2,096,985 | <p>I think this is not possible with a simple switch in the <code>InlineAdmin</code>
subclass. But I can think of a small "hack" that achieves the same:</p>
<p>Use the <code>template</code> attribute on your <code>InlineAdmin</code> to specify a custom template
to render your inlines. Now copy the original template yo... | 2 | 2010-01-19T20:54:11Z | [
"python",
"django"
] |
Is it possible to have an admin inline without original data being shown? | 2,094,140 | <p>In the django admin I have a model with an inline. I would like to be able to only show "add new" lines for the inline, and not show any preexisting, original data in the table belonging to the inline. Is this possible? I have tried every combination of max_num and extra, and it always shows existing table data.</p>... | 3 | 2010-01-19T14:32:26Z | 4,996,427 | <pre><code>from django.forms.models import inlineformset_factory
</code></pre>
<p>and then</p>
<pre><code>class ModelNameInlineFormSet(BaseInlineFormSet):
def __init__(self, **kwargs):
super(ModelNameInlineFormSet, self).__init__(**kwargs)
self.queryset = ModelName.objects.none()
class ModelNameI... | 1 | 2011-02-14T19:34:03Z | [
"python",
"django"
] |
split a string in python | 2,094,176 | <p>All,</p>
<p>I have a string in python say <code>a="Show details1\nShow details2\nShow details3\nShow details4\nShow details5\n"</code></p>
<p>How do we split the above with the delimiter <code>\n</code> (a newline).</p>
<p>The result should be as <code>['Show details1', 'Show details2', ..., 'Show details... | 12 | 2010-01-19T14:38:36Z | 2,094,190 | <p><a href="http://docs.python.org/library/stdtypes.html#str.split" rel="nofollow"><code>split</code></a> method:</p>
<pre><code>a.split('\n')[:-1]
</code></pre>
| 5 | 2010-01-19T14:39:48Z | [
"python",
"string"
] |
split a string in python | 2,094,176 | <p>All,</p>
<p>I have a string in python say <code>a="Show details1\nShow details2\nShow details3\nShow details4\nShow details5\n"</code></p>
<p>How do we split the above with the delimiter <code>\n</code> (a newline).</p>
<p>The result should be as <code>['Show details1', 'Show details2', ..., 'Show details... | 12 | 2010-01-19T14:38:36Z | 2,094,196 | <p>try:</p>
<pre><code>a.split('\n')
</code></pre>
| 0 | 2010-01-19T14:40:32Z | [
"python",
"string"
] |
split a string in python | 2,094,176 | <p>All,</p>
<p>I have a string in python say <code>a="Show details1\nShow details2\nShow details3\nShow details4\nShow details5\n"</code></p>
<p>How do we split the above with the delimiter <code>\n</code> (a newline).</p>
<p>The result should be as <code>['Show details1', 'Show details2', ..., 'Show details... | 12 | 2010-01-19T14:38:36Z | 2,094,199 | <p>Use <code>a.splitlines()</code>. This will return you a list of the separate lines. To get your "should be" result, add <code>" ".join(a.splitlines())</code>, and to get all in lower case as shown, the whole enchilada looks like <code>" ".join(a.splitlines()).lower()</code>.</p>
| 19 | 2010-01-19T14:41:04Z | [
"python",
"string"
] |
split a string in python | 2,094,176 | <p>All,</p>
<p>I have a string in python say <code>a="Show details1\nShow details2\nShow details3\nShow details4\nShow details5\n"</code></p>
<p>How do we split the above with the delimiter <code>\n</code> (a newline).</p>
<p>The result should be as <code>['Show details1', 'Show details2', ..., 'Show details... | 12 | 2010-01-19T14:38:36Z | 2,094,840 | <p>If you are concerned only with the trailing newline, you can do:</p>
<pre><code>a.rstrip().split('\n')
</code></pre>
<p>See, str.lstrip() and str.strip() for variations.</p>
<p>If you are more generally concerned by superfluous newlines producing empty items, you can do:</p>
<pre><code>filter(None, a.split('\n')... | 14 | 2010-01-19T15:59:35Z | [
"python",
"string"
] |
split a string in python | 2,094,176 | <p>All,</p>
<p>I have a string in python say <code>a="Show details1\nShow details2\nShow details3\nShow details4\nShow details5\n"</code></p>
<p>How do we split the above with the delimiter <code>\n</code> (a newline).</p>
<p>The result should be as <code>['Show details1', 'Show details2', ..., 'Show details... | 12 | 2010-01-19T14:38:36Z | 2,094,914 | <pre><code> a.split('\n')
</code></pre>
<p>would return an empty entry as the last member of the list.so use</p>
<blockquote>
<p><code>a.split('\n')[:-1]</code></p>
</blockquote>
| 1 | 2010-01-19T16:12:30Z | [
"python",
"string"
] |
How do I declare an attribute in Python without a value? | 2,094,658 | <p>In C# I would go:</p>
<pre><code>string UserName;
string Password;
</code></pre>
<p>But now, in Python:</p>
<pre><code>class User:
UserName
Password
</code></pre>
<p>I recieve an error that UserName isn't defined. I can't declare a variable without a variable?</p>
| 12 | 2010-01-19T15:40:23Z | 2,094,681 | <p>First of all, you should rewrite like this:</p>
<pre><code>class User(object):
def __init__(self, username, password):
self.username = username
self.password = password
</code></pre>
<p>This way, username and password are instance variables instead of class variables (in your example, they are class vari... | 10 | 2010-01-19T15:42:50Z | [
"python",
"class"
] |
How do I declare an attribute in Python without a value? | 2,094,658 | <p>In C# I would go:</p>
<pre><code>string UserName;
string Password;
</code></pre>
<p>But now, in Python:</p>
<pre><code>class User:
UserName
Password
</code></pre>
<p>I recieve an error that UserName isn't defined. I can't declare a variable without a variable?</p>
| 12 | 2010-01-19T15:40:23Z | 2,094,690 | <p>In Python, and many other languages, there is a value that means "no value". In Python, that value is <code>None</code>. So you could do something like this:</p>
<pre><code>class User:
UserName = None
PassWord = None
</code></pre>
<p>Those sure sound like instance variables though, and not class variables, ... | 23 | 2010-01-19T15:43:29Z | [
"python",
"class"
] |
How do I declare an attribute in Python without a value? | 2,094,658 | <p>In C# I would go:</p>
<pre><code>string UserName;
string Password;
</code></pre>
<p>But now, in Python:</p>
<pre><code>class User:
UserName
Password
</code></pre>
<p>I recieve an error that UserName isn't defined. I can't declare a variable without a variable?</p>
| 12 | 2010-01-19T15:40:23Z | 2,094,691 | <p>Just assign the value of None:</p>
<p><code>self.username = None</code></p>
| 1 | 2010-01-19T15:43:58Z | [
"python",
"class"
] |
How do I declare an attribute in Python without a value? | 2,094,658 | <p>In C# I would go:</p>
<pre><code>string UserName;
string Password;
</code></pre>
<p>But now, in Python:</p>
<pre><code>class User:
UserName
Password
</code></pre>
<p>I recieve an error that UserName isn't defined. I can't declare a variable without a variable?</p>
| 12 | 2010-01-19T15:40:23Z | 2,094,698 | <p>You can't. In Python, "Variables" are just names. A name always points ("is bound") to an object. It's convention to assign names that don't yet have a sensible value, but should be present, to <code>None</code>.</p>
<p>You might also be interested in my <a href="http://stackoverflow.com/questions/2055029/why-cant-... | 4 | 2010-01-19T15:44:38Z | [
"python",
"class"
] |
How do I declare an attribute in Python without a value? | 2,094,658 | <p>In C# I would go:</p>
<pre><code>string UserName;
string Password;
</code></pre>
<p>But now, in Python:</p>
<pre><code>class User:
UserName
Password
</code></pre>
<p>I recieve an error that UserName isn't defined. I can't declare a variable without a variable?</p>
| 12 | 2010-01-19T15:40:23Z | 2,094,815 | <p>In your code:</p>
<pre><code>class User:
UserName
Password
</code></pre>
<p><code>UserName</code> and <code>Password</code> are parsed as expressions. Since they have not been assigned at this point, you get a <code>NameError</code>.</p>
<p>In Python, a variable must be defined with a assignment statement... | 2 | 2010-01-19T15:56:08Z | [
"python",
"class"
] |
Mod_Python + Django library import issue | 2,094,783 | <p>I recently had a site that was running perfect for months, all of a sudden it decided to dump itself for no approximate reason.</p>
<p>I am running django + mod_python + apache, and the system decided it was time to start ignoring the import of the pycurl library, my intial first thought was that somehow the librar... | 0 | 2010-01-19T15:52:39Z | 2,096,642 | <p>The httpd process could be running into the open file limit; see <code>help ulimit</code> in bash for the relevant option to change.</p>
| 0 | 2010-01-19T19:59:15Z | [
"python",
"django",
"apache",
"mod-python",
"pycurl"
] |
Mod_Python + Django library import issue | 2,094,783 | <p>I recently had a site that was running perfect for months, all of a sudden it decided to dump itself for no approximate reason.</p>
<p>I am running django + mod_python + apache, and the system decided it was time to start ignoring the import of the pycurl library, my intial first thought was that somehow the librar... | 0 | 2010-01-19T15:52:39Z | 2,097,533 | <p>If the problem is a failing import when running under Apache but the import works when running from your login shell, double-check that there isn't a directory/file permission problem with the failing module(s). They must be read-accessible and in some cases also execute-accessible from the user id that Apache is r... | 1 | 2010-01-19T22:09:53Z | [
"python",
"django",
"apache",
"mod-python",
"pycurl"
] |
Mod_Python + Django library import issue | 2,094,783 | <p>I recently had a site that was running perfect for months, all of a sudden it decided to dump itself for no approximate reason.</p>
<p>I am running django + mod_python + apache, and the system decided it was time to start ignoring the import of the pycurl library, my intial first thought was that somehow the librar... | 0 | 2010-01-19T15:52:39Z | 2,098,295 | <p>Well now ... I have debugged this issue ... and the answer is quite surprising.</p>
<p>R**kspace decided to do a few updates to the box, updating the dependent library in question and it caused the issues ... after reinstalling the library it would try to load the c module and it was not a comp version with the cur... | 0 | 2010-01-20T00:37:43Z | [
"python",
"django",
"apache",
"mod-python",
"pycurl"
] |
How to use one app to satisfy multiple URLs in Django | 2,094,952 | <p>I'm trying to use one app to satisfy multiple url paths. That is to say, I want the url <code>/blog/</code> and <code>/job/</code> to use the same app, but different views. There are a number of ways to do this I'm sure, but none of them seem very clean. Here's what I'm doing right now</p>
<pre><code># /urls.py
... | 4 | 2010-01-19T16:17:06Z | 2,094,984 | <p>Looks pretty good to me. If you want reverse lookups, just have a different reverse name for each url format, even if they end up pointing to the same view.</p>
| 0 | 2010-01-19T16:21:57Z | [
"python",
"django",
"django-urls"
] |
How to use one app to satisfy multiple URLs in Django | 2,094,952 | <p>I'm trying to use one app to satisfy multiple url paths. That is to say, I want the url <code>/blog/</code> and <code>/job/</code> to use the same app, but different views. There are a number of ways to do this I'm sure, but none of them seem very clean. Here's what I'm doing right now</p>
<pre><code># /urls.py
... | 4 | 2010-01-19T16:17:06Z | 2,095,463 | <p>You can have more than one modules defining URLs. You can have <code>/blog/</code> URLs in <code>myapp/urls.py</code> and <code>/job/</code> URLs in <code>myapp/job_urls.py</code>. Or you can have two modules within a <code>urls</code> subpackage.</p>
<p>Alternatively you can manually prefix your url definitions:</... | 4 | 2010-01-19T17:22:29Z | [
"python",
"django",
"django-urls"
] |
Python re.sub question | 2,094,975 | <p>Greetings all,</p>
<p>I'm not sure if this is possible but I'd like to use matched groups in a regex substitution to call variables.</p>
<pre><code>a = 'foo'
b = 'bar'
text = 'find a replacement for me [[:a:]] and [[:b:]]'
desired_output = 'find a replacement for me foo and bar'
re.sub('\[\[:(.+):\]\]',group(1)... | 12 | 2010-01-19T16:20:39Z | 2,095,007 | <p>Sounds like overkill. Why not just do something like</p>
<pre><code>text = "find a replacement for me %(a)s and %(b)s"%dict(a='foo', b='bar')
</code></pre>
<p>?</p>
| 8 | 2010-01-19T16:24:46Z | [
"python",
"regex"
] |
Python re.sub question | 2,094,975 | <p>Greetings all,</p>
<p>I'm not sure if this is possible but I'd like to use matched groups in a regex substitution to call variables.</p>
<pre><code>a = 'foo'
b = 'bar'
text = 'find a replacement for me [[:a:]] and [[:b:]]'
desired_output = 'find a replacement for me foo and bar'
re.sub('\[\[:(.+):\]\]',group(1)... | 12 | 2010-01-19T16:20:39Z | 2,095,012 | <p>You can specify a callback when using re.sub, which has access to the groups:
<a href="http://docs.python.org/library/re.html#text-munging">http://docs.python.org/library/re.html#text-munging</a></p>
<pre><code>a = 'foo'
b = 'bar'
text = 'find a replacement for me [[:a:]] and [[:b:]]'
desired_output = 'find a rep... | 22 | 2010-01-19T16:25:26Z | [
"python",
"regex"
] |
Python re.sub question | 2,094,975 | <p>Greetings all,</p>
<p>I'm not sure if this is possible but I'd like to use matched groups in a regex substitution to call variables.</p>
<pre><code>a = 'foo'
b = 'bar'
text = 'find a replacement for me [[:a:]] and [[:b:]]'
desired_output = 'find a replacement for me foo and bar'
re.sub('\[\[:(.+):\]\]',group(1)... | 12 | 2010-01-19T16:20:39Z | 2,098,320 | <pre><code>>>> d={}
>>> d['a'] = 'foo'
>>> d['b'] = 'bar'
>>> text = 'find a replacement for me [[:a:]] and [[:b:]]'
>>> t=text.split(":]]")
>>> for n,item in enumerate(t):
... ... | 2 | 2010-01-20T00:45:18Z | [
"python",
"regex"
] |
Reverse loop inside a loop with same list | 2,095,068 | <pre><code>num = list(str(1234567))
for n1 in num:
print n1
for n2 in reversed(num):
print '\t', n2
</code></pre>
<p>On each iteration, it prints the first digit from the first loop and all 7 from the reverse loop. How can I print not all digits but only the last (i.e first) digit from reverse loop?</... | 2 | 2010-01-19T16:34:05Z | 2,095,108 | <p>Here's a feeble attempt. Is this the kind of thing you're looking for?</p>
<pre><code> for idx,i in enumerate(x):
print i,"\t",x[-(idx+1)]
</code></pre>
| 1 | 2010-01-19T16:38:49Z | [
"python",
"loops",
"for-loop",
"reverse"
] |
Reverse loop inside a loop with same list | 2,095,068 | <pre><code>num = list(str(1234567))
for n1 in num:
print n1
for n2 in reversed(num):
print '\t', n2
</code></pre>
<p>On each iteration, it prints the first digit from the first loop and all 7 from the reverse loop. How can I print not all digits but only the last (i.e first) digit from reverse loop?</... | 2 | 2010-01-19T16:34:05Z | 2,095,110 | <p>Do you mean like this?</p>
<pre><code>num = list(str(1234567))
for i in range(len(num)):
print num[i], '\t', num[-(i+1)]
</code></pre>
<p>Output is:</p>
<pre><code>1 7
2 6
3 5
4 4
5 3 ... | 1 | 2010-01-19T16:39:07Z | [
"python",
"loops",
"for-loop",
"reverse"
] |
Reverse loop inside a loop with same list | 2,095,068 | <pre><code>num = list(str(1234567))
for n1 in num:
print n1
for n2 in reversed(num):
print '\t', n2
</code></pre>
<p>On each iteration, it prints the first digit from the first loop and all 7 from the reverse loop. How can I print not all digits but only the last (i.e first) digit from reverse loop?</... | 2 | 2010-01-19T16:34:05Z | 2,095,111 | <p>Simplest way is to just zip the forward and reverse lists together:</p>
<pre><code>for n1, n2 in izip(num, reversed(num)):
print n1, '\t', n2
</code></pre>
| 7 | 2010-01-19T16:39:16Z | [
"python",
"loops",
"for-loop",
"reverse"
] |
Reverse loop inside a loop with same list | 2,095,068 | <pre><code>num = list(str(1234567))
for n1 in num:
print n1
for n2 in reversed(num):
print '\t', n2
</code></pre>
<p>On each iteration, it prints the first digit from the first loop and all 7 from the reverse loop. How can I print not all digits but only the last (i.e first) digit from reverse loop?</... | 2 | 2010-01-19T16:34:05Z | 2,095,125 | <p>You should make a second list:</p>
<pre><code>>>> num_rev = num[:]
>>> num_rev.reverse()
>>> num_rev
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
</code></pre>
<p>Then do something like:</p>
<pre><code>>>> for n1,n2 in zip(num,num_rev):
... print n1, n2
...
0 9
1 8
2 7
3 6
4 5
5 4
6 3
... | 0 | 2010-01-19T16:40:46Z | [
"python",
"loops",
"for-loop",
"reverse"
] |
Reverse loop inside a loop with same list | 2,095,068 | <pre><code>num = list(str(1234567))
for n1 in num:
print n1
for n2 in reversed(num):
print '\t', n2
</code></pre>
<p>On each iteration, it prints the first digit from the first loop and all 7 from the reverse loop. How can I print not all digits but only the last (i.e first) digit from reverse loop?</... | 2 | 2010-01-19T16:34:05Z | 2,095,257 | <p>Nothing to do with Python, but here it is in Haskell :)</p>
<pre><code>myDie = [1,2,3,4,5,6]
sevens = [ (x,y) | x <- myDie, y <- myDie, x+y == 7]
</code></pre>
| 0 | 2010-01-19T16:58:46Z | [
"python",
"loops",
"for-loop",
"reverse"
] |
Pylons and AuthKit OpenID problem | 2,095,120 | <p>I have troubles setting up the support for openID authentication, using authkit and pylons.
I set up everything as described in the <a href="http://docs.pythonweb.org/display/authkitcookbook/OpenID+Passurl" rel="nofollow">cookbook</a>, but still get the following error:</p>
<pre><code> File "/usr/lib/python2.6/dis... | 3 | 2010-01-19T16:40:27Z | 2,170,667 | <p>Take this line in your middleware.py:</p>
<pre><code>app = authkit.authenticate.middleware(app, app_conf)
</code></pre>
<p>And move it immediately below this line:</p>
<pre><code>app = PylonsApp()
</code></pre>
| 4 | 2010-01-31T05:30:03Z | [
"python",
"openid",
"pylons",
"authkit"
] |
Django app initalization code (like connecting to signals) | 2,095,155 | <p>I need a place to run an initialization code that is application specific (like connecting to signals).
When I put the code to <code>__init__.py</code> module of an application I've ended up with a circular import of the models.</p>
<p>Is there a way to fire a function when the framework is setup and before any req... | 8 | 2010-01-19T16:44:21Z | 2,095,234 | <p>Signals, specifically, are recommended to be put in the models.py of your app.</p>
<p>Try models.py or urls.py and let us know if you have any luck.</p>
| 5 | 2010-01-19T16:56:24Z | [
"python",
"django"
] |
Django app initalization code (like connecting to signals) | 2,095,155 | <p>I need a place to run an initialization code that is application specific (like connecting to signals).
When I put the code to <code>__init__.py</code> module of an application I've ended up with a circular import of the models.</p>
<p>Is there a way to fire a function when the framework is setup and before any req... | 8 | 2010-01-19T16:44:21Z | 2,095,253 | <p>The best place for stuff like this... anywhere, just import it in your urls.py file (for obvious reasons urls are loading before any requests).</p>
| 5 | 2010-01-19T16:58:12Z | [
"python",
"django"
] |
Django app initalization code (like connecting to signals) | 2,095,155 | <p>I need a place to run an initialization code that is application specific (like connecting to signals).
When I put the code to <code>__init__.py</code> module of an application I've ended up with a circular import of the models.</p>
<p>Is there a way to fire a function when the framework is setup and before any req... | 8 | 2010-01-19T16:44:21Z | 2,096,047 | <p>If you don't provide urls, then you really need to put it in <code>models.py</code>, that's just the way it is.</p>
<p>Now, on to your problems: You want to define it in its own module, great, do that. To avoid a circular import, use <code>django.db.models.get_model</code> to return the model dynamically for you. Y... | 2 | 2010-01-19T18:37:43Z | [
"python",
"django"
] |
Django app initalization code (like connecting to signals) | 2,095,155 | <p>I need a place to run an initialization code that is application specific (like connecting to signals).
When I put the code to <code>__init__.py</code> module of an application I've ended up with a circular import of the models.</p>
<p>Is there a way to fire a function when the framework is setup and before any req... | 8 | 2010-01-19T16:44:21Z | 26,021,706 | <p>For me, the following works:</p>
<p>In <strong>init</strong>.py:</p>
<pre><code>from . import models
from . import signals
</code></pre>
<p><code>signals.py</code> imports from models, but not vice versa. signals.py contains module code that is run immediately when it is imported and is thus run when the django s... | 0 | 2014-09-24T16:12:02Z | [
"python",
"django"
] |
How can I find out why PIL isn't drawing the font correctly? | 2,095,189 | <p>Here's the code I'm using:</p>
<pre><code>from PIL import Image
import ImageFont, ImageDraw
import sys
import pdb
img = Image.new("RGBA",(300,300))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(sys.argv[1],30)
draw.text((0,100),"world",font=font,fill="red")
del draw
img.save(sys.argv[2],"PNG")
</code></pre>... | 0 | 2010-01-19T16:49:43Z | 2,096,470 | <p>PIL uses the freetype2 library, so most possibly it is an issue with the font file; for example, it could have bad metrics defined (e.g see the OS/2 related ones opening the font with FontForge).</p>
| 1 | 2010-01-19T19:35:30Z | [
"python",
"fonts",
"python-imaging-library"
] |
Extended Form silently fails | 2,095,213 | <p>SOvians.
I have customized one of my forms and now it does not pass the is_valid() test. No form.errors are visible. Any ideas for where I went wrong?</p>
<p>Form:</p>
<pre><code>class SearchForm(forms.Form):
param = forms.CharField(required=False, max_length = 500, label = 'Search for')
sets = forms.Model... | 1 | 2010-01-19T16:53:21Z | 2,095,316 | <p>That's probably because you pass request.POST onto userN parameter. If you have keyword argument first it doesn't mean, that request.POST will automatically be put into args - quite contrary, it will be put onto userN. Try this:</p>
<pre><code>form = SearchForm(False, request.POST)
</code></pre>
| 2 | 2010-01-19T17:05:39Z | [
"python",
"django",
"django-forms"
] |
Extended Form silently fails | 2,095,213 | <p>SOvians.
I have customized one of my forms and now it does not pass the is_valid() test. No form.errors are visible. Any ideas for where I went wrong?</p>
<p>Form:</p>
<pre><code>class SearchForm(forms.Form):
param = forms.CharField(required=False, max_length = 500, label = 'Search for')
sets = forms.Model... | 1 | 2010-01-19T16:53:21Z | 2,095,380 | <p>gruzczy has the right idea, but a better way to do it is to avoid changing the function signature of <code>__init__</code> in the first place.</p>
<pre><code>def __init__(self, *args, **kwargs):
self.userN = kwargs.pop('userN', None)
super(SearchForm,self).__init__(*args,**kwargs)
...etc...
</code></pre... | 3 | 2010-01-19T17:14:05Z | [
"python",
"django",
"django-forms"
] |
Python newbie - Input strings, return a value to a web page | 2,095,227 | <p>I've got a program I would like to use to input a password and one or multiple strings from a web page. The program takes the strings and outputs them to a time-datestamped text file, but only if the password matches the set MD5 hash.</p>
<p>The problems I'm having here are that</p>
<ul>
<li>I don't know how to ge... | 0 | 2010-01-19T16:55:39Z | 2,095,260 | <p>Take a look at <a href="http://www.djangoproject.com/" rel="nofollow">django</a>. It's an excellent web framework that can accomplish exactly what you are asking. It also has an authentication module that handles password hashing and logins for you.</p>
| 1 | 2010-01-19T16:59:00Z | [
"python",
"html",
"return-value"
] |
Python newbie - Input strings, return a value to a web page | 2,095,227 | <p>I've got a program I would like to use to input a password and one or multiple strings from a web page. The program takes the strings and outputs them to a time-datestamped text file, but only if the password matches the set MD5 hash.</p>
<p>The problems I'm having here are that</p>
<ul>
<li>I don't know how to ge... | 0 | 2010-01-19T16:55:39Z | 2,095,261 | <p>You'll need to read up on <a href="http://www.modpython.org/" rel="nofollow">mod_python</a> (if you're using Apache) and the Python <a href="http://docs.python.org/library/cgi.html" rel="nofollow">CGI</a> module.</p>
| 2 | 2010-01-19T16:59:03Z | [
"python",
"html",
"return-value"
] |
First Python Program - Multiple Errors | 2,095,298 | <p>I am trying to write a python program that will eventually take a command line argument of a file, determine if its a tar or zip etc file and then exctract it accordingly. I am just trying to get the tar part working now and I am getting multiple errors. The file I am checking for resides in my ~/ directory. Any ... | 2 | 2010-01-19T17:03:39Z | 2,095,334 | <p>You can clearly see in your error it states</p>
<pre><code>NameError: global name 'ReadError' is not defined
</code></pre>
<p>ReadError is not a global python name. If you look at the <a href="http://docs.python.org/library/tarfile.html#tarfile.ReadError">tarfile</a> documentation you will see ReadError is part of... | 10 | 2010-01-19T17:08:20Z | [
"python"
] |
First Python Program - Multiple Errors | 2,095,298 | <p>I am trying to write a python program that will eventually take a command line argument of a file, determine if its a tar or zip etc file and then exctract it accordingly. I am just trying to get the tar part working now and I am getting multiple errors. The file I am checking for resides in my ~/ directory. Any ... | 2 | 2010-01-19T17:03:39Z | 2,095,345 | <p>I think you might need tarfile.ReadError rather than just ReadError?</p>
| 1 | 2010-01-19T17:09:56Z | [
"python"
] |
First Python Program - Multiple Errors | 2,095,298 | <p>I am trying to write a python program that will eventually take a command line argument of a file, determine if its a tar or zip etc file and then exctract it accordingly. I am just trying to get the tar part working now and I am getting multiple errors. The file I am checking for resides in my ~/ directory. Any ... | 2 | 2010-01-19T17:03:39Z | 2,095,346 | <p>Okay. All your exceptions (<code>ReadError</code>, <code>CompressionError</code> etc.) are inside the <code>tarfile</code> module and so you'll have to say <code>except tarfile.ReadError</code> instead of just <code>except ReadError</code>.</p>
| 1 | 2010-01-19T17:09:58Z | [
"python"
] |
First Python Program - Multiple Errors | 2,095,298 | <p>I am trying to write a python program that will eventually take a command line argument of a file, determine if its a tar or zip etc file and then exctract it accordingly. I am just trying to get the tar part working now and I am getting multiple errors. The file I am checking for resides in my ~/ directory. Any ... | 2 | 2010-01-19T17:03:39Z | 2,095,351 | <p>You would need to use <code>except tarfile.ReadError</code> or alternatively use <code>from tarfile import is_tarfile, open, ReadError, CompressionError, etc.</code> and put that inside the open_tar function instead of globally.</p>
| 2 | 2010-01-19T17:10:24Z | [
"python"
] |
Check even/odd for Palindrome? | 2,095,404 | <p>Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no? </p>
<pre><code>if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
</code></pre>
<p>Or is it just better (i.e ... | 3 | 2010-01-19T17:16:10Z | 2,095,416 | <p>baab = palindrome and has length of 4 which is even</p>
| 8 | 2010-01-19T17:17:41Z | [
"python",
"testing",
"palindrome"
] |
Check even/odd for Palindrome? | 2,095,404 | <p>Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no? </p>
<pre><code>if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
</code></pre>
<p>Or is it just better (i.e ... | 3 | 2010-01-19T17:16:10Z | 2,095,443 | <p>Even length strings can be palindromes too. <a href="http://en.wikipedia.org/wiki/Palindrome" rel="nofollow">Wikipedia</a> doesn't say anything about this restriction.</p>
| 1 | 2010-01-19T17:20:22Z | [
"python",
"testing",
"palindrome"
] |
Check even/odd for Palindrome? | 2,095,404 | <p>Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no? </p>
<pre><code>if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
</code></pre>
<p>Or is it just better (i.e ... | 3 | 2010-01-19T17:16:10Z | 2,095,444 | <p><a href="http://www.abbasite.com/" rel="nofollow">ABBA</a> - an example of <a href="https://en.wikipedia.org/wiki/Palindrome" rel="nofollow">palindrome</a> of four letters meaning even length.</p>
<blockquote>
<p>A <strong>palindrome</strong> is a word, phrase, <a href="https://en.wikipedia.org/wiki/Palindromic_n... | 20 | 2010-01-19T17:20:30Z | [
"python",
"testing",
"palindrome"
] |
Check even/odd for Palindrome? | 2,095,404 | <p>Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no? </p>
<pre><code>if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
</code></pre>
<p>Or is it just better (i.e ... | 3 | 2010-01-19T17:16:10Z | 2,095,577 | <p>The easiest way to check for a palindrome is to simply compare the string against it's reverse:</p>
<pre><code>def ispalindrome(s):
return s == s[::-1]
</code></pre>
<p>This uses extended slices with a negative step to walk backwards through <code>s</code> and get the reverse.</p>
| 10 | 2010-01-19T17:36:45Z | [
"python",
"testing",
"palindrome"
] |
Check even/odd for Palindrome? | 2,095,404 | <p>Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no? </p>
<pre><code>if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
</code></pre>
<p>Or is it just better (i.e ... | 3 | 2010-01-19T17:16:10Z | 2,095,600 | <p>Simple case: aa.</p>
<p>More complicated case: aaaa.</p>
<p>And so on.</p>
| 2 | 2010-01-19T17:40:19Z | [
"python",
"testing",
"palindrome"
] |
Check even/odd for Palindrome? | 2,095,404 | <p>Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no? </p>
<pre><code>if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
</code></pre>
<p>Or is it just better (i.e ... | 3 | 2010-01-19T17:16:10Z | 2,096,927 | <p>Try this:</p>
<pre><code>is_palindrome = lambda s : all(s1==s2 for s1,s2 in zip(s[:len(s)/2],s[-1:-(len(s)+1)/2:-1]))
</code></pre>
<p>only checks the front half with the back half, and short-circuits as soon as a mismatch is found.</p>
| 3 | 2010-01-19T20:47:20Z | [
"python",
"testing",
"palindrome"
] |
Check even/odd for Palindrome? | 2,095,404 | <p>Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no? </p>
<pre><code>if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
</code></pre>
<p>Or is it just better (i.e ... | 3 | 2010-01-19T17:16:10Z | 3,447,772 | <pre><code>n=raw_input("Enter a string==>")
n=int(n)
start=0
term=n
while n>0:
result=n%10
start=start*10+result
n=n/10
print start
if term==start:
print "True"
else:
print "False"
</code></pre>
| 0 | 2010-08-10T09:59:10Z | [
"python",
"testing",
"palindrome"
] |
A few questions regarding Pythons 'import' feature | 2,095,505 | <p>I just downloaded Beautiful Soup and I've decided I'll make a small library (is that what they call them in Python?) that will return results of a movie given and IMDB movie search.</p>
<p>My question is, how exactly does this import thing work?</p>
<p>For example, I downloaded BeautifulSoup and all it is, is a .p... | 2 | 2010-01-19T17:28:01Z | 2,095,535 | <p>See the <a href="http://docs.python.org/tutorial/modules.html#the-module-search-path" rel="nofollow">module search path</a>. For your case, placing the .py file in the same folder will work.</p>
| 1 | 2010-01-19T17:32:00Z | [
"python",
"import"
] |
A few questions regarding Pythons 'import' feature | 2,095,505 | <p>I just downloaded Beautiful Soup and I've decided I'll make a small library (is that what they call them in Python?) that will return results of a movie given and IMDB movie search.</p>
<p>My question is, how exactly does this import thing work?</p>
<p>For example, I downloaded BeautifulSoup and all it is, is a .p... | 2 | 2010-01-19T17:28:01Z | 2,095,536 | <p>BeautifulSoup.py will need to be placed somewhere on the Python search path, which is available to you in the <code>sys.path</code> array. Note that the current directory is always included in this array (as the empty string).</p>
<pre><code>>>> import sys
>>> sys.path
['', 'C:\\Windows\\system32\... | 3 | 2010-01-19T17:32:08Z | [
"python",
"import"
] |
A few questions regarding Pythons 'import' feature | 2,095,505 | <p>I just downloaded Beautiful Soup and I've decided I'll make a small library (is that what they call them in Python?) that will return results of a movie given and IMDB movie search.</p>
<p>My question is, how exactly does this import thing work?</p>
<p>For example, I downloaded BeautifulSoup and all it is, is a .p... | 2 | 2010-01-19T17:28:01Z | 2,095,548 | <p>Have a look at the documentation on <a href="http://docs.python.org/tutorial/modules.html#packages" rel="nofollow">packages</a>. When you import a package, python searches within <code>sys.path</code>, so you must place Beautiful Soup within the path, or append a new directory to the path.</p>
<p>Example:</p>
<pre... | 0 | 2010-01-19T17:33:35Z | [
"python",
"import"
] |
A few questions regarding Pythons 'import' feature | 2,095,505 | <p>I just downloaded Beautiful Soup and I've decided I'll make a small library (is that what they call them in Python?) that will return results of a movie given and IMDB movie search.</p>
<p>My question is, how exactly does this import thing work?</p>
<p>For example, I downloaded BeautifulSoup and all it is, is a .p... | 2 | 2010-01-19T17:28:01Z | 2,095,576 | <p>Python <em>modules</em> are top level entities in python programs that can be imported (analogous to C files). There is a load path which contains a list of directories to search for modules when you're importing them. I'd recommend that you go through <a href="http://docs.python.org/tutorial/modules.html" rel="nofo... | 1 | 2010-01-19T17:36:43Z | [
"python",
"import"
] |
A few questions regarding Pythons 'import' feature | 2,095,505 | <p>I just downloaded Beautiful Soup and I've decided I'll make a small library (is that what they call them in Python?) that will return results of a movie given and IMDB movie search.</p>
<p>My question is, how exactly does this import thing work?</p>
<p>For example, I downloaded BeautifulSoup and all it is, is a .p... | 2 | 2010-01-19T17:28:01Z | 2,095,622 | <p>For Ubuntu, you can search for packages with the command</p>
<pre><code>apt-cache search beautifulsoup
</code></pre>
<p>This should yield </p>
<pre><code>python-beautifulsoup - error-tolerant HTML parser for Python
</code></pre>
<p>So the easiest way to install BeautifulSoup for ubuntu would be to run</p>
<pre>... | 1 | 2010-01-19T17:44:35Z | [
"python",
"import"
] |
A few questions regarding Pythons 'import' feature | 2,095,505 | <p>I just downloaded Beautiful Soup and I've decided I'll make a small library (is that what they call them in Python?) that will return results of a movie given and IMDB movie search.</p>
<p>My question is, how exactly does this import thing work?</p>
<p>For example, I downloaded BeautifulSoup and all it is, is a .p... | 2 | 2010-01-19T17:28:01Z | 2,097,024 | <p>Might not be relevant, but have you considered using imdbpy? Last time I used it it worked pretty well...</p>
| -1 | 2010-01-19T20:58:27Z | [
"python",
"import"
] |
Python: arguments for using itertools to split a list into groups | 2,095,637 | <p>This is a question about the relative merits of fast code that uses the standard library but is obscure (at least to me) versus a hand-rolled alternative. In this <a href="http://stackoverflow.com/questions/1825907/python-how-do-i-split-a-list-into-groups-closed">thread</a> (and others that it duplicates), it seems... | 5 | 2010-01-19T17:47:23Z | 2,095,687 | <p>Time spent learning the fundamentals of Python will pay off in spades later on.
Therefore, learn itertools, and how groupby works.
Not only is using itertools likely to be faster than any hand-rolled solutions,
it will help you write better code in the future.</p>
| 5 | 2010-01-19T17:53:39Z | [
"python"
] |
Python: arguments for using itertools to split a list into groups | 2,095,637 | <p>This is a question about the relative merits of fast code that uses the standard library but is obscure (at least to me) versus a hand-rolled alternative. In this <a href="http://stackoverflow.com/questions/1825907/python-how-do-i-split-a-list-into-groups-closed">thread</a> (and others that it duplicates), it seems... | 5 | 2010-01-19T17:47:23Z | 2,095,838 | <p>When you reuse tools from the standard library, rather than "reinventing the wheel" by coding them yourself from scratch, you're not only getting well-optimized and tuned software (sometimes amazingly so, as often in the case of <code>itertools</code> components): more importantly, you're getting large amounts of fu... | 15 | 2010-01-19T18:11:37Z | [
"python"
] |
Get current timepoint from Totem application | 2,095,848 | <p>I want to find the exact time where a media file is currently paused at (or playing) in a running Totem instance using D-Bus. To be precise, what I want is available from the Totem python console (if the plugin exists and is enabled) by the following command:</p>
<pre><code>>>> print totem_object.props.cur... | 2 | 2010-01-19T18:12:43Z | 5,494,336 | <p>I'm currently researching the the API for a different reason, I need to retrieve the path or location being played, and I stumbled upon this question.</p>
<p>First things first, you'll want to activate the D-Bus Service Plugin (Edit -> Plugins) which will expose the <code>org.mpris.Totem</code> service. Then on the... | 4 | 2011-03-31T01:18:19Z | [
"python",
"linux",
"gnome",
"dbus",
"totem"
] |
module level garbage collection in python | 2,095,907 | <p>Let's say I have a module <code>mod_x</code> like the following:</p>
<pre><code>class X:
pass
x=X()
</code></pre>
<p>Now, let's say I have another module that just performs <code>import mod_x</code>, and goes about its business. The module variable <code>x</code> will not be referenced further during the lifecy... | 1 | 2010-01-19T18:20:31Z | 2,095,920 | <p>Only if something else does a <code>del mod_x.x</code> or a rebind at some point, or if the module itself becomes fully deleted.</p>
| 3 | 2010-01-19T18:22:42Z | [
"python",
"garbage-collection"
] |
module level garbage collection in python | 2,095,907 | <p>Let's say I have a module <code>mod_x</code> like the following:</p>
<pre><code>class X:
pass
x=X()
</code></pre>
<p>Now, let's say I have another module that just performs <code>import mod_x</code>, and goes about its business. The module variable <code>x</code> will not be referenced further during the lifecy... | 1 | 2010-01-19T18:20:31Z | 2,095,948 | <p>No, the variable will never get garbage-collected (until the end of the process), because the module object will stay in <code>sys.modules['mod_x']</code> and it will have a reference to <code>mod_x.x</code> -- the reference count will never drop to 0 (until all modules are removed at the end of the program) and it'... | 3 | 2010-01-19T18:25:30Z | [
"python",
"garbage-collection"
] |
module level garbage collection in python | 2,095,907 | <p>Let's say I have a module <code>mod_x</code> like the following:</p>
<pre><code>class X:
pass
x=X()
</code></pre>
<p>Now, let's say I have another module that just performs <code>import mod_x</code>, and goes about its business. The module variable <code>x</code> will not be referenced further during the lifecy... | 1 | 2010-01-19T18:20:31Z | 2,095,969 | <p>Once the module is imported it will be in the <code>sys.modules</code> dict so unless it is removed from there (which is possible though not standard practice) it will not be garbage collected.</p>
<p>So if you have a reason for wanting a module that has been loaded to be garbage collected you have to mess with <co... | 1 | 2010-01-19T18:27:50Z | [
"python",
"garbage-collection"
] |
How can I get Geany to show me the methods a library has when I press the '.' key? | 2,096,000 | <p>In visual studio, I could just press ctrl+spacekey and the methods appeared. In Geany is there a way for me to get this functionality?</p>
| 7 | 2010-01-19T18:31:18Z | 2,096,071 | <p>No, because is Python is dynamically typed language and quite hard to achieve that. Python plugins for netbeans do that partially, but I believe such plugin is not in geany developers plans. There are different things to be done ;-)</p>
<p>However, geany provides some completions support. First, it analyzes your im... | 5 | 2010-01-19T18:42:33Z | [
"python",
"ide",
"intellisense",
"geany"
] |
How can I get Geany to show me the methods a library has when I press the '.' key? | 2,096,000 | <p>In visual studio, I could just press ctrl+spacekey and the methods appeared. In Geany is there a way for me to get this functionality?</p>
| 7 | 2010-01-19T18:31:18Z | 19,875,773 | <p>shortcut <code>ctrl+space</code> works for me. also, you can setup autocomplete suggestion length (ie how many letters you must type before the autocomplete tooltip pops up automatically - <a href="http://www.geany.org/manual/current/#editor-completions-preferences" rel="nofollow">http://www.geany.org/manual/curren... | 0 | 2013-11-09T12:09:54Z | [
"python",
"ide",
"intellisense",
"geany"
] |
How can I get Geany to show me the methods a library has when I press the '.' key? | 2,096,000 | <p>In visual studio, I could just press ctrl+spacekey and the methods appeared. In Geany is there a way for me to get this functionality?</p>
| 7 | 2010-01-19T18:31:18Z | 39,988,536 | <p>You can use PyCharm. Does exactly what you need plus jump to the source file of the imported file-imported method.</p>
| 0 | 2016-10-11T23:58:00Z | [
"python",
"ide",
"intellisense",
"geany"
] |
Closest language to Python's syntax that is more low level language! | 2,096,015 | <p>I guess topic says it all! But, I really wan't a syntax similar to Python's! And low-level... like C++ for example. I guess Java and C# is OK too, but I really have a huge problem with the { }, and always ; <-- and each line. I hate it so much...</p>
| 5 | 2010-01-19T18:32:36Z | 2,096,045 | <p><a href="http://www.cython.org/" rel="nofollow">Cython</a> is a lower-level language with a syntax similar to Python's.</p>
| 12 | 2010-01-19T18:37:29Z | [
"python",
"programming-languages",
"syntax",
"low-level"
] |
Closest language to Python's syntax that is more low level language! | 2,096,015 | <p>I guess topic says it all! But, I really wan't a syntax similar to Python's! And low-level... like C++ for example. I guess Java and C# is OK too, but I really have a huge problem with the { }, and always ; <-- and each line. I hate it so much...</p>
| 5 | 2010-01-19T18:32:36Z | 2,096,048 | <p><a href="http://www.cython.org/" rel="nofollow">cython</a> may be pretty close to what you want: syntax just about identical to Python, and you can basically write C-level code in it. It's tuned to generate Python-usable extensions, but you could then "freeze" them into a stand-alone executable.</p>
<p><a href="ht... | 15 | 2010-01-19T18:37:45Z | [
"python",
"programming-languages",
"syntax",
"low-level"
] |
Closest language to Python's syntax that is more low level language! | 2,096,015 | <p>I guess topic says it all! But, I really wan't a syntax similar to Python's! And low-level... like C++ for example. I guess Java and C# is OK too, but I really have a huge problem with the { }, and always ; <-- and each line. I hate it so much...</p>
| 5 | 2010-01-19T18:32:36Z | 2,096,054 | <p>Google's <a href="http://golang.org/" rel="nofollow">Go</a> language was designed with Python syntax in mind though its got a hell of a lot of C in its genes too.</p>
| 3 | 2010-01-19T18:38:33Z | [
"python",
"programming-languages",
"syntax",
"low-level"
] |
Closest language to Python's syntax that is more low level language! | 2,096,015 | <p>I guess topic says it all! But, I really wan't a syntax similar to Python's! And low-level... like C++ for example. I guess Java and C# is OK too, but I really have a huge problem with the { }, and always ; <-- and each line. I hate it so much...</p>
| 5 | 2010-01-19T18:32:36Z | 2,096,083 | <p><a href="http://cobra-language.com/">Cobra</a> compiles to C#. Variables get typed after their first usage. Performance is about the same as C#. </p>
| 6 | 2010-01-19T18:44:49Z | [
"python",
"programming-languages",
"syntax",
"low-level"
] |
Closest language to Python's syntax that is more low level language! | 2,096,015 | <p>I guess topic says it all! But, I really wan't a syntax similar to Python's! And low-level... like C++ for example. I guess Java and C# is OK too, but I really have a huge problem with the { }, and always ; <-- and each line. I hate it so much...</p>
| 5 | 2010-01-19T18:32:36Z | 2,096,155 | <p><a href="http://live.gnome.org/Genie" rel="nofollow">Genie</a> could be what you are looking for. Is a python-like language (at least no semicolons) that compiles to c.</p>
| 0 | 2010-01-19T18:54:33Z | [
"python",
"programming-languages",
"syntax",
"low-level"
] |
When Does It Make Sense To Rewrite A Python Module in C? | 2,096,334 | <p>In a game that I am writing, I use a 2D vector class which I have written to handle the speeds of the objects. This is called a large number of times every frame as there are a lot of objects on the screen, so any increase I can make in its speed will be useful.</p>
<p>It is pretty simple, consisting mostly of wrap... | 3 | 2010-01-19T19:19:28Z | 2,096,344 | <p>If you're vector-munging, give <a href="http://numpy.scipy.org/" rel="nofollow">numpy</a> a try first. Chances are you will get speeds not far from C if you utilize numpy's vector manipulation functions wisely.</p>
<p>Other than that, your question is very heuristic. If your code is too slow:</p>
<ol>
<li>Profile ... | 14 | 2010-01-19T19:20:56Z | [
"python",
"c",
"optimization"
] |
When Does It Make Sense To Rewrite A Python Module in C? | 2,096,334 | <p>In a game that I am writing, I use a 2D vector class which I have written to handle the speeds of the objects. This is called a large number of times every frame as there are a lot of objects on the screen, so any increase I can make in its speed will be useful.</p>
<p>It is pretty simple, consisting mostly of wrap... | 3 | 2010-01-19T19:19:28Z | 2,096,358 | <p>First measure then optimize</p>
| 9 | 2010-01-19T19:22:19Z | [
"python",
"c",
"optimization"
] |
When Does It Make Sense To Rewrite A Python Module in C? | 2,096,334 | <p>In a game that I am writing, I use a 2D vector class which I have written to handle the speeds of the objects. This is called a large number of times every frame as there are a lot of objects on the screen, so any increase I can make in its speed will be useful.</p>
<p>It is pretty simple, consisting mostly of wrap... | 3 | 2010-01-19T19:19:28Z | 2,098,040 | <p>A nice Profiler I use on Linux is <a href="http://pycallgraph.slowchop.com/" rel="nofollow">pycallgraph</a> - however, as your program gets bigger it starts to create much larger images which are harder to trace. I'm pretty sure you can exclude modules, though.</p>
| 0 | 2010-01-19T23:34:22Z | [
"python",
"c",
"optimization"
] |
When Does It Make Sense To Rewrite A Python Module in C? | 2,096,334 | <p>In a game that I am writing, I use a 2D vector class which I have written to handle the speeds of the objects. This is called a large number of times every frame as there are a lot of objects on the screen, so any increase I can make in its speed will be useful.</p>
<p>It is pretty simple, consisting mostly of wrap... | 3 | 2010-01-19T19:19:28Z | 2,104,706 | <p>Common wisdom is "profile", "measure", etc. Well - maybe. Just get in the debugger and take 10 <a href="http://stackoverflow.com/questions/406760/whats-your-most-controversial-programming-opinion/1562802#1562802">stackshots</a>. If more than one of them terminates in your wrapper code, then it is costing more than 1... | 0 | 2010-01-20T20:29:38Z | [
"python",
"c",
"optimization"
] |
When Does It Make Sense To Rewrite A Python Module in C? | 2,096,334 | <p>In a game that I am writing, I use a 2D vector class which I have written to handle the speeds of the objects. This is called a large number of times every frame as there are a lot of objects on the screen, so any increase I can make in its speed will be useful.</p>
<p>It is pretty simple, consisting mostly of wrap... | 3 | 2010-01-19T19:19:28Z | 2,242,195 | <p>You should never optimize anything, be it in C or any other language, without timing your code before <em>and</em> after your optimization:</p>
<ul>
<li>your clever optimization could in fact induce a slow down</li>
<li>optimizing something that takes 1% of the total execution time will never give you more than 1% ... | 1 | 2010-02-11T04:04:39Z | [
"python",
"c",
"optimization"
] |
Sphinx - generate automatic references to Trac tickets and changesets | 2,096,401 | <p>Is <a href="http://sphinx.pocoo.org/" rel="nofollow">Sphinx</a>, is there way to automatically link text like <code>#112</code> or <code>r1023</code> to the corresponding tickets/changesets in <a href="http://trac.edgewall.org/" rel="nofollow">Trac</a>?</p>
<p>For eg:</p>
<pre><code>#112 -> http://mytracsite/t... | 5 | 2010-01-19T19:27:05Z | 2,111,327 | <p>If you put this in your config.py</p>
<pre><code>
trac_url = 'http://mytratsite/'
from docutils import nodes, utils
from docutils.parsers.rst import roles
import urllib
def trac_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
ref = trac_url + '/intertrac/' + urllib.quote(text, safe='')
nod... | 9 | 2010-01-21T17:23:54Z | [
"python",
"trac",
"python-sphinx",
"restructuredtext"
] |
Sphinx - generate automatic references to Trac tickets and changesets | 2,096,401 | <p>Is <a href="http://sphinx.pocoo.org/" rel="nofollow">Sphinx</a>, is there way to automatically link text like <code>#112</code> or <code>r1023</code> to the corresponding tickets/changesets in <a href="http://trac.edgewall.org/" rel="nofollow">Trac</a>?</p>
<p>For eg:</p>
<pre><code>#112 -> http://mytracsite/t... | 5 | 2010-01-19T19:27:05Z | 8,463,378 | <p>Sphinx 1.0 now supports <a href="http://sphinx.pocoo.org/latest/ext/extlinks.html" rel="nofollow">external links</a> using the <code>extlinks</code> extension. Using a configurable role name (e.g. 'issue') you can write your links like:</p>
<pre><code>:issue:`123`
</code></pre>
<p>and it will be converted to <code... | 4 | 2011-12-11T10:48:12Z | [
"python",
"trac",
"python-sphinx",
"restructuredtext"
] |
TypeError upon merely opening a file with csv.DictReader? | 2,096,466 | <p>I've just uploaded this CSV file via a form, POSTing it to my Python CGI script. The upload seems to have completed successfully. Permissions on the folder are 777, on the file are 755.</p>
<pre><code>>>> import csv
>>> csvHandle = open('files/TestData.csv', "rb")
>>> csvRawRecordDicts = ... | 0 | 2010-01-19T19:35:04Z | 2,096,538 | <p>There are a couple of things you could be doing:</p>
<ul>
<li>read the <a href="http://www.python.org/doc/2.3.5/lib/csv-contents.html" rel="nofollow">relevant docs</a> and see that <code>DictReader</code> requires two arguments at least, while you're passing one</li>
<li>try to do <code>>>> help(csv.DictRe... | 1 | 2010-01-19T19:46:41Z | [
"python",
"csv"
] |
TypeError upon merely opening a file with csv.DictReader? | 2,096,466 | <p>I've just uploaded this CSV file via a form, POSTing it to my Python CGI script. The upload seems to have completed successfully. Permissions on the folder are 777, on the file are 755.</p>
<pre><code>>>> import csv
>>> csvHandle = open('files/TestData.csv', "rb")
>>> csvRawRecordDicts = ... | 0 | 2010-01-19T19:35:04Z | 2,097,190 | <p>All of what Silent Ghost said, plus:</p>
<p>A change of emphasis: In my opinion, the most important point is to read the error message carefully. In this case, it is telling you simply and plainly that you need to supply another argument. Checking the help (or the docs for the Python version that you are running) f... | 1 | 2010-01-19T21:23:05Z | [
"python",
"csv"
] |
Property XXXX is not multi-line exception in python GAE | 2,096,471 | <p>I have a simple model object with </p>
<pre><code>profilename = db.StringProperty()
</code></pre>
<p>and when I get a string with "Some More" and try to </p>
<blockquote>
<p>put</p>
</blockquote>
<p>it in model
it throws exception </p>
<blockquote>
<p>Property profilename is not multi-line</p>
</blockquote>... | 3 | 2010-01-19T19:35:34Z | 2,097,640 | <p>The check's being done at application level, specifically in StringProperty.validate -- the code in question (which you can find in your SDK's sources in ext/db/<strong>init</strong>.py) is:</p>
<pre><code>if not self.multiline and value and value.find('\n') != -1:
raise BadValueError('Property %s is not multi-li... | 4 | 2010-01-19T22:26:15Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Fetch certain .html files from web server | 2,096,484 | <p>I would like to fetch certain .html files from a web server. My intention is to fetch .html files from a web site (http://www.thetabworld.com/) that has a word "metallica" on file name. How is that possible using python? I have heard about urllib2 but as a python noob, I don't have a slightest idea how to use it.</p... | 0 | 2010-01-19T19:37:16Z | 2,096,493 | <p>You need to use urllib2 together with a HTML parser such as <code>lxml</code> or <code>BeautifulSoup</code> in order to extract the links from the retrieved pages in order to crawl the site.</p>
| 1 | 2010-01-19T19:38:56Z | [
"python",
"urllib2"
] |
Fetch certain .html files from web server | 2,096,484 | <p>I would like to fetch certain .html files from a web server. My intention is to fetch .html files from a web site (http://www.thetabworld.com/) that has a word "metallica" on file name. How is that possible using python? I have heard about urllib2 but as a python noob, I don't have a slightest idea how to use it.</p... | 0 | 2010-01-19T19:37:16Z | 2,096,857 | <blockquote>
<p>"I have heard about urllib2 but as a
python noob, I don't have a slightest
idea how to use it."</p>
</blockquote>
<p>well if you don't know how to use urllib2, reading some docs would be a good start.</p>
<p>the following are excellent resources (with examples):</p>
<p><a href="http://docs.pyt... | 1 | 2010-01-19T20:34:53Z | [
"python",
"urllib2"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 2,096,714 | <p>if n is not far from r then using the recursive definition of combination is probably better, since xC0 == 1 you will only have a few iterations:</p>
<p>The relevant recursive definition here is:</p>
<p>nCr = (n-1)C(r-1) * n/r</p>
<p>This can be nicely computed using tail recursion with the following list:</p>
<... | 20 | 2010-01-19T20:11:44Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 2,096,735 | <p>Using <code>xrange()</code> instead of <code>range()</code> will speed things up slightly due to the fact that no intermediate list is created, populated, iterated through, and then destroyed. Also, <code>reduce()</code> with <code>operator.mul</code>.</p>
| 0 | 2010-01-19T20:14:32Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 2,096,751 | <p>If you are computing N choose K (which is what I think you're doing with ncr), there is a dynamic programming solution that may be a lot faster. This will avoid factorial, plus you can keep the table if you want for later use.</p>
<p>Here is a teaching link for it:</p>
<p><a href="http://www.csc.liv.ac.uk/~ped/tea... | 3 | 2010-01-19T20:16:24Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 2,096,894 | <p>Two fairly simple suggestions:</p>
<ol>
<li><p>To avoid overflow, do everything in log space. Use the fact that log(a * b) = log(a) + log(b), and log(a / b) = log(a) - log(b). This makes it easy to work with very large factorials: log(n! / m!) = log(n!) - log(m!), etc.</p></li>
<li><p>Use the gamma function inst... | 16 | 2010-01-19T20:40:55Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 2,096,937 | <p>For N choose K you could use Pascals triangle. Basically you would need to keep array of size N around to compute all the N choose K values. Only additions would be required.</p>
| 0 | 2010-01-19T20:47:58Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 2,097,030 | <p>If your problem does not require knowing the exact number of permutations or combinations, then you could use <a href="http://en.wikipedia.org/wiki/Stirling%27s_approximation" rel="nofollow">Stirling's approximation</a> for the factorial.</p>
<p>That would lead to code like this:</p>
<pre><code>import math
def st... | 2 | 2010-01-19T20:58:39Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 2,097,660 | <p>If you don't need a pure-python solution, <a href="https://pypi.python.org/pypi/gmpy2" rel="nofollow">gmpy2</a> might help (<code>gmpy2.comb</code> is very fast).</p>
| 6 | 2010-01-19T22:30:08Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
counting combinations and permutations efficiently | 2,096,573 | <p>I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers.</p>
<p>I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations.</p>
<p>So far, I've put in a special case to reflect th... | 22 | 2010-01-19T19:52:03Z | 15,738,101 | <p>You could input two integers and import math library to find the factorial and then apply the nCr formula</p>
<pre><code>import math
n,r=[int(_)for _ in raw_input().split()]
f=math.factorial
print f(n)/f(r)/f(n-r)
</code></pre>
| 0 | 2013-04-01T05:27:48Z | [
"python",
"algorithm",
"math",
"combinations",
"permutation"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.