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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Writing XML from Python : Python equivalent of .NET XmlTextWriter? | 1,022,429 | <p>I have some IronPython code which makes use of XmlTextWriter which allows me to write code like</p>
<pre><code>self.writer = System.Xml.XmlTextWriter(filename, None)
self.writer.Formatting = Formatting.Indented
self.writer.WriteStartElement(name)
self.writer.WriteString(str(text))
self.writer.WriteEndElement()
...... | 3 | 2009-06-20T20:10:28Z | 1,022,437 | <p>I've never used the .NET implementation you're talking about, but it sounds like the closest you're going to get is Python's <a href="http://docs.python.org/library/xml.sax.html" rel="nofollow">SAX parser</a> (specifically, the <a href="http://docs.python.org/library/xml.sax.utils.html#xml.sax.saxutils.XMLGenerator"... | 2 | 2009-06-20T20:14:54Z | [
"python",
"xml",
"ironpython",
"jython"
] |
Writing XML from Python : Python equivalent of .NET XmlTextWriter? | 1,022,429 | <p>I have some IronPython code which makes use of XmlTextWriter which allows me to write code like</p>
<pre><code>self.writer = System.Xml.XmlTextWriter(filename, None)
self.writer.Formatting = Formatting.Indented
self.writer.WriteStartElement(name)
self.writer.WriteString(str(text))
self.writer.WriteEndElement()
...... | 3 | 2009-06-20T20:10:28Z | 1,023,168 | <p>I wrote a tool to facilitate XML generation from Python (<a href="http://github.com/billzeller/xmlegant-for-python/tree/master" rel="nofollow">code</a> and <a href="http://www.from.bz/2009/03/28/announcing-xmlegant-for-python/" rel="nofollow">tutorial</a>)</p>
| 2 | 2009-06-21T03:54:44Z | [
"python",
"xml",
"ironpython",
"jython"
] |
Writing XML from Python : Python equivalent of .NET XmlTextWriter? | 1,022,429 | <p>I have some IronPython code which makes use of XmlTextWriter which allows me to write code like</p>
<pre><code>self.writer = System.Xml.XmlTextWriter(filename, None)
self.writer.Formatting = Formatting.Indented
self.writer.WriteStartElement(name)
self.writer.WriteString(str(text))
self.writer.WriteEndElement()
...... | 3 | 2009-06-20T20:10:28Z | 2,884,756 | <p>I wrote a module named loxun to do just that: <a href="http://pypi.python.org/pypi/loxun/" rel="nofollow">http://pypi.python.org/pypi/loxun/</a>. It runs with CPython 2.5 and Jython 2.5, but I never tried it with IronPython.</p>
<p>Example usage:</p>
<pre><code>with open("...", "wb") as out:
xml = XmlWriter(out)... | 3 | 2010-05-21T18:56:15Z | [
"python",
"xml",
"ironpython",
"jython"
] |
Emulating membership-test in Python: delegating __contains__ to contained-object correctly | 1,022,499 | <p>I am used to that Python allows some neat tricks to delegate functionality to other objects. One example is delegation to contained objects.</p>
<p>But it seams, that I don't have luck, when I want to delegate __contains __:</p>
<pre><code>class A(object):
def __init__(self):
self.mydict = {}
sel... | 6 | 2009-06-20T20:39:05Z | 1,022,505 | <p>Special methods such as <code>__contains__</code> are only special when defined on the class, not on the instance (except in legacy classes in Python 2, which you should <em>not</em> use anyway).</p>
<p>So, do your delegation at class level:</p>
<pre><code>class A(object):
def __init__(self):
self.mydic... | 17 | 2009-06-20T20:42:37Z | [
"python",
"containers",
"delegation",
"emulation",
"iterable"
] |
Problem getting date with Universal Feed Parser | 1,022,504 | <p>It looks like <a href="http://portland.beerandblog.com/feed/atom/" rel="nofollow">http://portland.beerandblog.com/feed/atom/</a> is messed up (as are the 0.92 and 2.0 RSS feeds). </p>
<p>Universal Feed Parser (latest version from <a href="http://code.google.com/p/feedparser/source/browse/trunk/feedparser/feedparse... | 1 | 2009-06-20T20:42:09Z | 1,022,720 | <p>Using a naked <code>except</code> may be masking a problem in your code. Assuming (I don't use feed parsers) that AttributeError is the specific exception that you should be checking for, try (accidental pun) this:</p>
<pre><code>try:
published = e.published_parsed
except AttributeError:
try:
publis... | 1 | 2009-06-20T22:36:49Z | [
"python",
"parsing",
"feeds",
"feed"
] |
Problem getting date with Universal Feed Parser | 1,022,504 | <p>It looks like <a href="http://portland.beerandblog.com/feed/atom/" rel="nofollow">http://portland.beerandblog.com/feed/atom/</a> is messed up (as are the 0.92 and 2.0 RSS feeds). </p>
<p>Universal Feed Parser (latest version from <a href="http://code.google.com/p/feedparser/source/browse/trunk/feedparser/feedparse... | 1 | 2009-06-20T20:42:09Z | 1,022,776 | <p>Works for me:</p>
<pre><code>>>> e = feedparser.parse('http://portland.beerandblog.com/feed/atom/')
>>> e.feed.date
u'2009-06-19T22:54:57Z'
>>> e.feed.date_parsed
(2009, 6, 19, 22, 54, 57, 4, 170, 0)
>>> e.feed.updated_parsed
(2009, 6, 19, 22, 54, 57, 4, 170, 0)
</code></pre>
<p... | 3 | 2009-06-20T23:14:58Z | [
"python",
"parsing",
"feeds",
"feed"
] |
Weighted slope one algorithm? (porting from Python to R) | 1,022,649 | <p>I was reading about the <a href="http://en.wikipedia.org/wiki/Slope%5FOne#Slope%5Fone%5Fcollaborative%5Ffiltering%5Ffor%5Frated%5Fresources">Weighted slope one algorithm</a> ( and more
formally <a href="http://www.daniel-lemire.com/fr/documents/publications/lemiremaclachlan%5Fsdm05.pdf">here (PDF)</a>) which is supp... | 7 | 2009-06-20T21:53:56Z | 1,054,561 | <p>I used the same reference (Bryan O'Sullivan's python code) to write an R version of Slope One a while back. I'm pasting the code below in case it helps.</p>
<pre><code>predict <- function(userprefs, data.freqs, data.diffs) {
seen <- names(userprefs)
preds <- sweep(data.diffs[ , seen, drop=FALSE],... | 9 | 2009-06-28T08:57:29Z | [
"python",
"prediction",
"recommendation-engine"
] |
How can I pass the environment from my Python web application to a Perl program? | 1,022,694 | <p>How do I set Perl's %ENV to introduce a Perl script into the context of my web application?</p>
<p>I have a website, written in a language different from Perl (Python). However I need to use a Perl application, which consists of a .pl file:</p>
<pre><code> #!/usr/bin/env perl
"$ENV{DOCUMENT_ROOT}/foo/bar.pm... | 1 | 2009-06-20T22:19:43Z | 1,022,711 | <p>Perl's special <code>%ENV</code> hash is the interface to the environment. (Under the hood, it calls <code>getenv</code> and <code>putenv</code> as appropriate.)</p>
<p>For example:</p>
<pre><code>$ cat run.sh
#! /bin/bash
export REMOTE_ADDR=127.0.0.1
perl -le 'print $ENV{REMOTE_ADDR}'
$ ./run.sh
127.0.0.1
</... | 2 | 2009-06-20T22:30:14Z | [
"python",
"perl",
"environment"
] |
How can I pass the environment from my Python web application to a Perl program? | 1,022,694 | <p>How do I set Perl's %ENV to introduce a Perl script into the context of my web application?</p>
<p>I have a website, written in a language different from Perl (Python). However I need to use a Perl application, which consists of a .pl file:</p>
<pre><code> #!/usr/bin/env perl
"$ENV{DOCUMENT_ROOT}/foo/bar.pm... | 1 | 2009-06-20T22:19:43Z | 1,022,793 | <p>If you're spawning that Perl process from your Python code (as opposed to "directly from the webserver"), there are several ways to set the child process environment from the Python parent process environment, depending on what you're using for the "spawning".</p>
<p>For example, if you're using <code>subprocess.Po... | 4 | 2009-06-20T23:29:10Z | [
"python",
"perl",
"environment"
] |
Deploying Django | 1,022,914 | <p>When finding web hosting for Rails apps, the hoster must have support for ruby on rails -- that is evident. What about hosting for Django? What support does the hoster need to provide? Python, or more than just Python?</p>
<p>This might seem like an obvious question, but I'm new to web development frameworks so ... | 2 | 2009-06-21T01:00:04Z | 1,022,921 | <p>It just needs to support Python 2.3 or later (but not 3.0, yet), preferably with <code>mod_wsgi</code> support (although it also works with <a href="http://code.djangoproject.com/wiki/ServerArrangements">a bunch of other options</a>, if required).</p>
| 6 | 2009-06-21T01:04:55Z | [
"python",
"ruby-on-rails",
"django"
] |
Deploying Django | 1,022,914 | <p>When finding web hosting for Rails apps, the hoster must have support for ruby on rails -- that is evident. What about hosting for Django? What support does the hoster need to provide? Python, or more than just Python?</p>
<p>This might seem like an obvious question, but I'm new to web development frameworks so ... | 2 | 2009-06-21T01:00:04Z | 1,022,932 | <p>Python is all that is needed.</p>
<p>I think there is a cPanel plugin which allows your users to create and deploy Django applications, so if you have a VPS or Reseller account, or your host is running cPanel, you could simply tell them to install it. If I find the link to the plugin I will post it here.</p>
| 2 | 2009-06-21T01:10:17Z | [
"python",
"ruby-on-rails",
"django"
] |
Deploying Django | 1,022,914 | <p>When finding web hosting for Rails apps, the hoster must have support for ruby on rails -- that is evident. What about hosting for Django? What support does the hoster need to provide? Python, or more than just Python?</p>
<p>This might seem like an obvious question, but I'm new to web development frameworks so ... | 2 | 2009-06-21T01:00:04Z | 1,023,270 | <p>Technically, as other responders say, the host needs very little (hey, Django even runs with Google app engine for all the latter's limitations!-). But if you want a little bit more (as in, say, <em>support</em> for any issues you might encounter!), I suggest you read <a href="http://djangohosting.org/" rel="nofoll... | 3 | 2009-06-21T05:22:15Z | [
"python",
"ruby-on-rails",
"django"
] |
Deploying Django | 1,022,914 | <p>When finding web hosting for Rails apps, the hoster must have support for ruby on rails -- that is evident. What about hosting for Django? What support does the hoster need to provide? Python, or more than just Python?</p>
<p>This might seem like an obvious question, but I'm new to web development frameworks so ... | 2 | 2009-06-21T01:00:04Z | 1,027,937 | <p>Other responses have covered the technical question, but it should also be mentioned that <a href="http://djangofriendly.com" rel="nofollow">djangofriendly.com</a> is an invaluable resource for selecting a Django web host.</p>
| 3 | 2009-06-22T15:47:24Z | [
"python",
"ruby-on-rails",
"django"
] |
Deploying Django | 1,022,914 | <p>When finding web hosting for Rails apps, the hoster must have support for ruby on rails -- that is evident. What about hosting for Django? What support does the hoster need to provide? Python, or more than just Python?</p>
<p>This might seem like an obvious question, but I'm new to web development frameworks so ... | 2 | 2009-06-21T01:00:04Z | 1,857,390 | <p>Well, Python is <strong>not</strong> the <em>only</em> thing need <strong>if you run a dedicated server</strong>.</p>
<p>You need(please correct me if I'm missing something):</p>
<ul>
<li>A webserver which will communicate
with your Django web application,
e.g.: Apache with mod_wsgi.</li>
<li>A database interface,... | 0 | 2009-12-07T02:06:17Z | [
"python",
"ruby-on-rails",
"django"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,023,009 | <p>I almost exclusively use Python to support my development of software in other languages. I should stress, this is not a result of some failing in Python, rather that the software domains I am working in tend to have other languages/frameworks that are more appropriate or simply the only option:</p>
<ul>
<li>Web D... | 3 | 2009-06-21T02:16:06Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,023,054 | <p>JavaScript and Python have affected how I program even in C now. I think the best thing about knowing multiple languages is that you get more tools to use mentally, because you often don't have a choice of which language to use.</p>
| 2 | 2009-06-21T02:34:20Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,023,110 | <p>My motto is (and has long been) "Python where I can, C++ where I must" (one day I'll find opportunity to actually use Java, C#, &c &C, in a real-world project, but I haven't yet, except for a pilot project in Java 1.1, more tha ten years ago...;-) -- Javascript (with dojo) when code has to run in the client'... | 10 | 2009-06-21T03:16:41Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,023,383 | <p>Python is much more strictly OO than Java and C#.</p>
<p>But if your question is when to use Python and when Java or C#, I find Python useful for small programs that build on existing libraries and don't involve much domain modelling. For example, little desktop utilities written with the Python Gtk bindings or web... | 1 | 2009-06-21T07:33:07Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,023,545 | <p>Both C and python are my languages of choice, but I almost always start doing something in python for correctness, and then dive into C when needed. I am mostly using programming for research/numerical code, where the specifications keep changing, and C is an awful language for prototyping (this is true for most sta... | 0 | 2009-06-21T09:45:41Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,023,659 | <p>Generally the language is dictated by the job, who wants the stuff done and who you are working with. I only use java and c/c++ for my programming needs, mainly because the people i work with use it. That being said ive used python for fast prototyping and such.</p>
| 0 | 2009-06-21T10:59:39Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,024,405 | <p>I select Python as often as possible. It is the most useful and productive programming environment that I know of.</p>
<p>If I run into projects where Python cannot be used directly or for the entire project (for instance a .NET-based app. server) my approach is usually to do as much with Python as possible. Depend... | 4 | 2009-06-21T17:49:01Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
What classes of applications or problems do you prefer Python to strictly OO Languages? | 1,022,971 | <p>I've got a pretty strong background in C-style languages. And have worked on several different types of projects. I have just started taking a serious look at Python after reading <a href="http://oreilly.com/catalog/9780596529321/" rel="nofollow">Programming Collective Intelligence</a>. I understand that Python c... | 4 | 2009-06-21T01:50:07Z | 1,352,569 | <p><strong>All</strong> of them. </p>
<p>Except for code that is already written in different language, obviously.</p>
<p>Even if something seems too big for python to handle, I usually make Python prototype anyway, mainly because it's goes so smooth. Often I'll stick with Python eitherway and just use C API or ctype... | 0 | 2009-08-29T22:42:47Z | [
"c#",
"java",
"c++",
"python",
"programming-languages"
] |
Change process priority in Python, cross-platform | 1,023,038 | <p>I've got a Python program that does time-consuming computations. Since it uses high CPU, and I want my system to remain responsive, I'd like the program to change its priority to below-normal.</p>
<p>I found this:
<a href="http://code.activestate.com/recipes/496767/">Set Process Priority In Windows - ActiveState</a... | 17 | 2009-06-21T02:27:19Z | 1,023,088 | <p>On every Unix-like platform (including Linux and MacOsX), see <code>os.nice</code> <a href="http://docs.python.org/library/os.html">here</a>:</p>
<pre><code>os.nice(increment)
Add increment to the processâs ânicenessâ. Return the new niceness. Availability: Unix.
</code></pre>
<p>Since you already have a rec... | 9 | 2009-06-21T03:01:50Z | [
"python"
] |
Change process priority in Python, cross-platform | 1,023,038 | <p>I've got a Python program that does time-consuming computations. Since it uses high CPU, and I want my system to remain responsive, I'd like the program to change its priority to below-normal.</p>
<p>I found this:
<a href="http://code.activestate.com/recipes/496767/">Set Process Priority In Windows - ActiveState</a... | 17 | 2009-06-21T02:27:19Z | 1,023,269 | <p>Here's the solution I'm using to set my process to below-normal priority:</p>
<p><strong><code>lowpriority.py</code></strong></p>
<pre><code>def lowpriority():
""" Set the priority of the process to below-normal."""
import sys
try:
sys.getwindowsversion()
except:
isWindows = False
... | 24 | 2009-06-21T05:21:37Z | [
"python"
] |
Change process priority in Python, cross-platform | 1,023,038 | <p>I've got a Python program that does time-consuming computations. Since it uses high CPU, and I want my system to remain responsive, I'd like the program to change its priority to below-normal.</p>
<p>I found this:
<a href="http://code.activestate.com/recipes/496767/">Set Process Priority In Windows - ActiveState</a... | 17 | 2009-06-21T02:27:19Z | 6,245,096 | <p>You can use <a href="http://code.google.com/p/psutil/wiki/Documentation" rel="nofollow">psutil</a> module.</p>
<p>On POSIX platforms:</p>
<pre><code>>>> import psutil, os
>>> p = psutil.Process(os.getpid())
>>> p.nice()
0
>>> p.nice(10) # set
>>> p.nice()
10
</code></p... | 12 | 2011-06-05T18:56:37Z | [
"python"
] |
Connecting C# (frontend) to an apache/php/python (backend) | 1,023,187 | <p><strong>Overview:</strong> We are looking to write a C# user interface to select parts of our web applications. This is for a very captive audience (internally, for example).</p>
<p>Our web applications are written in PHP and/or Python using Apache as the web server.</p>
<p><sup>Why? A well thought out native Wi... | 1 | 2009-06-21T04:17:05Z | 1,023,201 | <p>Using web services sounds like the most appropriate way for your scenario.</p>
| 0 | 2009-06-21T04:28:12Z | [
"c#",
"php",
"python",
"web-applications",
"data-structures"
] |
Connecting C# (frontend) to an apache/php/python (backend) | 1,023,187 | <p><strong>Overview:</strong> We are looking to write a C# user interface to select parts of our web applications. This is for a very captive audience (internally, for example).</p>
<p>Our web applications are written in PHP and/or Python using Apache as the web server.</p>
<p><sup>Why? A well thought out native Wi... | 1 | 2009-06-21T04:17:05Z | 1,023,220 | <p>I have no real experience with PHP, but I've done plenty of Python back-end web services consumed by front-end clients in a variety of languages and environment. SOAP is the only technology, out of those I've tried, that has mostly left a sour taste in my mouth -- too much "ceremony"/overhead. (Back in the far past ... | 4 | 2009-06-21T04:44:50Z | [
"c#",
"php",
"python",
"web-applications",
"data-structures"
] |
Connecting C# (frontend) to an apache/php/python (backend) | 1,023,187 | <p><strong>Overview:</strong> We are looking to write a C# user interface to select parts of our web applications. This is for a very captive audience (internally, for example).</p>
<p>Our web applications are written in PHP and/or Python using Apache as the web server.</p>
<p><sup>Why? A well thought out native Wi... | 1 | 2009-06-21T04:17:05Z | 1,023,436 | <p>I have done this using a PHP SOAP Server and VB.Net client. Once you connect the VB.Net/C# client to the server (the location of the WSDL file) C# will automatically detect all the functions and all the objects that are exposed. Making programming much easier.</p>
<p>I would also recommend using NuSOAP which I foun... | 0 | 2009-06-21T08:25:45Z | [
"c#",
"php",
"python",
"web-applications",
"data-structures"
] |
Connecting C# (frontend) to an apache/php/python (backend) | 1,023,187 | <p><strong>Overview:</strong> We are looking to write a C# user interface to select parts of our web applications. This is for a very captive audience (internally, for example).</p>
<p>Our web applications are written in PHP and/or Python using Apache as the web server.</p>
<p><sup>Why? A well thought out native Wi... | 1 | 2009-06-21T04:17:05Z | 1,162,990 | <p>I recommend the PHP/Java Bridge. Don't let the name fool you. This can be used to connect both PHP and Python to any ECMA-335 virtual machine (Java and C#)!</p>
<p><a href="http://php-java-bridge.sourceforge.net/pjb/" rel="nofollow">http://php-java-bridge.sourceforge.net/pjb/</a></p>
<p>To answer your comment:</p>... | 0 | 2009-07-22T03:58:52Z | [
"c#",
"php",
"python",
"web-applications",
"data-structures"
] |
How to pickle a CookieJar? | 1,023,224 | <p>I have an object with a CookieJar that I want to pickle. </p>
<p>However as you all probably know, pickle chokes on objects that contain lock objects. And for some horrible reason, a CookieJar has a lock object.</p>
<pre><code>from cPickle import dumps
from cookielib import CookieJar
class Person(object):
def... | 8 | 2009-06-21T04:46:07Z | 1,023,235 | <p><code>CookieJar</code> is not particularly well-designed for persisting (that's what the <code>FileCookieJar</code> subclasses are mostly about!-), but you can iterate over a <code>CookieJar</code> instance to get all cookies (and persist a list of those, for example), and, to rebuild the jar given the cookies, use ... | 6 | 2009-06-21T04:56:19Z | [
"python",
"persistence",
"pickle",
"cookiejar",
"cookielib"
] |
How to pickle a CookieJar? | 1,023,224 | <p>I have an object with a CookieJar that I want to pickle. </p>
<p>However as you all probably know, pickle chokes on objects that contain lock objects. And for some horrible reason, a CookieJar has a lock object.</p>
<pre><code>from cPickle import dumps
from cookielib import CookieJar
class Person(object):
def... | 8 | 2009-06-21T04:46:07Z | 1,023,245 | <p>Here is an attempt, by deriving a class from CookieJar, which override getstate/setstate used by pickle. I haven't used cookieJar, so don't know if it is usable but you can dump derived class</p>
<pre><code>from cPickle import dumps
from cookielib import CookieJar
import threading
class MyCookieJar(CookieJar):
... | 9 | 2009-06-21T05:01:30Z | [
"python",
"persistence",
"pickle",
"cookiejar",
"cookielib"
] |
Why does mass importing not work but importing definition individually works? | 1,023,326 | <p>So I just met a strange so-called bug. Because this work on my other .py files, but just on this file it suddenly stopped working.</p>
<pre><code>from tuttobelo.management.models import *
</code></pre>
<p>The above used to work, but it stopped working all of a sudden, and I had to replace it with the bottom.</p>
... | 2 | 2009-06-21T06:33:41Z | 1,023,344 | <p>Maybe the <code>models</code> module has an <code>__all__</code> which does not include what you're looking for. Anyway, <code>from ... import *</code> is <strong>never</strong> a good idea in production code -- we always meant the <code>import *</code> feature for interactive exploratory use, <em>not</em> productio... | 4 | 2009-06-21T07:02:51Z | [
"python",
"django"
] |
Why does mass importing not work but importing definition individually works? | 1,023,326 | <p>So I just met a strange so-called bug. Because this work on my other .py files, but just on this file it suddenly stopped working.</p>
<pre><code>from tuttobelo.management.models import *
</code></pre>
<p>The above used to work, but it stopped working all of a sudden, and I had to replace it with the bottom.</p>
... | 2 | 2009-06-21T06:33:41Z | 1,023,836 | <p>There are some cases in Python where importing with * will not yield anything. In your example, if tuttobelo.management.models is a package (i.e. a directory with an <code>__init__.py</code>) with the files Preferences.py, ProductVariant.py, etc in it, importing with star will not work, unless you already have impor... | 1 | 2009-06-21T12:56:27Z | [
"python",
"django"
] |
working with django and sqlalchemy but backend mysql | 1,023,417 | <p>i am working with python django framework but in model part is sqlalchemy and back end data base is mysql how i will configure them?</p>
| 1 | 2009-06-21T08:09:55Z | 1,023,490 | <p>See <a href="http://docs.djangoproject.com/en/dev/topics/install/#database-installation" rel="nofollow">Django database installation</a>,</p>
<blockquote>
<p>If youâre using MySQL, youâll need MySQLdb, version 1.2.1p2 or higher. You will also want to read the database-specific notes for the MySQL backend.</p>... | 0 | 2009-06-21T09:09:24Z | [
"python",
"mysql",
"django",
"sqlalchemy"
] |
working with django and sqlalchemy but backend mysql | 1,023,417 | <p>i am working with python django framework but in model part is sqlalchemy and back end data base is mysql how i will configure them?</p>
| 1 | 2009-06-21T08:09:55Z | 1,023,828 | <p>Some links that might help you:</p>
<blockquote>
<p><a href="http://lethain.com/entry/2008/jul/23/replacing-django-s-orm-with-sqlalchemy/" rel="nofollow">http://lethain.com/entry/2008/jul/23/replacing-django-s-orm-with-sqlalchemy/</a></p>
<p><a href="http://code.google.com/p/django-sqlalchemy/" rel="nofollow... | 1 | 2009-06-21T12:52:13Z | [
"python",
"mysql",
"django",
"sqlalchemy"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,023,740 | <p>what about something like this, keep storing values till time difference with last time is > 100, average and yield such values
e.g.</p>
<pre><code>def getAvgValues(data):
lastTime = 0
prevValues = []
avgSampleTime=100
for t, v in data:
if t - lastTime < avgSampleTime:
prevVa... | -1 | 2009-06-21T11:50:55Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,023,819 | <p>You haven't said exactly when you want output. I'm assuming that you want one smoothed reading for each raw reading, and the smoothed reading is to be the arithmetic mean of the raw reading and any others in the previous 100 (delta) seconds.</p>
<p>Short answer: use a collections.deque ... it will never hold more t... | 2 | 2009-06-21T12:48:04Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,023,823 | <p>Your data seems to be roughly linear:</p>
<p><img src="http://rix0r.nl/~rix0r/share/shot-20090621.144851.gif" alt="Plot of your data" /></p>
<p>What kind of smoothing are you looking for? A least squares fit of a line to this data set? Some sort of low-pass filter? Or something else?</p>
<p>Please tell us the app... | 0 | 2009-06-21T12:50:36Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,023,872 | <p>I'm using a sum result to which I'm adding the new members and subtracting the old ones. However in this way one may suffer accumulating floating point inaccuracies.</p>
<p>Therefore I implement a "Deque" with a list. And whenever my Deque reallocates to a smaller size. I recalculate the sum at the same occasion.</... | 2 | 2009-06-21T13:17:51Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,023,969 | <p>This one makes it linear:</p>
<pre><code>def process_data(datafile):
previous_n = 0
previous_t = 0
for line in datafile:
t, number = line.strip().split()
t = int(t)
number = float(number)
delta_n = number - previous_n
delta_t = t - previous_t
n_per_t = del... | 0 | 2009-06-21T14:02:32Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,023,994 | <p>Sounds like you need a simple rounding formula. To round any number to an arbitrary interval:</p>
<p>round(num/interval)*interval</p>
<p>You can substitute round with floor or ceiling for "leading up to" or "since" affects. It can work in any language, including SQL. </p>
| -2 | 2009-06-21T14:13:38Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,024,066 | <p>O(1) memory in case you can iterate the input more than once - you can use one iterator for the "left" and one for the "right".</p>
<pre><code>def getAvgValues(makeIter, avgSampleTime):
leftIter = makeIter()
leftT, leftV = leftIter.next()
tot = 0
count = 0
for rightT, rightV in makeIter():
tot += righ... | 0 | 2009-06-21T14:46:42Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
smoothing irregularly sampled time data | 1,023,719 | <p>Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement:</p>
<pre><code>6 0.738158581
21 0.801697222
39 1.797224596
49 2.77920469
54 2.839757536
79 3.832232283
91 4.676794376
97 5.18244704
100 5.521878863
118 6.316630137
131 6.778507504
147 7.020... | 5 | 2009-06-21T11:36:57Z | 1,030,120 | <p>While it gives an exponentially decaying average, rather than a total average, I think you may want what I called an <a href="http://stackoverflow.com/questions/1023860/exponential-moving-average-sampled-at-varying-times">exponential moving average with varying alpha</a>, which is really a single-pole low-pass filte... | 0 | 2009-06-23T00:51:54Z | [
"python",
"datetime",
"data-mining",
"smoothing"
] |
How can I have variable assertions in Perl? | 1,023,813 | <p>How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables?</p>
<p>I wonder if I can use the Pythonic practice of inserting:</p>
<pre><code> assert 0, (foo, bar)
</code></pre>
<p>to debug scripts in a debuger-less way?</p>
| 6 | 2009-06-21T12:45:21Z | 1,023,831 | <p>There is a script at <a href="http://www.perlmonks.org/?node%5Fid=391780" rel="nofollow">PerlMonks</a> that introduces a fast assert method.</p>
<p>Speed is important since Perl is interpreted and any inline checks will impact performance (unlike simple C macros for example)</p>
<p><hr /></p>
<p>I am not sure if ... | 2 | 2009-06-21T12:54:23Z | [
"python",
"perl",
"debugging",
"assertions"
] |
How can I have variable assertions in Perl? | 1,023,813 | <p>How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables?</p>
<p>I wonder if I can use the Pythonic practice of inserting:</p>
<pre><code> assert 0, (foo, bar)
</code></pre>
<p>to debug scripts in a debuger-less way?</p>
| 6 | 2009-06-21T12:45:21Z | 1,023,839 | <p>A quick CPAN search suggests <a href="http://search.cpan.org/perldoc?Carp::Assert">Carp::Assert</a>.</p>
| 10 | 2009-06-21T12:58:04Z | [
"python",
"perl",
"debugging",
"assertions"
] |
How can I have variable assertions in Perl? | 1,023,813 | <p>How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables?</p>
<p>I wonder if I can use the Pythonic practice of inserting:</p>
<pre><code> assert 0, (foo, bar)
</code></pre>
<p>to debug scripts in a debuger-less way?</p>
| 6 | 2009-06-21T12:45:21Z | 1,023,840 | <p>See <a href="http://search.cpan.org/perldoc?Carp::Assert">Carp::Assert</a>.</p>
| 5 | 2009-06-21T12:58:05Z | [
"python",
"perl",
"debugging",
"assertions"
] |
How can I have variable assertions in Perl? | 1,023,813 | <p>How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables?</p>
<p>I wonder if I can use the Pythonic practice of inserting:</p>
<pre><code> assert 0, (foo, bar)
</code></pre>
<p>to debug scripts in a debuger-less way?</p>
| 6 | 2009-06-21T12:45:21Z | 1,023,925 | <p><a href="http://search.cpan.org/perldoc?Smart::Comments">Smart::Comments</a> are nice.</p>
| 5 | 2009-06-21T13:44:06Z | [
"python",
"perl",
"debugging",
"assertions"
] |
How can I have variable assertions in Perl? | 1,023,813 | <p>How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables?</p>
<p>I wonder if I can use the Pythonic practice of inserting:</p>
<pre><code> assert 0, (foo, bar)
</code></pre>
<p>to debug scripts in a debuger-less way?</p>
| 6 | 2009-06-21T12:45:21Z | 1,023,941 | <pre><code>$var_to_check =~ /sometest/ or die "bad variable!";
</code></pre>
<p>I tend to throw things like this in my code, and later use a find and replace to get rid of them (in production code).</p>
<p>Also, '<a href="http://perldoc.perl.org/functions/eval.html" rel="nofollow">eval</a>' can be used to run a secti... | 1 | 2009-06-21T13:51:18Z | [
"python",
"perl",
"debugging",
"assertions"
] |
How can I have variable assertions in Perl? | 1,023,813 | <p>How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables?</p>
<p>I wonder if I can use the Pythonic practice of inserting:</p>
<pre><code> assert 0, (foo, bar)
</code></pre>
<p>to debug scripts in a debuger-less way?</p>
| 6 | 2009-06-21T12:45:21Z | 9,707,289 | <pre><code>if ( $next_sunrise_time > 24*60*60 ) { warn( "assertion failed" ); } # Assert that the sun must rise in the next 24 hours.
</code></pre>
<p>You can do this if you do not have access to Perl 5.9 which is required for <a href="http://search.cpan.org/perldoc?Carp%3a%3aAssert" rel="nofollow">Carp::Assert</a>... | 0 | 2012-03-14T17:50:37Z | [
"python",
"perl",
"debugging",
"assertions"
] |
It is possible to match a character repetition with regex? How? | 1,023,902 | <p><strong>Question:</strong><br />
Is is possible, with regex, to match a word that contains the same character in different positions?</p>
<p><strong>Condition:</strong><br />
All words have the same length, you know the character positions (example the 1st, the 2nd and the 4th) of the repeated char, but you don't k... | 5 | 2009-06-21T13:33:53Z | 1,023,909 | <p>You can use a backreference to do this:</p>
<pre><code>(.)\1
</code></pre>
<p>This will match consecutive occurrences of any character.</p>
<p><hr /></p>
<p><strong>Edit</strong>Â Â Â Hereâs some Python example:</p>
<pre><code>import re
regexp = re.compile(r"(.)\1")
data = ["parrot","follia","carrot","mattia... | 22 | 2009-06-21T13:38:33Z | [
"python",
"regex"
] |
It is possible to match a character repetition with regex? How? | 1,023,902 | <p><strong>Question:</strong><br />
Is is possible, with regex, to match a word that contains the same character in different positions?</p>
<p><strong>Condition:</strong><br />
All words have the same length, you know the character positions (example the 1st, the 2nd and the 4th) of the repeated char, but you don't k... | 5 | 2009-06-21T13:33:53Z | 1,023,920 | <p><code>/(\b\w*?(\w)\2.*?\b)/</code></p>
<p>will match any word with atleast on character repetition
$1 being the word
$2 the first repetition.</p>
| 2 | 2009-06-21T13:42:34Z | [
"python",
"regex"
] |
It is possible to match a character repetition with regex? How? | 1,023,902 | <p><strong>Question:</strong><br />
Is is possible, with regex, to match a word that contains the same character in different positions?</p>
<p><strong>Condition:</strong><br />
All words have the same length, you know the character positions (example the 1st, the 2nd and the 4th) of the repeated char, but you don't k... | 5 | 2009-06-21T13:33:53Z | 1,023,922 | <p>You need to use back references for such cases. I am not sure which language you are using, I tried the following example in my VI editor to search for any alphabet repeating.
<strong>Pattern Regex:</strong> <code>\([a-z]\)\1</code> </p>
<p>If you see the example, [a-z] is the pattern you are searching for, and ... | 6 | 2009-06-21T13:42:59Z | [
"python",
"regex"
] |
It is possible to match a character repetition with regex? How? | 1,023,902 | <p><strong>Question:</strong><br />
Is is possible, with regex, to match a word that contains the same character in different positions?</p>
<p><strong>Condition:</strong><br />
All words have the same length, you know the character positions (example the 1st, the 2nd and the 4th) of the repeated char, but you don't k... | 5 | 2009-06-21T13:33:53Z | 1,024,178 | <p>Yes, you can use backreference construct to match the double letters.</p>
<p>The regular expression <code>(?<char>\w)\k<char></code>, using named groups and backreferencing, searches for adjacent paired characters. When applied to the string "I'll have a small coffee," it finds matches in the words "I'l... | 0 | 2009-06-21T15:43:40Z | [
"python",
"regex"
] |
Is it pythonic to import inside functions? | 1,024,049 | <p><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> says:</p>
<blockquote>
<ul>
<li>Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.</li>
</ul>
</blockquote>
<p>On occation, I violate PEP 8. Some times I import s... | 41 | 2009-06-21T14:41:00Z | 1,024,058 | <p>As long as it's <code>import</code> and not <code>from x import *</code>, you should put them at the top. It adds just one name to the global namespace, and you stick to PEP 8. Plus, if you later need it somewhere else, you don't have to move anything around.</p>
<p>It's no big deal, but since there's almost no dif... | 2 | 2009-06-21T14:44:43Z | [
"python",
"conventions"
] |
Is it pythonic to import inside functions? | 1,024,049 | <p><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> says:</p>
<blockquote>
<ul>
<li>Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.</li>
</ul>
</blockquote>
<p>On occation, I violate PEP 8. Some times I import s... | 41 | 2009-06-21T14:41:00Z | 1,024,087 | <p>There are two occasions where I violate PEP 8 in this regard:</p>
<ul>
<li>Circular imports: module A imports module B, but something in module B needs module A (though this is often a sign that I need to refactor the modules to eliminate the circular dependency)</li>
<li>Inserting a pdb breakpoint: <code>import pd... | 19 | 2009-06-21T14:53:55Z | [
"python",
"conventions"
] |
Is it pythonic to import inside functions? | 1,024,049 | <p><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> says:</p>
<blockquote>
<ul>
<li>Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.</li>
</ul>
</blockquote>
<p>On occation, I violate PEP 8. Some times I import s... | 41 | 2009-06-21T14:41:00Z | 1,024,117 | <p>One thing to bear in mind: needless imports can cause performance problems. So if this is a function that will be called frequently, you're better off just putting the import at the top. Of course this <em>is</em> an optimization, so if there's a valid case to be made that importing inside a function is more clea... | 6 | 2009-06-21T15:08:40Z | [
"python",
"conventions"
] |
Is it pythonic to import inside functions? | 1,024,049 | <p><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> says:</p>
<blockquote>
<ul>
<li>Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.</li>
</ul>
</blockquote>
<p>On occation, I violate PEP 8. Some times I import s... | 41 | 2009-06-21T14:41:00Z | 1,024,120 | <p>I've broken this rule before for modules that are self-testing. That is, they are normally just used for support, but I define a main for them so that if you run them by themselves you can test their functionality. In that case I sometimes import <code>getopt</code> and <code>cmd</code> just in main, because I wa... | 5 | 2009-06-21T15:10:58Z | [
"python",
"conventions"
] |
Is it pythonic to import inside functions? | 1,024,049 | <p><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> says:</p>
<blockquote>
<ul>
<li>Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.</li>
</ul>
</blockquote>
<p>On occation, I violate PEP 8. Some times I import s... | 41 | 2009-06-21T14:41:00Z | 1,024,139 | <p>Here are the four import use cases that we use</p>
<ol>
<li><p><code>import</code> (and <code>from x import y</code> and <code>import x as y</code>) at the top</p></li>
<li><p>Choices for Import. At the top.</p>
<pre><code>import settings
if setting.something:
import this as foo
else:
import that as foo
<... | 11 | 2009-06-21T15:20:52Z | [
"python",
"conventions"
] |
Is it pythonic to import inside functions? | 1,024,049 | <p><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> says:</p>
<blockquote>
<ul>
<li>Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.</li>
</ul>
</blockquote>
<p>On occation, I violate PEP 8. Some times I import s... | 41 | 2009-06-21T14:41:00Z | 1,025,259 | <p>In the long run I think you'll appreciate having most of your imports at the top of the file, that way you can tell at a glance how complicated your module is by what it needs to import.</p>
<p>If I'm adding new code to an existing file I'll usually do the import where it's needed and then if the code stays I'll ma... | 31 | 2009-06-22T02:05:00Z | [
"python",
"conventions"
] |
What's a good beginner setup for C++/Python on OSX? | 1,024,062 | <p>I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was think... | 4 | 2009-06-21T14:45:46Z | 1,024,089 | <p>I'd definitely go GTK+. It is very easy. I'm not sure about graphics libraries on OS X. I know OS X primarily uses Objective-C, but if the native graphics library can be used from C++, use that for game graphics.</p>
<p>As far as IDEs, I don't know. I use GNU Emacs, but I wouldn't recommend that to a beginner. Lear... | 0 | 2009-06-21T14:54:04Z | [
"c++",
"python",
"osx",
"ide"
] |
What's a good beginner setup for C++/Python on OSX? | 1,024,062 | <p>I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was think... | 4 | 2009-06-21T14:45:46Z | 1,024,104 | <p>You can use VIM with cscope and ctags plugins for C++, I personally find that to be the fastest. Eclipse for C++ is also good if you need a gui, but it is not as feature rich as it is for Java but it is a good open source IDE. </p>
<p>In terms of books, Effective C++ and More Effective C++ are good.</p>
| 0 | 2009-06-21T15:00:54Z | [
"c++",
"python",
"osx",
"ide"
] |
What's a good beginner setup for C++/Python on OSX? | 1,024,062 | <p>I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was think... | 4 | 2009-06-21T14:45:46Z | 1,024,118 | <blockquote>
<p>As I'm going use C++ I don't
want to use XCode, as (I understand)
this is primarily used with
Objective-C.</p>
</blockquote>
<p>XCode is a fine choice, even for pure C++ solutions.</p>
<blockquote>
<p>Work through Accelerated C++.</p>
</blockquote>
<p>That's the book that got me started! It... | 3 | 2009-06-21T15:10:17Z | [
"c++",
"python",
"osx",
"ide"
] |
What's a good beginner setup for C++/Python on OSX? | 1,024,062 | <p>I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was think... | 4 | 2009-06-21T14:45:46Z | 1,024,141 | <p>XCode is a mature IDE well suited to almost any language. C++ is particularly well supported. </p>
<p>Apparently GTK+ has <a href="http://gtk-osx.sourceforge.net/" rel="nofollow">native OSX widget support</a>, though I've never used it, so you could skip the X11 stack altogether if you desired. Other cross platf... | 2 | 2009-06-21T15:22:29Z | [
"c++",
"python",
"osx",
"ide"
] |
What's a good beginner setup for C++/Python on OSX? | 1,024,062 | <p>I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was think... | 4 | 2009-06-21T14:45:46Z | 1,024,162 | <blockquote>
<ol>
<li>Work through Accelerated C++.</li>
<li>Write a couple of small math-programs; something like the
Mandelbrot set, a PDE-solver, or a
graphing-app. This would be done using
a widget toolkit.</li>
<li>Write a small game with really crappy graphics. This is probably
going to be a rip-o... | 0 | 2009-06-21T15:33:40Z | [
"c++",
"python",
"osx",
"ide"
] |
What's a good beginner setup for C++/Python on OSX? | 1,024,062 | <p>I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was think... | 4 | 2009-06-21T14:45:46Z | 1,024,165 | <p>When choosing an IDE, it's very much a matter of taste, so the best choice is probably to try out several for a day or two each. Eclipse and XCode are both popular choices that surely are excellent in their own ways. I can't help you with the widgets, as I know very little about that. GTK+ is a popular framework, bu... | 1 | 2009-06-21T15:36:08Z | [
"c++",
"python",
"osx",
"ide"
] |
What's a good beginner setup for C++/Python on OSX? | 1,024,062 | <p>I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was think... | 4 | 2009-06-21T14:45:46Z | 1,024,205 | <p><a href="http://www.netbeans.org/features/cpp/index.html" rel="nofollow">NetBeans</a> is another choice. Although both Python and C++ support are rather new for it. The Python works find, but I haven't tried the C support.</p>
| 0 | 2009-06-21T15:57:02Z | [
"c++",
"python",
"osx",
"ide"
] |
How to stop Python parse_qs from parsing single values into lists? | 1,024,143 | <p>In python 2.6, the following code:</p>
<pre><code>import urlparse
qsdata = "test=test&test2=test2&test2=test3"
qs = urlparse.parse_qs(qsdata)
print qs
</code></pre>
<p>Gives the following output:</p>
<pre><code>{'test': ['test'], 'test2': ['test2', 'test3']}
</code></pre>
<p>Which means that even though ... | 22 | 2009-06-21T15:23:35Z | 1,024,164 | <p>You could fix it afterwards...</p>
<pre><code>import urlparse
qsdata = "test=test&test2=test2&test2=test3"
qs = dict( (k, v if len(v)>1 else v[0] )
for k, v in urlparse.parse_qs(qsdata).iteritems() )
print qs
</code></pre>
<p>However, I don't think <em>I</em> would want this. If a parameter... | 21 | 2009-06-21T15:35:11Z | [
"python",
"python-2.6"
] |
How to stop Python parse_qs from parsing single values into lists? | 1,024,143 | <p>In python 2.6, the following code:</p>
<pre><code>import urlparse
qsdata = "test=test&test2=test2&test2=test3"
qs = urlparse.parse_qs(qsdata)
print qs
</code></pre>
<p>Gives the following output:</p>
<pre><code>{'test': ['test'], 'test2': ['test2', 'test3']}
</code></pre>
<p>Which means that even though ... | 22 | 2009-06-21T15:23:35Z | 8,239,167 | <p>A sidenote for someone just wanting a simple dictionary and never needing multiple values with the same key, try:</p>
<pre><code>dict(urlparse.parse_qsl('foo=bar&baz=qux'))
</code></pre>
<p>This will give you a nice <code>{'foo': 'bar', 'baz': 'qux'}</code>. Please note that if there <em>are</em> multiple valu... | 72 | 2011-11-23T08:35:34Z | [
"python",
"python-2.6"
] |
Looping Fget with fsockopen in PHP 5.x | 1,024,370 | <p>I have a Python Server finally working and responding to multiple command's with the output's, however I'm now having problem's with PHP receiving the full output. I have tried commands such as fgets, fread, the only command that seems to work is "fgets".</p>
<p>However this only recieve's on line of data, I then c... | 3 | 2009-06-21T17:31:28Z | 1,024,459 | <p>I believe you need to fix your server code a bit. I have removed the inner while loop. The problem with your code was that the server never closed the connection, so <code>feof</code> never returned true.</p>
<p>I also removed the <code>+ " &"</code> bit. To get the output, you need to wait until the process en... | 1 | 2009-06-21T18:19:09Z | [
"php",
"python",
"sockets",
"tcp",
"fgets"
] |
Can python doctest ignore some output lines? | 1,024,411 | <p>I'd like to write a doctest like this:</p>
<pre><code>"""
>>> print a.string()
foo : a
bar : b
date : <I don't care about the date output>
baz : c
"""
</code></pre>
<p>Is there any way to do this? I think it would make more sense to switch to unittest, but I'm... | 18 | 2009-06-21T17:54:11Z | 1,024,426 | <p>With <code>doctest.ELLIPSIS</code>, you can use <code>...</code> to mean "match any string here". You can set <code>doctest</code> options with a doctest directive, to make it active for just one test case: one example in the <a href="http://docs.python.org/library/doctest.html">online docs</a> is:</p>
<pre><code>&... | 30 | 2009-06-21T18:03:19Z | [
"python",
"doctest"
] |
Can python doctest ignore some output lines? | 1,024,411 | <p>I'd like to write a doctest like this:</p>
<pre><code>"""
>>> print a.string()
foo : a
bar : b
date : <I don't care about the date output>
baz : c
"""
</code></pre>
<p>Is there any way to do this? I think it would make more sense to switch to unittest, but I'm... | 18 | 2009-06-21T17:54:11Z | 9,399,878 | <p>Ignoring the whole line is bit tricky though. Here:</p>
<pre><code>"""
>>> do_your_thing() #doctest:+ELLIPSIS
...
"""
</code></pre>
<p>The triple dot will be interpreted as line continuation, and cause a syntax error.</p>
<p>If you want to ignore the whole line, you'll need something like:</p>
<pre><cod... | 4 | 2012-02-22T17:27:29Z | [
"python",
"doctest"
] |
Can python doctest ignore some output lines? | 1,024,411 | <p>I'd like to write a doctest like this:</p>
<pre><code>"""
>>> print a.string()
foo : a
bar : b
date : <I don't care about the date output>
baz : c
"""
</code></pre>
<p>Is there any way to do this? I think it would make more sense to switch to unittest, but I'm... | 18 | 2009-06-21T17:54:11Z | 9,400,829 | <p>Responding to questions about "how can we ignore the whole line": yes, the fact that "..." also looks like a continuation like makes it hard to ignore the entire output. You can use "#doctest: +SKIP" if you just want to skip the example entirely, but that won't work if you are relying on its side-effects. If you <... | 5 | 2012-02-22T18:33:27Z | [
"python",
"doctest"
] |
Can python doctest ignore some output lines? | 1,024,411 | <p>I'd like to write a doctest like this:</p>
<pre><code>"""
>>> print a.string()
foo : a
bar : b
date : <I don't care about the date output>
baz : c
"""
</code></pre>
<p>Is there any way to do this? I think it would make more sense to switch to unittest, but I'm... | 18 | 2009-06-21T17:54:11Z | 12,227,048 | <p><a href="http://stackoverflow.com/questions/5812833/can-i-have-an-ellipsis-at-the-beginning-of-the-line-in-a-python-doctest">Can I have an ellipsis at the beginning of the line in a Python doctest?</a> explains how to create a custom output checker that uses an additional string as an ellipsis. This would let you w... | 0 | 2012-09-01T10:39:45Z | [
"python",
"doctest"
] |
Can python doctest ignore some output lines? | 1,024,411 | <p>I'd like to write a doctest like this:</p>
<pre><code>"""
>>> print a.string()
foo : a
bar : b
date : <I don't care about the date output>
baz : c
"""
</code></pre>
<p>Is there any way to do this? I think it would make more sense to switch to unittest, but I'm... | 18 | 2009-06-21T17:54:11Z | 22,537,703 | <p>I found it easier to simply assign the unneeded return values to a variable:</p>
<pre><code>>>> _ = do_something()
>>> check_something()
True
</code></pre>
| 2 | 2014-03-20T15:29:32Z | [
"python",
"doctest"
] |
Can python doctest ignore some output lines? | 1,024,411 | <p>I'd like to write a doctest like this:</p>
<pre><code>"""
>>> print a.string()
foo : a
bar : b
date : <I don't care about the date output>
baz : c
"""
</code></pre>
<p>Is there any way to do this? I think it would make more sense to switch to unittest, but I'm... | 18 | 2009-06-21T17:54:11Z | 33,400,983 | <p>You can write tuples before and after your function (hack inspired by answer of Mark Horvath):</p>
<pre><code>def foo():
"""
>>> ();foo();() # doctest: +ELLIPSIS
(...)
"""
print "Hello world"
return "Hello world"
</code></pre>
| 1 | 2015-10-28T20:27:08Z | [
"python",
"doctest"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 1,024,448 | <p>Using vim, it shouldn't be more involved than hitting Esc, and then typing..</p>
<pre><code>:%s/\t/ /g
</code></pre>
<p>..on the file you want to change. That will convert all tabs to 4 spaces. If you have inconsistent spacing as well, then that will be more difficult.</p>
| 6 | 2009-06-21T18:14:12Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 1,024,460 | <p>Try emacs. It has good support for indentation needed in Python. Please check this link <a href="http://python.about.com/b/2007/09/24/emacs-tips-for-python-programmers.htm" rel="nofollow">http://python.about.com/b/2007/09/24/emacs-tips-for-python-programmers.htm</a></p>
<p>cheers</p>
| 2 | 2009-06-21T18:19:32Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 1,024,463 | <p>If you're using <a href="http://www.vim.org/">Vim</a>, see <a href="http://vimdoc.sourceforge.net/htmldoc/change.html#:retab"><code>:h retab</code></a>.</p>
<pre> *:ret* *:retab*
:[range]ret[ab][!] [new_tabstop]
Replace all sequences of ... | 37 | 2009-06-21T18:20:38Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 1,024,489 | <p>Use the <code>reindent.py</code> script that you find in the <code>Tools/scripts/</code> directory of your Python installation:</p>
<blockquote>
<p>Change Python (.py) files to use
4-space indents and no hard tab
characters. Also trim excess spaces
and tabs from ends of lines, and
remove empty lines at th... | 235 | 2009-06-21T18:36:59Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 2,260,185 | <p>There is also PythonTidy (since you said you like HTMLTidy)
It can be found here: <a href="http://pypi.python.org/pypi/PythonTidy/1.16">http://pypi.python.org/pypi/PythonTidy/1.16</a>
It can do a lot more than just clean up tabs though. If you like that type of thing it's worth a look.</p>
| 7 | 2010-02-14T04:55:29Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 3,539,318 | <p>If you're lazy (like me), you can also download a trial version of Wingware Python IDE, which has an auto-fix tool for messed up indentation. It works pretty well.
<a href="http://www.wingware.com/">http://www.wingware.com/</a></p>
| 5 | 2010-08-21T22:35:51Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 15,983,399 | <p>I have a simple solution for this problem. You can first type ":retab" and then ":retab!", then everything would be fine</p>
| 0 | 2013-04-13T01:59:44Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 16,749,450 | <p>try Idle, and use ALT+X to find indentation</p>
| 0 | 2013-05-25T12:14:22Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 16,749,652 | <p>On most UNIX-like systems, you can also run:</p>
<pre><code>expand -t4 oldfilename.py > newfilename.py
</code></pre>
<p>from the command line, changing the number if you want to replace tabs with a number of spaces other than 4. You can easily write a shell script to do this with a bunch of files at once, retai... | 0 | 2013-05-25T12:40:05Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 26,643,477 | <p>I would reach for <a href="https://pypi.python.org/pypi/autopep8">autopep8</a> to do this:</p>
<pre class="lang-sh prettyprint-override"><code>$ # see what changes it would make
$ autopep8 path/to/file.py --select=E101,E121 --diff
$ # make these changes
$ autopep8 path/to/file.py --select=E101,E121 --in-place
</co... | 21 | 2014-10-30T01:19:35Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 29,636,895 | <p>Use <a href="https://pypi.python.org/pypi/autopep8/1.1.1" rel="nofollow">autopep8</a></p>
<p>autopep8 automatically formats Python code to conform to the PEP 8
nullstyle guide. It uses the pep8 utility to determine what parts of the
nullcode needs to be formatted. autopep8 is capable of fixing most of the
nullfo... | 4 | 2015-04-14T20:33:02Z | [
"python"
] |
How to fix python indentation | 1,024,435 | <p>I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserved.</p>
<p>The code works as expected but it's difficult to maintain.</p>
<p>How can I fix the indentation (like "html tidy" but for python) wi... | 185 | 2009-06-21T18:10:18Z | 33,320,387 | <p>The reindent script did not work for me, due to some missing module. Anyways, I found this <code>sed</code> command which does the job perfect for me:</p>
<pre><code>sed -r 's/^([ ]*)([^ ])/\1\1\2/' file.py
</code></pre>
| 3 | 2015-10-24T16:17:15Z | [
"python"
] |
Python newbie: What does this code do? | 1,024,437 | <p>This is a snippet from Google AppEngine tutorial.</p>
<pre><code>application = webapp.WSGIApplication([('/', MainPage)], debug=True)
</code></pre>
<p>I'm not quite sure what <strong><code>debug=True</code></strong> does inside the constructor call.
Does it create a local variable with name <code>debug</code>, ass... | 1 | 2009-06-21T18:10:57Z | 1,024,442 | <p>It's using named arguments. See <a href="http://diveintopython.net/power_of_introspection/optional_arguments.html" rel="nofollow">Using Optional and Named Arguments</a>.</p>
| 3 | 2009-06-21T18:12:54Z | [
"python"
] |
Python newbie: What does this code do? | 1,024,437 | <p>This is a snippet from Google AppEngine tutorial.</p>
<pre><code>application = webapp.WSGIApplication([('/', MainPage)], debug=True)
</code></pre>
<p>I'm not quite sure what <strong><code>debug=True</code></strong> does inside the constructor call.
Does it create a local variable with name <code>debug</code>, ass... | 1 | 2009-06-21T18:10:57Z | 1,024,444 | <p>Neither -- rather, <code>webapp.WSGIApplication</code> takes an optional argument named <code>debug</code>, and this code is passing the value <code>True</code> for that parameter.</p>
<p>The reference page for <code>WSGIApplication</code> is <a href="http://code.google.com/appengine/docs/python/tools/webapp/wsgiap... | 4 | 2009-06-21T18:13:42Z | [
"python"
] |
Python newbie: What does this code do? | 1,024,437 | <p>This is a snippet from Google AppEngine tutorial.</p>
<pre><code>application = webapp.WSGIApplication([('/', MainPage)], debug=True)
</code></pre>
<p>I'm not quite sure what <strong><code>debug=True</code></strong> does inside the constructor call.
Does it create a local variable with name <code>debug</code>, ass... | 1 | 2009-06-21T18:10:57Z | 1,024,449 | <p>Python functions accept keyword arguments. If you define a function like so:</p>
<pre><code>def my_func(a, b='abc', c='def'):
print a, b, c
</code></pre>
<p>You can call it like this:</p>
<pre><code>my_func('hello', c='world')
</code></pre>
<p>And the result will be:</p>
<pre><code>hello abc world
</code></... | 11 | 2009-06-21T18:14:24Z | [
"python"
] |
Perl's AUTOLOAD in Python (__getattr__ on a module) | 1,024,455 | <p>In the past I've used perl's AUTOLOAD facility for implementing lazy loading of symbols into a namespace, and wanted the same functionality in python. </p>
<p>Traditionally the closest you appear to be able to get is to use a class and a <code>__getattr__</code> class to achieve this sort of thing. However I've als... | 14 | 2009-06-21T18:17:47Z | 1,024,468 | <p>"Lazy imports" could be built on top of the "new import hooks" specified in <a href="http://www.python.org/dev/peps/pep-0302/">PEP 302</a>, and now fully implemented. PEP 369 used to cover "lazy imports" as well as post-import hooks, but has since been simplified and now only covers post-import hooks; still, you mig... | 10 | 2009-06-21T18:24:23Z | [
"python",
"module",
"autoload",
"getattr"
] |
Perl's AUTOLOAD in Python (__getattr__ on a module) | 1,024,455 | <p>In the past I've used perl's AUTOLOAD facility for implementing lazy loading of symbols into a namespace, and wanted the same functionality in python. </p>
<p>Traditionally the closest you appear to be able to get is to use a class and a <code>__getattr__</code> class to achieve this sort of thing. However I've als... | 14 | 2009-06-21T18:17:47Z | 1,026,612 | <p>No, I don't think that's useful.</p>
<p>Why create a function on the fly for <strong>every</strong> attribute you're trying to get from the module? Seems confusing to me. It appears that new functions are being created by magic so one has to look deep into the implementation to understand what is going on. And all ... | -1 | 2009-06-22T11:18:48Z | [
"python",
"module",
"autoload",
"getattr"
] |
Resolving a relative path from py:match in a genshi template | 1,024,475 | <pre><code><py:match path="foo">
<?python
import os
href = select('@href').render()
SOMEWHERE = ... # what file contained the foo tag?
path = os.path.abspath(os.path.join(os.path.dirname(SOMEWHERE), href)
f = file(path,'r')
# (do something interesting with f... | 0 | 2009-06-21T18:28:47Z | 2,875,664 | <p>You need to make sure that the driver program (i.e., the Python program that parses the input file) runs in the directory of the file containing the <code>foo</code> tag. Otherwise, you need to pass down the relative path (i.e., how to get from the directory in which the reader runs to the directory of the file bein... | 1 | 2010-05-20T16:09:39Z | [
"python",
"relative-path",
"genshi"
] |
How to test a Python script with an input file filled with testcases? | 1,024,529 | <p>I'm participating in online judge contests and I want to test my code with a .in file full of testcases to time my algorithm. How can I get my script to take input from this .in file?</p>
| 1 | 2009-06-21T18:57:59Z | 1,024,544 | <p><a href="http://pyunit.sourceforge.net/" rel="nofollow">PyUnit</a> "the standard unit testing framework for Python" might be what you are looking for.</p>
<p><hr /></p>
<p>Doing a small script that does something like this:</p>
<pre><code>#!/usr/bin/env python
import sys
def main():
in_file = open('path_to_f... | 1 | 2009-06-21T19:06:44Z | [
"python",
"input"
] |
How to test a Python script with an input file filled with testcases? | 1,024,529 | <p>I'm participating in online judge contests and I want to test my code with a .in file full of testcases to time my algorithm. How can I get my script to take input from this .in file?</p>
| 1 | 2009-06-21T18:57:59Z | 1,024,592 | <p>So the script normally takes test cases from stdin, and now you want to test using test cases from a file?</p>
<p>If that is the case, use the <code><</code> redirection operation on the cmd line:</p>
<pre><code>my_script < testcases.in
</code></pre>
| 6 | 2009-06-21T19:31:23Z | [
"python",
"input"
] |
How to test a Python script with an input file filled with testcases? | 1,024,529 | <p>I'm participating in online judge contests and I want to test my code with a .in file full of testcases to time my algorithm. How can I get my script to take input from this .in file?</p>
| 1 | 2009-06-21T18:57:59Z | 1,024,633 | <p>Read from file(s) and/or stdin:</p>
<pre><code>import fileinput
for line in fileinput.input():
process(line)
</code></pre>
| 2 | 2009-06-21T19:57:07Z | [
"python",
"input"
] |
How to test a Python script with an input file filled with testcases? | 1,024,529 | <p>I'm participating in online judge contests and I want to test my code with a .in file full of testcases to time my algorithm. How can I get my script to take input from this .in file?</p>
| 1 | 2009-06-21T18:57:59Z | 1,024,718 | <p>You can do this in a separate file.</p>
<p><code>testmyscript.py</code></p>
<pre><code>import sys
someFile= open( "somefile.in", "r" )
sys.stdin= someFile
execfile( "yourscript.py" )
</code></pre>
| 0 | 2009-06-21T20:48:35Z | [
"python",
"input"
] |
Django - alternative to subclassing User? | 1,024,684 | <p>I am using the standard User model (django.contrib.auth) which comes with Django. I have made some of my own models in a Django application and created a relationship between like this:</p>
<pre><code>from django.db import models
from django.contrib.auth.models import User
class GroupMembership(models.Model):
... | 0 | 2009-06-21T20:27:52Z | 1,024,765 | <p>First, calling <code>select_related</code> and passing arguments, doesn't do anything. It's a hint that cache should be populated.</p>
<p>You would never call <code>select_related</code> in a template, only a view function. And only when you knew you needed all those related objects for other processing.</p>
<p>... | 3 | 2009-06-21T21:12:30Z | [
"python",
"django"
] |
Add key to a dictionary in Python? | 1,024,847 | <p>Is it possible to add a key to a Python dictionary after it has been created? It doesn't seem to have an <code>.add()</code> method.</p>
| 1,201 | 2009-06-21T22:07:39Z | 1,024,850 | <pre><code>dictionary[key] = value
</code></pre>
| 60 | 2009-06-21T22:08:57Z | [
"python",
"dictionary"
] |
Add key to a dictionary in Python? | 1,024,847 | <p>Is it possible to add a key to a Python dictionary after it has been created? It doesn't seem to have an <code>.add()</code> method.</p>
| 1,201 | 2009-06-21T22:07:39Z | 1,024,851 | <pre><code>>>> d = {'key':'value'}
>>> print d
{'key': 'value'}
>>> d['mynewkey'] = 'mynewvalue'
>>> print d
{'mynewkey': 'mynewvalue', 'key': 'value'}
</code></pre>
| 1,611 | 2009-06-21T22:09:06Z | [
"python",
"dictionary"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.