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 |
|---|---|---|---|---|---|---|---|---|---|
Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time | 1,216,794 | <p><strong>Note</strong>: This question has been re-asked with a summary of all debugging attempts <a href="http://stackoverflow.com/questions/1367373/python-subprocess-popen-oserror-errno-12-cannot-allocate-memory">here</a>.</p>
<p><hr /></p>
<p>I have a Python script that is running as a background process executin... | 8 | 2009-08-01T15:14:30Z | 1,270,442 | <p>You've perhaps got a memory leak bounded by some <a href="http://www.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html" rel="nofollow">resource limit</a> (<code>RLIMIT_DATA</code>, <code>RLIMIT_AS</code>?) inherited by your python script. Check your <em>ulimit(1)</em>s before you run your script, and pro... | 6 | 2009-08-13T07:02:04Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time | 1,216,794 | <p><strong>Note</strong>: This question has been re-asked with a summary of all debugging attempts <a href="http://stackoverflow.com/questions/1367373/python-subprocess-popen-oserror-errno-12-cannot-allocate-memory">here</a>.</p>
<p><hr /></p>
<p>I have a Python script that is running as a background process executin... | 8 | 2009-08-01T15:14:30Z | 1,270,848 | <p>You need to</p>
<pre><code>ps = subprocess.Popen(["sleep", "1000"])
os.waitpid(ps.pid, 0)
</code></pre>
<p>to free resources.</p>
<p>Note: this does not work on Windows.</p>
| 0 | 2009-08-13T08:50:18Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time | 1,216,794 | <p><strong>Note</strong>: This question has been re-asked with a summary of all debugging attempts <a href="http://stackoverflow.com/questions/1367373/python-subprocess-popen-oserror-errno-12-cannot-allocate-memory">here</a>.</p>
<p><hr /></p>
<p>I have a Python script that is running as a background process executin... | 8 | 2009-08-01T15:14:30Z | 1,278,961 | <p>If you're running a background process, chances are that you've redirected your processes stdin/stdout/stderr.</p>
<p>In that case, append the option "close_fds=True" to your Popen call, which will prevent the child process from inheriting your redirected output. This may be the limit you're bumping into.</p>
| 2 | 2009-08-14T16:54:35Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time | 1,216,794 | <p><strong>Note</strong>: This question has been re-asked with a summary of all debugging attempts <a href="http://stackoverflow.com/questions/1367373/python-subprocess-popen-oserror-errno-12-cannot-allocate-memory">here</a>.</p>
<p><hr /></p>
<p>I have a Python script that is running as a background process executin... | 8 | 2009-08-01T15:14:30Z | 1,297,785 | <p>when you use popen you need to hand in close_fds=True if you want it to close extra file descriptors. </p>
<p>creating a new pipe, which occurs in the _get_handles function from the back trace, creates 2 file descriptors, but your current code never closes them and your eventually hitting your systems max fd limit... | 4 | 2009-08-19T04:18:56Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time | 1,216,794 | <p><strong>Note</strong>: This question has been re-asked with a summary of all debugging attempts <a href="http://stackoverflow.com/questions/1367373/python-subprocess-popen-oserror-errno-12-cannot-allocate-memory">here</a>.</p>
<p><hr /></p>
<p>I have a Python script that is running as a background process executin... | 8 | 2009-08-01T15:14:30Z | 9,530,431 | <p>Virtual Memory matters!!!</p>
<p>I encountered the same issue before I add swap to my OS. The formula for virtual memory is usually like: SwapSize + 50% * PhysicalMemorySize. I finally get this resolved by either adding more physical memory or adding a Swap disk. close_fds won't work in my case.</p>
| 0 | 2012-03-02T08:56:20Z | [
"python",
"linux",
"memory"
] |
google appengine/python: Can I depend on Task queue retry on failure to keep insertions to a minimum? | 1,216,947 | <p>Say my app has a page on which people can add comments.
Say after each comment is added a taskqueue worker is added.
So if a 100 comments are added a 100 taskqueue insertions are made. </p>
<p>(note: the above is a hypothetical example to illustrate my question)</p>
<p>Say I wanted to ensure that the number of i... | 1 | 2009-08-01T16:29:27Z | 1,217,108 | <p>There's no reason to fake a failure (and incur backoff &c) -- that's a hacky and fragile arrangement. If you fear that simply scheduling a task per new comment might exceed the task queues' currently strict limits, then "batch up" as-yet-unprocessed comments in the store (and possibly also in memcache, I guess, ... | 1 | 2009-08-01T17:47:22Z | [
"python",
"google-app-engine"
] |
Python: sorting a dictionary of lists | 1,217,251 | <p>Still learning python (finally!) and can't quite wrap my head around this one yet. What I want to do is sort a dictionary of lists by value using the third item in the list. It's easy enough sorting a dictionary by value when the value is just a single number or string, but this list thing has me baffled.</p>
<p>... | 21 | 2009-08-01T19:07:17Z | 1,217,269 | <p>Here is one way to do this:</p>
<pre><code>>>> sorted(myDict.items(), key=lambda e: e[1][2])
[('item2', [8, 2, 3]), ('item1', [7, 1, 9]), ('item3', [9, 3, 11])]
</code></pre>
<p>The <a href="http://wiki.python.org/moin/HowTo/Sorting#Sortingbykeys"><code>key</code> argument</a> of the <code>sorted</code> f... | 26 | 2009-08-01T19:15:11Z | [
"python",
"list",
"sorting",
"dictionary"
] |
Python: sorting a dictionary of lists | 1,217,251 | <p>Still learning python (finally!) and can't quite wrap my head around this one yet. What I want to do is sort a dictionary of lists by value using the third item in the list. It's easy enough sorting a dictionary by value when the value is just a single number or string, but this list thing has me baffled.</p>
<p>... | 21 | 2009-08-01T19:07:17Z | 1,217,823 | <p>You stated two quite different wants:</p>
<ol>
<li>"What I want to do is sort a dictionary of lists ..."</li>
<li>"I want to be able to iterate through the dictionary in order of ..."</li>
</ol>
<p>The first of those is by definition impossible -- to sort something implies a rearrangement in some order. Python dic... | 1 | 2009-08-02T00:04:33Z | [
"python",
"list",
"sorting",
"dictionary"
] |
Python: sorting a dictionary of lists | 1,217,251 | <p>Still learning python (finally!) and can't quite wrap my head around this one yet. What I want to do is sort a dictionary of lists by value using the third item in the list. It's easy enough sorting a dictionary by value when the value is just a single number or string, but this list thing has me baffled.</p>
<p>... | 21 | 2009-08-01T19:07:17Z | 1,218,570 | <p>As John Machlin said you can't actually sort a Python dictionary.</p>
<p>However, you can create an index of the keys which can be sorted in any order you like.</p>
<p>The preferred Python pattern (idiom) for sorting by any alternative criterium is called "decorate-sort-undecorate" (DSU). In this idiom you create... | 1 | 2009-08-02T10:01:05Z | [
"python",
"list",
"sorting",
"dictionary"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,217,282 | <p>I would say that integrated query technology in any language will become foundational in time, especially given the recent rise in interest of Functional programming languages.</p>
<p>LINQ is certainly one of the biggest reasons I personally am sticking with .NET, anyway - it's become foundational for me personally... | 2 | 2009-08-01T19:19:43Z | [
"java",
".net",
"python",
"linq"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,217,290 | <p>Disclaimer: I've never used LINQ. Please correct me if I'm wrong.</p>
<p>Many languages have constructs which allow to the same things as LINQ with the language data types.
Apparently the most interesting feature is that LINQ constructs can be converted to SQL, but it's not specific to LINQ: <a href="http://www.ami... | 1 | 2009-08-01T19:23:33Z | [
"java",
".net",
"python",
"linq"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,217,291 | <p>I don't think that you can really classify it (or many things) as either. While I would hardly say that LINQ is a niche tool -- it has many applications to many people -- it's not "foundational" IMO. However, I also wouldn't say that having LINQ (or an equivalent) language-specific querying language can be truly fou... | 0 | 2009-08-01T19:23:59Z | [
"java",
".net",
"python",
"linq"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,217,307 | <p>It sounds a lot to me like Ruby's Active Record, but I've never used LINQ. Anyone used both? (I would have posted this as a comment, but I'd really like to be updated on the answer--I'm probably wrong so it'll get downvoted :) )</p>
<p>(Actually I should say that AR is like LINQ to SQL, they haven't implemented AR... | 0 | 2009-08-01T19:33:10Z | [
"java",
".net",
"python",
"linq"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,217,313 | <p>After spending years</p>
<ul>
<li>Handcrafting database access(in oh so many languages)</li>
<li>Going throgh the Entity framework</li>
<li>Fetching and storing data through the fashioned ORM of the month</li>
</ul>
<p>It was about time somone made an easy to access and language integrated way to talk to a databas... | 4 | 2009-08-01T19:36:25Z | [
"java",
".net",
"python",
"linq"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,217,454 | <p>I think the functional concepts which are the under pinnings of LINQ will become popular in many languages. Passing a sequence of objects through a set of functions to get the desired set of objects. Essentially, using the lambda syntax over the query syntax. </p>
<p>This is a very powerful and expressive way of... | 2 | 2009-08-01T20:45:02Z | [
"java",
".net",
"python",
"linq"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,217,473 | <p>I don't think linq will be confined to the microsoft languages, check it out, there is already something for the php, check it out <a href="http://phplinq.codeplex.com/" rel="nofollow">http://phplinq.codeplex.com/</a></p>
<p>I think Linq is great tool in development process and personally would be really glad if it... | 1 | 2009-08-01T20:55:53Z | [
"java",
".net",
"python",
"linq"
] |
Is LINQ (or linq) a niche tool, or is it on the path to becoming foundational? | 1,217,274 | <p>After reading "<a href="http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq">What is the Java equivalent of LINQ?</a>", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or externa... | 7 | 2009-08-01T19:16:26Z | 1,218,086 | <p>Before LinQ, Python had <a href="http://www.python.org/dev/peps/pep-0289/" rel="nofollow">Generator Expressions</a> which are <em>specific syntax for performing queries over collections</em>. Python's syntax is more reduced than Linq's, but let you basically perform the same queries as easy as in linq. Months ago, ... | 6 | 2009-08-02T03:34:34Z | [
"java",
".net",
"python",
"linq"
] |
is it possible to add an element to a list and preserve the order | 1,217,780 | <p>I would like to add an element to a list that preserve the order of the list.</p>
<p>Let's assume the list of object is <em>[a, b, c, d]</em> I have a function <em>cmp</em> that compares two elements of the list. if I add f object which is the bigger I would like it to be at the last position.</p>
<p>maybe it's b... | 2 | 2009-08-01T23:34:04Z | 1,217,785 | <p>Yes, this is what <a href="http://effbot.org/librarybook/bisect.htm" rel="nofollow">bisect.insort</a> is for, however it doesn't take a comparison function. If the objects are custom objects, you can override one or more of the <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Flt%5F%5F" rel="nof... | 5 | 2009-08-01T23:37:42Z | [
"python"
] |
is it possible to add an element to a list and preserve the order | 1,217,780 | <p>I would like to add an element to a list that preserve the order of the list.</p>
<p>Let's assume the list of object is <em>[a, b, c, d]</em> I have a function <em>cmp</em> that compares two elements of the list. if I add f object which is the bigger I would like it to be at the last position.</p>
<p>maybe it's b... | 2 | 2009-08-01T23:34:04Z | 1,217,786 | <pre><code>L.insert(index, object) -- insert object before index
</code></pre>
| 0 | 2009-08-01T23:38:43Z | [
"python"
] |
is it possible to add an element to a list and preserve the order | 1,217,780 | <p>I would like to add an element to a list that preserve the order of the list.</p>
<p>Let's assume the list of object is <em>[a, b, c, d]</em> I have a function <em>cmp</em> that compares two elements of the list. if I add f object which is the bigger I would like it to be at the last position.</p>
<p>maybe it's b... | 2 | 2009-08-01T23:34:04Z | 1,217,883 | <p><code>bisect.insort</code> is a little bit faster, where applicable, than append-then-sort (unless you have a few elements to add before you need the list to be sorted again) -- measuring as usual on my laptop (a speedier machine will of course be faster across the board, but the ratio should remain roughly constant... | 4 | 2009-08-02T00:45:27Z | [
"python"
] |
Reverting a Python/Cocoa project to use the default OSX 10.5 Python (2.5) | 1,217,781 | <p>I have installed the latest MacPython (2.6.2) on my Leopard OS X and started an XCode PyObjC project. </p>
<p>When I finalized the app, I built the release version and sent it to a friend of mine to try if it runs with out of the box. It did not, because it expects the latest Python, as on my computer.</p>
<p>No m... | 1 | 2009-08-01T23:34:07Z | 1,217,912 | <p>Uninstalling what you now have in /Library/Frameworks (so XCode falls back to the Python in /System/Library/Frameworks) would work but may be considered a bit drastic. <a href="http://forums.macrumors.com/showthread.php?t=377881#6" rel="nofollow">This post</a> and its followups have other potentially useful recommen... | 1 | 2009-08-02T01:01:19Z | [
"python",
"cocoa",
"xcode",
"xcodebuild",
"pyobjc"
] |
PyOpenGL + Pygame capped to 60 FPS in Fullscreen | 1,217,939 | <p>I'm currently working on a game engine written in pygame and I wanted to add OpenGL support.</p>
<p>I wrote a test to see how to make pygame and OpenGL work together, and when it's running in windowed mode, it runs between 150 and 200 fps. When I run it full screen (all I did was add the FULLSCREEN flag when I set ... | 2 | 2009-08-02T01:22:31Z | 1,217,946 | <p>Is this a <a href="http://en.wikipedia.org/wiki/V-sync" rel="nofollow">V-Sync</a> issue? Something about the config or your environment may be limiting maximum frame rate to your monitor's refresh rate.</p>
| 1 | 2009-08-02T01:28:41Z | [
"python",
"fullscreen",
"pygame",
"pyopengl"
] |
PyOpenGL + Pygame capped to 60 FPS in Fullscreen | 1,217,939 | <p>I'm currently working on a game engine written in pygame and I wanted to add OpenGL support.</p>
<p>I wrote a test to see how to make pygame and OpenGL work together, and when it's running in windowed mode, it runs between 150 and 200 fps. When I run it full screen (all I did was add the FULLSCREEN flag when I set ... | 2 | 2009-08-02T01:22:31Z | 1,218,011 | <p>If you are not changing your clock.tick() when you change between full screen and windowed mode this is almost certainly a vsync issue. If you are on an LCD then it's 100% certain.</p>
<p>Unfortunately v-sync can be handled in many places including SDL, Pyopengl, your display server and your video drivers. If you a... | 0 | 2009-08-02T02:18:11Z | [
"python",
"fullscreen",
"pygame",
"pyopengl"
] |
PyOpenGL + Pygame capped to 60 FPS in Fullscreen | 1,217,939 | <p>I'm currently working on a game engine written in pygame and I wanted to add OpenGL support.</p>
<p>I wrote a test to see how to make pygame and OpenGL work together, and when it's running in windowed mode, it runs between 150 and 200 fps. When I run it full screen (all I did was add the FULLSCREEN flag when I set ... | 2 | 2009-08-02T01:22:31Z | 1,218,102 | <p>As frou pointed out, this would be due to Pygame waiting for the vertical retrace when you update the screen by calling <code>display.flip()</code>. As the <a href="http://www.pygame.org/docs/ref/display.html#pygame.display.flip">Pygame <code>display</code> documentation</a> notes, if you set the display mode using ... | 7 | 2009-08-02T03:46:05Z | [
"python",
"fullscreen",
"pygame",
"pyopengl"
] |
How do I forbid easy_install from zipping eggs? | 1,218,058 | <p>What must I put into <code>distutils.cfg</code> to prevent easy_install from ever installing a zipped egg? The compression is a nice thought, but I like to be able to grep through and debug that code.</p>
<p>I pulled in some dependencies with <code>python setup.py develop .</code> A closer look reveals that also ac... | 11 | 2009-08-02T03:07:06Z | 1,218,060 | <p>One solution?</p>
<pre><code>easy_install pip
rm easy_install
ln -s easy_install pip
</code></pre>
| 0 | 2009-08-02T03:08:49Z | [
"python",
"setuptools",
"easy-install"
] |
How do I forbid easy_install from zipping eggs? | 1,218,058 | <p>What must I put into <code>distutils.cfg</code> to prevent easy_install from ever installing a zipped egg? The compression is a nice thought, but I like to be able to grep through and debug that code.</p>
<p>I pulled in some dependencies with <code>python setup.py develop .</code> A closer look reveals that also ac... | 11 | 2009-08-02T03:07:06Z | 1,218,270 | <p>I doubt there is a setting in distutils.cfg for this, as easy_install is not a part of distutils. But run easy_install like this:</p>
<pre><code>easy_install --always-unzip
</code></pre>
<p>and it should solve the problem.</p>
| 3 | 2009-08-02T06:08:20Z | [
"python",
"setuptools",
"easy-install"
] |
How do I forbid easy_install from zipping eggs? | 1,218,058 | <p>What must I put into <code>distutils.cfg</code> to prevent easy_install from ever installing a zipped egg? The compression is a nice thought, but I like to be able to grep through and debug that code.</p>
<p>I pulled in some dependencies with <code>python setup.py develop .</code> A closer look reveals that also ac... | 11 | 2009-08-02T03:07:06Z | 1,218,426 | <p>the option is zip-ok, so put the following in your distutils.cfg:</p>
<pre><code>[easy_install]
# i don't like having zipped files.
zip_ok = 0
</code></pre>
| 14 | 2009-08-02T08:25:36Z | [
"python",
"setuptools",
"easy-install"
] |
How do I forbid easy_install from zipping eggs? | 1,218,058 | <p>What must I put into <code>distutils.cfg</code> to prevent easy_install from ever installing a zipped egg? The compression is a nice thought, but I like to be able to grep through and debug that code.</p>
<p>I pulled in some dependencies with <code>python setup.py develop .</code> A closer look reveals that also ac... | 11 | 2009-08-02T03:07:06Z | 17,781,086 | <p>I had the issue using buildout, and the solved it by adding:</p>
<pre><code>[buildout]
unzip = true
</code></pre>
<p>in the <code>buildout.cfg</code> file</p>
| 0 | 2013-07-22T06:19:07Z | [
"python",
"setuptools",
"easy-install"
] |
In erlang: How do I expand wxNotebook in a panel? | 1,218,433 | <p>(I have tagged this question as Python as well since I understand Python code so examples in Python are also welcome!).</p>
<p>I want to create a simple window in wxWidgets:<br />
I create a main panel which I add to a form<br />
I associate a boxsizer to the main panel (splitting it in two, horizontally).<br />
I ... | 8 | 2009-08-02T08:28:41Z | 1,218,627 | <p>I'm closing this question (as soon as I can) after I figured out what I needed to do.</p>
<p>Basically I changed the proportion to 1 of the add command to the main panel (this will expand the whole thing)</p>
<p>New code:</p>
<pre><code> %% Main Sizer
wxSizer:add(MainSizer, LeftPanel, [{proportion,0},{border, ... | 4 | 2009-08-02T10:30:42Z | [
"python",
"layout",
"erlang",
"wxwidgets"
] |
Python string templater | 1,218,457 | <p>I'm using this REST web service, which returns various templated strings as urls, for example:</p>
<pre><code>"http://api.app.com/{foo}"
</code></pre>
<p>In Ruby, I can then use </p>
<pre><code>url = Addressable::Template.new("http://api.app.com/{foo}").expand('foo' => 'bar')
</code></pre>
<p>to get</p>
<pre... | 3 | 2009-08-02T08:46:50Z | 1,218,577 | <p>In python 2.6 you can do this if you need exactly that syntax</p>
<pre><code>from string import Formatter
f = Formatter()
f.format("http://api.app.com/{foo}", foo="bar")
</code></pre>
<p>If you need to use an earlier python version then you can either copy the 2.6 formatter class or hand roll a parser/regex to do ... | 4 | 2009-08-02T10:03:52Z | [
"python",
"ruby",
"templates",
"string"
] |
Python string templater | 1,218,457 | <p>I'm using this REST web service, which returns various templated strings as urls, for example:</p>
<pre><code>"http://api.app.com/{foo}"
</code></pre>
<p>In Ruby, I can then use </p>
<pre><code>url = Addressable::Template.new("http://api.app.com/{foo}").expand('foo' => 'bar')
</code></pre>
<p>to get</p>
<pre... | 3 | 2009-08-02T08:46:50Z | 1,218,944 | <p>I cannot give you a perfect solution but you could try using <code>string.Template</code>.
You either pre-process your incoming URL and then use string.Template directly, like</p>
<pre><code>In [6]: url="http://api.app.com/{foo}"
In [7]: up=string.Template(re.sub("{", "${", url))
In [8]: up.substitute({"foo":"bar"}... | 0 | 2009-08-02T13:54:13Z | [
"python",
"ruby",
"templates",
"string"
] |
Python string templater | 1,218,457 | <p>I'm using this REST web service, which returns various templated strings as urls, for example:</p>
<pre><code>"http://api.app.com/{foo}"
</code></pre>
<p>In Ruby, I can then use </p>
<pre><code>url = Addressable::Template.new("http://api.app.com/{foo}").expand('foo' => 'bar')
</code></pre>
<p>to get</p>
<pre... | 3 | 2009-08-02T08:46:50Z | 1,223,406 | <p>Don't use a quick hack.</p>
<p>What is used there (and implemented by Addressable) are <a href="http://bitworking.org/projects/URI-Templates/spec/draft-gregorio-uritemplate-03.html" rel="nofollow">URI Templates</a>. There seem to be several libs for this in python, for example: <a href="http://code.google.com/p/uri... | 2 | 2009-08-03T16:51:09Z | [
"python",
"ruby",
"templates",
"string"
] |
python's sum() and non-integer values | 1,218,710 | <p>Is there a simple and quick way to use sum() with non-integer values?</p>
<p>So I can use it like this:</p>
<pre><code>class Foo(object):
def __init__(self,bar)
self.bar=bar
mylist=[Foo(3),Foo(34),Foo(63),200]
result=sum(mylist) # result should be 300
</code></pre>
<p>I tried overriding <code>__add__... | 15 | 2009-08-02T11:27:41Z | 1,218,724 | <p>Try:</p>
<pre><code>import operator
result=reduce(operator.add, mylist)
</code></pre>
<p>sum() works probably faster, but it is specialized for builtin numbers only. Of course you still have to provide a method to add your Foo() objects. So full example:</p>
<pre><code>class Foo(object):
def __init__(self, i)... | 4 | 2009-08-02T11:36:24Z | [
"python",
"list",
"sum"
] |
python's sum() and non-integer values | 1,218,710 | <p>Is there a simple and quick way to use sum() with non-integer values?</p>
<p>So I can use it like this:</p>
<pre><code>class Foo(object):
def __init__(self,bar)
self.bar=bar
mylist=[Foo(3),Foo(34),Foo(63),200]
result=sum(mylist) # result should be 300
</code></pre>
<p>I tried overriding <code>__add__... | 15 | 2009-08-02T11:27:41Z | 1,218,732 | <p>Try using the <code>__int__</code> method and then mapping each element in your list to the <code>int</code> function to get the values out:</p>
<pre><code>class Foo(object):
def __init__(self,bar):
self.bar = bar
def __int__(self):
return self.bar
mylist = [Foo(3),Foo(34),Foo(63),200]
result = s... | 3 | 2009-08-02T11:40:48Z | [
"python",
"list",
"sum"
] |
python's sum() and non-integer values | 1,218,710 | <p>Is there a simple and quick way to use sum() with non-integer values?</p>
<p>So I can use it like this:</p>
<pre><code>class Foo(object):
def __init__(self,bar)
self.bar=bar
mylist=[Foo(3),Foo(34),Foo(63),200]
result=sum(mylist) # result should be 300
</code></pre>
<p>I tried overriding <code>__add__... | 15 | 2009-08-02T11:27:41Z | 1,218,733 | <p>Or if you don't want to import anything,</p>
<pre><code>result=reduce( (lambda x,y:x+y), mylist
</code></pre>
<p>Another small advantage is that you don't have to necessarily declare an <strong>add</strong> method as part of your Foo objects, if this happens to be the only circumstance in which you'd want to do ad... | 3 | 2009-08-02T11:41:55Z | [
"python",
"list",
"sum"
] |
python's sum() and non-integer values | 1,218,710 | <p>Is there a simple and quick way to use sum() with non-integer values?</p>
<p>So I can use it like this:</p>
<pre><code>class Foo(object):
def __init__(self,bar)
self.bar=bar
mylist=[Foo(3),Foo(34),Foo(63),200]
result=sum(mylist) # result should be 300
</code></pre>
<p>I tried overriding <code>__add__... | 15 | 2009-08-02T11:27:41Z | 1,218,735 | <p>You may also need to implement the <code>__radd__</code> function, which represents "reverse add" and is called when the arguments can't be resolved in the "forward" direction. For example, <code>x + y</code> is evaluated as <code>x.__add__(y)</code> if possible, but if that doesn't exist then Python tries <code>y._... | 13 | 2009-08-02T11:42:10Z | [
"python",
"list",
"sum"
] |
python's sum() and non-integer values | 1,218,710 | <p>Is there a simple and quick way to use sum() with non-integer values?</p>
<p>So I can use it like this:</p>
<pre><code>class Foo(object):
def __init__(self,bar)
self.bar=bar
mylist=[Foo(3),Foo(34),Foo(63),200]
result=sum(mylist) # result should be 300
</code></pre>
<p>I tried overriding <code>__add__... | 15 | 2009-08-02T11:27:41Z | 1,218,742 | <p>Its a bit tricky - the sum() function takes the start and adds it to the next and so on</p>
<p>You need to implement the <code>__radd__</code> method:</p>
<pre><code>class T:
def __init__(self,x):
self.x = x
def __radd__(self, other):
return other + self.x
test = (T(1),T(2),T(3),200)
print sum(t... | 18 | 2009-08-02T11:45:03Z | [
"python",
"list",
"sum"
] |
Multiprocessing Debugging error | 1,218,757 | <p>Hey everyone, I am having a little trouble debugging my code. Please look below: </p>
<pre><code>import globalFunc
from globalFunc import systemPrint
from globalFunc import out
from globalFunc import debug
import math
import time
import multiprocessing
"""
Somehow this is not working well
"""
class urlServerM( mu... | 1 | 2009-08-02T11:56:40Z | 1,219,742 | <p>You're using multiprocessing, so the memory is not shared between main execution and your urlserver.</p>
<p>I.e. I think this is effectively a Noop: <code>{us.store('<a href="http://www.google.com" rel="nofollow">http://www.google.com</a>')}</code> because when it's executed in the main thread, it modifies only the... | 0 | 2009-08-02T20:18:11Z | [
"python"
] |
Segment a list in Python | 1,218,793 | <p>I am looking for an python inbuilt function (or mechanism) to segment a list into required segment lengths (without mutating the input list). Here is the code I already have:</p>
<pre><code>>>> def split_list(list, seg_length):
... inlist = list[:]
... outlist = []
...
... while inlist:
..... | 8 | 2009-08-02T12:14:15Z | 1,218,810 | <p>You can use list comprehension:</p>
<pre><code>>>> seg_length = 3
>>> a = range(10)
>>> [a[x:x+seg_length] for x in range(0,len(a),seg_length)]
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
</code></pre>
| 15 | 2009-08-02T12:26:09Z | [
"python",
"list",
"segments"
] |
Segment a list in Python | 1,218,793 | <p>I am looking for an python inbuilt function (or mechanism) to segment a list into required segment lengths (without mutating the input list). Here is the code I already have:</p>
<pre><code>>>> def split_list(list, seg_length):
... inlist = list[:]
... outlist = []
...
... while inlist:
..... | 8 | 2009-08-02T12:14:15Z | 1,218,828 | <p>not the same output, I still think the <a href="http://docs.python.org/library/itertools.html" rel="nofollow">grouper function</a> is helpful:</p>
<pre><code>from itertools import izip_longest
def grouper(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return izip_longest(*args, fillvalue=fillvalu... | 2 | 2009-08-02T12:38:36Z | [
"python",
"list",
"segments"
] |
Segment a list in Python | 1,218,793 | <p>I am looking for an python inbuilt function (or mechanism) to segment a list into required segment lengths (without mutating the input list). Here is the code I already have:</p>
<pre><code>>>> def split_list(list, seg_length):
... inlist = list[:]
... outlist = []
...
... while inlist:
..... | 8 | 2009-08-02T12:14:15Z | 1,218,844 | <p>How do you need to use the output? If you only need to iterate over it, you are better off creating an iterable, one that yields your groups:</p>
<pre><code>def split_by(sequence, length):
iterable = iter(sequence)
def yield_length():
for i in xrange(length):
yield iterable.next()
w... | 3 | 2009-08-02T12:51:07Z | [
"python",
"list",
"segments"
] |
Multiple versions of Python on OS X Leopard | 1,218,891 | <p>I currently have multiple versions of Python installed on my Mac, the one that came with it, a version I downloaded recently from python.org, an older version used to run Zope locally and another version that Appengine is using. It's kind of a mess. Any recommendations of using one version of python to rule them all... | 21 | 2009-08-02T13:23:32Z | 1,219,166 | <p>There's nothing inherently wrong with having multiple versions of Python around. Sometimes it's a necessity when using applications with version dependencies. Probably the biggest issue is dealing with site-package dependencies which may vary from app to app. Tools like <a href="http://pypi.python.org/pypi/virtuale... | 20 | 2009-08-02T16:09:49Z | [
"python",
"osx",
"osx-leopard",
"zope"
] |
Multiple versions of Python on OS X Leopard | 1,218,891 | <p>I currently have multiple versions of Python installed on my Mac, the one that came with it, a version I downloaded recently from python.org, an older version used to run Zope locally and another version that Appengine is using. It's kind of a mess. Any recommendations of using one version of python to rule them all... | 21 | 2009-08-02T13:23:32Z | 1,219,303 | <p>The approach I prefer which should work on every UNIX-like operating system:</p>
<p>Create for each application which need an specific python version an user account. Install in each user count the corresponding python version with an user-local prefix (like ~/build/python) and add ~/build/bin/ to the PATH environm... | 1 | 2009-08-02T17:13:27Z | [
"python",
"osx",
"osx-leopard",
"zope"
] |
Multiple versions of Python on OS X Leopard | 1,218,891 | <p>I currently have multiple versions of Python installed on my Mac, the one that came with it, a version I downloaded recently from python.org, an older version used to run Zope locally and another version that Appengine is using. It's kind of a mess. Any recommendations of using one version of python to rule them all... | 21 | 2009-08-02T13:23:32Z | 1,219,486 | <p>Ian Bicking's <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> allows me to have isolated Pythons for each application I build, and lets me decide whether or not to include the global site-packages in the isolated Python environment.</p>
<p>I haven't tried it with Zope, but I'm guessing that the foll... | 9 | 2009-08-02T18:27:39Z | [
"python",
"osx",
"osx-leopard",
"zope"
] |
Multiple versions of Python on OS X Leopard | 1,218,891 | <p>I currently have multiple versions of Python installed on my Mac, the one that came with it, a version I downloaded recently from python.org, an older version used to run Zope locally and another version that Appengine is using. It's kind of a mess. Any recommendations of using one version of python to rule them all... | 21 | 2009-08-02T13:23:32Z | 1,321,011 | <p>+1 for virtualenv. </p>
<p>Even if you don't need different Python versions, it's still good to keep your development dependencies seperate from your system Python.</p>
<p>I'm not sure what OS you are using, but I find <a href="http://www.stereoplex.com/blog/creating-a-python-2-4-plone-and-zope-development-e" rel=... | 2 | 2009-08-24T07:57:54Z | [
"python",
"osx",
"osx-leopard",
"zope"
] |
How to get the biggest numbers out from huge amount of numbers? | 1,218,922 | <p>I'd like to get the largest 100 elements out from a list of at least 100000000 numbers.</p>
<p>I could sort the entire list and just take the last 100 elements from the sorted list, but that would be very expensive in terms of both memory and time.</p>
<p>Is there any existing easy, pythonic way of doing this?</p>... | 10 | 2009-08-02T13:43:21Z | 1,218,930 | <p><a href="http://en.wikipedia.org/wiki/Selection%5Falgorithm" rel="nofollow">Selection algorithms</a> should help here. </p>
<p>A very easy solution is to find the 100th biggest element, then run through the list picking off elements that are bigger than this element. That will give you the 100 biggest elements. Thi... | 6 | 2009-08-02T13:45:45Z | [
"python",
"sorting",
"max",
"minimum"
] |
How to get the biggest numbers out from huge amount of numbers? | 1,218,922 | <p>I'd like to get the largest 100 elements out from a list of at least 100000000 numbers.</p>
<p>I could sort the entire list and just take the last 100 elements from the sorted list, but that would be very expensive in terms of both memory and time.</p>
<p>Is there any existing easy, pythonic way of doing this?</p>... | 10 | 2009-08-02T13:43:21Z | 1,218,943 | <p>You can use a Heap data structure. A heap will not necessarily be ordered, but it is a fairly fast way to keep semi-ordered data, and it has the benefit of the smallest item always being the first element in the heap.</p>
<p>A heap has two basic operations that will help you: Add and Replace.</p>
<p>Basically what... | 5 | 2009-08-02T13:53:21Z | [
"python",
"sorting",
"max",
"minimum"
] |
How to get the biggest numbers out from huge amount of numbers? | 1,218,922 | <p>I'd like to get the largest 100 elements out from a list of at least 100000000 numbers.</p>
<p>I could sort the entire list and just take the last 100 elements from the sorted list, but that would be very expensive in terms of both memory and time.</p>
<p>Is there any existing easy, pythonic way of doing this?</p>... | 10 | 2009-08-02T13:43:21Z | 1,218,945 | <p>The heapq module in the standard library offers the nlargest() function to do this:</p>
<pre><code>top100 = heapq.nlargest(100, iterable [,key])
</code></pre>
<p>It won't sort the entire list, so you won't waste time on the elements you don't need.</p>
| 27 | 2009-08-02T13:54:27Z | [
"python",
"sorting",
"max",
"minimum"
] |
How to get the biggest numbers out from huge amount of numbers? | 1,218,922 | <p>I'd like to get the largest 100 elements out from a list of at least 100000000 numbers.</p>
<p>I could sort the entire list and just take the last 100 elements from the sorted list, but that would be very expensive in terms of both memory and time.</p>
<p>Is there any existing easy, pythonic way of doing this?</p>... | 10 | 2009-08-02T13:43:21Z | 1,218,953 | <p>The best way to do this is to maintain a heap sorted priority queue that you pop off of once it has 100 entries in it. </p>
<p>While you don't care if the results are sorted it is intuitively obvious you will get this for free. In order to know you have the top 100, you need to order your current list of top number... | 3 | 2009-08-02T13:59:47Z | [
"python",
"sorting",
"max",
"minimum"
] |
How to get the biggest numbers out from huge amount of numbers? | 1,218,922 | <p>I'd like to get the largest 100 elements out from a list of at least 100000000 numbers.</p>
<p>I could sort the entire list and just take the last 100 elements from the sorted list, but that would be very expensive in terms of both memory and time.</p>
<p>Is there any existing easy, pythonic way of doing this?</p>... | 10 | 2009-08-02T13:43:21Z | 1,219,090 | <p>Here is a solution I have used that is independent of libraries and that
will work in any programming language that has arrays:</p>
<p>Initialisation:</p>
<pre><code>Make an array of 100 elements and initialise all elements
with a low value (less than any value in your input list).
Initialise an integer variable ... | 2 | 2009-08-02T15:09:29Z | [
"python",
"sorting",
"max",
"minimum"
] |
How to get the biggest numbers out from huge amount of numbers? | 1,218,922 | <p>I'd like to get the largest 100 elements out from a list of at least 100000000 numbers.</p>
<p>I could sort the entire list and just take the last 100 elements from the sorted list, but that would be very expensive in terms of both memory and time.</p>
<p>Is there any existing easy, pythonic way of doing this?</p>... | 10 | 2009-08-02T13:43:21Z | 1,219,240 | <p>For the algorithms weenies in the audience: you can do this with a simple variation on Tony Hoare's algorithm <a href="http://portal.acm.org/citation.cfm?id=362489" rel="nofollow"><em>Find</em></a>:</p>
<pre><code>find(topn, a, i, j)
pick a random element x from a[i..j]
partition the subarray a[i..j] (just as... | 1 | 2009-08-02T16:45:34Z | [
"python",
"sorting",
"max",
"minimum"
] |
Can I redirect the stdout in python into some sort of string buffer? | 1,218,933 | <p>I'm using python's <code>ftplib</code> to write a small FTP client, but some of the functions in the package don't return string output, but print to <code>stdout</code>. I want to redirect <code>stdout</code> to an object which I'll be able to read the output from.</p>
<p>I know <code>stdout</code> can be redirect... | 76 | 2009-08-02T13:47:50Z | 1,218,940 | <p>Use <code>pipe()</code> and write to the appropriate file descriptor.</p>
<p><a href="https://docs.python.org/library/os.html#file-descriptor-operations" rel="nofollow">https://docs.python.org/library/os.html#file-descriptor-operations</a></p>
| 3 | 2009-08-02T13:51:08Z | [
"python",
"stream",
"stdout",
"redirect"
] |
Can I redirect the stdout in python into some sort of string buffer? | 1,218,933 | <p>I'm using python's <code>ftplib</code> to write a small FTP client, but some of the functions in the package don't return string output, but print to <code>stdout</code>. I want to redirect <code>stdout</code> to an object which I'll be able to read the output from.</p>
<p>I know <code>stdout</code> can be redirect... | 76 | 2009-08-02T13:47:50Z | 1,218,951 | <pre><code>from cStringIO import StringIO
import sys
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
# blah blah lots of code ...
sys.stdout = old_stdout
# examine mystdout.getvalue()
</code></pre>
| 121 | 2009-08-02T13:57:41Z | [
"python",
"stream",
"stdout",
"redirect"
] |
Can I redirect the stdout in python into some sort of string buffer? | 1,218,933 | <p>I'm using python's <code>ftplib</code> to write a small FTP client, but some of the functions in the package don't return string output, but print to <code>stdout</code>. I want to redirect <code>stdout</code> to an object which I'll be able to read the output from.</p>
<p>I know <code>stdout</code> can be redirect... | 76 | 2009-08-02T13:47:50Z | 1,220,002 | <p>Just to add to Ned's answer above: you can use this to redirect output to <strong>any object that implements a write(str) method</strong>.</p>
<p>This can be used to good effect to "catch" stdout output in a GUI application.</p>
<p>Here's a silly example in PyQt:</p>
<pre><code>import sys
from PyQt4 import QtGui
... | 30 | 2009-08-02T22:10:07Z | [
"python",
"stream",
"stdout",
"redirect"
] |
Can I redirect the stdout in python into some sort of string buffer? | 1,218,933 | <p>I'm using python's <code>ftplib</code> to write a small FTP client, but some of the functions in the package don't return string output, but print to <code>stdout</code>. I want to redirect <code>stdout</code> to an object which I'll be able to read the output from.</p>
<p>I know <code>stdout</code> can be redirect... | 76 | 2009-08-02T13:47:50Z | 19,345,047 | <p>Starting with Python 2.6 you can use anything implementing the <a href="http://docs.python.org/2/library/io.html#io.TextIOBase" rel="nofollow"><code>TextIOBase</code> API</a> from the io module as a replacement.
This solution also enables you to use <code>sys.stdout.buffer.write()</code> in Python 3 to write (alread... | 1 | 2013-10-13T12:10:50Z | [
"python",
"stream",
"stdout",
"redirect"
] |
Can I redirect the stdout in python into some sort of string buffer? | 1,218,933 | <p>I'm using python's <code>ftplib</code> to write a small FTP client, but some of the functions in the package don't return string output, but print to <code>stdout</code>. I want to redirect <code>stdout</code> to an object which I'll be able to read the output from.</p>
<p>I know <code>stdout</code> can be redirect... | 76 | 2009-08-02T13:47:50Z | 22,434,594 | <p>There is <a href="http://docs.python.org/3.4/library/contextlib.html#contextlib.redirect_stdout">contextlib.redirect_stdout() function</a> in Python 3.4:</p>
<pre><code>import io
from contextlib import redirect_stdout
with io.StringIO() as buf, redirect_stdout(buf):
print('redirected')
output = buf.getvalu... | 16 | 2014-03-16T08:18:22Z | [
"python",
"stream",
"stdout",
"redirect"
] |
Can I redirect the stdout in python into some sort of string buffer? | 1,218,933 | <p>I'm using python's <code>ftplib</code> to write a small FTP client, but some of the functions in the package don't return string output, but print to <code>stdout</code>. I want to redirect <code>stdout</code> to an object which I'll be able to read the output from.</p>
<p>I know <code>stdout</code> can be redirect... | 76 | 2009-08-02T13:47:50Z | 33,979,942 | <p>This method restores sys.stdout even if there's an exception. It also gets any output before the exception.</p>
<pre><code>real_stdout = sys.stdout
fake_stdout = io.BytesIO()
try:
sys.stdout = fake_stdout
# do what you gotta do to create some output
finally:
sys.stdout = real_stdout
output_string =... | 2 | 2015-11-29T06:10:42Z | [
"python",
"stream",
"stdout",
"redirect"
] |
How do I do database transactions with psycopg2/python db api? | 1,219,326 | <p>Im fiddling with psycopg2 , and while there's a .commit() and .rollback() there's no .begin() or similar to start a transaction , or so it seems ?
I'd expect to be able to do </p>
<pre><code>db.begin() # possible even set the isolation level here
curs = db.cursor()
cursor.execute('select etc... for update')
...
cur... | 17 | 2009-08-02T17:26:17Z | 1,219,376 | <p>Use <code>db.set_isolation_level(n)</code>, assuming <code>db</code> is your connection object. As Federico wrote <a href="https://web.archive.org/web/20100828225638/http://lists.initd.org/pipermail/psycopg/2004-February/002577.html" rel="nofollow">here</a>, the meaning of <code>n</code> is:</p>
<pre><code>0 -> ... | 21 | 2009-08-02T17:47:18Z | [
"python",
"database",
"postgresql"
] |
How do I do database transactions with psycopg2/python db api? | 1,219,326 | <p>Im fiddling with psycopg2 , and while there's a .commit() and .rollback() there's no .begin() or similar to start a transaction , or so it seems ?
I'd expect to be able to do </p>
<pre><code>db.begin() # possible even set the isolation level here
curs = db.cursor()
cursor.execute('select etc... for update')
...
cur... | 17 | 2009-08-02T17:26:17Z | 1,226,713 | <p>I prefer to explicitly see where my transactions are : </p>
<ul>
<li>cursor.execute("BEGIN")</li>
<li>cursor.execute("COMMIT")</li>
</ul>
| 3 | 2009-08-04T10:18:15Z | [
"python",
"database",
"postgresql"
] |
How do I do database transactions with psycopg2/python db api? | 1,219,326 | <p>Im fiddling with psycopg2 , and while there's a .commit() and .rollback() there's no .begin() or similar to start a transaction , or so it seems ?
I'd expect to be able to do </p>
<pre><code>db.begin() # possible even set the isolation level here
curs = db.cursor()
cursor.execute('select etc... for update')
...
cur... | 17 | 2009-08-02T17:26:17Z | 1,265,499 | <p>The <code>BEGIN</code> with python standard DB API is always implicit. When you start working with the database the driver issues a <code>BEGIN</code> and after any <code>COMMIT</code> or <code>ROLLBACK</code> another <code>BEGIN</code> is issued. A python DB API compliant with the specification should always work t... | 10 | 2009-08-12T11:03:28Z | [
"python",
"database",
"postgresql"
] |
Accessing data files before and after distutils/setuptools | 1,219,367 | <p>I'm doing a platform independent PyQt application. I intend to use write a setup.py files using setuptools. So far I've managed to detech platform, e.g. load specific options for setup() depending on platform in order to use py2exe on Windows... etc...</p>
<p>However, with my application I'm distributing some theme... | 10 | 2009-08-02T17:42:45Z | 1,219,406 | <p>I've used a utility method called data_file:</p>
<pre><code>def data_file(fname):
"""Return the path to a data file of ours."""
return os.path.join(os.path.split(__file__)[0], fname)
</code></pre>
<p>I put this in the <strong>init</strong>.py file in my project, and then call it from anywhere in my package... | 5 | 2009-08-02T17:58:14Z | [
"python",
"setuptools",
"distutils"
] |
Accessing data files before and after distutils/setuptools | 1,219,367 | <p>I'm doing a platform independent PyQt application. I intend to use write a setup.py files using setuptools. So far I've managed to detech platform, e.g. load specific options for setup() depending on platform in order to use py2exe on Windows... etc...</p>
<p>However, with my application I'm distributing some theme... | 10 | 2009-08-02T17:42:45Z | 2,568,149 | <p>You could try <a href="http://setuptools.readthedocs.io/en/latest/pkg_resources.html#resourcemanager-api" rel="nofollow"><code>pkg_resources</code></a>:</p>
<pre><code>my_data = pkg_resources.resource_string(__name__, fname)
</code></pre>
| 6 | 2010-04-02T17:35:44Z | [
"python",
"setuptools",
"distutils"
] |
Accessing data files before and after distutils/setuptools | 1,219,367 | <p>I'm doing a platform independent PyQt application. I intend to use write a setup.py files using setuptools. So far I've managed to detech platform, e.g. load specific options for setup() depending on platform in order to use py2exe on Windows... etc...</p>
<p>However, with my application I'm distributing some theme... | 10 | 2009-08-02T17:42:45Z | 3,702,842 | <p>You should <a href="http://setuptools.readthedocs.io/en/latest/pkg_resources.html" rel="nofollow">use the pkgutil/pkg_resources module to load the data files</a>. It even works from within ziped eggs.</p>
| 5 | 2010-09-13T17:27:02Z | [
"python",
"setuptools",
"distutils"
] |
Python Matplotlib hangs when asked to plot a second chart (after closing first chart window) | 1,219,394 | <p>Weird behaviour, I'm sure it's me screwing up, but I'd like to get to the bottom of what's happening: </p>
<p>I am running the following code to create a very simple graph window using matplotlib:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_... | 5 | 2009-08-02T17:53:36Z | 1,219,471 | <p>did you try:</p>
<pre><code>plt.close()
</code></pre>
<p>to make sure you closed the plot object? </p>
| 0 | 2009-08-02T18:22:44Z | [
"python",
"matplotlib"
] |
Python Matplotlib hangs when asked to plot a second chart (after closing first chart window) | 1,219,394 | <p>Weird behaviour, I'm sure it's me screwing up, but I'd like to get to the bottom of what's happening: </p>
<p>I am running the following code to create a very simple graph window using matplotlib:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_... | 5 | 2009-08-02T17:53:36Z | 1,220,036 | <p>Have you tried to use ipython instead of the standard python interpreter?</p>
<p>You can install ipython with the following command:</p>
<pre><code>easy_install ipython
</code></pre>
<p>and then, ipython has a specific mode to be ran with pylab, called -pylab:</p>
<pre><code>ipython -pylab
In[1]: ...
</code></p... | 2 | 2009-08-02T22:29:21Z | [
"python",
"matplotlib"
] |
Python Matplotlib hangs when asked to plot a second chart (after closing first chart window) | 1,219,394 | <p>Weird behaviour, I'm sure it's me screwing up, but I'd like to get to the bottom of what's happening: </p>
<p>I am running the following code to create a very simple graph window using matplotlib:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_... | 5 | 2009-08-02T17:53:36Z | 1,249,939 | <p>Apparently, this is caused by a bug in the tkinter backend. See, e.g., <a href="https://bugs.launchpad.net/ubuntu/+source/matplotlib/+bug/313834" rel="nofollow">https://bugs.launchpad.net/ubuntu/+source/matplotlib/+bug/313834</a> . It's being worked on...
If you can regress to a slightly older tkinter library, that... | 2 | 2009-08-08T21:23:59Z | [
"python",
"matplotlib"
] |
Python Matplotlib hangs when asked to plot a second chart (after closing first chart window) | 1,219,394 | <p>Weird behaviour, I'm sure it's me screwing up, but I'd like to get to the bottom of what's happening: </p>
<p>I am running the following code to create a very simple graph window using matplotlib:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_... | 5 | 2009-08-02T17:53:36Z | 1,787,772 | <p>Three months late to the party, but I found a suggestion in the matlibplot documentation to use draw() rather than show(); the former apparently just does a render of the current plot, while the latter starts up all the interactive tools, which is where the problems seem to start.</p>
<p>It's not terribly prominent... | 7 | 2009-11-24T04:25:16Z | [
"python",
"matplotlib"
] |
Python Matplotlib hangs when asked to plot a second chart (after closing first chart window) | 1,219,394 | <p>Weird behaviour, I'm sure it's me screwing up, but I'd like to get to the bottom of what's happening: </p>
<p>I am running the following code to create a very simple graph window using matplotlib:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_... | 5 | 2009-08-02T17:53:36Z | 1,895,460 | <p>As posted somewhere above:</p>
<p>Use <code>plt.draw()</code> for all your plots except the last one.</p>
<p>For your last plot, use <code>plt.show()</code> </p>
<p>It's weird, but if you don't use <code>plt.show()</code> in the last one and try <code>plt.draw()</code> instead, you don't see any plots.</p>
<p>Go... | 0 | 2009-12-13T03:19:05Z | [
"python",
"matplotlib"
] |
Python Matplotlib hangs when asked to plot a second chart (after closing first chart window) | 1,219,394 | <p>Weird behaviour, I'm sure it's me screwing up, but I'd like to get to the bottom of what's happening: </p>
<p>I am running the following code to create a very simple graph window using matplotlib:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_... | 5 | 2009-08-02T17:53:36Z | 39,326,913 | <p>I had this problem when using TkAgg as the backend. After using <code>plt.close('all')</code> my computer froze.</p>
<p>The solution was to switch to a different backend. I now use Qt4Agg instead.</p>
<p>If you have <a href="https://pypi.python.org/pypi/PyQt4" rel="nofollow">Qt4Agg installed</a> it is possible to ... | 0 | 2016-09-05T08:50:44Z | [
"python",
"matplotlib"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,219,563 | <p>in Python:</p>
<pre><code>for key, value in stateDict.items(): # .iteritems() in Python 2.x
print "The abbreviation for %s is %s." % (key, value)
</code></pre>
<p>in Java:</p>
<pre><code>Map<String,String> stateDict;
for (Map.Entry<String,String> e : stateDict.entrySet())
System.out.println("... | 30 | 2009-08-02T19:07:31Z | [
"java",
"php",
"python",
"associative-array"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,219,580 | <p>in java for associative array use Map</p>
<pre><code>import java.util.*;
class Foo
{
public static void main(String[] args)
{
Map<String, String> stateMap = new HashMap<String, String>();
stateMap.put("ALABAMA", "AL");
stateMap.put("ALASKA", "AK");
// ...
stateMap.put("... | 5 | 2009-08-02T19:13:14Z | [
"java",
"php",
"python",
"associative-array"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,219,601 | <p>Another way of doing it in Java. Although a better way has already been posted, this one's syntactically closer to your php code.</p>
<pre><code>for (String x:stateDict.keySet()){
System.out.printf("The abbreviation for %s is %s\n",x,stateDict.get(x));
}
</code></pre>
| 1 | 2009-08-02T19:25:27Z | [
"java",
"php",
"python",
"associative-array"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,219,684 | <p>Also, to maintain insertion order, you can use a LinkedHashMap instead of a HashMap.</p>
| 2 | 2009-08-02T19:55:56Z | [
"java",
"php",
"python",
"associative-array"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,219,813 | <p>In python an <a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">ordered dictionary</a> is available in Python 2.7 (not yet released) and Python 3.1. It's called OrderedDict.</p>
| 2 | 2009-08-02T20:49:19Z | [
"java",
"php",
"python",
"associative-array"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,219,820 | <p>This is the modified code from o948 where you use a TreeMap instead of a HashMap. The Tree map will preserve the ordering of the keys by the key.</p>
<pre><code>import java.util.*;
class Foo
{
public static void main(String[] args)
{
Map<String, String> stateMap = new TreeMap<String, String>();
... | 1 | 2009-08-02T20:50:26Z | [
"java",
"php",
"python",
"associative-array"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,219,975 | <p>Along the lines of Alexander's answer...</p>
<p>The native python dictionary doesn't maintain ordering for maximum efficiency of its primary use: an unordered mapping of keys to values.</p>
<p>I can think of two workarounds:</p>
<ol>
<li><p>look at the source code of OrderedDict and include it in your own program... | 1 | 2009-08-02T21:57:32Z | [
"java",
"php",
"python",
"associative-array"
] |
java and python equivalent of php's foreach($array as $key => $value) | 1,219,548 | <p>In php, one can handle a list of state names and their abbreviations with an associative array like this:</p>
<pre><code><?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
// etc...
"WYOMING"=>"WY"
);
foreach ($stateArray as $stateName => $stateAb... | 11 | 2009-08-02T19:02:46Z | 1,221,284 | <p>TreeMap is not an answer to your question because it sorts elements by key, while LinkedHashMap preserves original order. However, TreeMap is more suitable for the dictionary because of sorting.</p>
| 0 | 2009-08-03T08:49:52Z | [
"java",
"php",
"python",
"associative-array"
] |
Workarounds when a string is too long for a .join. OverflowError occurs | 1,219,733 | <p>I'm working through some python problems on pythonchallenge.com to teach myself python and I've hit a roadblock, since the string I am to be using is too large for python to handle. I receive this error:</p>
<pre><code>my-macbook:python owner1$ python singleoccurrence.py
Traceback (most recent call last):
File "... | 0 | 2009-08-02T20:13:52Z | 1,219,754 | <p><a href="http://docs.python.org/library/string.html">string.join</a> doesn't do what you think. join is used to combine a list of words into a single string with the given seperator. Ie:</p>
<pre><code>>>> ",".join(('foo', 'bar', 'baz'))
'foo,bar,baz'
</code></pre>
<p>The code snippet you posted will atte... | 10 | 2009-08-02T20:21:24Z | [
"python",
"overflow"
] |
Python: prefer several small modules or one larger module? | 1,219,815 | <p>I'm working on a Python web application in which I have some small modules that serve very specific functions: <code>session.py</code>, <code>logger.py</code>, <code>database.py</code>, etc. And by "small" I really do mean small; each of these files currently includes around 3-5 lines of code, or maybe up to 10 at m... | 8 | 2009-08-02T20:49:23Z | 1,219,844 | <blockquote>
<p>My thoughts are that having separate
modules helps with code clarity, and
later on, if by some chance these
modules grow to more than 10 lines, I
won't feel so bad about having them
separated.</p>
</blockquote>
<p>This. Keep it the way you have it. </p>
| 4 | 2009-08-02T21:00:45Z | [
"python",
"refactoring",
"module"
] |
Python: prefer several small modules or one larger module? | 1,219,815 | <p>I'm working on a Python web application in which I have some small modules that serve very specific functions: <code>session.py</code>, <code>logger.py</code>, <code>database.py</code>, etc. And by "small" I really do mean small; each of these files currently includes around 3-5 lines of code, or maybe up to 10 at m... | 8 | 2009-08-02T20:49:23Z | 1,219,850 | <p>Personally I find it easier to keep things like this in a single file, just for the practicality of editing a smaller number of files in my editor.</p>
<p>The important thing to do is <em>treat</em> the different pieces of code as though they were in separate files, so you ensure that you can trivially separate the... | 3 | 2009-08-02T21:03:37Z | [
"python",
"refactoring",
"module"
] |
Python: prefer several small modules or one larger module? | 1,219,815 | <p>I'm working on a Python web application in which I have some small modules that serve very specific functions: <code>session.py</code>, <code>logger.py</code>, <code>database.py</code>, etc. And by "small" I really do mean small; each of these files currently includes around 3-5 lines of code, or maybe up to 10 at m... | 8 | 2009-08-02T20:49:23Z | 1,219,867 | <p>Off course you can have as many modules as you like.</p>
<p>But now let as think a little, what happens when we put every small code snippet into one single file.</p>
<p>We will end up in hundreds of import statements in any less trivial module. And off course you could also save a little by having all explicit in... | 2 | 2009-08-02T21:11:27Z | [
"python",
"refactoring",
"module"
] |
Python: prefer several small modules or one larger module? | 1,219,815 | <p>I'm working on a Python web application in which I have some small modules that serve very specific functions: <code>session.py</code>, <code>logger.py</code>, <code>database.py</code>, etc. And by "small" I really do mean small; each of these files currently includes around 3-5 lines of code, or maybe up to 10 at m... | 8 | 2009-08-02T20:49:23Z | 1,219,881 | <p>As a user of modules, I greatly prefer when I can include the entire module via a single import. Don't make a user of your package do multiple imports unless there's some reason to allow for importing different alternates.</p>
<p>BTW, there's no reason a single modules can't consist of multiple source files. The si... | 4 | 2009-08-02T21:18:18Z | [
"python",
"refactoring",
"module"
] |
Python: prefer several small modules or one larger module? | 1,219,815 | <p>I'm working on a Python web application in which I have some small modules that serve very specific functions: <code>session.py</code>, <code>logger.py</code>, <code>database.py</code>, etc. And by "small" I really do mean small; each of these files currently includes around 3-5 lines of code, or maybe up to 10 at m... | 8 | 2009-08-02T20:49:23Z | 1,219,914 | <p>Small. </p>
| 0 | 2009-08-02T21:36:19Z | [
"python",
"refactoring",
"module"
] |
Python: prefer several small modules or one larger module? | 1,219,815 | <p>I'm working on a Python web application in which I have some small modules that serve very specific functions: <code>session.py</code>, <code>logger.py</code>, <code>database.py</code>, etc. And by "small" I really do mean small; each of these files currently includes around 3-5 lines of code, or maybe up to 10 at m... | 8 | 2009-08-02T20:49:23Z | 1,220,447 | <p>For command line scripts there most likely will not be much difference unless each invocation invokes all files in the module, in which case there will be a slight performance cost as n files need to be opened vs one.</p>
<p>For mod_python there most likely will be no difference as byte-compiled modules stay alive ... | 2 | 2009-08-03T02:12:08Z | [
"python",
"refactoring",
"module"
] |
Python GTK Drag and Drop - Get URL | 1,219,863 | <p>I'm creating a small app must be able to receive URLs. If the apps window is open, I should be able to drag a link from a browser and drop it into the app - and the app will save the URL to a database.</p>
<p>I'm creating this in Python/GTk. But I am a bit confused about the drag and drop functionality in it. So, h... | 4 | 2009-08-02T21:09:50Z | 1,221,896 | <p>You must fetch the data yourself. Here's a simple working example that will set a label to the url dropped:</p>
<pre><code>#!/usr/local/env python
import pygtk
pygtk.require('2.0')
import gtk
def motion_cb(wid, context, x, y, time):
l.set_text('\n'.join([str(t) for t in context.targets]))
context.drag_sta... | 8 | 2009-08-03T11:47:36Z | [
"python",
"drag-and-drop",
"gtk",
"gdk"
] |
Python GTK Drag and Drop - Get URL | 1,219,863 | <p>I'm creating a small app must be able to receive URLs. If the apps window is open, I should be able to drag a link from a browser and drop it into the app - and the app will save the URL to a database.</p>
<p>I'm creating this in Python/GTk. But I am a bit confused about the drag and drop functionality in it. So, h... | 4 | 2009-08-02T21:09:50Z | 5,389,964 | <p>To be sure to get only the data of one file or directory on DnD'ing a list of files from your file explorer, you could use something like:</p>
<pre><code>data.get_text().split(None,1)[0]
</code></pre>
<p>the code for the "got_data_cb" method would then look like this:</p>
<pre><code>def got_data_cb(wid, context, ... | 3 | 2011-03-22T10:42:03Z | [
"python",
"drag-and-drop",
"gtk",
"gdk"
] |
Python GTK Drag and Drop - Get URL | 1,219,863 | <p>I'm creating a small app must be able to receive URLs. If the apps window is open, I should be able to drag a link from a browser and drop it into the app - and the app will save the URL to a database.</p>
<p>I'm creating this in Python/GTk. But I am a bit confused about the drag and drop functionality in it. So, h... | 4 | 2009-08-02T21:09:50Z | 15,137,112 | <p>The only solution working for me is :</p>
<pre><code>def got_data_cb(wid, context, x, y, data, info, time):
# Got data.
l.set_text(data.get_uris()[0])
context.finish(True, False, time)
</code></pre>
| 1 | 2013-02-28T13:45:38Z | [
"python",
"drag-and-drop",
"gtk",
"gdk"
] |
Python GTK Drag and Drop - Get URL | 1,219,863 | <p>I'm creating a small app must be able to receive URLs. If the apps window is open, I should be able to drag a link from a browser and drop it into the app - and the app will save the URL to a database.</p>
<p>I'm creating this in Python/GTk. But I am a bit confused about the drag and drop functionality in it. So, h... | 4 | 2009-08-02T21:09:50Z | 38,056,395 | <p>The following code is ported from <a href="http://www.pygtk.org/pygtk2tutorial/examples/dragtargets.py" rel="nofollow">an example of the (old) PyGTK tutorial</a> which I guess inspired <a href="http://stackoverflow.com/a/1221896/2015768">the accepted answer</a>, but with pygi:</p>
<pre><code>#!/usr/local/env python... | 0 | 2016-06-27T14:21:40Z | [
"python",
"drag-and-drop",
"gtk",
"gdk"
] |
Storing data and searching by metadata? | 1,220,440 | <p>Let's say I have a set of data where each row is a pair of coordinates: (X, Y). Associated with each point I have arbitrary metadata, such as <code>{color: yellow}</code> or <code>{age: 2 years}</code>.</p>
<p>I'd like to be able to store the data and metadata in such a way that I can query the metadata (eg: <code>... | 0 | 2009-08-03T02:08:17Z | 1,220,446 | <p>Any relational database should be able to handle something like that (you'd basically just being doing a join between a couple of tables, one for the data and one for the metadata). SQLite should work fine.</p>
<p>Your first table would have the data itself with a unique IDs for each entry. Then your second table w... | 2 | 2009-08-03T02:12:02Z | [
"python",
"metadata"
] |
Storing data and searching by metadata? | 1,220,440 | <p>Let's say I have a set of data where each row is a pair of coordinates: (X, Y). Associated with each point I have arbitrary metadata, such as <code>{color: yellow}</code> or <code>{age: 2 years}</code>.</p>
<p>I'd like to be able to store the data and metadata in such a way that I can query the metadata (eg: <code>... | 0 | 2009-08-03T02:08:17Z | 1,220,471 | <p>Since the columns are neither predefined nor consistent across all rows you have to either go
with bigtable type implementations such as google appengine (exapndo models w/listproperty) or cassandra/hbase etc. (see <a href="http://en.wikipedia.org/wiki/BigTable" rel="nofollow">http://en.wikipedia.org/wiki/BigTable</... | 0 | 2009-08-03T02:27:01Z | [
"python",
"metadata"
] |
Storing data and searching by metadata? | 1,220,440 | <p>Let's say I have a set of data where each row is a pair of coordinates: (X, Y). Associated with each point I have arbitrary metadata, such as <code>{color: yellow}</code> or <code>{age: 2 years}</code>.</p>
<p>I'd like to be able to store the data and metadata in such a way that I can query the metadata (eg: <code>... | 0 | 2009-08-03T02:08:17Z | 1,220,533 | <p>Using @Dav's schema, a way to get " [all coordinate rows where age=2 and color=blue] " is (assuming (ID, Key, Value) is Unique in metadatatable, i.e., the latter has no entirely duplicate rows):</p>
<pre><code>SELECT datatable.Data
FROM datatable
JOIN metatadatable AS m USING(ID)
WHERE (m.Key="age" AND m.Val... | 1 | 2009-08-03T03:09:50Z | [
"python",
"metadata"
] |
"Watching" program being proccessed line-by-line? | 1,220,465 | <p>I'm looking for a debugging tool that will run my Python app, but display which line is currently being processed -- like an automatically stepping debugger. Basically I want to see what is going on, but be able to jump in if a traceback occurs.</p>
<p>Any suggestions?</p>
| 1 | 2009-08-03T02:24:32Z | 1,220,474 | <p>The integrated debugger in <a href="http://www.wingware.com/" rel="nofollow">Wing IDE</a> is quite versatile and nice to work with. (The <a href="http://www.wingware.com/wingide-101/index" rel="nofollow">Wing IDE 101</a> version is freeware.)</p>
| 0 | 2009-08-03T02:28:03Z | [
"python",
"debugging"
] |
"Watching" program being proccessed line-by-line? | 1,220,465 | <p>I'm looking for a debugging tool that will run my Python app, but display which line is currently being processed -- like an automatically stepping debugger. Basically I want to see what is going on, but be able to jump in if a traceback occurs.</p>
<p>Any suggestions?</p>
| 1 | 2009-08-03T02:24:32Z | 1,220,500 | <p>I think you're looking for the <a href="http://docs.python.org/library/pdb" rel="nofollow">pdb</a> module.</p>
| 1 | 2009-08-03T02:47:06Z | [
"python",
"debugging"
] |
"Watching" program being proccessed line-by-line? | 1,220,465 | <p>I'm looking for a debugging tool that will run my Python app, but display which line is currently being processed -- like an automatically stepping debugger. Basically I want to see what is going on, but be able to jump in if a traceback occurs.</p>
<p>Any suggestions?</p>
| 1 | 2009-08-03T02:24:32Z | 1,220,539 | <p><a href="http://winpdb.org/" rel="nofollow">Winpdb</a> is a good python debugger. It is written in Python under the GPL, so adding the automatic stepping functionality you want should not be too complicated. </p>
| 3 | 2009-08-03T03:13:45Z | [
"python",
"debugging"
] |
"Watching" program being proccessed line-by-line? | 1,220,465 | <p>I'm looking for a debugging tool that will run my Python app, but display which line is currently being processed -- like an automatically stepping debugger. Basically I want to see what is going on, but be able to jump in if a traceback occurs.</p>
<p>Any suggestions?</p>
| 1 | 2009-08-03T02:24:32Z | 1,221,572 | <p>"Basically I want to see what is going on, but be able to jump in if a traceback occurs."</p>
<p>Here's a radical thought: Don't.</p>
<p>"Watching" is a crutch. You should be writing small sections of code that you <strong>know</strong> will work. Then put those together.</p>
<p>Watching sometimes results from ... | 1 | 2009-08-03T10:17:47Z | [
"python",
"debugging"
] |
"Watching" program being proccessed line-by-line? | 1,220,465 | <p>I'm looking for a debugging tool that will run my Python app, but display which line is currently being processed -- like an automatically stepping debugger. Basically I want to see what is going on, but be able to jump in if a traceback occurs.</p>
<p>Any suggestions?</p>
| 1 | 2009-08-03T02:24:32Z | 1,222,253 | <p>There is also a very nice debugger in The <a href="http://pydev.sourceforge.net/" rel="nofollow">Python Eclipse plugin.</a></p>
| 0 | 2009-08-03T13:06:24Z | [
"python",
"debugging"
] |
"Watching" program being proccessed line-by-line? | 1,220,465 | <p>I'm looking for a debugging tool that will run my Python app, but display which line is currently being processed -- like an automatically stepping debugger. Basically I want to see what is going on, but be able to jump in if a traceback occurs.</p>
<p>Any suggestions?</p>
| 1 | 2009-08-03T02:24:32Z | 1,224,093 | <p>Try <a href="http://ipython.scipy.org/" rel="nofollow">IPython</a> alongwith <a href="http://pypi.python.org/pypi/ipdb/" rel="nofollow">ipdb</a></p>
| 0 | 2009-08-03T19:07:54Z | [
"python",
"debugging"
] |
How to make authkit session cookie HttpOnly in pylons? | 1,220,555 | <p>I use authkit module with Pylons and I see that session cookie it sets (aptly named authkit) is not set to be HttpOnly.</p>
<p>Is there a simple way to make it HttpOnly? (By "simple" I mean the one that does not involve hacking authkit's code.)</p>
| 1 | 2009-08-03T03:21:24Z | 1,220,664 | <p>This is not documented in authkit, because it only started working in Python 2.6 (see <a href="http://docs.python.org/library/cookie.html#Cookie.Morsel" rel="nofollow">here</a>), but if you do have Python 2.6 then </p>
<pre><code>authkit.cookie.params.httponly = true
</code></pre>
<p>in the config should work and ... | 1 | 2009-08-03T04:24:55Z | [
"python",
"cookies",
"pylons",
"authkit"
] |
Need to get the rest of an iterator in python | 1,220,640 | <p>Say I have an iterator.<br />
After iterating over a few items of the iterator, I will have to get rid of these first few items and return an iterator(preferably the same) with the rest of the items. How do I go about?
Also, Do iterators support remove or pop operations (like lists)?</p>
| 2 | 2009-08-03T04:11:13Z | 1,220,642 | <p>Yes, just use iter.next()</p>
<p>Example</p>
<pre><code>iter = xrange(3).__iter__()
iter.next() # this pops 0
for i in iter:
print i
1
2
</code></pre>
<p>You can pop off the front of an iterator with .next(). You cannot do any other fancy operations.</p>
| 6 | 2009-08-03T04:12:33Z | [
"python",
"iterator"
] |
Need to get the rest of an iterator in python | 1,220,640 | <p>Say I have an iterator.<br />
After iterating over a few items of the iterator, I will have to get rid of these first few items and return an iterator(preferably the same) with the rest of the items. How do I go about?
Also, Do iterators support remove or pop operations (like lists)?</p>
| 2 | 2009-08-03T04:11:13Z | 1,221,400 | <p>The <a href="http://docs.python.org/library/itertools.html#itertools.dropwhile" rel="nofollow"><code>itertools.dropwhile()</code></a> function might be helpful, too:</p>
<pre><code>dropwhile(lambda x: x<5, xrange(10))
</code></pre>
| 6 | 2009-08-03T09:25:25Z | [
"python",
"iterator"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.