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
list
Store output of subprocess.Popen call in a string
2,502,833
<p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p> <pre><code>#!/usr/bin/python import subprocess p2 = subprocess.Popen("ntpq -p") </code></pre> <p>I've tried a few things including some of the suggestions here:</p> <p><a href="http://stack...
155
2010-03-23T19:05:01Z
33,542,403
<p>This was perfect for me. You will get the return code, stdout and stderr in a tuple.</p> <pre><code>from subprocess import Popen, PIPE def console(cmd): p = Popen(cmd, shell=True, stdout=PIPE) out, err = p.communicate() return (p.returncode, out, err) </code></pre> <p>For Example:</p> <pre><code>res...
2
2015-11-05T10:38:21Z
[ "python", "subprocess" ]
Store output of subprocess.Popen call in a string
2,502,833
<p>I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.</p> <pre><code>#!/usr/bin/python import subprocess p2 = subprocess.Popen("ntpq -p") </code></pre> <p>I've tried a few things including some of the suggestions here:</p> <p><a href="http://stack...
155
2010-03-23T19:05:01Z
35,857,912
<p><strong>for Python 2.7+ the idiomatic answer is to use <a href="https://docs.python.org/2/library/subprocess.html#subprocess.check_output" rel="nofollow"><code>subprocess.check_output()</code></a></strong></p> <p>You should also note the handling of arguments when invoking a subprocess, as it can be a little confus...
4
2016-03-08T02:38:33Z
[ "python", "subprocess" ]
Using boost.python to import a method with opencv calls but failing due to symbols not being found after compilation
2,502,921
<p>So I don't have the code right now, as I am not home... but i used the boost library for python in C++ to allow python to access a function called something like loadImageIntoMainWindow(string filepath)</p> <p>in the C++ source code the method calls opencv methods that are imported at the top of the file, I include...
1
2010-03-23T19:20:21Z
3,378,327
<p>Add the lines (editing <code>/your/lib/path</code> as appropriate...):</p> <pre><code>lib cvlib : : &lt;name&gt;cv &lt;search&gt;/your/lib/path/lib ; lib cxcorelib : : &lt;name&gt;cxcore &lt;search&gt;/your/lib/path/lib ; </code></pre> <p>to your Jamfile, and edit</p> <pre><code>python-extension uTrackSpheresForP...
0
2010-07-31T13:39:05Z
[ "c++", "python", "opencv", "boost-python", "missing-symbols" ]
Superfluous python parameters
2,503,281
<p>I've noticed a discrepancy in the way that python parameters are called. In every other language I've dealt with, you either have </p> <pre><code>foo() </code></pre> <p>meaning either no parameters, or as many parameters as you like, or </p> <pre><code>foo(arg1, arg2,...,argn) </code></pre> <p>where you pass i...
1
2010-03-23T20:17:17Z
2,503,295
<p><code>zoo</code> is the self parameter.</p> <p>In C++, for example, you get the object passed implicitly as the <code>this</code> pointer. In Python, this parameter is explicit.</p>
3
2010-03-23T20:19:12Z
[ "python", "function", "parameters", "class" ]
Superfluous python parameters
2,503,281
<p>I've noticed a discrepancy in the way that python parameters are called. In every other language I've dealt with, you either have </p> <pre><code>foo() </code></pre> <p>meaning either no parameters, or as many parameters as you like, or </p> <pre><code>foo(arg1, arg2,...,argn) </code></pre> <p>where you pass i...
1
2010-03-23T20:17:17Z
2,503,307
<blockquote> <p>Where did the self parameter go?</p> </blockquote> <p>It's in front of the dot when you call the function, i.e. in your case it's <code>zoo</code>.</p> <p>Note that you can also call the function as <code>foo.bar(zoo, arg1, arg2)</code>. Basically in python <code>object.method(arguments)</code> is a...
6
2010-03-23T20:20:59Z
[ "python", "function", "parameters", "class" ]
Superfluous python parameters
2,503,281
<p>I've noticed a discrepancy in the way that python parameters are called. In every other language I've dealt with, you either have </p> <pre><code>foo() </code></pre> <p>meaning either no parameters, or as many parameters as you like, or </p> <pre><code>foo(arg1, arg2,...,argn) </code></pre> <p>where you pass i...
1
2010-03-23T20:17:17Z
2,503,308
<p><code>zoo</code> is implicitly passed as the first parameter in your example.</p>
1
2010-03-23T20:21:10Z
[ "python", "function", "parameters", "class" ]
Superfluous python parameters
2,503,281
<p>I've noticed a discrepancy in the way that python parameters are called. In every other language I've dealt with, you either have </p> <pre><code>foo() </code></pre> <p>meaning either no parameters, or as many parameters as you like, or </p> <pre><code>foo(arg1, arg2,...,argn) </code></pre> <p>where you pass i...
1
2010-03-23T20:17:17Z
2,503,677
<p>As I remember, "zoo.bar" gives you just an attribute "bar" of object "zoo" that can be called. All magic is done at construction where all methods of class is <em>binded</em> to that object while dictionary of attributes is populated. Consider next example:</p> <pre><code>zoo = foo() xbar = zoo.bar xbar(arg1, arg2)...
0
2010-03-23T21:15:29Z
[ "python", "function", "parameters", "class" ]
How to make Python Extensions for Windows for absolute beginners
2,503,310
<p>I've been looking around the internet trying to find a good step by step guide to extend Python in Windows, and I haven't been able to find something for my skill level.</p> <p>let's say you have some c code that looks like this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; double valuex(float ...
3
2010-03-23T20:21:17Z
2,503,350
<p>A start would be the documentation <a href="http://docs.python.org/py3k/extending/windows.html" rel="nofollow">Building C and C++ Extensions on Windows</a>.</p>
1
2010-03-23T20:27:24Z
[ "python", "windows", "python-3.x" ]
How to make Python Extensions for Windows for absolute beginners
2,503,310
<p>I've been looking around the internet trying to find a good step by step guide to extend Python in Windows, and I haven't been able to find something for my skill level.</p> <p>let's say you have some c code that looks like this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; double valuex(float ...
3
2010-03-23T20:21:17Z
2,503,385
<p>Well, the easiest way to create Python plugins is to use C++ and Boost.Python. In your example, the extension module would look as simple as this:</p> <pre><code>#include &lt;boost/python.hpp&gt; using namespace boost::python; // ... your valuex function goes here ... BOOST_PYTHON_MODULE(yourModuleName) { def...
0
2010-03-23T20:33:06Z
[ "python", "windows", "python-3.x" ]
How to make Python Extensions for Windows for absolute beginners
2,503,310
<p>I've been looking around the internet trying to find a good step by step guide to extend Python in Windows, and I haven't been able to find something for my skill level.</p> <p>let's say you have some c code that looks like this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; double valuex(float ...
3
2010-03-23T20:21:17Z
2,503,419
<p>Cython (Pyrex with a few kinks worked out and decisions made for practicality) can use one code base to make Python 2 and Python 3 modules. It's a really great choice for making libraries for 2 and 3. The <a href="http://docs.cython.org/" rel="nofollow">user guide</a> explains how to use it, but it doesn't demystify...
2
2010-03-23T20:37:20Z
[ "python", "windows", "python-3.x" ]
How to make Python Extensions for Windows for absolute beginners
2,503,310
<p>I've been looking around the internet trying to find a good step by step guide to extend Python in Windows, and I haven't been able to find something for my skill level.</p> <p>let's say you have some c code that looks like this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; double valuex(float ...
3
2010-03-23T20:21:17Z
2,503,458
<p>Depending on what you're trying to do, building your "extension" as a simple DLL and accessing it with <a href="http://docs.python.org/py3k/library/ctypes.html#module-ctypes" rel="nofollow">ctypes</a> could be, by far, the simplest approach.</p> <p>I used your code, slightly adjusted and saved as <code>mydll.c</cod...
2
2010-03-23T20:42:49Z
[ "python", "windows", "python-3.x" ]
How to make Python Extensions for Windows for absolute beginners
2,503,310
<p>I've been looking around the internet trying to find a good step by step guide to extend Python in Windows, and I haven't been able to find something for my skill level.</p> <p>let's say you have some c code that looks like this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; double valuex(float ...
3
2010-03-23T20:21:17Z
2,503,691
<p>At PyCon 2009, I gave a talk on how to write Python C extensions: <a href="http://nedbatchelder.com/text/whirlext.html" rel="nofollow">A Whirlwind Excursion through Python C Extensions</a>. There's nothing specific to Windows in it, but it covers the basic structure of an extension.</p>
0
2010-03-23T21:17:49Z
[ "python", "windows", "python-3.x" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,474
<p>If you write good unit tests for all of your code, you should find the errors very quickly when testing code.</p>
4
2010-03-23T20:44:20Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,516
<p>I tend to use</p> <pre><code>if x is None: raise ValueError('x cannot be None') </code></pre> <p>But this will only work with the actual <code>None</code> value.</p> <p>A more general approach is to test for the necessary attributes before you try to use them. For example:</p> <pre><code>def write_data(f): ...
-1
2010-03-23T20:50:40Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,535
<p>I haven’t done a lot of Python programming, but I’ve done no programming at all in staticly typed languages, so I don’t tend to think about things in terms of variable types. That might explain why I haven’t come across this problem much. (Although the small amount of Python programming I’ve done might exp...
0
2010-03-23T20:53:27Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,564
<p>Something you can use to simplify your code is using the <a href="http://code.activestate.com/recipes/68205-null-object-design-pattern/" rel="nofollow">Null Object Design Pattern</a> (to which I was introduced in <a href="http://books.google.com.ar/books?id=Q0s6Vgb98CQC&amp;pg=PT311&amp;lpg=PT311&amp;dq=Null+object+...
-1
2010-03-23T20:56:21Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,615
<p>One advantage of TDD is that you end up writing code that is easier to write tests for.</p> <p>Writing code first and then the tests can result in code that superficially works the same, but is much harder to write 100% coverage tests for.</p> <p>Each case is likely to be different</p> <p>It might make sense to h...
1
2010-03-23T21:04:29Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,704
<blockquote> <p>forgetting to check a type</p> </blockquote> <p>This doesn't make much sense. You so rarely need to "check" a type. You simply run unit tests and if you've provided the wrong type object, things fail. You never need to "check" much, in my experience.</p> <blockquote> <p>trying to call an attrib...
7
2010-03-23T21:19:36Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,849
<p>One tool to try to help you keep your pieces fitting together well is <em>interfaces</em>. <code>zope.interface</code> is the most notable package in the Python world for using interfaces. Check out <a href="http://wiki.zope.org/zope3/WhatAreInterfaces" rel="nofollow">http://wiki.zope.org/zope3/WhatAreInterfaces</a>...
2
2010-03-23T21:43:59Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,865
<p>You can also use <a href="http://wiki.python.org/moin/PythonDecoratorLibrary#TypeEnforcement.28accepts.2BAC8-returns.29" rel="nofollow">decorators to enforce the type of attributes</a>.</p> <pre><code>&gt;&gt;&gt; @accepts(int, int, int) ... @returns(float) ... def average(x, y, z): ... return (x + y + z) / 2 ....
3
2010-03-23T21:46:30Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
2,503,942
<blockquote> <p>forgetting to check a type</p> </blockquote> <p>With duck typing, it shouldn't be necessary to check a type. But that's theory, in reality you will often want to validate input parameters (e.g. checking a UUID with a regex). For that purpose, I created myself some handy decorators for simple type and...
1
2010-03-23T22:00:17Z
[ "python" ]
What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?
2,503,444
<p>I'm not sure if I like Python's dynamic-ness. It often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. </p> <p>Over...
8
2010-03-23T20:40:59Z
34,310,569
<p>You can hint your IDE via function doc, for example: <a href="http://www.pydev.org/manual_adv_type_hints.html" rel="nofollow">http://www.pydev.org/manual_adv_type_hints.html</a>, in JavaScript the jsDoc helps in a similar way.</p> <p>But at some point you will face errors that a typed language would avoid immediate...
0
2015-12-16T11:14:43Z
[ "python" ]
Simple forloop - Python
2,503,543
<p>this is probably too simple of a question, but here I go.</p> <p>I have paginated items, each page contains 100 items. The program fetches items till it reaches the item index specified within item_num</p> <p>This is what I have:</p> <pre><code>item_num = 56 range(0, item_num/100 + (item_num%100 &gt; 0)): get_...
2
2010-03-23T20:54:11Z
2,503,582
<p>You seem to be trying to call the function zero times if item_num is 0, once if item_num is 1 to 100, twice if item_num is between 101 and 200, etc...</p> <p>A simpler way to write this is:</p> <pre><code>n = 0 while n &lt; item_num: get_next_100() n += 100 </code></pre> <p>Or you could do it as a for loop:...
6
2010-03-23T20:58:33Z
[ "python" ]
Simple forloop - Python
2,503,543
<p>this is probably too simple of a question, but here I go.</p> <p>I have paginated items, each page contains 100 items. The program fetches items till it reaches the item index specified within item_num</p> <p>This is what I have:</p> <pre><code>item_num = 56 range(0, item_num/100 + (item_num%100 &gt; 0)): get_...
2
2010-03-23T20:54:11Z
2,503,599
<p>range takes a 3rd optional parameter of step.</p> <p>So</p> <pre><code>range(0,234,100) </code></pre> <p>Gives</p> <pre><code>[0, 100, 200] </code></pre> <p>So you can do something like</p> <pre><code>for items in range(0,234,100): get_next_100() </code></pre>
4
2010-03-23T21:01:52Z
[ "python" ]
Pygtk entry placeholder
2,503,562
<p>How to create pygtk entry with placeholder like in HTML 5 input element?</p>
2
2010-03-23T20:56:15Z
2,504,473
<p>Try this code if it does what you need:</p> <pre><code>import gtk class PlaceholderEntry(gtk.Entry): placeholder = 'Username' _default = True def __init__(self, *args, **kwds): gtk.Entry.__init__(self, *args, **kwds) self.connect('focus-in-event', self._focus_in_event) self.c...
8
2010-03-23T23:52:43Z
[ "python", "pygtk" ]
Pygtk entry placeholder
2,503,562
<p>How to create pygtk entry with placeholder like in HTML 5 input element?</p>
2
2010-03-23T20:56:15Z
8,696,530
<p>Since version 3.2, Gtk+ supports GtkEntry placeholder, but the only way to take advantage of it with Python is by using <a href="http://live.gnome.org/PyGObject" rel="nofollow">PyGobject</a> instead of PyGtk.</p> <p>Regards</p>
4
2012-01-02T00:29:08Z
[ "python", "pygtk" ]
Pygtk entry placeholder
2,503,562
<p>How to create pygtk entry with placeholder like in HTML 5 input element?</p>
2
2010-03-23T20:56:15Z
14,070,047
<p>You can use PyGobject instead of pygtk, and then setting a placeholder is a piece of cake: entry.set_placeholder_text("some string")</p>
0
2012-12-28T13:09:26Z
[ "python", "pygtk" ]
SWIG: Python list to uint32_t *?
2,503,592
<p>I'm trying to work with a Python module that was generated by SWIG. There's a C++ class defined that works like this (simplified):</p> <pre><code>namespace Foo { class Thing { public: Thing(); ~Thing(); bool DoSomething(uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer); ...
1
2010-03-23T21:00:17Z
2,506,609
<p>The last parameter to <code>DoSomething</code> is a <em>pointer to</em> <code>uint32_t</code>, not <code>uint32_t</code>. So unlike the other parameters, the function expects to receive a pointer to an integer or an array of integers (since arrays can be used wherever pointers are expected).</p> <p>I suspect in th...
2
2010-03-24T09:47:11Z
[ "c++", "python", "swig" ]
Should I use a metaclass, class decorator, or override the __new__ method?
2,503,676
<p>Here is my problem. I want the following class to have a bunch of property attributes. I could either write them all out like <code>foo</code> and <code>bar</code>, or based on some other examples I've seen, it looks like I could use a class decorator, a metaclass, or override the <code>__new__</code> method to se...
4
2010-03-23T21:15:29Z
2,503,795
<p>A metaclass's <code>__new__</code> does not become the <code>__new__</code> for the class you make—it's used to make the class itself. The <em>actual class object</em> is returned by the metaclass. A new instance of a class is returned by <code>__new__</code>.</p> <p>Consider the following (insane) code:</p> <pr...
2
2010-03-23T21:33:48Z
[ "python", "inheritance", "metaclass" ]
Should I use a metaclass, class decorator, or override the __new__ method?
2,503,676
<p>Here is my problem. I want the following class to have a bunch of property attributes. I could either write them all out like <code>foo</code> and <code>bar</code>, or based on some other examples I've seen, it looks like I could use a class decorator, a metaclass, or override the <code>__new__</code> method to se...
4
2010-03-23T21:15:29Z
2,503,801
<p>Metaclass is used when new class - not instance - is created. This way you can for example register classes (django does it and uses it for example to create tables in the database). Since <code>class</code> is an instruction you can think about as a decorator for a class.</p>
1
2010-03-23T21:34:22Z
[ "python", "inheritance", "metaclass" ]
Should I use a metaclass, class decorator, or override the __new__ method?
2,503,676
<p>Here is my problem. I want the following class to have a bunch of property attributes. I could either write them all out like <code>foo</code> and <code>bar</code>, or based on some other examples I've seen, it looks like I could use a class decorator, a metaclass, or override the <code>__new__</code> method to se...
4
2010-03-23T21:15:29Z
2,504,510
<p>Magic is bad. It makes your code harder to understand and maintain. You virtually never need metaclasses or <code>__new__</code>. </p> <p>It looks like your use case could be implemented with pretty straightforward code (with only a small hint of magic):</p> <pre><code>class Test(object): def calculate_attr(se...
4
2010-03-24T00:01:18Z
[ "python", "inheritance", "metaclass" ]
pylint ignore by directory
2,503,717
<p>Following is from <a href="http://linux.die.net/man/1/pylint">pylint docs</a>:</p> <pre><code>--ignore=&lt;file&gt; Add &lt;file or directory&gt; to the black list. It should be a base name, not a path. You may set this option multiple times. [current: %default] </code></pre> <p>Yet I'm not having luck getting...
8
2010-03-23T21:20:59Z
2,506,112
<p>You can then use Bash expansion to your advantage:</p> <pre><code>--ignore=migrations/{0000..1000}_something </code></pre>
-1
2010-03-24T07:57:11Z
[ "python", "pylint" ]
pylint ignore by directory
2,503,717
<p>Following is from <a href="http://linux.die.net/man/1/pylint">pylint docs</a>:</p> <pre><code>--ignore=&lt;file&gt; Add &lt;file or directory&gt; to the black list. It should be a base name, not a path. You may set this option multiple times. [current: %default] </code></pre> <p>Yet I'm not having luck getting...
8
2010-03-23T21:20:59Z
8,427,174
<p>Adding:</p> <pre><code>[MASTER] ignore=migrations </code></pre> <p>To my .pylintrc works with pylint 0.25. My problems are with PyDev which (it seems) is not respecting my settings. This is due, I think, to the fact that it's running pylint per-file, which I think bypasses 'ignore' checks - whether for modules/dir...
6
2011-12-08T06:40:23Z
[ "python", "pylint" ]
pylint ignore by directory
2,503,717
<p>Following is from <a href="http://linux.die.net/man/1/pylint">pylint docs</a>:</p> <pre><code>--ignore=&lt;file&gt; Add &lt;file or directory&gt; to the black list. It should be a base name, not a path. You may set this option multiple times. [current: %default] </code></pre> <p>Yet I'm not having luck getting...
8
2010-03-23T21:20:59Z
32,480,426
<p>You can not give a path but only the "basename" of the directory. E.g. use <code>--ignore=lib</code> instead of <code>--ignore-=appengine-toolkit/gaetk/lib</code>.</p> <p>Problem is you will ignore <em>bold</em> all directories named <code>lib</code>.</p>
2
2015-09-09T13:07:27Z
[ "python", "pylint" ]
WxPython, popup menus, callbacks and Windows XP
2,504,094
<p>My goal: the user clicks a button. From the button pops up a two-level menu. The user clicks on something, and this triggers a callback which does stuff.</p> <p>Here is a minimal example:</p> <pre><code>import wx class MyApp(wx.App): def OnInit(self): frame = TestFrame(None, -1, "Hello from wxPython...
1
2010-03-23T22:34:21Z
2,505,415
<p>You are handling ID generation yourself and in doing that mixing up IDs, anyway you do not need to generate IDs yourself use <code>wx.NewId()</code>, if you replace next_id with that it will work e.g.</p> <pre><code>mit = wx.MenuItem(submenu, id=wx.NewId(), text=item) </code></pre>
2
2010-03-24T04:55:19Z
[ "python", "windows-xp", "wxpython" ]
How to resize and draw an image using wxpython?
2,504,143
<p>I want to load an image, resize it to a given size and after draw it in a specific position in a panel.</p> <p>All this using wxpython.</p> <p>How can I do it?</p> <p>Thanks in advance!</p>
8
2010-03-23T22:41:50Z
2,504,531
<p>First off I think the wxPython Docs and Demos do a <em>great</em> job explaining how to use their libraries, especially because the demos can be played with on the fly to see the affect or you can revert to the original. Here is the Windows link to download all the files:</p> <p><a href="http://www.wxpython.org/d...
0
2010-03-24T00:07:08Z
[ "python", "image", "wxpython", "resize", "draw" ]
How to resize and draw an image using wxpython?
2,504,143
<p>I want to load an image, resize it to a given size and after draw it in a specific position in a panel.</p> <p>All this using wxpython.</p> <p>How can I do it?</p> <p>Thanks in advance!</p>
8
2010-03-23T22:41:50Z
2,504,607
<p><code>wx.Image</code> has a <code>Scale</code> method that will do the resizing. The rest is normal wx coding.</p> <p>Here's a complete example for you.</p> <pre><code>import wx def scale_bitmap(bitmap, width, height): image = wx.ImageFromBitmap(bitmap) image = image.Scale(width, height, wx.IMAGE_QUALITY...
20
2010-03-24T00:27:04Z
[ "python", "image", "wxpython", "resize", "draw" ]
How to resize and draw an image using wxpython?
2,504,143
<p>I want to load an image, resize it to a given size and after draw it in a specific position in a panel.</p> <p>All this using wxpython.</p> <p>How can I do it?</p> <p>Thanks in advance!</p>
8
2010-03-23T22:41:50Z
8,466,013
<p>If you mean adding the image to a toolbar / listbook / toolbook etc.. you will have to convert it to a bitmap (usually only bitmaps allowed).</p> <p>As far as i know you can't re-size a bitmap, therefore you will have to resize an image before and then convert it.</p> <p>Here is a good example <a href="http://mark...
1
2011-12-11T17:35:08Z
[ "python", "image", "wxpython", "resize", "draw" ]
Keeping track of changes - Django
2,504,386
<p>I have various models of which I would like to keep track and collect statistical data.</p> <p>The problem is how to store the changes throughout time.</p> <p>I thought of various alternative:</p> <ul> <li>Storing a log in a TextField, open it and update it every time the model is saved.</li> <li>Alternatively pi...
6
2010-03-23T23:27:16Z
2,504,417
<p>Don't reinvent the wheel.. Use <a href="http://code.google.com/p/django-reversion/">django-reversion</a> for logging changes.</p> <p>I'd break statistics off into a separate model though.</p>
6
2010-03-23T23:37:31Z
[ "python", "django", "django-models" ]
Keeping track of changes - Django
2,504,386
<p>I have various models of which I would like to keep track and collect statistical data.</p> <p>The problem is how to store the changes throughout time.</p> <p>I thought of various alternative:</p> <ul> <li>Storing a log in a TextField, open it and update it every time the model is saved.</li> <li>Alternatively pi...
6
2010-03-23T23:27:16Z
2,504,441
<p>Quoth my elementary chemistry teacher: "If you don't write it down, it didn't happen", therefore save logs in a file.</p> <p>Since the log information is disjoint from your application data (it's meta-data, actually), keep them separate. You could log to a database table but it should be distinct from your model.</...
1
2010-03-23T23:42:40Z
[ "python", "django", "django-models" ]
Keeping track of changes - Django
2,504,386
<p>I have various models of which I would like to keep track and collect statistical data.</p> <p>The problem is how to store the changes throughout time.</p> <p>I thought of various alternative:</p> <ul> <li>Storing a log in a TextField, open it and update it every time the model is saved.</li> <li>Alternatively pi...
6
2010-03-23T23:27:16Z
2,504,809
<p>I've had similar situation in which we were supposed to keep the history of changed. But we also needed audit to track who made the changes and the ability to revert. In our approach storing in database seemed more logical. However considering you have statistical data and it's gonnna be large, perhaps separate file...
1
2010-03-24T01:34:30Z
[ "python", "django", "django-models" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
2,504,427
<p>It depends on how you want the text to display. If you want it all to be left-aligned then either format it as in the first snippet or iterate through the lines left-trimming all the space.</p>
0
2010-03-23T23:39:19Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
2,504,454
<p>The <a href="http://docs.python.org/library/textwrap.html#textwrap.dedent"><code>textwrap.dedent</code></a> function allows one to start with <strong>correct indentation in the source</strong>, and then strip it from the text before use.</p> <p>The trade-off, as noted by some others, is that this is an extra functi...
163
2010-03-23T23:45:46Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
2,504,457
<p>You probably want to line up with the <code>"""</code></p> <pre><code>def foo(): string = """line one line two line three""" </code></pre> <p>Since the newlines and spaces are included in the string itself, you will have to postprocess it. If you don't want to do that and you have a w...
338
2010-03-23T23:46:35Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
9,931,625
<p>I came here looking for a simple 1-liner to <strong>remove/correct the identation level</strong> of the docstring for printing, <strong>without making it look untidy</strong>, for example by making it "hang outside the function" within the script.</p> <p>Here's what I ended up doing: </p> <pre><code>import string...
0
2012-03-29T18:53:40Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
16,829,814
<p>Some more options. In Ipython with pylab enabled, dedent is already in the namespace. I checked and it is from matplotlib. Or it can be imported with:</p> <pre><code>from matplotlib.cbook import dedent </code></pre> <p>In documentation it states that it is faster than the textwrap equivalent one and in my tests...
12
2013-05-30T06:56:58Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
32,926,139
<p>One option which seems to missing from the other answers (only mentioned deep down in a comment by naxa) is the following:</p> <pre><code>def foo(): string = ("line one\n" # Add \n in the string "line two" "\n" # Add "\n" after the string "line three\n") </code></pre> ...
8
2015-10-03T18:41:07Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
33,924,077
<p>If you want a quick&amp;easy solution and save yourself from typing newlines, you could opt for a list instead, e.g.:</p> <pre><code>def func(*args, **kwargs): string = '\n'.join([ 'first line of very long string and', 'second line of the same long thing and', 'third line of ...', ...
1
2015-11-25T18:36:26Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
35,885,957
<p>I prefer</p> <pre><code> def method(): string = \ """\ line one line two line three\ """ </code></pre> <p>or</p> <pre><code> def method(): string = """\ line one line two line three\ """ </code></pre>
3
2016-03-09T07:57:22Z
[ "python", "string" ]
Proper indentation for Python multiline strings
2,504,411
<p>What is the proper indentation for Python multiline strings within a function?</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or</p> <pre><code> def method(): string = """line one line two line three""" </code></pre> <p>or somethin...
307
2010-03-23T23:35:28Z
36,533,159
<p>My two cents, escape the end of line to get the indents:</p> <pre><code>def foo(): return "{}\n"\ "freq: {}\n"\ "temp: {}\n".format( time, freq, temp ) </code></pre>
0
2016-04-10T17:36:18Z
[ "python", "string" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
2,504,545
<p>I certainly have in both C and C++. Offhand, I don't see much relationship between its utility and how "modern" the language is.</p>
0
2010-03-24T00:10:59Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
2,504,549
<p>So that you can split long string literals across lines.</p> <p>And yes, I've seen it in production code.</p>
1
2010-03-24T00:11:27Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
2,504,550
<p>Cases where this can be useful:</p> <ul> <li>Generating strings including components defined by the preprocessor (this is perhaps the largest use case in C, and it's one I see very, very frequently).</li> <li>Splitting string constants over multiple lines</li> </ul> <p>To provide a more concrete example for the fo...
5
2010-03-24T00:11:33Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
2,504,553
<p>It's a great feature that allows you to combine preprocessor strings with your strings.</p> <pre><code>// Here we define the correct printf modifier for time_t #ifdef TIME_T_LONG #define TIME_T_MOD "l" #elif defined(TIME_T_LONG_LONG) #define TIME_T_MOD "ll" #else #define TIME_T_MOD "" #endif // And he ...
17
2010-03-24T00:12:02Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
2,504,555
<p>Sure, it's the easy way to make your code look good:</p> <pre><code>char *someGlobalString = "very long " "so broken " "onto multiple " "lines"; </code></pre> <p>The best reason, though, is for weird printf formats, like type forcing:</p> ...
22
2010-03-24T00:12:54Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
2,504,617
<p>I'm not sure about other programming languages, but for example C# doesn't allow you to do this (and I think this is a good thing). As far as I can tell, most of the examples that show why this is useful in C++ would still work if you could use some special operator for string concatenation:</p> <pre><code>string s...
2
2010-03-24T00:30:23Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
2,504,630
<p>From the python lexical analysis reference, section 2.4.2:</p> <blockquote> <p>This feature can be used to reduce the number of backslashes needed, to split long strings conveniently across long lines, or even to add comments to parts of strings</p> </blockquote> <p><a href="http://docs.python.org/refere...
3
2010-03-24T00:34:03Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
5,369,200
<p>While people have taken the words out of my mouth about the practical uses of the feature, nobody has so far tried to defend the choice of syntax.</p> <p>For all I know, the typo that can slip through as a result was probably just overlooked. After all, it seems robustness against typos wasn't at the front of Denn...
0
2011-03-20T14:52:42Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
21,629,914
<p>I see several <em>C</em> and <em>C++</em> answers but none of the really answer <em>why</em> or really what was the rationale for this feature? In <em>C++</em> this is feature comes from <em>C99</em> and we can find the rationale for this feature by going to <a href="http://www.open-std.org/jtc1/sc22/wg14/www/C99Rat...
4
2014-02-07T14:12:13Z
[ "python", "c++", "c", "d", "string-literals" ]
Why allow concatenation of string literals?
2,504,536
<p>I was recently bitten by a subtle bug.</p> <pre><code>char ** int2str = { "zero", // 0 "one", // 1 "two" // 2 "three",// 3 nullptr }; assert( int2str[1] == std::string("one") ); // passes assert( int2str[2] == std::string("two") ); // fails </code></pre> <p>If you have godlike code review powers...
11
2010-03-24T00:08:04Z
24,668,255
<p>For rationale, expanding and simplifying Shafik Yaghmour’s answer: string literal concatenation originated in C (hence inherited by C++), as did the term, for two reasons (references are from <em><a href="http://www.lysator.liu.se/c/rat/title.html" rel="nofollow">Rationale for the ANSI C Programming Language</a></...
1
2014-07-10T04:00:17Z
[ "python", "c++", "c", "d", "string-literals" ]
add properties to users google app engine
2,504,748
<p>What is the best way to save a user profile with Google App Engine (Python) ? What I did to solve this problem is create another Model, with a UserProperty, but requesting the profile from the user I have to do something like this:</p> <pre><code>if user: profile = Profile.all().filter('user =', user).fetch(1) ...
2
2010-03-24T01:14:57Z
2,505,056
<p>No, this is a pretty correct approach (though you might want to also store some of those profiles in memcache, of course;-). It's going to be fast, since there will be an index on the <code>user</code> field. You sure can't modify the Google-supplied user model, if that's what you're asking.</p>
1
2010-03-24T02:59:36Z
[ "python", "google-app-engine", "profiling" ]
add properties to users google app engine
2,504,748
<p>What is the best way to save a user profile with Google App Engine (Python) ? What I did to solve this problem is create another Model, with a UserProperty, but requesting the profile from the user I have to do something like this:</p> <pre><code>if user: profile = Profile.all().filter('user =', user).fetch(1) ...
2
2010-03-24T01:14:57Z
2,505,287
<p>If you make the user_id of the user the key_name of the user's Profile entity, you can fetch it using Profile.get_by_key_name(), which will be faster than querying and then fetching.</p> <p>Memcaching including the user_id as part of the key will allow even faster access to the profile.</p>
4
2010-03-24T04:11:19Z
[ "python", "google-app-engine", "profiling" ]
add properties to users google app engine
2,504,748
<p>What is the best way to save a user profile with Google App Engine (Python) ? What I did to solve this problem is create another Model, with a UserProperty, but requesting the profile from the user I have to do something like this:</p> <pre><code>if user: profile = Profile.all().filter('user =', user).fetch(1) ...
2
2010-03-24T01:14:57Z
3,890,869
<p>This is not a solution but a warning.</p> <p>user value is not a unique and stable identifier for a User. And the user_id property only exists for google users not for OpenId. So don't trust this solution.</p>
1
2010-10-08T13:18:17Z
[ "python", "google-app-engine", "profiling" ]
Hooking up Sproutcore frontend and custom Python backend
2,504,772
<p>I am building a web-based application. The frontend has been designed in Sproutcore. For the backend, we have our own python API which handles all transactions with multiple databases. What is the best way to hook up the front-end with the back-end. </p> <p>AFAIK django is pretty monolithic (correct me if i am wron...
2
2010-03-24T01:22:28Z
2,505,144
<p>The only thing I know about sproutcore is what I read about 10 seconds ago to answer this. Javascript can do ajax so I assume so can sproutcore. So providing a restful api+json to your backend would be an option. If you need to sell it to your boss, call it a service oriented architecture. You'll probably have it wo...
2
2010-03-24T03:27:31Z
[ "python", "django", "django-models", "sproutcore" ]
Hooking up Sproutcore frontend and custom Python backend
2,504,772
<p>I am building a web-based application. The frontend has been designed in Sproutcore. For the backend, we have our own python API which handles all transactions with multiple databases. What is the best way to hook up the front-end with the back-end. </p> <p>AFAIK django is pretty monolithic (correct me if i am wron...
2
2010-03-24T01:22:28Z
2,505,486
<p>There's also <a href="http://bottle.paws.de" rel="nofollow">Bottle.py</a> if you just want it simple.</p>
2
2010-03-24T05:12:20Z
[ "python", "django", "django-models", "sproutcore" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,504,806
<p>Python (duh), setuptools or pip, virtualenv, and an editor. I suggest geany, but that's just me. And of course, any other Python modules you'll need.</p>
2
2010-03-24T01:33:35Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,504,835
<p>Your system already has Python on it. Use the text editor or IDE of your choice; I like vim. </p> <p>I can't tell you what third-party modules you need without knowing what kind of development you will be doing. Use apt as much as you can to get the libraries.</p> <hr> <p>To speak to your edit:</p> <p>This isn't...
14
2010-03-24T01:44:02Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,504,838
<p>If you launch a terminal and type <code>python</code> you'll get an interpreter, where you can start trying stuff.</p> <p>Just in case you haven't seen it, check out the book <strong>Dive Into Python</strong>, is free on-line. <a href="http://www.diveintopython.org/" rel="nofollow">http://www.diveintopython.org/</a...
3
2010-03-24T01:45:13Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,504,896
<p>Since I'm accustomed to Eclipse, I find Eclipse + PyDev convenient for Python. For quick computations, Idle is great.</p> <p>I've used Python on Windows and on Ubuntu, and Linux is much cleaner.</p>
4
2010-03-24T02:02:01Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,505,093
<p>In order to reduce the chance of effecting/hosing the system install of python, I typically install <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> on the ubuntu python install. I then create a virtualenv in my home directory so that subsequent packages I install via pip or easy_install do not effect...
6
2010-03-24T03:11:31Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,505,275
<p>If you're just starting out with Python, I'd actually argue against bringing in the complexity of <code>virtualenv</code> (which I think can be pretty overwhelming), at least until you've got a firm grasp of Python basics (especially regarding library/dependency management).</p> <p>If you're using Ubuntu and the G...
1
2010-03-24T04:06:36Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,505,304
<p>You would probably like to give <a href="http://wiki.netbeans.org/Python" rel="nofollow">NetBeans Python IDE</a> a shot. You can choose to use either Windows/Linux. </p>
0
2010-03-24T04:19:09Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,505,840
<p>Database: sqlite (inbuilt). You might want SQLAlchemy though.</p> <p>GUI: tcl is inbuilt, but wxPython or pyQt are recommended.</p> <p>IDE: I use idle (inbuilt) on windows, TextMate on Mac, but you might like PyDev. I've also heard good things about ulipad.</p> <p>Numerics: numpy.</p> <p>Fast inline code: lots o...
0
2010-03-24T06:50:01Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
2,506,982
<p>You don't need much. Python comes with "Batteries Included."</p> <p>Visual Studio == IDLE. You already have it. If you want more IDE-like environment, install Komodo Edit.</p> <p>NUnit == <code>unittest</code>. You already have it in the standard library.</p> <p>SQL Server == <code>sqlite</code>. You already...
1
2010-03-24T10:48:32Z
[ "python", "programming-languages", "development-environment" ]
How do I set up a Python development environment on Linux?
2,504,800
<p>I'm a .NET developer who knows very little about Python, but want to give it a test drive for a small project I'm working on.</p> <p>What tools and packages should I install on my machine? I'm looking for a common, somewhat comprehensive, development environment.</p> <p>I'll likely run Ubuntu 9.10, but I'm flexibl...
11
2010-03-24T01:31:36Z
6,586,855
<p><em>Getting to Python from .NET world</em></p> <p>Jumping into the Linux world from a .NET / WIndows background can be a bit disconcerting (but I do encourage you to keep trying Linux)</p> <p>But I would suggest to anyone coming from Windows, to stick with Windows for a little while. goto www.Activestate.com and ...
2
2011-07-05T17:59:36Z
[ "python", "programming-languages", "development-environment" ]
Backup of folder + database - Python
2,504,907
<p>I feel like this is quite delicate, </p> <p>I have various folders whith projects I would like to backup into a zip/tar file, but would like to avoid backing up files such as <strong>pyc</strong> files and temporary files.</p> <p>I also have a Postgres db I need to backup.</p> <hr> <p>Any tips for running this o...
2
2010-03-24T02:06:34Z
2,504,982
<p>If you're on Linux (or any other form of Unix, such as MacOSX), a simple way to reduce a process's priority -- and therefore, indirectly, its consumption of CPU if other processes want some -- is the <a href="http://en.wikipedia.org/wiki/Nice_%28Unix%29" rel="nofollow">nice</a> command. In Python (same OSs), <a hre...
4
2010-03-24T02:34:41Z
[ "python", "bash", "postgresql", "backup", "archiving" ]
Backup of folder + database - Python
2,504,907
<p>I feel like this is quite delicate, </p> <p>I have various folders whith projects I would like to backup into a zip/tar file, but would like to avoid backing up files such as <strong>pyc</strong> files and temporary files.</p> <p>I also have a Postgres db I need to backup.</p> <hr> <p>Any tips for running this o...
2
2010-03-24T02:06:34Z
2,505,103
<p>On linux, you can use tar with <code>--exclude</code> option. an example, to exclude your <code>.pyc</code> files and temp files (in this example, <code>.tmp</code>)</p> <pre><code>$ tar zcvf backup.tar.gz --exclude "*.tmp" --exclude "*.pyc" </code></pre> <p>use the <code>z</code> option to zip it up as well.</p>
2
2010-03-24T03:13:46Z
[ "python", "bash", "postgresql", "backup", "archiving" ]
Backup of folder + database - Python
2,504,907
<p>I feel like this is quite delicate, </p> <p>I have various folders whith projects I would like to backup into a zip/tar file, but would like to avoid backing up files such as <strong>pyc</strong> files and temporary files.</p> <p>I also have a Postgres db I need to backup.</p> <hr> <p>Any tips for running this o...
2
2010-03-24T02:06:34Z
2,505,453
<p>With today's multicore cpus, you may find that cpu is not the bottle neck. It is now far more likely to the the disk I/O that needs to be shared better.</p> <p>Linux has the ionice command to allow you to control this</p> <blockquote> <p>ionice(1)</p> <p>NAME </p> <pre><code> ionice - get/set program io...
1
2010-03-24T05:04:14Z
[ "python", "bash", "postgresql", "backup", "archiving" ]
Backup of folder + database - Python
2,504,907
<p>I feel like this is quite delicate, </p> <p>I have various folders whith projects I would like to backup into a zip/tar file, but would like to avoid backing up files such as <strong>pyc</strong> files and temporary files.</p> <p>I also have a Postgres db I need to backup.</p> <hr> <p>Any tips for running this o...
2
2010-03-24T02:06:34Z
2,505,574
<p>Backup is at least as much about the importance of <strong>recovery</strong> using whatever backup you make.</p> <p>The right way to back up source code is to <strong>keep source files in a VCS (version control system)</strong>, and back up the VCS repository. Exclude any auto-generated easily-replaced files (like ...
1
2010-03-24T05:34:44Z
[ "python", "bash", "postgresql", "backup", "archiving" ]
wx Menu disappears from frame when shown as a popup
2,504,962
<p>I'm trying to create a wx.Menu that will be shared between a popup (called on right-click), and a sub menu accessible from the frame menubar. The following code demonstrates the problem. </p> <p>If you open the "MENU>submenu" from the menubar the item "asdf" is visible. If you right click on the frame content ar...
1
2010-03-24T02:29:05Z
2,504,991
<p>I would make a function, <code>create_menu</code>, that creates and returns a <code>wx.Menu</code> object. Call it once to add it to your menu bar and call it in <code>show_popup</code>. So you're using separate Menu objects. Don't worry about creating them on each right-click, it's not a big deal.</p>
1
2010-03-24T02:37:32Z
[ "python", "wxpython", "menu" ]
Python class design - Splitting up big classes into multiple ones to group functionality
2,505,166
<p>OK I've got 2 really big classes > 1k lines each that I currently have split up into multiple ones. They then get recombined using multiple inheritance. Now I'm wondering, if there is any cleaner/better more pythonic way of doing this. Completely factoring them out would result in endless amounts of <code>self.other...
9
2010-03-24T03:34:35Z
2,505,183
<p>I think this is more of a general OO-design problem than Python problem. Python pretty much gives you all the classic OOP tools, conveniently packaged. You'd have to describe the problem in more detail (e.g. what do the <code>GUIEvents</code> and <code>GUIHelpers</code> classes contain?)</p> <p>One Python-specific ...
1
2010-03-24T03:38:01Z
[ "python", "design", "class" ]
Python class design - Splitting up big classes into multiple ones to group functionality
2,505,166
<p>OK I've got 2 really big classes > 1k lines each that I currently have split up into multiple ones. They then get recombined using multiple inheritance. Now I'm wondering, if there is any cleaner/better more pythonic way of doing this. Completely factoring them out would result in endless amounts of <code>self.other...
9
2010-03-24T03:34:35Z
2,505,578
<p>Your code may be substantially improved by implementing a Model-View-Controller design. Depending on how your GUI and tool are setup, you may also benefit from "widgetizing" portions of your GUI, so that rather than having one giant Model-View-Controller, you have a main Model-View-Controller that manages a bunch o...
0
2010-03-24T05:36:08Z
[ "python", "design", "class" ]
Python class design - Splitting up big classes into multiple ones to group functionality
2,505,166
<p>OK I've got 2 really big classes > 1k lines each that I currently have split up into multiple ones. They then get recombined using multiple inheritance. Now I'm wondering, if there is any cleaner/better more pythonic way of doing this. Completely factoring them out would result in endless amounts of <code>self.other...
9
2010-03-24T03:34:35Z
2,505,605
<p>Start by finding classes that model <strong>real world concepts</strong> that your application needs to work with. Those are natural candidates for classes.</p> <p>Try to <strong>avoid multiple inheritance</strong> as much as possible; it's rarely useful and always somewhat confusing. Instead, look to use <strong>f...
4
2010-03-24T05:44:18Z
[ "python", "design", "class" ]
Python class design - Splitting up big classes into multiple ones to group functionality
2,505,166
<p>OK I've got 2 really big classes > 1k lines each that I currently have split up into multiple ones. They then get recombined using multiple inheritance. Now I'm wondering, if there is any cleaner/better more pythonic way of doing this. Completely factoring them out would result in endless amounts of <code>self.other...
9
2010-03-24T03:34:35Z
2,505,659
<p>If you want to use multiple inheritance to combine everything into one big class (it might make sense to do this), then you can refactor each of the parent classes so that every method and property is either private (starts with '<code>__</code>') or has a short 2-3 character prefix unique to that class. For example...
5
2010-03-24T06:00:59Z
[ "python", "design", "class" ]
Splitting a list in python
2,505,251
<p>Hey im new to python. How do you get a portion of a list by the relative value of its sorting key.</p> <p>example...</p> <pre> list = [11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10] list.sort() newList = list.split("all numbers that are over 13") assert newList == [14,15,16] </pre>
2
2010-03-24T03:59:49Z
2,505,261
<pre><code>&gt;&gt;&gt; l = [11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10] &gt;&gt;&gt; sorted(x for x in l if x &gt; 13) [14, 15, 16] </code></pre> <p>or with filter (would be a little bit slower if you have big list, because of lambda)</p> <pre><code>&gt;&gt;&gt; sorted(filter(lambda x: x &gt; 13, l)) [14, 15, 16] </code...
3
2010-03-24T04:02:05Z
[ "python" ]
Splitting a list in python
2,505,251
<p>Hey im new to python. How do you get a portion of a list by the relative value of its sorting key.</p> <p>example...</p> <pre> list = [11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10] list.sort() newList = list.split("all numbers that are over 13") assert newList == [14,15,16] </pre>
2
2010-03-24T03:59:49Z
2,505,268
<p>Use <code>[item for item in newList if item &gt; 13]</code>.</p> <p>There is a decent chance this could be replaced with the generator expression <code>(item for item in newList if item &gt; 13)</code>, which filters lazily rather than storing the whole list in memory.</p> <hr> <p>You might also be interested in ...
3
2010-03-24T04:03:46Z
[ "python" ]
Python ldap AttributeError
2,505,317
<p>I have an python error <strong>AttributeError: 'module' object has no attribute 'initialize'</strong> I am running Python 2.6.2 on Solaris 10 UNIX and recently installed the pythonldap 2.3.9. The script is very basic, only has these 2 lines. Can anyone tell me why?? Traceback error below. </p> <pre><code>#!/usr/lo...
4
2010-03-24T04:22:20Z
2,505,330
<p>Did you name a file in the current directory ldap.py that is shadowing the one that you want?</p>
17
2010-03-24T04:24:55Z
[ "python", "openldap" ]
Python ldap AttributeError
2,505,317
<p>I have an python error <strong>AttributeError: 'module' object has no attribute 'initialize'</strong> I am running Python 2.6.2 on Solaris 10 UNIX and recently installed the pythonldap 2.3.9. The script is very basic, only has these 2 lines. Can anyone tell me why?? Traceback error below. </p> <pre><code>#!/usr/lo...
4
2010-03-24T04:22:20Z
2,505,361
<p>An easy way to tell if the <code>ldap</code> you're importing is the right one is to print <code>ldap.__file__</code>, which prints the full path to the module file (usually a '.pyc'). If it's not the one installed in the location you are expecting, this is your problem, as <a href="http://stackoverflow.com/users/19...
2
2010-03-24T04:37:18Z
[ "python", "openldap" ]
Python ldap AttributeError
2,505,317
<p>I have an python error <strong>AttributeError: 'module' object has no attribute 'initialize'</strong> I am running Python 2.6.2 on Solaris 10 UNIX and recently installed the pythonldap 2.3.9. The script is very basic, only has these 2 lines. Can anyone tell me why?? Traceback error below. </p> <pre><code>#!/usr/lo...
4
2010-03-24T04:22:20Z
2,505,400
<p>You can get that error if you're somehow picking up the "ldap.py" from sos/plugins/ instead of the ldap package itself. Make sure the "python-ldap" package is actually installed...</p>
1
2010-03-24T04:49:46Z
[ "python", "openldap" ]
Sqlalchemy layout with WSGI application
2,505,426
<p>I'm working on writing a small WSGI application using <a href="http://bottle.paws.de/" rel="nofollow">Bottle</a> and SqlAlchemy and am confused on how the "layout" of my application should be in terms of SqlAlchemy.</p> <p>My confusion is with creating engines and sessions. My understanding is that I should only cr...
4
2010-03-24T04:57:58Z
2,506,092
<p>You don't have to create an engine manually. For web applications, it's best to use a scoped session which is effectively a threadlocal, used during a single request.</p> <pre><code>from sqlalchemy import MetaData from sqlalchemy.orm import scoped_session, sessionmaker session = scoped_session(sessionmaker()) meta...
2
2010-03-24T07:54:15Z
[ "python", "sqlalchemy" ]
Sqlalchemy layout with WSGI application
2,505,426
<p>I'm working on writing a small WSGI application using <a href="http://bottle.paws.de/" rel="nofollow">Bottle</a> and SqlAlchemy and am confused on how the "layout" of my application should be in terms of SqlAlchemy.</p> <p>My confusion is with creating engines and sessions. My understanding is that I should only cr...
4
2010-03-24T04:57:58Z
2,511,335
<p>What you need to achieve is well described in the pylons documentation: <a href="http://pylonshq.com/docs/en/0.9.7/models/#defining-tables-and-orm-classes">Defining Tables and ORM classes</a>:</p> <blockquote> <p>The model consists of two files: <code>__init__.py</code> and meta.py. <code>__init__.py</code> conta...
6
2010-03-24T20:55:57Z
[ "python", "sqlalchemy" ]
Appending item to lists within a list comprehension
2,505,529
<p>I have a list, let's say, <code>a = [[1,2],[3,4],[5,6]]</code></p> <p>I want to add the string <code>'a'</code> to each item in the list <code>a</code>.</p> <p>When I use:</p> <pre><code> a = [x.append('a') for x in a] </code></pre> <p>it returns <code>[None,None,None]</code>. </p> <p>But if I use:</p> <pre><...
9
2010-03-24T05:23:23Z
2,505,542
<p>For the first case, the reason it returns <code>[None, None, None]</code> is because the <code>list.append</code> function returns <code>None</code>, and that's what it stores in the list.</p> <p>In the second case, it's because the list is mutable, and each time you append the value, the original list is modified....
7
2010-03-24T05:27:17Z
[ "python", "list", "append", "list-comprehension" ]
Appending item to lists within a list comprehension
2,505,529
<p>I have a list, let's say, <code>a = [[1,2],[3,4],[5,6]]</code></p> <p>I want to add the string <code>'a'</code> to each item in the list <code>a</code>.</p> <p>When I use:</p> <pre><code> a = [x.append('a') for x in a] </code></pre> <p>it returns <code>[None,None,None]</code>. </p> <p>But if I use:</p> <pre><...
9
2010-03-24T05:23:23Z
2,505,556
<p><code>list.append</code> mutates the list itself and returns <code>None</code>. List comprehensions are for storing the result, which isn't what you want in this case if you want to just change the original lists.</p> <pre><code>&gt;&gt;&gt; x = [[1, 2], [3, 4], [5, 6]] &gt;&gt;&gt; for sublist in x: ... sublis...
19
2010-03-24T05:29:29Z
[ "python", "list", "append", "list-comprehension" ]
Appending item to lists within a list comprehension
2,505,529
<p>I have a list, let's say, <code>a = [[1,2],[3,4],[5,6]]</code></p> <p>I want to add the string <code>'a'</code> to each item in the list <code>a</code>.</p> <p>When I use:</p> <pre><code> a = [x.append('a') for x in a] </code></pre> <p>it returns <code>[None,None,None]</code>. </p> <p>But if I use:</p> <pre><...
9
2010-03-24T05:23:23Z
2,505,590
<p>(This is a combination of the answers by Mike Graham and sykora):</p> <p>If you merely want to change the values in-place, try a regular for-loop, and not a list comprehension:</p> <pre><code>for sublist in a: sublist.append('a') </code></pre> <p>If you want to leave a alone, and put the result in a1:</p> <p...
3
2010-03-24T05:40:04Z
[ "python", "list", "append", "list-comprehension" ]
Appending item to lists within a list comprehension
2,505,529
<p>I have a list, let's say, <code>a = [[1,2],[3,4],[5,6]]</code></p> <p>I want to add the string <code>'a'</code> to each item in the list <code>a</code>.</p> <p>When I use:</p> <pre><code> a = [x.append('a') for x in a] </code></pre> <p>it returns <code>[None,None,None]</code>. </p> <p>But if I use:</p> <pre><...
9
2010-03-24T05:23:23Z
2,507,024
<p>leave the <code>a =</code> and use the side effect on <code>a</code>:</p> <pre><code>[x.append('a') for x in a] print a </code></pre>
0
2010-03-24T10:57:37Z
[ "python", "list", "append", "list-comprehension" ]
Appending item to lists within a list comprehension
2,505,529
<p>I have a list, let's say, <code>a = [[1,2],[3,4],[5,6]]</code></p> <p>I want to add the string <code>'a'</code> to each item in the list <code>a</code>.</p> <p>When I use:</p> <pre><code> a = [x.append('a') for x in a] </code></pre> <p>it returns <code>[None,None,None]</code>. </p> <p>But if I use:</p> <pre><...
9
2010-03-24T05:23:23Z
28,010,280
<p>As others have said, <code>append</code> mutates the list itself and you shouldn't assign it to a variable. Executing it changes it's data, effectively updating everyone pointing at it.</p> <p><strong>But</strong>, there's a trick I use when I want to do stuff in a functional* way while mutating existing objects (r...
3
2015-01-18T13:38:30Z
[ "python", "list", "append", "list-comprehension" ]
How do I do multiple processes for Django, on my WSGI apache?
2,505,541
<p>My friend says that Django only has 1 thread or something? </p> <p>And I have to edit my 000-default in order to add more processes? He suggests 4 or 5.</p> <p>What exactly is this, and what do I have to do?</p> <p>Thanks, I'm a noob.</p>
4
2010-03-24T05:26:58Z
2,505,562
<p>Use the <a href="http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess" rel="nofollow"><code>WSGIDaemonProcess</code></a> directive to put the app in daemon mode and specify the number of daemon processes and threads.</p>
3
2010-03-24T05:32:26Z
[ "python", "linux", "django", "apache", "unix" ]
python manage.py runserver fails
2,506,079
<p>I am trying to learn django by following along with <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#the-development-server" rel="nofollow">this tutorial</a>. I am using django version 1.1.1</p> <p>I run</p> <pre><code>django-admin.py startproject mysite </code></pre> <p>and it creates the files it...
0
2010-03-24T07:50:30Z
2,506,667
<p>Can't really explain that. Try removing the project directory and starting again.</p> <p>Are you definitely running the <code>manage.py</code> from within the directory with the settings file?</p>
0
2010-03-24T09:58:40Z
[ "python", "django" ]
python manage.py runserver fails
2,506,079
<p>I am trying to learn django by following along with <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/#the-development-server" rel="nofollow">this tutorial</a>. I am using django version 1.1.1</p> <p>I run</p> <pre><code>django-admin.py startproject mysite </code></pre> <p>and it creates the files it...
0
2010-03-24T07:50:30Z
2,513,754
<p>Something is broken in your django installation. maybe you have a (very) old version somewhere in the path? </p> <p><a href="http://code.djangoproject.com/changeset/6701" rel="nofollow">LOCALE_PATHS was given a default value in the global settings file a long time ago</a>.</p>
1
2010-03-25T07:38:21Z
[ "python", "django" ]
Python Pari Library?
2,506,087
<p><a href="http://pari.math.u-bordeaux.fr/" rel="nofollow">Pari/GP</a> is an excellent library for functions relating to number theory. The problem is that there doesn't seem to be an up to date wrapper for python anywhere around, (<a href="http://code.google.com/p/pari-python/" rel="nofollow">pari-python</a> uses an ...
4
2010-03-24T07:53:39Z
2,708,319
<p>Actually, <a href="http://code.google.com/p/pari-python/" rel="nofollow">pari-python</a> works with the latest stable release of PARI. And it is very easy to use:</p> <pre><code>&gt;&gt;&gt; from pari import * &gt;&gt;&gt; fibonacci(100) 354224848179261915075 &gt;&gt;&gt; intnum(0,1,lambda x:x**2) 0.333333333333333...
3
2010-04-25T13:09:05Z
[ "python", "pari" ]