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 |
|---|---|---|---|---|---|---|---|---|---|
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 623,198 | <p>I like the closure solution for being "cleaner" and more Pythonic (so +1 to mmarshall answer) but Django forms also have a callback mechanism you can use for filtering querysets in formsets.</p>
<p>It's also not documented, which I think is an indicator the Django devs might not like it as much.</p>
<p>So you basi... | 9 | 2009-03-08T07:08:41Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 624,013 | <p>I would use <a href="http://docs.python.org/2/library/functools.html#functools.partial">functools.partial</a> and <a href="http://docs.python.org/2/library/functools.html#functools.wraps">functools.wraps</a>:</p>
<pre><code>from functools import partial, wraps
from django.forms.formsets import formset_factory
Serv... | 92 | 2009-03-08T18:00:26Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 813,647 | <p>I wanted to place this as a comment to Carl Meyers answer, but since that requires points I just placed it here. This took me 2 hours to figure out so I hope it will help someone.</p>
<p>A note about using the inlineformset_factory.</p>
<p>I used that solution my self and it worked perfect, until I tried it with t... | 9 | 2009-05-01T23:00:06Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 1,341,544 | <p>I spent some time trying to figure out this problem before I saw this posting.</p>
<p>The solution I came up with was the closure solution (and it is a solution I've used before with Django model forms).</p>
<p>I tried the curry() method as described above, but I just couldn't get it to work with Django 1.0 so in ... | 1 | 2009-08-27T14:38:38Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 4,033,007 | <p>I had to do a similar thing. This is similar to the <code>curry</code> solution:</p>
<pre><code>def form_with_my_variable(myvar):
class MyForm(ServiceForm):
def __init__(self, myvar=myvar, *args, **kwargs):
super(SeriveForm, self).__init__(myvar=myvar, *args, **kwargs)
return MyForm
factory = inl... | 0 | 2010-10-27T12:12:55Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 9,206,827 | <p>Carl Meyer's solution looks very elegant. I tried implementing it for modelformsets. I was under the impression that I could not call staticmethods within a class, but the following inexplicably works:</p>
<pre><code>class MyModel(models.Model):
myField = models.CharField(max_length=10)
class MyForm(ModelForm)... | 3 | 2012-02-09T07:16:01Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 18,348,930 | <p>I'm a newbie here so I can't add comment. I hope this code will work too:</p>
<pre><code>ServiceFormSet = formset_factory(ServiceForm, extra=3)
ServiceFormSet.formset = staticmethod(curry(ServiceForm, affiliate=request.affiliate))
</code></pre>
<p>as for adding additional parameters to the formset's <code>BaseFor... | 0 | 2013-08-21T04:36:35Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 25,766,319 | <p>As of commit e091c18f50266097f648efc7cac2503968e9d217 on Tue Aug 14 23:44:46 2012 +0200 the accepted solution can't work anymore. </p>
<p>The current version of django.forms.models.modelform_factory() function uses a "type construction technique", calling the type() function on the passed form to get the metaclass... | 8 | 2014-09-10T13:09:20Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 25,915,489 | <p>This is what worked for me, Django 1.7:</p>
<pre><code>from django.utils.functional import curry
lols = {'lols':'lols'}
formset = modelformset_factory(MyModel, form=myForm, extra=0)
formset.form = staticmethod(curry(MyForm, lols=lols))
return formset
#form.py
class MyForm(forms.ModelForm):
def __init__(s... | 12 | 2014-09-18T14:29:59Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 35,811,020 | <p>Django 1.9:</p>
<pre><code>ArticleFormSet = formset_factory(MyArticleForm)
formset = ArticleFormSet(form_kwargs={'user': request.user})
</code></pre>
<p><a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms" rel="nofollow">https://docs.djangoproject.com/en... | 4 | 2016-03-05T06:41:12Z | [
"python",
"django",
"forms",
"django-forms"
] |
Django Passing Custom Form Parameters to Formset | 622,982 | <blockquote>
<p>This was fixed in Django 1.9 with <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/#passing-custom-parameters-to-formset-forms">form_kwargs</a>.</p>
</blockquote>
<p>I have a Django Form that looks like this:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelC... | 113 | 2009-03-08T03:36:08Z | 39,229,572 | <p>based on <a href="http://stackoverflow.com/questions/622982/django-passing-custom-form-parameters-to-formset/#answer-623198">this answer</a> I found more clear solution:</p>
<pre><code>class ServiceForm(forms.Form):
option = forms.ModelChoiceField(
queryset=ServiceOption.objects.filter(affiliate=sel... | 0 | 2016-08-30T13:59:30Z | [
"python",
"django",
"forms",
"django-forms"
] |
For my app, how many threads would be optimal? | 623,054 | <p>I have a simple Python web crawler. It uses SQLite to store its output and also to keep a queue. I want to make the crawler multi-threaded so that it can crawl several pages at a time. I figured i would make a thread and just run several instances of the class at once, so they all run concurrently. But the question ... | 3 | 2009-03-08T04:44:41Z | 623,064 | <p>It's usually simpler to make multiple concurrent processes. Simply use subprocess to create as many Popens as you feel it necessary to run concurrently.</p>
<p>There's no "optimal" number. Generally, when you run just one crawler, your PC spends a lot of time waiting. How much? Hard to say.</p>
<p>When you're ... | 3 | 2009-03-08T04:55:05Z | [
"python",
"multithreading"
] |
For my app, how many threads would be optimal? | 623,054 | <p>I have a simple Python web crawler. It uses SQLite to store its output and also to keep a queue. I want to make the crawler multi-threaded so that it can crawl several pages at a time. I figured i would make a thread and just run several instances of the class at once, so they all run concurrently. But the question ... | 3 | 2009-03-08T04:44:41Z | 623,070 | <p>You will probably find your application is bandwidth limited not CPU or I/O limited.</p>
<p>As such, add as many as you like until performance begins to degrade.</p>
<p>You may come up against other limits depending on your network setup. Like if you're behind an ADSL router, there will be a limit on the number o... | 13 | 2009-03-08T04:57:01Z | [
"python",
"multithreading"
] |
For my app, how many threads would be optimal? | 623,054 | <p>I have a simple Python web crawler. It uses SQLite to store its output and also to keep a queue. I want to make the crawler multi-threaded so that it can crawl several pages at a time. I figured i would make a thread and just run several instances of the class at once, so they all run concurrently. But the question ... | 3 | 2009-03-08T04:44:41Z | 623,073 | <p>You can go higher that two. How much higher depends entirely on the hardware of the system you're running this on, how much processing is going on after the network operations, and what else is running on the machine at the time.</p>
<p>Since it's being written in Python (and being called "simple") I'm going to as... | 1 | 2009-03-08T04:58:47Z | [
"python",
"multithreading"
] |
For my app, how many threads would be optimal? | 623,054 | <p>I have a simple Python web crawler. It uses SQLite to store its output and also to keep a queue. I want to make the crawler multi-threaded so that it can crawl several pages at a time. I figured i would make a thread and just run several instances of the class at once, so they all run concurrently. But the question ... | 3 | 2009-03-08T04:44:41Z | 623,098 | <p>Threading isn't necessary in this case. Your program is <strong>I/O bound</strong> rather than CPU bound. The networking part would probably be <strong>better done using select()</strong> on the sockets. This reduces the overhead of creating and maintaining threads. I haven't used <a href="http://twistedmatrix.com" ... | 0 | 2009-03-08T05:16:08Z | [
"python",
"multithreading"
] |
For my app, how many threads would be optimal? | 623,054 | <p>I have a simple Python web crawler. It uses SQLite to store its output and also to keep a queue. I want to make the crawler multi-threaded so that it can crawl several pages at a time. I figured i would make a thread and just run several instances of the class at once, so they all run concurrently. But the question ... | 3 | 2009-03-08T04:44:41Z | 623,138 | <p>I would use one thread and <a href="http://twistedmatrix.com/">twisted</a> with either a deferred semaphore or a task cooperator if you already have an easy way to feed an arbitrarily long list of URLs in.</p>
<p>It's extremely unlikely you'll be able to make a multi-threaded crawler that's faster or smaller than a... | 7 | 2009-03-08T05:54:32Z | [
"python",
"multithreading"
] |
For my app, how many threads would be optimal? | 623,054 | <p>I have a simple Python web crawler. It uses SQLite to store its output and also to keep a queue. I want to make the crawler multi-threaded so that it can crawl several pages at a time. I figured i would make a thread and just run several instances of the class at once, so they all run concurrently. But the question ... | 3 | 2009-03-08T04:44:41Z | 623,496 | <p>cletus's answer is the one you want.</p>
<p>A couple of people proposed an alternate solution using asynchronous I/O, especially looking at Twisted. If you decide to go that route, a different solution is <a href="http://pycurl.sourceforge.net/" rel="nofollow">pycurl</a>, which is a thin wrapper to libcurl, which ... | 3 | 2009-03-08T12:24:00Z | [
"python",
"multithreading"
] |
For my app, how many threads would be optimal? | 623,054 | <p>I have a simple Python web crawler. It uses SQLite to store its output and also to keep a queue. I want to make the crawler multi-threaded so that it can crawl several pages at a time. I figured i would make a thread and just run several instances of the class at once, so they all run concurrently. But the question ... | 3 | 2009-03-08T04:44:41Z | 623,515 | <p>One thing you should keep in mind is that some servers may interpret too many concurrent requests from the same IP address as a DoS attack and abort connections or return error pages for requests that would otherwise succeed.</p>
<p>So it might be a good idea to limit the number of concurrent requests to the same s... | 1 | 2009-03-08T12:44:01Z | [
"python",
"multithreading"
] |
How can I insert RTF into a wxpython RichTextCtrl? | 623,384 | <p>Is there a way to directly insert RTF text in a RichTextCtrl, ex:without going through <strong>BeginTextColour</strong>? I would like to use pygments together with the RichTextCtrl.</p>
| 1 | 2009-03-08T10:37:36Z | 623,449 | <p><strong>No.</strong> As authors admit in <a href="http://docs.wxwidgets.org/stable/wx%5Fwxrichtextctrloverview.html#topic17" rel="nofollow">wxRichTextCtrl roadmap</a>:</p>
<blockquote>
<p>This is a list of some of the features that have yet to be implemented. Help with them will be appreciated.</p>
<ul>
<l... | 2 | 2009-03-08T11:42:26Z | [
"python",
"wxpython",
"rtf",
"richtextctrl"
] |
Retrieving the latitude/longitude from Google Map Mobile 3.0's MyLocation feature | 623,504 | <p>I want to fetch my current latitude/longitude from Google Maps Mobile 3.0 with the help of some script, which I guess could be a Python one. Is this possible? And, more importantly: is the Google Maps Mobile API designed for such interaction? Any legal issues?</p>
<p>Basically i have a S60 phone that doesnt have GP... | 1 | 2009-03-08T12:34:30Z | 858,276 | <p>No, you can't access it from a Python script or another S60 application because of platform security features of S60 3rd ed. Even if Google Maps application would write information to disk, your app is not able to access application specific files of other apps. </p>
<p>Google Maps use cell-based locationing in add... | 1 | 2009-05-13T14:26:46Z | [
"python",
"google-maps",
"s60",
"pys60"
] |
Retrieving the latitude/longitude from Google Map Mobile 3.0's MyLocation feature | 623,504 | <p>I want to fetch my current latitude/longitude from Google Maps Mobile 3.0 with the help of some script, which I guess could be a Python one. Is this possible? And, more importantly: is the Google Maps Mobile API designed for such interaction? Any legal issues?</p>
<p>Basically i have a S60 phone that doesnt have GP... | 1 | 2009-03-08T12:34:30Z | 965,834 | <p>About reading any file from the disk:</p>
<p>Only when you have an <a href="https://rdcertification.nokia.com/rdcertification/app" rel="nofollow">R&D (Research and Development) certificate</a> that grants you the <code>AllFiles</code> capability, can you access nearly any file.</p>
| 0 | 2009-06-08T16:44:29Z | [
"python",
"google-maps",
"s60",
"pys60"
] |
Retrieving the latitude/longitude from Google Map Mobile 3.0's MyLocation feature | 623,504 | <p>I want to fetch my current latitude/longitude from Google Maps Mobile 3.0 with the help of some script, which I guess could be a Python one. Is this possible? And, more importantly: is the Google Maps Mobile API designed for such interaction? Any legal issues?</p>
<p>Basically i have a S60 phone that doesnt have GP... | 1 | 2009-03-08T12:34:30Z | 1,467,215 | <p>You don't have to do this through Google Maps. The mapping for Cell ID to latitude and longitude is available from <a href="http://www.opencellid.org" rel="nofollow">http://www.opencellid.org</a>.</p>
<p>You can get the raw data file and then sample part of the data to the accuracy you need. Then, using the pys60 e... | 1 | 2009-09-23T16:38:44Z | [
"python",
"google-maps",
"s60",
"pys60"
] |
Why can't I directly add attributes to any python object? | 623,520 | <p>I have this code:</p>
<pre><code>>>> class G:
... def __init__(self):
... self.x = 20
...
>>> gg = G()
>>> gg.x
20
>>> gg.y = 2000
</code></pre>
<p>And this code:</p>
<pre><code>>>> from datetime import datetime
>>> my_obj = datetime.now()
>>> m... | 21 | 2009-03-08T12:46:56Z | 623,531 | <p>My guess, is that the implementation of datetime uses <a href="http://docs.python.org/reference/datamodel.html#id3">__slots__</a> for better performance.</p>
<p>When using <code>__slots__</code>, the interpreter reserves storage for just the attributes listed, nothing else. This gives better performance and uses le... | 32 | 2009-03-08T12:54:54Z | [
"python",
"attributes",
"object"
] |
Why can't I directly add attributes to any python object? | 623,520 | <p>I have this code:</p>
<pre><code>>>> class G:
... def __init__(self):
... self.x = 20
...
>>> gg = G()
>>> gg.x
20
>>> gg.y = 2000
</code></pre>
<p>And this code:</p>
<pre><code>>>> from datetime import datetime
>>> my_obj = datetime.now()
>>> m... | 21 | 2009-03-08T12:46:56Z | 623,544 | <p>It's written in C</p>
<p><a href="http://svn.python.org/view/python/trunk/Modules/datetimemodule.c?view=markup">http://svn.python.org/view/python/trunk/Modules/datetimemodule.c?view=markup</a></p>
<p>It doesn't seem to implement setattr.</p>
| 18 | 2009-03-08T13:07:39Z | [
"python",
"attributes",
"object"
] |
Why can't I directly add attributes to any python object? | 623,520 | <p>I have this code:</p>
<pre><code>>>> class G:
... def __init__(self):
... self.x = 20
...
>>> gg = G()
>>> gg.x
20
>>> gg.y = 2000
</code></pre>
<p>And this code:</p>
<pre><code>>>> from datetime import datetime
>>> my_obj = datetime.now()
>>> m... | 21 | 2009-03-08T12:46:56Z | 15,627,778 | <p>While the question has already been answered; if anyone is interested in a workaround, here's an example --</p>
<pre><code>mydate = datetime.date(2013, 3, 26)
mydate.special = 'Some special date annotation' # doesn't work
...
class CustomDate(datetime.date):
pass
mydate = datetime.date(2013, 3, 26)
mydate = Cu... | 2 | 2013-03-26T01:27:33Z | [
"python",
"attributes",
"object"
] |
How do you add event to Trac event time line | 623,822 | <p>I am writing a plug-in for Trac. I would like to add an event to the time line each time the plug-in receives some data from a Git post-receive hook.</p>
<p>Looking at <a href="http://trac.edgewall.org/browser/trunk/trac/timeline/api.py" rel="nofollow">the timeline API</a>, it seems you can only add new source of e... | 1 | 2009-03-08T16:30:07Z | 636,842 | <p>The timeline API is a level higher than what you need to do. There is a general VCS implementation of it in <a href="http://trac.edgewall.org/browser/trunk/trac/versioncontrol/web%5Fui/changeset.py" rel="nofollow">ChangesetModule</a>, which delegates the changeset (event) retrieval itself to a VCS-specific <code>Rep... | 2 | 2009-03-11T23:57:51Z | [
"python",
"plugins",
"trac"
] |
django login middleware not working as expected | 624,043 | <p>A quickie, and hopefully an easy one. I'm following the docs at <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/auth/</a> to get just some simple user authentication in place. I don't have any special requirements at all, I just need to know if a... | 1 | 2009-03-08T18:24:40Z | 624,068 | <p>I believe I fixed it:</p>
<p>Right:</p>
<pre><code>url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'quiz/quiz_login.html'})
</code></pre>
<p>Wrong:</p>
<pre><code>url(r'^login$', 'django.contrib.auth.views.login', {'template_name': 'quiz/quiz_login.html'})
</code></pre>
<p>Meh.</p>
| 0 | 2009-03-08T18:38:37Z | [
"python",
"django",
"django-authentication"
] |
wx's idle and UI update events in PyQt | 624,050 | <p>wx (and wxPython) has two events I miss in PyQt: </p>
<ul>
<li><code>EVT_IDLE</code> that's being sent to a frame. It can be used to update the various widgets according to the application's state</li>
<li><code>EVT_UPDATE_UI</code> that's being sent to a widget when it has to be repainted and updated, so I can com... | 1 | 2009-03-08T18:26:51Z | 624,282 | <p>As far as I understand EVT_IDLE is sent when application message queue is empty. There is no such event in Qt, but if you need to execute something in Qt when there are no pending events, you should use QTimer with 0 timeout.</p>
| 1 | 2009-03-08T21:04:37Z | [
"python",
"qt",
"wxpython",
"pyqt"
] |
wx's idle and UI update events in PyQt | 624,050 | <p>wx (and wxPython) has two events I miss in PyQt: </p>
<ul>
<li><code>EVT_IDLE</code> that's being sent to a frame. It can be used to update the various widgets according to the application's state</li>
<li><code>EVT_UPDATE_UI</code> that's being sent to a widget when it has to be repainted and updated, so I can com... | 1 | 2009-03-08T18:26:51Z | 624,734 | <p>The use of EVT_UPDATE_UI in wxWidgets seems to highlight one of the fundamental differences in the way wxWidgets and Qt expect developers to handle events in their code.</p>
<p>With Qt, you connect signals and slots between widgets in the user interface, either handling "business logic" in each slot or delegating i... | 5 | 2009-03-09T01:40:31Z | [
"python",
"qt",
"wxpython",
"pyqt"
] |
wx's idle and UI update events in PyQt | 624,050 | <p>wx (and wxPython) has two events I miss in PyQt: </p>
<ul>
<li><code>EVT_IDLE</code> that's being sent to a frame. It can be used to update the various widgets according to the application's state</li>
<li><code>EVT_UPDATE_UI</code> that's being sent to a widget when it has to be repainted and updated, so I can com... | 1 | 2009-03-08T18:26:51Z | 626,368 | <p>I would send Qt signals to indicate state changes (e.g. fileOpened, processingStarted, processingDone). Slots in objects managing the start button and status bar widget (or subclasses) can be connected to those signals, rather than "polling" for current state in an idle event.</p>
<p>If you want the signal to be d... | 2 | 2009-03-09T14:06:54Z | [
"python",
"qt",
"wxpython",
"pyqt"
] |
wx's idle and UI update events in PyQt | 624,050 | <p>wx (and wxPython) has two events I miss in PyQt: </p>
<ul>
<li><code>EVT_IDLE</code> that's being sent to a frame. It can be used to update the various widgets according to the application's state</li>
<li><code>EVT_UPDATE_UI</code> that's being sent to a widget when it has to be repainted and updated, so I can com... | 1 | 2009-03-08T18:26:51Z | 627,484 | <p>In general, the more Qt-ish way is to update the button/toolbar as necessary in whatever functions require the update, or to consolidate some of the functionality and directly call that function when the program needs it (such as an updateUi function).</p>
<p>You should be aware that in Qt, changing an attribute of... | 1 | 2009-03-09T18:31:03Z | [
"python",
"qt",
"wxpython",
"pyqt"
] |
What should I be aware of when moving from asp.net to python for web development? | 624,062 | <p>I'm thinking about converting an app from Asp.net to python. I would like to know: what are the key comparisons to be aware of when moving a asp.net app to python(insert framework)?</p>
<p>Does python have user controls? Master pages? </p>
| 3 | 2009-03-08T18:34:58Z | 624,079 | <p>First, Python is a language, while ASP.NET is a web framework. In fact, you can code ASP.NET applications using <a href="http://www.codeplex.com/IronPython" rel="nofollow">IronPython</a>.</p>
<p>If you want to leave ASP.NET behind and go with the Python "stack," then you can choose from several different web applic... | 8 | 2009-03-08T18:44:05Z | [
"asp.net",
"python"
] |
What should I be aware of when moving from asp.net to python for web development? | 624,062 | <p>I'm thinking about converting an app from Asp.net to python. I would like to know: what are the key comparisons to be aware of when moving a asp.net app to python(insert framework)?</p>
<p>Does python have user controls? Master pages? </p>
| 3 | 2009-03-08T18:34:58Z | 624,119 | <p>I second the note by Out Into Space on how python is a language versus a web framework; it's an important observation that underlies pretty much everything you will experience in moving from ASP.NET to Python.</p>
<p>On a similar note, you will also find that the differences in language style and developer communit... | 4 | 2009-03-08T19:18:05Z | [
"asp.net",
"python"
] |
What should I be aware of when moving from asp.net to python for web development? | 624,062 | <p>I'm thinking about converting an app from Asp.net to python. I would like to know: what are the key comparisons to be aware of when moving a asp.net app to python(insert framework)?</p>
<p>Does python have user controls? Master pages? </p>
| 3 | 2009-03-08T18:34:58Z | 637,273 | <p>Most frameworks for python has a 'templating' engine which provide similar functionality of ASP.NET's Master pages and User Controls. :)</p>
<p>Thanks for the replies Out Of Space and Jarret Hardie</p>
| 0 | 2009-03-12T03:38:56Z | [
"asp.net",
"python"
] |
Twill/Mechanize access to html content | 624,232 | <p>Couple of questions regarding <a href="http://twill.idyll.org/" rel="nofollow">Twill</a> and <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">Mechanize</a>:</p>
<ol>
<li><p>Is Twill still relevant as a web-automation tool? If yes, then why is not currently maintained? If no, has Mechanize matu... | 5 | 2009-03-08T20:30:54Z | 1,718,676 | <p>Twill is a <a href="http://twill.idyll.org/python-api.html" rel="nofollow">thin shell around the mechanize package</a>. You are right it does not appear to be actively maintained so I would stick with Mechanize.</p>
<p>However Mechanize does not support the simple interface you are after. For that I would recommend... | 1 | 2009-11-11T22:54:49Z | [
"python",
"twill",
"mechanize-python"
] |
Twill/Mechanize access to html content | 624,232 | <p>Couple of questions regarding <a href="http://twill.idyll.org/" rel="nofollow">Twill</a> and <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">Mechanize</a>:</p>
<ol>
<li><p>Is Twill still relevant as a web-automation tool? If yes, then why is not currently maintained? If no, has Mechanize matu... | 5 | 2009-03-08T20:30:54Z | 22,848,600 | <p>This question is old, but ranking high on google.</p>
<p>As of 2014 oficial twill seems quite dead, also the mailing list.</p>
<p>There are forks on github:</p>
<p><a href="https://github.com/zenoss/twill" rel="nofollow">https://github.com/zenoss/twill</a></p>
<p><a href="https://github.com/ctb/twill" rel="nofol... | 0 | 2014-04-03T20:42:59Z | [
"python",
"twill",
"mechanize-python"
] |
How do I make a Django ModelForm menu item selected by default? | 624,265 | <p>I am working on a Django app. One of my models, "User", includes a "gender" field, as defined below:</p>
<pre><code>GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, null=True)
</code></pre>
<p>I am using a ModelForm to generate... | 9 | 2009-03-08T20:56:46Z | 624,308 | <p>Surely <code>default</code> will do the trick?</p>
<p>e.g.</p>
<pre><code>gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='M', null=True)</code></pre>
| 7 | 2009-03-08T21:19:46Z | [
"python",
"django",
"django-forms"
] |
How do I make a Django ModelForm menu item selected by default? | 624,265 | <p>I am working on a Django app. One of my models, "User", includes a "gender" field, as defined below:</p>
<pre><code>GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, null=True)
</code></pre>
<p>I am using a ModelForm to generate... | 9 | 2009-03-08T20:56:46Z | 624,361 | <p>If you need a blank form with a default value selected, then pass an 'initial' dictionary to the constructor of your model form using the name of your field as the key:</p>
<pre><code>form = MyModelForm (initial={'gender':'M'})
</code></pre>
<p>-OR-</p>
<p>You can override certain attributes of a ModelForm using ... | 15 | 2009-03-08T21:45:42Z | [
"python",
"django",
"django-forms"
] |
How can I customize the output from pygments? | 624,345 | <p>If I run a python source file through pygments, it outputs html code whose elements class belong to some CSS file pygments is using. Could the style attributes be included in the outputted html so that I don't have to provide a CSS file?</p>
| 1 | 2009-03-08T21:37:16Z | 624,477 | <p>Usually, your code is only one of many things on a web page. You often want code to look different from the other content. You, generally, want to control the style of the code as part of the overall page style. CSS is your first, best choice for this.</p>
<p>However, you can embed the styles in the HTML if that... | -2 | 2009-03-08T22:43:01Z | [
"python",
"html",
"css",
"pygments"
] |
How can I customize the output from pygments? | 624,345 | <p>If I run a python source file through pygments, it outputs html code whose elements class belong to some CSS file pygments is using. Could the style attributes be included in the outputted html so that I don't have to provide a CSS file?</p>
| 1 | 2009-03-08T21:37:16Z | 624,532 | <p>By setting the <strong>noclasses</strong> attribute to <strong>True</strong>, only inline styles will be generated. Here's a snippet that does the job just fine:</p>
<pre><code>
formatter = HtmlFormatter(style=MyStyle)
formatter.noclasses = True
print highlight(content,PythonLexer(),formatter)
</code></pre>
| 5 | 2009-03-08T23:22:37Z | [
"python",
"html",
"css",
"pygments"
] |
How can I customize the output from pygments? | 624,345 | <p>If I run a python source file through pygments, it outputs html code whose elements class belong to some CSS file pygments is using. Could the style attributes be included in the outputted html so that I don't have to provide a CSS file?</p>
| 1 | 2009-03-08T21:37:16Z | 624,717 | <p>Pass full=True to the HtmlFormatter constructor.</p>
| 0 | 2009-03-09T01:29:47Z | [
"python",
"html",
"css",
"pygments"
] |
How can I customize the output from pygments? | 624,345 | <p>If I run a python source file through pygments, it outputs html code whose elements class belong to some CSS file pygments is using. Could the style attributes be included in the outputted html so that I don't have to provide a CSS file?</p>
| 1 | 2009-03-08T21:37:16Z | 10,409,731 | <p>@Ignacio: quite the opposite:</p>
<pre><code>from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
code = 'print "Hello World"'
print highlight(code, PythonLexer(), HtmlFormatter(noclasses=True))
</code></pre>
<p>[ ref.: <a href="http://pygments.org/d... | 0 | 2012-05-02T07:51:03Z | [
"python",
"html",
"css",
"pygments"
] |
Why am I getting an invalid syntax easy_install error? | 624,492 | <p>I need to use easy_install to install a package. I installed the enthought distribution, and popped into IDLE to say: </p>
<pre><code>>>> easy_install SQLobject
SyntaxError: invalid syntax
</code></pre>
<p>What am I doing wrong? <code>easy_install</code> certainly exists, as does the package. help('eas... | 4 | 2009-03-08T22:51:58Z | 624,499 | <p>easy_install is a shell command. You don't need to put it in a python script.</p>
<pre><code>easy_install SQLobject
</code></pre>
<p>Type that straight into a bash (or other) shell, as long as easy_install is in your path.</p>
| 18 | 2009-03-08T22:58:13Z | [
"python",
"easy-install"
] |
Using Django admin look and feel in my own application | 624,535 | <p>I like the very simple but still really elegant look and feel of the django admin and I was wondering if there is a way to apply it to my own application.</p>
<p>(I think that I've read something like that somewhere, but now I cannot find the page again.)</p>
<p>(edited: what I am looking for is a way to do it aut... | 0 | 2009-03-08T23:22:51Z | 625,235 | <p>Are you sure you want to take every bit of admin-site's look & feel??
I think you would need to customize some, as in header footer etc.</p>
<p>To do that, just copy base.html from </p>
<blockquote>
<p>"djangosrc/contrib/admin/templates/admin/"</p>
</blockquote>
<p>and keep it in </p>
<blockquote>
<p>"yo... | 4 | 2009-03-09T06:47:34Z | [
"python",
"django",
"django-admin",
"styles",
"look-and-feel"
] |
Using Django admin look and feel in my own application | 624,535 | <p>I like the very simple but still really elegant look and feel of the django admin and I was wondering if there is a way to apply it to my own application.</p>
<p>(I think that I've read something like that somewhere, but now I cannot find the page again.)</p>
<p>(edited: what I am looking for is a way to do it aut... | 0 | 2009-03-08T23:22:51Z | 625,891 | <pre><code>{% extends "admin/base_site.html" %}
</code></pre>
<p>is usually a good place to start but do look at the templates in contrib/admin/templates and copy some of the techniques there. </p>
| 2 | 2009-03-09T11:34:30Z | [
"python",
"django",
"django-admin",
"styles",
"look-and-feel"
] |
Unable to install python-setuptools: ./configure: No such file or directory | 624,671 | <p>The question is related to <a href="http://stackoverflow.com/questions/622744/unable-to-install-python-without-sudo-access/622810#622810">the answer to "Unable to install Python without sudo access"</a>.</p>
<p>I need to install python-setuptools to install python modules.
I have extracted the installation package.... | 2 | 2009-03-09T01:06:48Z | 624,731 | <p>You might want to check <a href="http://peak.telecommunity.com/DevCenter/EasyInstall#custom-installation-locations" rel="nofollow">http://peak.telecommunity.com/DevCenter/EasyInstall#custom-installation-locations</a>.</p>
<p>EasyInstall is a python module with some shell scripts (or some shell scripts with a python... | 1 | 2009-03-09T01:34:49Z | [
"python",
"setuptools",
"failed-installation"
] |
Unable to install python-setuptools: ./configure: No such file or directory | 624,671 | <p>The question is related to <a href="http://stackoverflow.com/questions/622744/unable-to-install-python-without-sudo-access/622810#622810">the answer to "Unable to install Python without sudo access"</a>.</p>
<p>I need to install python-setuptools to install python modules.
I have extracted the installation package.... | 2 | 2009-03-09T01:06:48Z | 624,998 | <p>As Noah states, setuptools isn't an automake package so doesn't use â./configureâ. Instead it's a pure-Python-style âsetup.pyâ (distutils) script.</p>
<p>You shouldn't normally need to play with .pydistutils.cfg, as long as you run it with the right version of Python. So if you haven't added the .local/bin ... | 2 | 2009-03-09T04:22:19Z | [
"python",
"setuptools",
"failed-installation"
] |
Why aren't signals simply called events? | 624,844 | <p>From what I can tell, in Python and and Django, signals are simply delegated events. Is there anything that functionally differentiates them from the typical notion of events in C#, Java, ActionScript, etc?</p>
| 4 | 2009-03-09T02:42:37Z | 624,855 | <p>Signals typically have an association with an operating system facility and events are typically application-defined. In some technology stacks, the OS-level stuff may be hidden well enough that there isn't a difference in the API, but in others perhaps not.</p>
| 4 | 2009-03-09T02:47:44Z | [
"python",
"signals",
"django-signals"
] |
Why aren't signals simply called events? | 624,844 | <p>From what I can tell, in Python and and Django, signals are simply delegated events. Is there anything that functionally differentiates them from the typical notion of events in C#, Java, ActionScript, etc?</p>
| 4 | 2009-03-09T02:42:37Z | 624,860 | <p>You might as well ask "Why aren't events simply called signals?". Differences in terminology happen.</p>
| 1 | 2009-03-09T02:49:20Z | [
"python",
"signals",
"django-signals"
] |
Why aren't signals simply called events? | 624,844 | <p>From what I can tell, in Python and and Django, signals are simply delegated events. Is there anything that functionally differentiates them from the typical notion of events in C#, Java, ActionScript, etc?</p>
| 4 | 2009-03-09T02:42:37Z | 624,861 | <p>Afaik Qt had the first signal/slot implementation. <a href="http://doc.trolltech.com/4.4/signalsandslots.html" rel="nofollow">Qt's docs</a> explain the metaphor: "A signal is emitted when a particular event occurs". The distinction is so subtle that the nomenclature has been blurred.</p>
| 2 | 2009-03-09T02:51:10Z | [
"python",
"signals",
"django-signals"
] |
Why aren't signals simply called events? | 624,844 | <p>From what I can tell, in Python and and Django, signals are simply delegated events. Is there anything that functionally differentiates them from the typical notion of events in C#, Java, ActionScript, etc?</p>
| 4 | 2009-03-09T02:42:37Z | 624,865 | <p>Actually, "signals" have been around longer than events have. In the earliest usage, a signal was an asynchronous way for processes to get notified that events had occurred. Since Unix is much older than Django (and since a lot of the Django work came from pydispatcher, where the original stuff was done), the name h... | 24 | 2009-03-09T02:52:18Z | [
"python",
"signals",
"django-signals"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 624,930 | <p>The following should return a boolean:</p>
<pre><code>callable(x)
</code></pre>
| 24 | 2009-03-09T03:33:49Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 624,933 | <p>Try using <code>callable(x)</code>.</p>
| 6 | 2009-03-09T03:35:11Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 624,939 | <p>If this is for Python 2.x or for Python 3.2+, you can also use <code>callable()</code>. It used to be deprecated, but is now undeprecated, so you can use it again. You can read the discussion here: <a href="http://bugs.python.org/issue10518">http://bugs.python.org/issue10518</a>. You can do this with:</p>
<pre><cod... | 401 | 2009-03-09T03:39:02Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 624,948 | <p>Builtin types that don't have constructors in the built-in namespace (e.g. functions, generators, methods) are in the <code>types</code> module. You can use <code>types.FunctionType</code> in an isinstance call.</p>
<pre><code>In [1]: import types
In [2]: types.FunctionType
Out[2]: <type 'function'>
In [3]: d... | 198 | 2009-03-09T03:47:57Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 624,966 | <p><code>callable(x)</code> <em>will</em> return true if the object passed can be called in Python, but the function does not exist in Python 3.0, and properly speaking will not distinguish between:</p>
<pre><code>class A(object):
def __call__(self):
return 'Foo'
def B():
return 'Bar'
a = A()
b = B
... | 16 | 2009-03-09T03:58:55Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 624,994 | <p>A function is just a class with a <code>__call__</code> method, so you can do</p>
<pre><code>hasattr(obj, '__call__')
</code></pre>
<p>For example:</p>
<pre><code>>>> hasattr(x, '__call__')
True
>>> x = 2
>>> hasattr(x, '__call__')
False
</code></pre>
<p>That is the "best" way of doin... | 3 | 2009-03-09T04:19:43Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 4,234,284 | <p>Python's 2to3 tool (<a href="http://docs.python.org/dev/library/2to3.html">http://docs.python.org/dev/library/2to3.html</a>) suggests:</p>
<pre><code>import collections
isinstance(obj, collections.Callable)
</code></pre>
<p>It seems this was chosen instead of the <code>hasattr(x, '__call__')</code> method because ... | 20 | 2010-11-20T18:27:53Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 7,548,584 | <p>In Python3 I came up with <code>type (f) == type (lambda x:x)</code> which yields <code>True</code> if <code>f</code> is a function and <code>False</code> if it is not. But I think I prefer <code>isinstance (f, types.FunctionType)</code>, which feels less ad hoc. I wanted to do <code>type (f) is function</code>, but... | 1 | 2011-09-25T21:02:46Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 8,302,728 | <p><a href="http://docs.python.org/library/inspect.html#module-inspect">Since Python 2.1</a> you can import <code>isfunction</code> from the <a href="http://docs.python.org/library/inspect.html"><code>inspect</code></a> module.</p>
<pre><code>>>> from inspect import isfunction
>>> def f(): pass
>&... | 66 | 2011-11-28T21:40:27Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 13,605,330 | <p>If you want to detect everything that syntactically looks like a function: a function, method, built-in fun/meth, lambda ... but <strong>exclude</strong> callable objects (objects with <code>__call__</code> method defined), then try this one:</p>
<pre><code>import types
isinstance(x, (types.FunctionType, types.Buil... | 9 | 2012-11-28T12:42:38Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 17,008,232 | <p>Following previous replies, I came up with this:</p>
<pre><code>from pprint import pprint
def print_callables_of(obj):
li = []
for name in dir(obj):
attr = getattr(obj, name)
if hasattr(attr, '__call__'):
li.append(name)
pprint(li)
</code></pre>
| 0 | 2013-06-09T09:26:26Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 18,419,706 | <p>Whatever function is a class so you can take the name of the class of instance x and compare:</p>
<pre><code>
if(x.__class__.__name__ == 'function'):
print "it's a function"
</code></pre>
| 1 | 2013-08-24T14:38:39Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 18,703,281 | <p>Instead of checking for <code>'__call__'</code> (which is not exclusive to functions), you can check whether a user-defined function has attributes <code>func_name</code>, <code>func_doc</code>, etc. This does not work for methods. </p>
<pre><code>>>> def x(): pass
...
>>> hasattr(x, 'func_name')... | 1 | 2013-09-09T16:59:39Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 18,704,793 | <p>The accepted answer was at the time it was offered thought to be correct; As it
turns out, there is <em>no substitute</em> for <code>callable()</code>, which is back in python
3.2: Specifically, <code>callable()</code> checks the <code>tp_call</code> field of the object being
tested. There is no plain python equiv... | 30 | 2013-09-09T18:42:29Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 19,898,483 | <p>If the code will go on to perform the call if the value is callable, just perform the call and catch <code>TypeError</code>.</p>
<pre><code>def myfunc(x):
try:
x()
except TypeError:
raise Exception("Not callable")
</code></pre>
| 1 | 2013-11-11T03:45:17Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 20,291,931 | <p>The solutions using <code>hasattr(obj, '__call__')</code> and <code>callable(.)</code> mentioned in some of the answers have a main drawback: both also return <code>True</code> for classes and instances of classes with a <code>__call__()</code> method. Eg.</p>
<pre><code>>>> import collections
>>>... | 2 | 2013-11-29T19:00:03Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 21,311,982 | <p>Here's a couple of other ways:</p>
<pre><code>def isFunction1(f) :
return type(f) == type(lambda x: x);
def isFunction2(f) :
return 'function' in str(type(f));
</code></pre>
<p>Here's how I came up with the second:</p>
<pre><code>>>> type(lambda x: x);
<type 'function'>
>>> str(ty... | 3 | 2014-01-23T15:08:58Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 27,432,144 | <p>Since classes also have <code>__call__</code> method, I recommend another solution:</p>
<pre><code>class A(object):
def __init__(self):
pass
def __call__(self):
print 'I am a Class'
MyClass = A()
def foo():
pass
print hasattr(foo.__class__, 'func_name') # Returns True
print hasattr(A.... | 3 | 2014-12-11T20:51:58Z | [
"python"
] |
how to detect whether a python variable is a function? | 624,926 | <p>I have a variable, <code>x</code>, and I want to know whether it is pointing to a function or not.</p>
<p>I had hoped I could do something like:</p>
<pre><code>>>> isinstance(x, function)
</code></pre>
<p>But that gives me:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent cal... | 321 | 2009-03-09T03:31:30Z | 39,288,418 | <p>Note that Python classes are also callable.</p>
<p>To get functions (and by functions we mean standard functions and lambdas) use:</p>
<pre><code>import types
def is_func(obj):
return isinstance(obj, (types.FunctionType, types.LambdaType))
def f(x):
return x
assert is_func(f)
assert is_func(lambda x: ... | 0 | 2016-09-02T09:02:19Z | [
"python"
] |
What will be the upgrade path to Python 3.x for Google App Engine Applications? | 625,042 | <p>What is required to make the transition to Python 3.x for Google App Engine?</p>
<p>I know Google App Engine requires the use of at least Python 2.5.
Is it possible to use Python 3.0 already on Google App Engine?</p>
| 9 | 2009-03-09T04:43:51Z | 625,119 | <p>It is impossible to currently use Python 3.x applications on Google App Engine. It's simply not supported, and I'd expect to see support for Java (or Perl, or PHP) before Python 3.x.</p>
<p>That said, the upgrade path is likely to be very simple from Python 2.5 to Python 3.x on App Engine. If/when the capability ... | 5 | 2009-03-09T05:30:17Z | [
"python",
"google-app-engine"
] |
What will be the upgrade path to Python 3.x for Google App Engine Applications? | 625,042 | <p>What is required to make the transition to Python 3.x for Google App Engine?</p>
<p>I know Google App Engine requires the use of at least Python 2.5.
Is it possible to use Python 3.0 already on Google App Engine?</p>
| 9 | 2009-03-09T04:43:51Z | 625,130 | <p>At least at the being, Guido was working closely with the team at Google who is building AppEngine. When this option does become available, you will have to <strong>edit your main XAML file</strong>.</p>
<p>I agree with Chris B. that Python 3.0 support may not be forthcoming too soon, but I'm not sure I agree that ... | 1 | 2009-03-09T05:37:58Z | [
"python",
"google-app-engine"
] |
What will be the upgrade path to Python 3.x for Google App Engine Applications? | 625,042 | <p>What is required to make the transition to Python 3.x for Google App Engine?</p>
<p>I know Google App Engine requires the use of at least Python 2.5.
Is it possible to use Python 3.0 already on Google App Engine?</p>
| 9 | 2009-03-09T04:43:51Z | 625,632 | <p>The app.yaml syntax already supports multiple languages and multiple API versions, though only one of each (Python, API version 1) is currently supported. Presumably, one of those extension mechanisms will be used to specify that you want Python 3, and it'll be up to you to port your app over to work in Python 3, th... | 1 | 2009-03-09T10:04:23Z | [
"python",
"google-app-engine"
] |
What will be the upgrade path to Python 3.x for Google App Engine Applications? | 625,042 | <p>What is required to make the transition to Python 3.x for Google App Engine?</p>
<p>I know Google App Engine requires the use of at least Python 2.5.
Is it possible to use Python 3.0 already on Google App Engine?</p>
| 9 | 2009-03-09T04:43:51Z | 4,182,126 | <p>As it does not look like that google updates app engine to python 3 soon it might be worth to keep an eye on <a href="http://wiki.python.org/jython/RoadMap" rel="nofollow">Jython</a>. As of now they still work on 2.6, but that would already be better than 2.5.</p>
| 1 | 2010-11-15T07:03:40Z | [
"python",
"google-app-engine"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 625,095 | <p>You would be correct, they are object-oriented constructs. Basically <code>self</code> is a reference (kind of like a pointer, but <code>self</code> is a special reference which you can't assign to) to an object, and <code>__init__</code> is a function which is called to initialize the object - that is, set the valu... | 6 | 2009-03-09T05:17:16Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 625,096 | <p><code>__init__</code> does act like a constructor. You'll need to pass "self" to any class functions as the first argument if you want them to behave as non-static methods. "self" are instance variables for your class.</p>
| 14 | 2009-03-09T05:18:20Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 625,097 | <p>Yep, you are right, these are oop constructs.</p>
<p>init is the constructor for a class. The self parameter refers to the instance of the object (like <strong>this</strong> in C++).</p>
<pre><code>class Point:
def __init__(self, x, y):
self._x = x
self._y = y
</code></pre>
<p>The init method... | 92 | 2009-03-09T05:18:21Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 625,098 | <p>In this code:</p>
<pre><code>class A(object):
def __init__(self):
self.x = 'Hello'
def method_a(self, foo):
print self.x + ' ' + foo
</code></pre>
<p>... the <code>self</code> variable represents the instance of the object itself. Most object-oriented languages pass this as a hidden param... | 315 | 2009-03-09T05:18:46Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 625,133 | <p>In short:</p>
<ol>
<li><code>self</code> as it suggests, refers to <em>itself</em>- the object which has called the method. That is, if you have N objects calling the method, then <code>self.a</code> will refer to a separate instance of the variable for each of the N objects. Imagine N copies of the variable <code>... | 21 | 2009-03-09T05:41:21Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 625,174 | <p>The 'self' is a reference to the class instance</p>
<pre><code>class foo:
def bar(self):
print "hi"
</code></pre>
<p>Now we can create an instance of foo and call the method on it, the self parameter is added by Python in this case:</p>
<pre><code>f = foo()
f.bar()
</code></pre>
<p>But it can be ... | 9 | 2009-03-09T06:09:20Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 626,081 | <p>note that <code>self</code> could actually be any valid python identifier. For example, we could just as easily write, from Chris B's example:</p>
<pre><code>class A(object):
def __init__(foo):
foo.x = 'Hello'
def method_a(bar, foo):
print bar.x + ' ' + foo
</code></pre>
<p>and it would w... | 11 | 2009-03-09T12:50:30Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 12,552,203 | <p>Basically, you need to use the 'self' keyword when using a variable in multiple functions within the same class. As for <strong>init</strong>, it's used to setup default values incase no other functions from within that class are called.</p>
| 12 | 2012-09-23T12:02:55Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 16,474,519 | <p>Try out this code. Hope it helps many C programmers like me to Learn Py.</p>
<pre><code>#! /usr/bin/python2
class Person:
'''Doc - Inside Class '''
def __init__(self, name):
'''Doc - __init__ Constructor'''
self.n_name = name
def show(self, n1, n2):
'''Doc - Inside Sh... | 13 | 2013-05-10T03:03:13Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 17,260,649 | <h1>A brief illustrative example</h1>
<p>In the hope it might help a little, here's a simple example I used to understand the difference between a variable declared inside a class, and a variable declared inside an <code>__init__</code> function:</p>
<pre><code>class MyClass(object):
i = 123
def __init__(se... | 74 | 2013-06-23T12:15:34Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 21,032,703 | <p>Had trouble undestanding this myself. Even after reading the answers here. </p>
<p>To properly understand the <code>__init__</code> method you need to understand self. </p>
<p><strong>The self Parameter</strong></p>
<p>The arguments accepted by the <code>__init__</code> method are :</p>
<pre><code>def __init__(s... | 11 | 2014-01-09T22:39:09Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 28,946,924 | <p>Section 9.3 in <a href="https://docs.python.org/2/tutorial/classes.html" rel="nofollow">this Python tutorial</a> gives a short introduction to the basic elements of a Python class: class variables, class methods and the roles of<code>__init__</code> and <code>__self__</code>.</p>
| 3 | 2015-03-09T16:23:06Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 31,988,134 | <p>Here, the guy has written pretty well and simple: <a href="https://www.jeffknupp.com/blog/2014/06/18/improve-your-python-python-classes-and-object-oriented-programming/" rel="nofollow">https://www.jeffknupp.com/blog/2014/06/18/improve-your-python-python-classes-and-object-oriented-programming/</a></p>
<p>Read above... | 3 | 2015-08-13T12:22:15Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 32,214,839 | <p>In this code:</p>
<p><code>class Cat:
def __init__(self, name):
self.name = name
def info(self):
print 'I am a cat and I am called', self.name</code></p>
<p>Here <code>__init__</code> acts as a constructor for the class and when an object is instantiated, this function is called. <code>self... | 4 | 2015-08-25T22:02:29Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 32,386,319 | <ol>
<li><strong><code>__init__</code></strong> is basically a function which will <strong>"initialize"</strong>/<strong>"activate"</strong> the properties of the class for a specific object, once created and matched to the corresponding class..</li>
<li><strong><code>self</code></strong> represents that object which ... | 7 | 2015-09-03T22:19:24Z | [
"python",
"oop"
] |
Python __init__ and self what do they do? | 625,083 | <p>I'm learning the Python programming language, and I've come across certain things I don't fully understand. I'm coming from a C background, but I never went far with that either.</p>
<p>What I'm trying to figure out is:</p>
<p>In a method:</p>
<pre><code>def method(self, blah):
def __init__(?):
....
... | 344 | 2009-03-09T05:09:51Z | 38,156,406 | <pre><code># Source: Class and Instance Variables
# https://docs.python.org/2/tutorial/classes.html#class-and-instance-variables
class MyClass(object):
# class variable
my_CLS_var = 10
# sets "init'ial" state to objects/instances, use self argument
def __init__(self):
# self usage => instan... | 1 | 2016-07-02T04:15:17Z | [
"python",
"oop"
] |
Select mails from inbox alone via poplib | 625,148 | <p>I need to download emails from the gmail inbox only using poplib.Unfortunately I do not see any option to select Inbox alone, and poplib gives me emails from sent items too.</p>
<p>How do I select emails only from inbox?</p>
<p>I dont want to use any gmail specific libraries.</p>
| 1 | 2009-03-09T05:49:32Z | 625,175 | <p>POP3 has no concept of 'folders'. If gmail is showing you both 'sent' as well as 'received' mail, then you really don't have any option but to receive all that email.</p>
<p>Perhaps you would be better off using IMAP4 instead of POP3. Python has libraries that will work with gmail's IMAP4 server.</p>
| 3 | 2009-03-09T06:09:32Z | [
"python",
"gmail",
"pop3",
"poplib"
] |
Select mails from inbox alone via poplib | 625,148 | <p>I need to download emails from the gmail inbox only using poplib.Unfortunately I do not see any option to select Inbox alone, and poplib gives me emails from sent items too.</p>
<p>How do I select emails only from inbox?</p>
<p>I dont want to use any gmail specific libraries.</p>
| 1 | 2009-03-09T05:49:32Z | 625,191 | <p>This Java code would suggest that you can select a particular "folder" to download, even when using POP3. Again, this is using Java, not Python so YMMV.</p>
<p><a href="http://blog.prolificprogrammer.com/2008/04/04/how-to-search-gmail-from-the-comfort-of-your-command-line" rel="nofollow">How to download message fro... | 1 | 2009-03-09T06:18:44Z | [
"python",
"gmail",
"pop3",
"poplib"
] |
Select mails from inbox alone via poplib | 625,148 | <p>I need to download emails from the gmail inbox only using poplib.Unfortunately I do not see any option to select Inbox alone, and poplib gives me emails from sent items too.</p>
<p>How do I select emails only from inbox?</p>
<p>I dont want to use any gmail specific libraries.</p>
| 1 | 2009-03-09T05:49:32Z | 627,402 | <p>I assume you have enabled POP3/IMAP access to your GMail account.</p>
<p>This is sample code:</p>
<pre><code>import imaplib
conn= imaplib.IMAP4_SSL('imap.googlemail.com')
conn.login('yourusername', 'yourpassword')
code, dummy= conn.select('INBOX')
if code != 'OK':
raise RuntimeError, "Failed to select inbox"
... | 2 | 2009-03-09T18:09:55Z | [
"python",
"gmail",
"pop3",
"poplib"
] |
Best practice for integrating CherryPy web-framework, SQLAlchemy sessions and lighttpd to serve a high-load webservice | 625,288 | <p>I'm developing a CherryPy FastCGI server behind lighttpd with the following setup to enable using ORM SQLAlchemy sessions inside CherryPy controllers. However, when I run stress tests with 14 concurrent requests for about 500 loops, it starts to give errors like <code>AttributeError: '_ThreadData' object has no attr... | 6 | 2009-03-09T07:28:24Z | 627,335 | <p>If you look at <code>plugins.ThreadManager.acquire_thread</code>, you'll see the line <code>self.bus.publish('start_thread', i)</code>, where <code>i</code> is the array index of the seen thread. Any listener subscribed to the <code>start_thread</code> channel needs to accept that <code>i</code> value as a positiona... | 1 | 2009-03-09T17:55:32Z | [
"python",
"sqlalchemy",
"lighttpd",
"cherrypy"
] |
Best practice for integrating CherryPy web-framework, SQLAlchemy sessions and lighttpd to serve a high-load webservice | 625,288 | <p>I'm developing a CherryPy FastCGI server behind lighttpd with the following setup to enable using ORM SQLAlchemy sessions inside CherryPy controllers. However, when I run stress tests with 14 concurrent requests for about 500 loops, it starts to give errors like <code>AttributeError: '_ThreadData' object has no attr... | 6 | 2009-03-09T07:28:24Z | 628,823 | <blockquote>
<p>I also tried assigning the return value of scoped_session to GlobalSession (like it does here), but then it gave out errors like UnboundExceptionError and other SA-level errors. (Concurrency: 10, loops: 1000, error rate: 16%)</p>
</blockquote>
<p>This error did not occur if I didn't instantiate the s... | 0 | 2009-03-10T03:13:21Z | [
"python",
"sqlalchemy",
"lighttpd",
"cherrypy"
] |
Dump memcache keys from GAE SDK Console? | 625,314 | <p>In the "Memcache Viewer", is there any way to dump a list of existing keys? Just for debugging, of course, not for use in any scripts!</p>
<p>I ask because it doesn't seem like the GAE SDK is using a "real" memcache server, so I'm guessing it's emulated in Python (for simplicity, as it's just a development server).... | 1 | 2009-03-09T07:49:02Z | 625,331 | <p>No. I did not found such functionality in memcached too.</p>
<p>Thinking about this issue, I found this limitation understandable - it would require keeping a registry of keys with all related problems like key expiration, invalidation and of course locking. Such system would not be as fast as memcaches are intende... | 4 | 2009-03-09T08:02:17Z | [
"python",
"google-app-engine",
"memcached"
] |
Dump memcache keys from GAE SDK Console? | 625,314 | <p>In the "Memcache Viewer", is there any way to dump a list of existing keys? Just for debugging, of course, not for use in any scripts!</p>
<p>I ask because it doesn't seem like the GAE SDK is using a "real" memcache server, so I'm guessing it's emulated in Python (for simplicity, as it's just a development server).... | 1 | 2009-03-09T07:49:02Z | 626,458 | <p>Memcache is designed to be quick and there's no convincing use case for this functionality
which would justify the overhead required for a command that is so at odds with the rest of memcached.</p>
<p>The GAE SDK is simulating memcached, so it doesn't offer this functionality either.</p>
| 0 | 2009-03-09T14:29:07Z | [
"python",
"google-app-engine",
"memcached"
] |
Dump memcache keys from GAE SDK Console? | 625,314 | <p>In the "Memcache Viewer", is there any way to dump a list of existing keys? Just for debugging, of course, not for use in any scripts!</p>
<p>I ask because it doesn't seem like the GAE SDK is using a "real" memcache server, so I'm guessing it's emulated in Python (for simplicity, as it's just a development server).... | 1 | 2009-03-09T07:49:02Z | 626,559 | <p>People ask for this on the memcached list a lot, sometimes with the same type of "just in case I want to look around to debug something" sentiment.</p>
<p>The best way to handle this is to know how you generate your keys, and just go look stuff up when you want to know what's stored for a given value.</p>
<p>If yo... | 8 | 2009-03-09T14:56:16Z | [
"python",
"google-app-engine",
"memcached"
] |
Dump memcache keys from GAE SDK Console? | 625,314 | <p>In the "Memcache Viewer", is there any way to dump a list of existing keys? Just for debugging, of course, not for use in any scripts!</p>
<p>I ask because it doesn't seem like the GAE SDK is using a "real" memcache server, so I'm guessing it's emulated in Python (for simplicity, as it's just a development server).... | 1 | 2009-03-09T07:49:02Z | 660,458 | <p>The easiest way that I could think of, would be to maintain a memcache key at a known ID, and then append to it every time you insert a new key. This way you could just query for the single key to get a list of existing keys.</p>
| 0 | 2009-03-18T23:12:49Z | [
"python",
"google-app-engine",
"memcached"
] |
Dump memcache keys from GAE SDK Console? | 625,314 | <p>In the "Memcache Viewer", is there any way to dump a list of existing keys? Just for debugging, of course, not for use in any scripts!</p>
<p>I ask because it doesn't seem like the GAE SDK is using a "real" memcache server, so I'm guessing it's emulated in Python (for simplicity, as it's just a development server).... | 1 | 2009-03-09T07:49:02Z | 5,171,815 | <p>Here is a possible work around. I am unfamiliar with Google App Engine but on a regular memcache server you can list out all the keys through telnet like so:</p>
<pre><code>telnet 127.0.0.1 11211
stats items
STAT items:7:number 5
STAT items:7:age 88779
STAT items:7:evicted 0
STAT items:7:evicted_time 0
STAT items:... | 0 | 2011-03-02T18:36:18Z | [
"python",
"google-app-engine",
"memcached"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.