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 |
|---|---|---|---|---|---|---|---|---|---|
Creating a mock web service from a WSDL file in Python | 2,131,207 | <p>We are writing a client for a remote service that exposes SOAP web services and publishes a WSDL definition for those services. </p>
<p>We don't have access to the system during testing, so we'd like to write a mock service. We're using Python for the client, so ideally we'd want to use Python for the mock server, ... | 10 | 2010-01-25T09:14:32Z | 28,284,506 | <p>You could use this code for creating a suds mock client.</p>
<pre><code>from suds.client import Client
class AlwaysCallable(object):
"""
Represents a chainable-access object and proxies calls to ClientMock.
"""
name = None
def __init__(self, client_cls):
self._client_cls = client_cls
... | 1 | 2015-02-02T18:41:16Z | [
"python",
"soap",
"wsdl",
"mocking"
] |
How can I normalize/collapse paths or URLs in Python in OS independent way? | 2,131,290 | <p>I tried to use <code>os.normpath</code> in order to convert <code>http://example.com/a/b/c/../</code> to <code>http://example.com/a/b/</code> but it doesn't work on Windows because it does convert the slash to backslash.</p>
| 5 | 2010-01-25T09:30:58Z | 2,131,301 | <p>Here is how to do it</p>
<pre><code>>>> import urlparse
>>> urlparse.urljoin("ftp://domain.com/a/b/c/d/", "../..")
'ftp://domain.com/a/b/'
>>> urlparse.urljoin("ftp://domain.com/a/b/c/d/e.txt", "../..")
'ftp://domain.com/a/b/'
</code></pre>
<p>Remember that <code>urljoin</code> consi... | 8 | 2010-01-25T09:33:59Z | [
"python",
"url",
"path",
"normalize"
] |
How can I normalize/collapse paths or URLs in Python in OS independent way? | 2,131,290 | <p>I tried to use <code>os.normpath</code> in order to convert <code>http://example.com/a/b/c/../</code> to <code>http://example.com/a/b/</code> but it doesn't work on Windows because it does convert the slash to backslash.</p>
| 5 | 2010-01-25T09:30:58Z | 2,131,306 | <p>Python's URL handling is in <a href="https://docs.python.org/3/library/urllib.parse.html" rel="nofollow"><code>urlparse</code></a>.</p>
| 2 | 2010-01-25T09:35:34Z | [
"python",
"url",
"path",
"normalize"
] |
How can I normalize/collapse paths or URLs in Python in OS independent way? | 2,131,290 | <p>I tried to use <code>os.normpath</code> in order to convert <code>http://example.com/a/b/c/../</code> to <code>http://example.com/a/b/</code> but it doesn't work on Windows because it does convert the slash to backslash.</p>
| 5 | 2010-01-25T09:30:58Z | 2,131,316 | <p>adopted from os module " - os.path is one of the modules posixpath, or ntpath", in your case explicitly using posixpath.</p>
<pre><code> >>> import posixpath
>>> posixpath.normpath("/a/b/../c")
'/a/c'
>>>
</code></pre>
| 3 | 2010-01-25T09:37:47Z | [
"python",
"url",
"path",
"normalize"
] |
Using Python like PHP in Apache/Windows | 2,131,417 | <p>I understand that I <em>should</em> use mod_wsgi to run Python, and I have been trying to get that set up, but I'm confused about it:</p>
<p>This is a sample configuration I found for web.py:</p>
<pre><code>LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /appname /var/www/webpy-app/code.py/
Alias /app... | 4 | 2010-01-25T09:57:36Z | 2,131,487 | <p>I think you can use mod_cgi with apache and put in the URL of an accessible python file, with the first line of the script</p>
<pre><code>#!/usr/bin/python
</code></pre>
<p>however this is a VERY inefficient way of accessing the python code because apache has to reload python every time the page is accessed. Ok fo... | 3 | 2010-01-25T10:08:30Z | [
"python",
"apache",
"configuration"
] |
Using Python like PHP in Apache/Windows | 2,131,417 | <p>I understand that I <em>should</em> use mod_wsgi to run Python, and I have been trying to get that set up, but I'm confused about it:</p>
<p>This is a sample configuration I found for web.py:</p>
<pre><code>LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /appname /var/www/webpy-app/code.py/
Alias /app... | 4 | 2010-01-25T09:57:36Z | 2,131,641 | <p>I don't think WSGI/mod_wsgi is compatible with what you want to do-- a WSGI application generally takes over URL parsing, which makes it incompatible with your "works like PHP" requirement.</p>
<p>If you don't want to use CGI, I think mod_python's Publisher is closer to what you want:
<a href="http://modpython.org/... | 2 | 2010-01-25T10:37:05Z | [
"python",
"apache",
"configuration"
] |
Using Python like PHP in Apache/Windows | 2,131,417 | <p>I understand that I <em>should</em> use mod_wsgi to run Python, and I have been trying to get that set up, but I'm confused about it:</p>
<p>This is a sample configuration I found for web.py:</p>
<pre><code>LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /appname /var/www/webpy-app/code.py/
Alias /app... | 4 | 2010-01-25T09:57:36Z | 2,131,663 | <p>Wandering a bit afield from your original question, but trying to answer some of what's come up in reply to sparklewhiskers:</p>
<p>For an example of how WSGI works in a shared hosting environment, see these pages on Passenger's WSGI support at <a href="http://wiki.asmallorange.com/HOWTOPythonWSGI" rel="nofollow">A... | 1 | 2010-01-25T10:42:06Z | [
"python",
"apache",
"configuration"
] |
Using Python like PHP in Apache/Windows | 2,131,417 | <p>I understand that I <em>should</em> use mod_wsgi to run Python, and I have been trying to get that set up, but I'm confused about it:</p>
<p>This is a sample configuration I found for web.py:</p>
<pre><code>LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /appname /var/www/webpy-app/code.py/
Alias /app... | 4 | 2010-01-25T09:57:36Z | 2,132,025 | <p>Contrary to what others say, you can get mostly where you want. StackOverflow is however not a very good place to get an explanation of what to do. Instead, you would in this case be better off going over to the official mod_wsgi mailing list on Google Groups at:</p>
<p><a href="http://groups.google.com/group/modws... | 2 | 2010-01-25T11:58:42Z | [
"python",
"apache",
"configuration"
] |
Using Python like PHP in Apache/Windows | 2,131,417 | <p>I understand that I <em>should</em> use mod_wsgi to run Python, and I have been trying to get that set up, but I'm confused about it:</p>
<p>This is a sample configuration I found for web.py:</p>
<pre><code>LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /appname /var/www/webpy-app/code.py/
Alias /app... | 4 | 2010-01-25T09:57:36Z | 2,132,383 | <p>Most similar to the PHP model is perhaps <a href="http://en.wikipedia.org/wiki/Python_Server_Pages" rel="nofollow">Python Server Pages</a>, PSP.</p>
<p><code>mod_python</code> has a <a href="http://modpython.org/live/mod_python-3.3.1/doc-html/hand-psp.html" rel="nofollow">PSP handler</a>. The files you create look ... | 6 | 2010-01-25T13:00:54Z | [
"python",
"apache",
"configuration"
] |
Alternative ways to browse the python api | 2,131,419 | <p>Is it just me, or the python standard library documentation is extremely difficult to browse through?</p>
<ul>
<li><a href="http://docs.python.org/3.1/library/index.html">http://docs.python.org/3.1/library/index.html</a></li>
<li><a href="http://docs.python.org/3.1/modindex.html">http://docs.python.org/3.1/modindex... | 14 | 2010-01-25T09:57:48Z | 2,131,443 | <p>you can go to <a href="http://downloads.activestate.com/ActivePython/etc/" rel="nofollow">here</a> and download the chm version of Python 3.1. With that, searching through the docs should be easy.</p>
| 2 | 2010-01-25T10:02:04Z | [
"python",
"documentation",
"standard-library"
] |
Alternative ways to browse the python api | 2,131,419 | <p>Is it just me, or the python standard library documentation is extremely difficult to browse through?</p>
<ul>
<li><a href="http://docs.python.org/3.1/library/index.html">http://docs.python.org/3.1/library/index.html</a></li>
<li><a href="http://docs.python.org/3.1/modindex.html">http://docs.python.org/3.1/modindex... | 14 | 2010-01-25T09:57:48Z | 2,131,611 | <p>I usually use the built-in <a href="http://docs.python.org/library/pydoc.html">pydoc</a>, if you are on windows it should be called Module Docs if you are on linux use <code>pydoc -p 8000</code> and connect through browser.</p>
| 7 | 2010-01-25T10:30:29Z | [
"python",
"documentation",
"standard-library"
] |
Alternative ways to browse the python api | 2,131,419 | <p>Is it just me, or the python standard library documentation is extremely difficult to browse through?</p>
<ul>
<li><a href="http://docs.python.org/3.1/library/index.html">http://docs.python.org/3.1/library/index.html</a></li>
<li><a href="http://docs.python.org/3.1/modindex.html">http://docs.python.org/3.1/modindex... | 14 | 2010-01-25T09:57:48Z | 2,131,622 | <p><code>pydoc</code> from the command line, <code>help()</code> from the interactive interpreter prompt.</p>
| 3 | 2010-01-25T10:32:36Z | [
"python",
"documentation",
"standard-library"
] |
Alternative ways to browse the python api | 2,131,419 | <p>Is it just me, or the python standard library documentation is extremely difficult to browse through?</p>
<ul>
<li><a href="http://docs.python.org/3.1/library/index.html">http://docs.python.org/3.1/library/index.html</a></li>
<li><a href="http://docs.python.org/3.1/modindex.html">http://docs.python.org/3.1/modindex... | 14 | 2010-01-25T09:57:48Z | 2,131,667 | <p><code>pydoc -p 8080</code></p>
<p>The python community is semi-hostile to automatically generated documentation, especially if it's Object-Orientated. Python isn't just object-orientated (it's a multi-paradigm language), so Python developers generally prefer human-written documentation. Sometimes the functions are ... | 3 | 2010-01-25T10:42:35Z | [
"python",
"documentation",
"standard-library"
] |
Alternative ways to browse the python api | 2,131,419 | <p>Is it just me, or the python standard library documentation is extremely difficult to browse through?</p>
<ul>
<li><a href="http://docs.python.org/3.1/library/index.html">http://docs.python.org/3.1/library/index.html</a></li>
<li><a href="http://docs.python.org/3.1/modindex.html">http://docs.python.org/3.1/modindex... | 14 | 2010-01-25T09:57:48Z | 2,131,685 | <p>I used to use the <a href="http://www.edgewall.org/python-sidebar/" rel="nofollow">python sidebar</a> from Edgewall a long time ago. </p>
<p>These days, I google for the python function (the standard docs almost always show up as the first link).If I want to browse the source of the module (useful sometimes), I use... | 0 | 2010-01-25T10:45:31Z | [
"python",
"documentation",
"standard-library"
] |
Alternative ways to browse the python api | 2,131,419 | <p>Is it just me, or the python standard library documentation is extremely difficult to browse through?</p>
<ul>
<li><a href="http://docs.python.org/3.1/library/index.html">http://docs.python.org/3.1/library/index.html</a></li>
<li><a href="http://docs.python.org/3.1/modindex.html">http://docs.python.org/3.1/modindex... | 14 | 2010-01-25T09:57:48Z | 2,167,371 | <p>I guess I'm going to get downvoted but I find nothing wrong with the Sphinx docs and I find them way way better than the java alternative.</p>
| 0 | 2010-01-30T09:14:42Z | [
"python",
"documentation",
"standard-library"
] |
Django-registration, force unique e-mail | 2,131,533 | <p>Can I force users to make unique e-mail addresses in django-registration?</p>
| 12 | 2010-01-25T10:16:23Z | 2,131,615 | <p>It should suffice to create your registration form from your user model. If the e-mail address is defined to be unique there, the form will output an error on submit for duplicate addresses.</p>
<p>Look <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#creating-forms-from-models" rel="nofollow"... | 2 | 2010-01-25T10:31:41Z | [
"python",
"django"
] |
Django-registration, force unique e-mail | 2,131,533 | <p>Can I force users to make unique e-mail addresses in django-registration?</p>
| 12 | 2010-01-25T10:16:23Z | 2,131,887 | <p><a href="http://bitbucket.org/ubernostrum/django-registration/" rel="nofollow">django-registration</a> has several forms included in the source â one is a <a href="http://bitbucket.org/ubernostrum/django-registration/src/tip/registration/forms.py#cl-82" rel="nofollow"><code>RegistrationFormUniqueEmail</code></a>, ... | 5 | 2010-01-25T11:28:31Z | [
"python",
"django"
] |
Django-registration, force unique e-mail | 2,131,533 | <p>Can I force users to make unique e-mail addresses in django-registration?</p>
| 12 | 2010-01-25T10:16:23Z | 3,481,932 | <pre><code>forms.py
from registration.forms import RegistrationFormUniqueEmail
class RegistroPerfilForm(RegistrationFormUniqueEmail):
first_name= forms.CharField(required=True)
last_name= forms.CharField(required=True)
kind__of_user= forms.CharField(widget=forms.RadioSelect(choices=TIPO))
</code></pre>
| 1 | 2010-08-14T03:50:43Z | [
"python",
"django"
] |
Django-registration, force unique e-mail | 2,131,533 | <p>Can I force users to make unique e-mail addresses in django-registration?</p>
| 12 | 2010-01-25T10:16:23Z | 7,004,207 | <p>As miku pointed out, you should simply use RegistrationFormUniqueEmail .</p>
<p>If you implement according to the documentation and bug report replies (as of mid-2011),
you'll probably end up with an exception like:</p>
<pre><code>TypeError at /accounts/register/
register() takes at least 2 non-keyword arguments (... | 3 | 2011-08-09T23:19:14Z | [
"python",
"django"
] |
Django-registration, force unique e-mail | 2,131,533 | <p>Can I force users to make unique e-mail addresses in django-registration?</p>
| 12 | 2010-01-25T10:16:23Z | 7,377,850 | <p>from rych's answer, I tested that the following runs ok - it only uses urls.py, you needn't write another cusotmer form.</p>
<pre><code>from registration.forms import RegistrationFormUniqueEmail
url(r'^accounts/register/$', 'registration.views.register',
{'form_class': RegistrationFormUniqueEmail,
'backen... | 13 | 2011-09-11T11:16:01Z | [
"python",
"django"
] |
Django-registration, force unique e-mail | 2,131,533 | <p>Can I force users to make unique e-mail addresses in django-registration?</p>
| 12 | 2010-01-25T10:16:23Z | 19,383,392 | <p>For later versions of django_registration (that use class-based views), you can do this:</p>
<pre><code>from registration.forms import RegistrationFormUniqueEmail
from registration.backends.default.views import RegistrationView
urlpatterns = patterns('',
url(r'^register/$',
RegistrationView.as_view(for... | 13 | 2013-10-15T14:10:05Z | [
"python",
"django"
] |
Django-registration, force unique e-mail | 2,131,533 | <p>Can I force users to make unique e-mail addresses in django-registration?</p>
| 12 | 2010-01-25T10:16:23Z | 37,694,543 | <p>For unique e-mail addresses in django-registration-redux 1.4.</p>
<p>In url.py add following</p>
<pre>from registration.forms import RegistrationFormUniqueEmail
from registration.backends.default.views import RegistrationView
urlpatterns = [
url(r'^accounts/register/$',RegistrationView.as_view(form_class=Regist... | 0 | 2016-06-08T06:11:48Z | [
"python",
"django"
] |
Django and SSL question | 2,131,727 | <p>I am planning to sell products by charging credit cards thus using SSL will be critical for Django-powered website. And I am very naive for this.</p>
<p>My initial django setup plan was using Apache as the webserver and using mod_wsgi to communicate with Django, static media again served by Apache. All seemed good ... | 22 | 2010-01-25T10:56:07Z | 2,131,974 | <p>Django doesn't handle the SSL stuff. Apache will take care of that for you transparently and Django will work as usual. You can check for SSL in a view with <code>request.is_secure()</code>.</p>
<p>However you must serve links where appropriate as https urls. You also may want to redirect certain http pages to http... | 6 | 2010-01-25T11:47:43Z | [
"python",
"django",
"ssl"
] |
Django and SSL question | 2,131,727 | <p>I am planning to sell products by charging credit cards thus using SSL will be critical for Django-powered website. And I am very naive for this.</p>
<p>My initial django setup plan was using Apache as the webserver and using mod_wsgi to communicate with Django, static media again served by Apache. All seemed good ... | 22 | 2010-01-25T10:56:07Z | 2,132,293 | <p>I have deployed Django apps on SSL using Apache's <code>mod_ssl</code> and <code>mod_wsgi</code>.</p>
<p>I am no Apache expert, but here's how I setup SSL for one site (put the directives below in the <code>httpd.conf</code> file, or in a file referenced from that file, for instance in the <code>sites-enabled</code... | 27 | 2010-01-25T12:50:15Z | [
"python",
"django",
"ssl"
] |
Django and SSL question | 2,131,727 | <p>I am planning to sell products by charging credit cards thus using SSL will be critical for Django-powered website. And I am very naive for this.</p>
<p>My initial django setup plan was using Apache as the webserver and using mod_wsgi to communicate with Django, static media again served by Apache. All seemed good ... | 22 | 2010-01-25T10:56:07Z | 8,064,356 | <p>For those coming through Google, heres an example config for Nginx:</p>
<pre><code>server {
listen 443 ssl default;
server_name example.com;
ssl on;
ssl_certificate /etc/nginx/server.crt;
ssl_certificate_key /etc/nginx/server.key;
add_header Cache-Control "public, must-revalidate";
# ad... | 14 | 2011-11-09T11:28:42Z | [
"python",
"django",
"ssl"
] |
posix_memalign within python | 2,131,946 | <p>I cannot seem to figure it out why the following does not work</p>
<pre><code>import ctypes
from ctypes.util import find_library
libc = ctypes.CDLL(find_library('c'))
userpointer = ctypes.c_void_p
sizeimage = 320*240*2
if libc.posix_memalign(userpointer, libc.getpagesize(), sizeimage) != 0:
raise Exception('E... | 0 | 2010-01-25T11:40:32Z | 2,131,993 | <p>You have two problems in your code: you make userpointer the ctypes.c_void_p <em>type</em> rather than an instance of it, and you're passing the void* that is userpointer to posix_memalign directly, instead of the void** that posix_memalign requires. The following will do what you want:</p>
<pre><code>import ctypes... | 1 | 2010-01-25T11:51:28Z | [
"python",
"ctypes"
] |
saving python variable to .mat file with scipy.io.savemat | 2,132,106 | <p>Here is my python code. </p>
<pre><code>>>import numpy as np
>>import scipy.io
>>exon = [ np.array([[1, 2], [3, 4], [5, 6]]), np.array([[7, 8], [9, 10]]) ]
>>obj_arr = np.zeros((2,), dtype=np.object)
>>obj_arr[0] = exon[0]
>>obj_arr[1] = exon[1]
>>scipy.io.savemat('/tmp/out... | 0 | 2010-01-25T12:13:47Z | 2,132,159 | <p>Looks like your scipy.io.savemat() doesn't take a 'format' keyword. Looks like it was added in SciPy 0.7, perhaps you need to upgrade?</p>
| 3 | 2010-01-25T12:24:29Z | [
"python",
"scipy",
"typeerror",
"mat-file"
] |
Function called three times when in facebook? | 2,132,215 | <p>I'm using the following code to add one to two values in case the user wins a challege.</p>
<pre><code>def challengewin(request):
uid = 1313693
tempuser = User.objects.get(id=uid)
tempuser.challengeswon = tempuser.challengeswon + 1
tempuser.silver = tempuser.silver + 1
tempuser.save()
return... | 1 | 2010-01-25T12:35:20Z | 2,132,351 | <p>I would guess that the code you have included is not the culprit.</p>
<p>Have you confirmed that <code>challengewin(request);</code> is not being called 3 times?</p>
| 0 | 2010-01-25T12:57:09Z | [
"python",
"facebook"
] |
Parse .strings file with Python | 2,132,291 | <p>I'm trying to write a small Python script to parse the .strings file in my iPhone application project and determine which keys might not be in use. I'm, also doing some string matching to filter out some of the results. This is where my problems start :). If I try something like</p>
<pre><code>for file_line in stri... | 1 | 2010-01-25T12:49:55Z | 2,132,359 | <p>No experience with those <code>.strings</code> files, but here is the reason why you don't find matches:</p>
<pre><code>strings_file.read()
</code></pre>
<p>returns a <em>string</em> with the full content of the file. Iterating over a string iterates over <em>single characters</em>, i.e. in your <code>for</code> l... | 2 | 2010-01-25T12:57:58Z | [
"iphone",
"python",
"objective-c",
"core-foundation"
] |
Parse .strings file with Python | 2,132,291 | <p>I'm trying to write a small Python script to parse the .strings file in my iPhone application project and determine which keys might not be in use. I'm, also doing some string matching to filter out some of the results. This is where my problems start :). If I try something like</p>
<pre><code>for file_line in stri... | 1 | 2010-01-25T12:49:55Z | 2,132,538 | <p>Use correct encoding to open the <code>.strings</code>-file and in your <a href="http://www.python.org/dev/peps/pep-0263/" rel="nofollow">source code</a>. According to <a href="http://developer.apple.com/iPhone/library/documentation/MacOSX/Conceptual/BPInternational/Articles/StringsFiles.html" rel="nofollow">documen... | 2 | 2010-01-25T13:27:13Z | [
"iphone",
"python",
"objective-c",
"core-foundation"
] |
Parse .strings file with Python | 2,132,291 | <p>I'm trying to write a small Python script to parse the .strings file in my iPhone application project and determine which keys might not be in use. I'm, also doing some string matching to filter out some of the results. This is where my problems start :). If I try something like</p>
<pre><code>for file_line in stri... | 1 | 2010-01-25T12:49:55Z | 2,132,572 | <p>It sounds like the stings file was saved as data. If python can't read it as is you can convert it to a plain text file in Objective-c. </p>
<p>Just: (1) read the strings file into a file with the proper encoding. (2) Convert to dictionary (3) write dictionary to another file.</p>
<p>So:</p>
<pre><code>NSString *... | 0 | 2010-01-25T13:33:59Z | [
"iphone",
"python",
"objective-c",
"core-foundation"
] |
How to get version of python dependencies/modules, including external applications called via subprocess.Popen? | 2,132,440 | <p>I have a set of python scripts that I run frequently on different machines that depend on a few external libraries as well as some other applications spawned via <code>subprocess.Popen</code>.</p>
<p>As expected depending on the version of the installed modules and applications the output varies. To address this I ... | 2 | 2010-01-25T13:10:18Z | 2,132,720 | <p>Instead of directly investigating your dependencies in python, and if you are running in Linux/Unix, you can wrapper your program with <CODE><a href="http://benno.id.au/blog/2008/06/06/memoize-build-framework" rel="nofollow">memoize.py</a></CODE>. <code>memoize.py</code> uses <CODE><a href="http://en.wikipedia.org/... | 0 | 2010-01-25T14:00:17Z | [
"python",
"linux",
"version-control",
"dependencies"
] |
How to get version of python dependencies/modules, including external applications called via subprocess.Popen? | 2,132,440 | <p>I have a set of python scripts that I run frequently on different machines that depend on a few external libraries as well as some other applications spawned via <code>subprocess.Popen</code>.</p>
<p>As expected depending on the version of the installed modules and applications the output varies. To address this I ... | 2 | 2010-01-25T13:10:18Z | 9,526,285 | <p>Two years passed and some new tools came into play.</p>
<p>To take care of point 1 and 2 there is now <code>pip freeze</code> specially when coupled with <code>virtualenv</code>.</p>
<p>For external applications I had to resource to the package manager (apt-file, dpkg, qlist, emerge,... depending on the system) on... | 1 | 2012-03-02T00:18:46Z | [
"python",
"linux",
"version-control",
"dependencies"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 2,132,727 | <p>There is nothing "dirty" about using try-except clause. This is the pythonic way. <code>ValueError</code> will be raised by the <code>.index</code> method only, because it's the only code you have there!</p>
<p>To answer the comment:<br>
In Python, <a href="http://docs.python.org/3.1/glossary.html#term-eafp"><em>ea... | 32 | 2010-01-25T14:02:07Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 2,132,769 | <p>The <a href="http://docs.python.org/library/stdtypes.html#dict" rel="nofollow"><CODE>dict</CODE> type</a> has a <a href="http://docs.python.org/library/stdtypes.html#dict.get" rel="nofollow"><CODE>get</CODE> function</a>, where if the key doesn't exist in the dictionary, the 2nd argument to <code>get</code> is the v... | 9 | 2010-01-25T14:08:51Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 2,132,917 | <p>I don't know why you should think it is dirty... because of the exception? if you want a oneliner, here it is:</p>
<pre><code>thing_index = thing_list.index(elem) if thing_list.count(elem) else -1
</code></pre>
<p>but i would advise against using it; I think Ross Rogers solution is the best, use an object to encap... | -1 | 2010-01-25T14:31:20Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 2,133,014 | <p>There is nothing wrong with your code that uses <code>ValueError</code>. Here's yet another one-liner if you'd like to avoid exceptions:</p>
<pre><code>thing_index = next((i for i, x in enumerate(thing_list) if x == thing), -1)
</code></pre>
| 3 | 2010-01-25T14:44:58Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 2,133,094 | <p>This issue is one of language philosophy. In Java for example there has always been a tradition that exceptions should really only be used in "exceptional circumstances" that is when errors have happened, rather than for <a href="http://c2.com/cgi/wiki?DontUseExceptionsForFlowControl" rel="nofollow">flow control</a>... | 3 | 2010-01-25T14:58:00Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 2,133,116 | <pre><code>thing_index = thing_list.index(elem) if elem in thing_list else -1
</code></pre>
<p>One line. Simple. No exceptions.</p>
| 22 | 2010-01-25T15:01:25Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 2,133,419 | <p>What about this:</p>
<pre><code>otherfunction(thing_collection, thing)
</code></pre>
<p>Rather than expose something so implementation-dependent like a list index in a function interface, pass the collection and the thing and let otherfunction deal with the "test for membership" issues. If otherfunction is writte... | 1 | 2010-01-25T15:45:25Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 17,524,851 | <p>I'd suggest:</p>
<pre><code>if thing in thing_list:
list_index = -1
else:
list_index = thing_list.index(thing)
</code></pre>
| -1 | 2013-07-08T10:54:34Z | [
"python",
"list",
"find",
"indexing"
] |
Best way to handle list.index(might-not-exist) in python? | 2,132,718 | <p>I have code which looks something like this:</p>
<pre><code>thing_index = thing_list.index(thing)
otherfunction(thing_list, thing_index)
</code></pre>
<p>ok so that's simplified but you get the idea. Now <code>thing</code> might not actually be in the list, in which case I want to pass -1 as <code>thing_index</cod... | 42 | 2010-01-25T13:59:37Z | 21,205,625 | <p>I have the same issue with the ".index()" method on lists. I have no issue with the fact that it throws an exception but I strongly disagree with the fact that it's a non-descriptive ValueError. I could understand if it would've been an IndexError, though.</p>
<p>I can see why returning "-1" would be an issue too b... | 0 | 2014-01-18T14:46:54Z | [
"python",
"list",
"find",
"indexing"
] |
How to import or include data structures (e.g. a dict) into a Python file from a separate file | 2,132,985 | <p>I know I can include Python code from a common file using <code>import MyModuleName</code> - but how do I go about importing just a dict?</p>
<p>The problem I'm trying to solve is I have a dict that needs to be in a file in an editable location, while the actual script is in another file. The dict might also be edi... | 11 | 2010-01-25T14:41:33Z | 2,133,011 | <p>Assuming your <code>import myDict</code> works, you need to do the following:</p>
<pre><code>from myDict import airportCode
</code></pre>
| 8 | 2010-01-25T14:44:49Z | [
"python",
"import",
"module"
] |
How to import or include data structures (e.g. a dict) into a Python file from a separate file | 2,132,985 | <p>I know I can include Python code from a common file using <code>import MyModuleName</code> - but how do I go about importing just a dict?</p>
<p>The problem I'm trying to solve is I have a dict that needs to be in a file in an editable location, while the actual script is in another file. The dict might also be edi... | 11 | 2010-01-25T14:41:33Z | 2,133,021 | <p>Well, it doesn't need to be a <code>.py</code> file. You could just do:</p>
<pre><code>eval(open("myDict").read())
</code></pre>
<p>It's a gaping security hole, though.</p>
<p>Another module you might want to look at is <code>csv</code> for importing CSV files. Then your users could edit it with a spreadsheet a... | 0 | 2010-01-25T14:46:22Z | [
"python",
"import",
"module"
] |
How to import or include data structures (e.g. a dict) into a Python file from a separate file | 2,132,985 | <p>I know I can include Python code from a common file using <code>import MyModuleName</code> - but how do I go about importing just a dict?</p>
<p>The problem I'm trying to solve is I have a dict that needs to be in a file in an editable location, while the actual script is in another file. The dict might also be edi... | 11 | 2010-01-25T14:41:33Z | 2,133,036 | <pre><code>from myDict import airportCode
airportNode = 'BRISTOL'
myAirportCode = airportCode[airportName]
</code></pre>
<p>If myDict should get accessed from a Python module in a different directory, you have to provide a <code>__init__.py</code> module.</p>
<p>For more Information about this topic have a look at th... | 0 | 2010-01-25T14:48:05Z | [
"python",
"import",
"module"
] |
How to import or include data structures (e.g. a dict) into a Python file from a separate file | 2,132,985 | <p>I know I can include Python code from a common file using <code>import MyModuleName</code> - but how do I go about importing just a dict?</p>
<p>The problem I'm trying to solve is I have a dict that needs to be in a file in an editable location, while the actual script is in another file. The dict might also be edi... | 11 | 2010-01-25T14:41:33Z | 2,133,037 | <p>Just import it</p>
<pre><code>import script
print script.airportCode
</code></pre>
<p>or, better</p>
<pre><code>from script import airportCode
print airportCode
</code></pre>
<p>Just be careful to put both scripts on the same directory (or make a python package, a subdir with <code>__init__.py</code> file; or pu... | 22 | 2010-01-25T14:48:14Z | [
"python",
"import",
"module"
] |
How to import or include data structures (e.g. a dict) into a Python file from a separate file | 2,132,985 | <p>I know I can include Python code from a common file using <code>import MyModuleName</code> - but how do I go about importing just a dict?</p>
<p>The problem I'm trying to solve is I have a dict that needs to be in a file in an editable location, while the actual script is in another file. The dict might also be edi... | 11 | 2010-01-25T14:41:33Z | 2,133,052 | <p>If your dict has to be hand-editable by a non-programmer, perhaps it might make more sense using a CSV file for this. Then you editor can even use Excel.</p>
<p>So you can use:</p>
<pre><code>import csv
csvfile = csv.reader(open("airports.csv"))
airportCode = dict(csvfile)
</code></pre>
<p>to read a CSV file like... | 0 | 2010-01-25T14:51:40Z | [
"python",
"import",
"module"
] |
How to import or include data structures (e.g. a dict) into a Python file from a separate file | 2,132,985 | <p>I know I can include Python code from a common file using <code>import MyModuleName</code> - but how do I go about importing just a dict?</p>
<p>The problem I'm trying to solve is I have a dict that needs to be in a file in an editable location, while the actual script is in another file. The dict might also be edi... | 11 | 2010-01-25T14:41:33Z | 2,133,227 | <p>When you perform an import in python you are really just pulling in names into your current namespace. It does not really matter what those names refer to so:</p>
<pre><code>from myDict import airportCode
</code></pre>
<p>Will work regardless of whether <code>airportCode</code> is a function, class or just a field... | 1 | 2010-01-25T15:19:43Z | [
"python",
"import",
"module"
] |
How to import or include data structures (e.g. a dict) into a Python file from a separate file | 2,132,985 | <p>I know I can include Python code from a common file using <code>import MyModuleName</code> - but how do I go about importing just a dict?</p>
<p>The problem I'm trying to solve is I have a dict that needs to be in a file in an editable location, while the actual script is in another file. The dict might also be edi... | 11 | 2010-01-25T14:41:33Z | 2,133,818 | <p>Use csv. Stick <code>import csv</code> with the rest of your module imports,
and then you can do as follows:</p>
<pre><code>f = open('somefile.csv')
reader = csv.DictReader(f, (airport, iatacode))
for row in reader:
print row
</code></pre>
<p>which should give you a list of dictionaries:</p>
<pre><code>airport... | 0 | 2010-01-25T16:36:19Z | [
"python",
"import",
"module"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 2,133,050 | <p>The only valid test is to benchmark it. It really depends on what your platform is, and how well the Biot-Savart Law maps to Matlab or NumPy/SciPy built-in operations.</p>
<p>As for making Python faster, Google's working on Unladen Swallow, a JIT compiler for Python. There are probably other projects like this as... | 7 | 2010-01-25T14:51:05Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 2,133,124 | <p>If you're just using Python (with NumPy), it may be slower, depending on which pieces you use, whether or not you have optimized linear algebra libraries installed, and how well you know how to take advantage of NumPy. </p>
<p>To make it faster, there are a few things you can do. There is a tool called <a href="htt... | 2 | 2010-01-25T15:03:32Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 2,133,556 | <p>You might find some useful results at the bottom of this link</p>
<p><a href="http://wiki.scipy.org/PerformancePython">http://wiki.scipy.org/PerformancePython</a></p>
<p>From the introduction,</p>
<blockquote>
<p>A comparison of weave with NumPy, Pyrex, Psyco, Fortran (77 and 90) and C++ for solving Laplace's e... | 25 | 2010-01-25T16:02:50Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 2,133,569 | <p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> and MATLAB both use an underlying <a href="http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms">BLAS</a> implementation for standard linear algebra operations. For some time both used <a href="http://en.wikipedia.org/wiki/Automatically_Tuned_Linear_Alg... | 14 | 2010-01-25T16:04:27Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 2,136,830 | <p>As per your edit 2, I recommend very strongly that you use Fortran because you can leverage the available linear algebra subroutines (Lapack and Blas) and it is way simpler than C/C++ for matrix computations.</p>
<p>If you prefer to go with a C/C++ approach, I would use C, because you presumably need raw performanc... | 4 | 2010-01-26T00:38:02Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 2,437,186 | <p>I would also like to point out that Python (+NumPy) can easily interface with Fortran via the F2Py module, which basically nets you native Fortran speeds on the pieces of code you offload into it.</p>
| 0 | 2010-03-13T03:41:54Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 2,456,299 | <p>And here is an updated "comparison" between MATLAB and <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>/<a href="http://en.wikipedia.org/wiki/Math_Kernel_Library" rel="nofollow">MKL</a> based on some linear algebra functions:</p>
<p><a href="http://dpinte.wordpress.com/2010/03/16/numpymkl-vs-ma... | 1 | 2010-03-16T16:43:41Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Is MATLAB faster than Python? | 2,133,031 | <p>I want to compute magnetic fields of some conductors using the <a href="http://en.wikipedia.org/wiki/Biot%E2%80%93Savart_law">BiotâSavart law</a> and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster? </p>
<p>EDIT:... | 29 | 2010-01-25T14:47:42Z | 39,107,508 | <p>I couldn't find much hard numbers to answer this same question so I went ahead and did the testing myself. The results, scripts, and data sets used are all available here on my post on <a href="http://blog.mide.com/matlab-vs-python-speed-for-vibration-analysis-free-download" rel="nofollow">MATLAB vs Python speed fo... | 0 | 2016-08-23T17:35:02Z | [
"python",
"matlab",
"matrix",
"performance"
] |
Paramiko equvalent of pipeline controls and input/output pipes | 2,133,326 | <p>I need a method of paramiko based file transfer with a lightweight <a href="http://en.wikipedia.org/wiki/SSH2" rel="nofollow">SSH2</a> server (<a href="http://matt.ucc.asn.au/dropbear/dropbear.html" rel="nofollow">dropbear</a>) which has no support for <a href="http://en.wikipedia.org/wiki/Scp" rel="nofollow">SCP</a... | 3 | 2010-01-25T15:33:37Z | 2,133,867 | <p>The following may be useful as a starting point (e.g. ./sshpipe host "command"):</p>
<pre><code>#! /usr/bin/env python
import sys
import paramiko
def sshpipe(host, line) :
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host)
stdin, stdout,... | 3 | 2010-01-25T16:43:03Z | [
"python",
"file",
"transfer",
"paramiko"
] |
python subprocess communicate() block | 2,133,345 | <p>I am using the <em>subprocess</em> module to call an external program (plink.exe) to log-in to a server; but when I call communicate to read the output, it is blocking. The code is below:</p>
<pre><code> import subprocess
process = subprocess.Popen('plink.exe hello@10.120.139.170 -pw 123456'.split(), shell=False, ... | 14 | 2010-01-25T15:36:36Z | 2,133,383 | <p>The whole purpose of the <code>communicate</code> method is to wait for the process to finish and return all the output. If you don't want to wait, don't call <code>communicate</code>. Instead, read from the <code>stdout</code> or <code>stderr</code> attribute to read the output.</p>
<p>If the process outputs to bo... | 22 | 2010-01-25T15:41:06Z | [
"python",
"subprocess",
"blocking"
] |
python subprocess communicate() block | 2,133,345 | <p>I am using the <em>subprocess</em> module to call an external program (plink.exe) to log-in to a server; but when I call communicate to read the output, it is blocking. The code is below:</p>
<pre><code> import subprocess
process = subprocess.Popen('plink.exe hello@10.120.139.170 -pw 123456'.split(), shell=False, ... | 14 | 2010-01-25T15:36:36Z | 13,819,753 | <p>I faced a similar situation where I had to execute a single command <code>lmstat -a</code> and then get the output of the terminal.</p>
<p>If you just need to run a single command and then read the output, you can use the following code:</p>
<pre><code>import subprocess
Username = 'your_username'
Password = 'your... | 0 | 2012-12-11T11:48:32Z | [
"python",
"subprocess",
"blocking"
] |
django: gettext and coercing to unicode | 2,133,508 | <p>I have following code in my django application.</p>
<pre><code>class Status(object):
def __init__(self, id, desc):
self.id = id
self.desc = desc
def __unicode__(self):
return self.desc
STATUS = Status(0, _(u"Some text"))
</code></pre>
<p>When I try to display some status (or even... | 6 | 2010-01-25T15:57:06Z | 2,133,690 | <p>The <code>_()</code> function from Django can return a <code>django.utils.functional.__proxy__</code> object, which is itself not unicode (see <a href="http://docs.djangoproject.com/en/1.1/ref/unicode/#translated-strings">http://docs.djangoproject.com/en/1.1/ref/unicode/#translated-strings</a>). Python does not call... | 20 | 2010-01-25T16:20:00Z | [
"python",
"django",
"unicode",
"gettext"
] |
Is it possible get all context nodes used to evalute xpath result? | 2,133,527 | <p>Is it possible get all context nodes used to evalute xpath result ?
In below code:</p>
<pre><code>test_xml = """
<r>
<a/>
<a>
<b/>
</a>
<a>
<b/>
</a>
</r>
"""
test_root = lxml.etree.fromstring(test_xml)
res = test_root.xpath("... | 1 | 2010-01-25T15:58:52Z | 2,163,631 | <p>If I am understanding your question correctly, you are trying to just get the ancestor nodes of particular nodes. The XPATH expression for this would be:</p>
<pre><code>//particular-element/ancestor::*
</code></pre>
<p>such as:</p>
<pre><code>/r/a[2]/b/ancestor::*
</code></pre>
| 0 | 2010-01-29T17:10:01Z | [
"python",
"xpath",
"lxml"
] |
Is it possible get all context nodes used to evalute xpath result? | 2,133,527 | <p>Is it possible get all context nodes used to evalute xpath result ?
In below code:</p>
<pre><code>test_xml = """
<r>
<a/>
<a>
<b/>
</a>
<a>
<b/>
</a>
</r>
"""
test_root = lxml.etree.fromstring(test_xml)
res = test_root.xpath("... | 1 | 2010-01-25T15:58:52Z | 7,154,713 | <p>I reversed the xpath for each stage to get which items would be evaluated in the result:</p>
<pre><code>for node in res:
j = node.xpath('./parent::*')[0]
k = j.xpath('./preceding-sibling::*[1]')[0]
# You didn't specify these but they were used in the evaluation
ancestors = k.xpath('./ancestor::*')
... | 1 | 2011-08-22T23:18:22Z | [
"python",
"xpath",
"lxml"
] |
Most Pythonic way to concatenate strings | 2,133,571 | <p>Given this harmless little list:</p>
<pre><code>>>> lst = ['o','s','s','a','m','a']
</code></pre>
<p>My goal is to pythonically concatenate the little devils using one of the following ways:</p>
<p>A. plain ol' string function to get the job done, short, no imports</p>
<pre><code>>>> ''.join(ls... | 21 | 2010-01-25T16:04:36Z | 2,133,580 | <pre><code>''.join(lst)
</code></pre>
<p>the only pythonic way:</p>
<ul>
<li>clear (that what all the big boys do and what they expect to see),</li>
<li>simple (no additional imports needed, stable across all versions),</li>
<li>fast (written in C) and </li>
<li>concise (on an empty string join elements of iterable!)... | 50 | 2010-01-25T16:05:45Z | [
"python",
"concatenation"
] |
Most Pythonic way to concatenate strings | 2,133,571 | <p>Given this harmless little list:</p>
<pre><code>>>> lst = ['o','s','s','a','m','a']
</code></pre>
<p>My goal is to pythonically concatenate the little devils using one of the following ways:</p>
<p>A. plain ol' string function to get the job done, short, no imports</p>
<pre><code>>>> ''.join(ls... | 21 | 2010-01-25T16:04:36Z | 2,133,605 | <p>Have a look at Guido's <a href="http://www.python.org/doc/essays/list2str/">essay</a> on python optimization, it covers converting lists of numbers to strings. Unless you have a <em>good</em> reason to do otherwise, use the <code>join</code> example.</p>
| 28 | 2010-01-25T16:08:48Z | [
"python",
"concatenation"
] |
Most Pythonic way to concatenate strings | 2,133,571 | <p>Given this harmless little list:</p>
<pre><code>>>> lst = ['o','s','s','a','m','a']
</code></pre>
<p>My goal is to pythonically concatenate the little devils using one of the following ways:</p>
<p>A. plain ol' string function to get the job done, short, no imports</p>
<pre><code>>>> ''.join(ls... | 21 | 2010-01-25T16:04:36Z | 2,133,625 | <p>Here's the least Pythonic way:</p>
<pre><code>out = ""
for x in range(len(lst)):
for y in range(len(lst)):
if x + y == len(lst)-1:
out = lst[y] + out
</code></pre>
| 5 | 2010-01-25T16:12:34Z | [
"python",
"concatenation"
] |
Most Pythonic way to concatenate strings | 2,133,571 | <p>Given this harmless little list:</p>
<pre><code>>>> lst = ['o','s','s','a','m','a']
</code></pre>
<p>My goal is to pythonically concatenate the little devils using one of the following ways:</p>
<p>A. plain ol' string function to get the job done, short, no imports</p>
<pre><code>>>> ''.join(ls... | 21 | 2010-01-25T16:04:36Z | 2,133,872 | <p>I myself use the "join" way, but from python 2.6 there is a base type that is little used: <strong>bytearray</strong>.</p>
<p>Bytearrays can be incredible useful -- for string containing texts, since the best thing is to have then in unicode, the "join" way is the way to go -- but if you are dealing with binary dat... | 5 | 2010-01-25T16:43:52Z | [
"python",
"concatenation"
] |
Most Pythonic way to concatenate strings | 2,133,571 | <p>Given this harmless little list:</p>
<pre><code>>>> lst = ['o','s','s','a','m','a']
</code></pre>
<p>My goal is to pythonically concatenate the little devils using one of the following ways:</p>
<p>A. plain ol' string function to get the job done, short, no imports</p>
<pre><code>>>> ''.join(ls... | 21 | 2010-01-25T16:04:36Z | 2,134,386 | <p>Great answer from SilenGhost BUT, just a few words about the presented <code>reduce</code> "alternative"</p>
<p>Unless you've got a very very <strong>VERY</strong> good reason to concatenate strings using <code>+</code> or <code>operator.add</code> (the most frequent one, that you've got few, fixed number of string... | 2 | 2010-01-25T17:58:11Z | [
"python",
"concatenation"
] |
Most Pythonic way to concatenate strings | 2,133,571 | <p>Given this harmless little list:</p>
<pre><code>>>> lst = ['o','s','s','a','m','a']
</code></pre>
<p>My goal is to pythonically concatenate the little devils using one of the following ways:</p>
<p>A. plain ol' string function to get the job done, short, no imports</p>
<pre><code>>>> ''.join(ls... | 21 | 2010-01-25T16:04:36Z | 2,134,393 | <p>Of course it's <code>join</code>. How do I know? Let's do it in a really stupid way:<br>
If the problem was only adding 2 strings, you'd most likely use <code>str1 + str2</code>. What does it take to get that to the next level? Instinctively, for most (I think), will be to use <code>sum</code>. Let's see how that g... | 15 | 2010-01-25T17:59:09Z | [
"python",
"concatenation"
] |
ArcGIS: accessing python list output from listFields geoprocessor | 2,133,576 | <p>I'm trying to access the output from the <code>listFields</code> geoprocessing object using the following code:</p>
<pre><code>sFields = gp.ListFields(linktofeatureclass)
for j in range(len(sFields)):
print sFields[j]
</code></pre>
<p>How do I get information about the fields that I have enumerated? Printing t... | 0 | 2010-01-25T16:05:06Z | 2,133,681 | <p>try this:</p>
<pre><code>sFields = gp.ListFields(linktofeatureclass)
for field in sFields:
print field.Name, field.Type, field.Scale
</code></pre>
<p>For more information, consult with <a href="http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=Field_properties" rel="nofollow">the docs</a>.</p>
| 1 | 2010-01-25T16:18:46Z | [
"python",
"arcgis"
] |
XQuery library under Python | 2,133,648 | <p>Hey
Is there any existing way to run XQuery under python? (not starting to build a parser yourself in other words).</p>
<p>I got a ton of legacy XQuery that I want to port to our new system, or rather I want to
port the framework and not XQuery.</p>
<p>Therefore: Is there any library that allows me to run XQuery ... | 14 | 2010-01-25T16:15:14Z | 2,133,842 | <p><strong>Sort of ...</strong></p>
<p>Looking through the <a href="http://www.w3.org/XML/Query/#implementations" rel="nofollow">W3C implementations list for XQuery</a> there is:</p>
<ol>
<li><a href="http://www.zorba-xquery.com/" rel="nofollow">Python bindings for Zorba</a></li>
<li><a href="http://modis.ispras.ru/s... | 11 | 2010-01-25T16:39:02Z | [
"python",
"api",
"xquery"
] |
XQuery library under Python | 2,133,648 | <p>Hey
Is there any existing way to run XQuery under python? (not starting to build a parser yourself in other words).</p>
<p>I got a ton of legacy XQuery that I want to port to our new system, or rather I want to
port the framework and not XQuery.</p>
<p>Therefore: Is there any library that allows me to run XQuery ... | 14 | 2010-01-25T16:15:14Z | 3,104,813 | <p>Zorba 1.2 works from python. After installation you will get a python folder under zorba folder. Append it to sys.path, with zorba\bin folder also. After all manipulations import "zorba_api" will work!</p>
| 0 | 2010-06-23T19:21:00Z | [
"python",
"api",
"xquery"
] |
XQuery library under Python | 2,133,648 | <p>Hey
Is there any existing way to run XQuery under python? (not starting to build a parser yourself in other words).</p>
<p>I got a ton of legacy XQuery that I want to port to our new system, or rather I want to
port the framework and not XQuery.</p>
<p>Therefore: Is there any library that allows me to run XQuery ... | 14 | 2010-01-25T16:15:14Z | 4,444,236 | <p>I had problems like Ted and tried to use answer from vadim.
However, I had still problems to load zorba_api properly, complaining "ImportError DLL load failed" (not telling which one, using %1 as great nickname).</p>
<p>Finally, I got the solution:</p>
<p><strong>Environment</strong></p>
<ul>
<li>WindowsXP</li>
<... | 0 | 2010-12-14T21:05:49Z | [
"python",
"api",
"xquery"
] |
XQuery library under Python | 2,133,648 | <p>Hey
Is there any existing way to run XQuery under python? (not starting to build a parser yourself in other words).</p>
<p>I got a ton of legacy XQuery that I want to port to our new system, or rather I want to
port the framework and not XQuery.</p>
<p>Therefore: Is there any library that allows me to run XQuery ... | 14 | 2010-01-25T16:15:14Z | 31,093,065 | <p>You could use <a href="http://www.jython.org" rel="nofollow">Jython</a> to run the Python code -- that gives you access to some of the XQuery processors from the Java world. For example <a href="http://saxon.sourceforge.net/" rel="nofollow">Saxon</a>.</p>
| 1 | 2015-06-27T20:13:02Z | [
"python",
"api",
"xquery"
] |
Using python graphviz ImportError: No module named _gv | 2,133,767 | <p>I'm trying to use graphviz with python and I get the error:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/gv.py", line 7, in <module>
import _gv
ImportError: No module named _gv
</code></pre>
<p>The system state:</... | 6 | 2010-01-25T16:29:20Z | 2,321,371 | <p>I fixed the problem. The solution was: </p>
<pre><code>sudo su
cd /usr/lib/pyshared/python2.6
mv _gv.so _gv.so-
ln -s libgv_python.so _gv.so
sys.path.append('/usr/lib/pyshared/python2.6')
</code></pre>
| 6 | 2010-02-23T20:14:09Z | [
"python",
"package",
"graphviz"
] |
Using python graphviz ImportError: No module named _gv | 2,133,767 | <p>I'm trying to use graphviz with python and I get the error:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/gv.py", line 7, in <module>
import _gv
ImportError: No module named _gv
</code></pre>
<p>The system state:</... | 6 | 2010-01-25T16:29:20Z | 5,267,848 | <p>For Ubuntu 10.04, </p>
<pre><code>cd /usr/lib/pymodules/python2.6
sudo ln -s libgv_python.so _gv.so
</code></pre>
| 2 | 2011-03-11T00:57:45Z | [
"python",
"package",
"graphviz"
] |
capture using v4l2 and display preview using gstreamer | 2,133,822 | <p>How to pass the buffer/userpointer to gstreamer after Q_BUF, STREAM_ON, DQ_BUF.</p>
<p>I tried using PIL's method frombuffer, but with no success. so I want to use gst sink now.</p>
<p>Should I use gst.parse_launch() and how?</p>
<p>Have anybody done it?</p>
| 1 | 2010-01-25T16:36:57Z | 2,342,360 | <p>The source code to Cheese tells all. <a href="http://projects.gnome.org/cheese/" rel="nofollow">http://projects.gnome.org/cheese/</a></p>
| 0 | 2010-02-26T14:45:21Z | [
"python",
"gstreamer",
"v4l2"
] |
Pyparsing - where order of tokens in unpredictable | 2,134,416 | <p>I want to be able to pull out the type and count of letters from a piece of text where the letters could be in any order. There is some other parsing going on which I have working, but this bit has me stumped! </p>
<pre><code>input -> result
"abc" -> [['a',1], ['b',1],['c',1]]
"bbbc" -> [['b',3],['c',1]]... | 4 | 2010-01-25T18:01:25Z | 2,134,640 | <p>One solution:</p>
<pre><code>text = 'sufja srfjhvlasfjkhv lasjfvhslfjkv hlskjfvh slfkjvhslk'
print([(x,text.count(x)) for x in set(text)])
</code></pre>
<p>No pyparsing involved, but it seems like overkill.</p>
| 6 | 2010-01-25T18:38:58Z | [
"python",
"pyparsing"
] |
Pyparsing - where order of tokens in unpredictable | 2,134,416 | <p>I want to be able to pull out the type and count of letters from a piece of text where the letters could be in any order. There is some other parsing going on which I have working, but this bit has me stumped! </p>
<pre><code>input -> result
"abc" -> [['a',1], ['b',1],['c',1]]
"bbbc" -> [['b',3],['c',1]]... | 4 | 2010-01-25T18:01:25Z | 2,134,710 | <p>pyparsing apart -- in Python 3.1, <a href="http://docs.python.org/3.1/library/collections.html?highlight=collections#collections.Counter" rel="nofollow">collections.Counter</a> makes such counting tasks really easy. A good version of <code>Counter</code> for Python 2 can be found <a href="http://code.activestate.co... | 1 | 2010-01-25T18:51:15Z | [
"python",
"pyparsing"
] |
Pyparsing - where order of tokens in unpredictable | 2,134,416 | <p>I want to be able to pull out the type and count of letters from a piece of text where the letters could be in any order. There is some other parsing going on which I have working, but this bit has me stumped! </p>
<pre><code>input -> result
"abc" -> [['a',1], ['b',1],['c',1]]
"bbbc" -> [['b',3],['c',1]]... | 4 | 2010-01-25T18:01:25Z | 2,134,777 | <p>I like <a href="http://stackoverflow.com/questions/2134416/pyparsing-where-order-of-tokens-in-unpredictable/2134640#2134640">Lennart's one-line solution</a>.</p>
<p><a href="http://stackoverflow.com/questions/2134416/pyparsing-where-order-of-tokens-in-unpredictable/2134710#2134710">Alex mentions another great optio... | 3 | 2010-01-25T19:00:55Z | [
"python",
"pyparsing"
] |
Pyparsing - where order of tokens in unpredictable | 2,134,416 | <p>I want to be able to pull out the type and count of letters from a piece of text where the letters could be in any order. There is some other parsing going on which I have working, but this bit has me stumped! </p>
<pre><code>input -> result
"abc" -> [['a',1], ['b',1],['c',1]]
"bbbc" -> [['b',3],['c',1]]... | 4 | 2010-01-25T18:01:25Z | 2,137,290 | <p>If you want a pure-pyparsing approach, this feels about right:</p>
<pre><code>from pyparsing import *
# lambda to define expressions
def makeExpr(ch):
expr = Literal(ch).setResultsName(ch, listAllMatches=True)
return expr
expr = OneOrMore(MatchFirst(makeExpr(c) for c in "abc"))
expr.setParseAction(lambda ... | 1 | 2010-01-26T03:08:28Z | [
"python",
"pyparsing"
] |
Pyparsing - where order of tokens in unpredictable | 2,134,416 | <p>I want to be able to pull out the type and count of letters from a piece of text where the letters could be in any order. There is some other parsing going on which I have working, but this bit has me stumped! </p>
<pre><code>input -> result
"abc" -> [['a',1], ['b',1],['c',1]]
"bbbc" -> [['b',3],['c',1]]... | 4 | 2010-01-25T18:01:25Z | 2,137,324 | <p>I wasn't clear from your description whether the input characters could be mixed like "ababc", since in all your test cases, the letters were always grouped together. If the letters <em>are</em> always grouped together, you could use this pyparsing code:</p>
<pre><code>def makeExpr(ch):
expr = Word(ch).setPars... | 5 | 2010-01-26T03:15:28Z | [
"python",
"pyparsing"
] |
Multiple Inheritance in Python (Problem Specific) | 2,134,452 | <p>Can anyone here identify why the TypeError is being raised at the bottom of this example shown below?</p>
<pre><code>>>> import threading
>>> class SessionManager(threading.Thread, threading._RLock, dict):
UPDATE = 60 * 60
def run(self):
while True:
time.sleep(self.UP... | 0 | 2010-01-25T18:07:56Z | 2,134,487 | <p>The problem is coming from <code>threading.py</code>, and can be reproduced more simply as follows:</p>
<pre><code>>>> import threading
>>> class SessionManager(threading.Thread, threading._RLock, dict): pass
...
>>> s = SessionManager()
>>> s.start()
Traceback (most recent call... | 2 | 2010-01-25T18:13:33Z | [
"python",
"multithreading",
"multiple-inheritance",
"typeerror"
] |
Multiple Inheritance in Python (Problem Specific) | 2,134,452 | <p>Can anyone here identify why the TypeError is being raised at the bottom of this example shown below?</p>
<pre><code>>>> import threading
>>> class SessionManager(threading.Thread, threading._RLock, dict):
UPDATE = 60 * 60
def run(self):
while True:
time.sleep(self.UP... | 0 | 2010-01-25T18:07:56Z | 2,134,843 | <p>Alex's on-point diagnosis of the problem notwithstanding, I would strongly argue that you should not multiply inherit from <code>dict</code> in this case (or in general, for that matter.) While it may seem convenient to subclass from it and automatically inherit all the dict behaviour, dicts (and builtin types in ge... | 1 | 2010-01-25T19:08:29Z | [
"python",
"multithreading",
"multiple-inheritance",
"typeerror"
] |
python select specific elements from a list | 2,134,539 | <p>Is there a "pythonic" way of getting only certain values from a list, similar to this perl code:</p>
<pre><code>my ($one,$four,$ten) = line.split(/,/)[1,4,10]
</code></pre>
| 19 | 2010-01-25T18:21:19Z | 2,134,551 | <pre><code>lst = line.split(',')
one, four, ten = lst[1], lst[4], lst[10]
</code></pre>
| 7 | 2010-01-25T18:24:21Z | [
"python",
"list"
] |
python select specific elements from a list | 2,134,539 | <p>Is there a "pythonic" way of getting only certain values from a list, similar to this perl code:</p>
<pre><code>my ($one,$four,$ten) = line.split(/,/)[1,4,10]
</code></pre>
| 19 | 2010-01-25T18:21:19Z | 2,134,570 | <p>I think you are looking for <code>operator.itemgetter</code>:</p>
<pre><code>import operator
line=','.join(map(str,range(11)))
print(line)
# 0,1,2,3,4,5,6,7,8,9,10
alist=line.split(',')
print(alist)
# ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
one,four,ten=operator.itemgetter(1,4,10)(alist)
print(one,... | 18 | 2010-01-25T18:26:35Z | [
"python",
"list"
] |
python select specific elements from a list | 2,134,539 | <p>Is there a "pythonic" way of getting only certain values from a list, similar to this perl code:</p>
<pre><code>my ($one,$four,$ten) = line.split(/,/)[1,4,10]
</code></pre>
| 19 | 2010-01-25T18:21:19Z | 2,134,581 | <p>Yes:</p>
<pre><code>data = line.split(',')
one, four, ten = data[1], data[4], data[10]
</code></pre>
<p>You can also use itemgetter, but I prefer the code above, it's clearer, and clarity == good code.</p>
| 1 | 2010-01-25T18:28:57Z | [
"python",
"list"
] |
python select specific elements from a list | 2,134,539 | <p>Is there a "pythonic" way of getting only certain values from a list, similar to this perl code:</p>
<pre><code>my ($one,$four,$ten) = line.split(/,/)[1,4,10]
</code></pre>
| 19 | 2010-01-25T18:21:19Z | 2,134,607 | <p>Try <a href="http://docs.python.org/library/operator.html#operator.itemgetter" rel="nofollow">operator.itemgetter</a> (available in python 2.4 or newer):</p>
<blockquote>
<p>Return a callable object that fetches item from its operand using the operandâs <strong>_<em>getitem</em>_</strong>() method. If multiple ... | 4 | 2010-01-25T18:34:07Z | [
"python",
"list"
] |
python select specific elements from a list | 2,134,539 | <p>Is there a "pythonic" way of getting only certain values from a list, similar to this perl code:</p>
<pre><code>my ($one,$four,$ten) = line.split(/,/)[1,4,10]
</code></pre>
| 19 | 2010-01-25T18:21:19Z | 9,286,644 | <p>Using a list comprehension</p>
<pre><code>line = '0,1,2,3,4,5,6,7,8,9,10'
lst = line.split(',')
one, four, ten = [lst[i] for i in [1,4,10]]
</code></pre>
| 12 | 2012-02-15T01:17:44Z | [
"python",
"list"
] |
python select specific elements from a list | 2,134,539 | <p>Is there a "pythonic" way of getting only certain values from a list, similar to this perl code:</p>
<pre><code>my ($one,$four,$ten) = line.split(/,/)[1,4,10]
</code></pre>
| 19 | 2010-01-25T18:21:19Z | 14,467,631 | <p>How about this: </p>
<pre><code>index = [1, 0, 0, 1, 0]
x = [1, 2, 3, 4, 5]
[i for j, i in enumerate(x) if index[j] == 1]
#[1, 4]
</code></pre>
| 2 | 2013-01-22T20:43:09Z | [
"python",
"list"
] |
python select specific elements from a list | 2,134,539 | <p>Is there a "pythonic" way of getting only certain values from a list, similar to this perl code:</p>
<pre><code>my ($one,$four,$ten) = line.split(/,/)[1,4,10]
</code></pre>
| 19 | 2010-01-25T18:21:19Z | 22,569,263 | <p>Alternatively, if you had a Numpy array instead of a list, you could do womething like:</p>
<pre><code>from numpy import array
# Assuming line = "0,1,2,3,4,5,6,7,8,9,10"
line_array = array(line.split(","))
one, four, ten = line_array[[1,4,10]]
</code></pre>
<p>The trick here is that you can pass a list (or a Num... | 0 | 2014-03-21T20:48:40Z | [
"python",
"list"
] |
gnomevfs or gio? | 2,134,691 | <p>For async IO using Python, is it preferable to rely on <a href="http://library.gnome.org/devel/gio/" rel="nofollow"><code>gio</code></a> or <a href="http://library.gnome.org/devel/gnome-vfs-2.0/" rel="nofollow"><code>gnomevfs</code></a>?</p>
<p>Also, which one is more "cross-platform"?</p>
| 0 | 2010-01-25T18:47:19Z | 2,134,705 | <p>Use GIO.</p>
<p>GnomeVFS has been deprecated since GNOME 2.22, in favour of GIO.</p>
| 4 | 2010-01-25T18:49:26Z | [
"python",
"gio"
] |
Hitting Maximum Recursion Depth Using Python's Pickle / cPickle | 2,134,706 | <p>The background: I'm building a trie to represent a dictionary, using a minimal construction algorithm. The input list is 4.3M utf-8 strings, sorted lexicographically. The resulting graph is acyclic and has a maximum depth of 638 nodes. The first line of my script sets the recursion limit to 1100 via <code>sys.se... | 28 | 2010-01-25T18:49:42Z | 2,135,176 | <p>From <a href="http://docs.python.org/library/pickle.html#what-can-be-pickled-and-unpickled">the docs</a>:</p>
<blockquote>
<p>Trying to pickle a highly recursive data structure may exceed the maximum recursion depth, a RuntimeError will be raised in this case. You can carefully raise this limit with <code>sys.se... | 22 | 2010-01-25T19:58:23Z | [
"python",
"recursion",
"tree",
"pickle",
"depth"
] |
Hitting Maximum Recursion Depth Using Python's Pickle / cPickle | 2,134,706 | <p>The background: I'm building a trie to represent a dictionary, using a minimal construction algorithm. The input list is 4.3M utf-8 strings, sorted lexicographically. The resulting graph is acyclic and has a maximum depth of 638 nodes. The first line of my script sets the recursion limit to 1100 via <code>sys.se... | 28 | 2010-01-25T18:49:42Z | 2,135,179 | <p>Double-check that your structure is indeed acyclic.</p>
<p>You could try bumping up the limit even further. There's a hard maximum that's platform dependent, but trying 50000 would be reasonable.</p>
<p>Also try pickling a trivially small version of your trie. If pickle dies even though it's only storing a couple ... | 3 | 2010-01-25T19:58:42Z | [
"python",
"recursion",
"tree",
"pickle",
"depth"
] |
Hitting Maximum Recursion Depth Using Python's Pickle / cPickle | 2,134,706 | <p>The background: I'm building a trie to represent a dictionary, using a minimal construction algorithm. The input list is 4.3M utf-8 strings, sorted lexicographically. The resulting graph is acyclic and has a maximum depth of 638 nodes. The first line of my script sets the recursion limit to 1100 via <code>sys.se... | 28 | 2010-01-25T18:49:42Z | 2,135,784 | <p>Pickle does need to recursively walk your trie. If Pickle is using just 5 levels of function calls to do the work your trie of depth 638 will need the level set to more than 3000.</p>
<p>Try a much bigger number, the recursion limit is really just there to protect users from having to wait too long if the recursion... | 8 | 2010-01-25T21:28:36Z | [
"python",
"recursion",
"tree",
"pickle",
"depth"
] |
PID files hanging around for daemons after server restart | 2,134,732 | <p>I have some daemons that use PID files to prevent parallel execution of my program. I have set up a signal handler to trap SIGTERM and do the necessary clean-up including the PID file. This works great when I test using "kill -s SIGTERM #PID". However, when I reboot the server the PID files are still hanging arou... | 2 | 2010-01-25T18:53:54Z | 2,134,763 | <p>Not a direct solution but it might be a good idea to check for an actual process running with the pid in the pid file at startup and if none exists, to cleanup the stale file. </p>
<p>It's possible that your process is getting a SIGKILL before it has a chance to cleanup the pid file.</p>
| 3 | 2010-01-25T18:57:56Z | [
"python",
"linux",
"sigterm"
] |
PID files hanging around for daemons after server restart | 2,134,732 | <p>I have some daemons that use PID files to prevent parallel execution of my program. I have set up a signal handler to trap SIGTERM and do the necessary clean-up including the PID file. This works great when I test using "kill -s SIGTERM #PID". However, when I reboot the server the PID files are still hanging arou... | 2 | 2010-01-25T18:53:54Z | 2,134,870 | <p>Remember that, after sending SIGTERM to all processes, the kernel wait some time (usually about 2 or 3 seconds), and then send SIGKILL. You can find that in <code>/etc/rc.d/rc0.d/S01halt</code> or similar (might vary depending on your distribution).</p>
<p>For example, on my Fedora 11 you have:</p>
<pre><code>acti... | 2 | 2010-01-25T19:12:50Z | [
"python",
"linux",
"sigterm"
] |
PID files hanging around for daemons after server restart | 2,134,732 | <p>I have some daemons that use PID files to prevent parallel execution of my program. I have set up a signal handler to trap SIGTERM and do the necessary clean-up including the PID file. This works great when I test using "kill -s SIGTERM #PID". However, when I reboot the server the PID files are still hanging arou... | 2 | 2010-01-25T18:53:54Z | 2,134,962 | <p>Use <code>flock</code> (or <code>lockf</code>) on your pidfile, if it succeeds, you can rewrite the pidfile and continue.</p>
<p><a href="http://stackoverflow.com/questions/380870/python-single-instance-of-program/1265445#1265445">This SO answer</a> has a good example on how this is done.</p>
| 3 | 2010-01-25T19:25:23Z | [
"python",
"linux",
"sigterm"
] |
Async HTTP request using GIO | 2,134,797 | <p>I would appreciate an example on how to perform an async HTTP POST request using Python's GIO binding.</p>
<p><strong>Edit</strong>: Example sought without using Twisted.</p>
| 2 | 2010-01-25T19:03:42Z | 2,134,950 | <p>An example using Twisted Deferred objects is available on <a href="http://blogs.gnome.org/jamesh/2009/01/06/twisted-gio/" rel="nofollow">James Henstridge's blog</a>.</p>
| 1 | 2010-01-25T19:23:22Z | [
"python",
"http",
"asynchronous",
"gio"
] |
Async HTTP request using GIO | 2,134,797 | <p>I would appreciate an example on how to perform an async HTTP POST request using Python's GIO binding.</p>
<p><strong>Edit</strong>: Example sought without using Twisted.</p>
| 2 | 2010-01-25T19:03:42Z | 12,220,153 | <p>Sorry this is not HTTP POST (just GET), but it is using Gio to asynchronously request a URL, with a callback that processes the resulting data when it's done downloading.</p>
<p><a href="https://github.com/robru/gottengeography/blob/65505bd0cf0060ec7397849e7c62c231367c7f1d/gg/datatypes.py#L242" rel="nofollow">https... | 0 | 2012-08-31T17:40:17Z | [
"python",
"http",
"asynchronous",
"gio"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.