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
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,035,296
<p>Do the next project you intended to program with your prefered language with Python.</p>
3
2010-01-09T22:57:50Z
[ "python" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,035,299
<p><a href="http://www.pythonchallenge.com/" rel="nofollow">PythonChallenge</a></p> <p><a href="http://codegolf.com/" rel="nofollow">Code Golf</a></p> <p><a href="http://code.google.com/codejam/" rel="nofollow">Google Code Jam</a></p> <p>These are good ways to practice learning Python.</p> <p>Might I also suggest t...
1
2010-01-09T22:58:28Z
[ "python" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,035,429
<p>A project I wish someone would write: a friendly GUI that wraps around the scanner library and the PDF library, and lets the user easily scan and file documents.</p> <p>It would have a toolbar with big buttons: "scan letter", "scan brochure", "scan photo". These would respectively choose high-resolution black-and-...
0
2010-01-09T23:48:08Z
[ "python" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
38,899,389
<p><a href="http://www.pythonchallenge.com/" rel="nofollow">Python Challenge</a> This is fun and interesting to learn Python programming.</p>
0
2016-08-11T14:37:09Z
[ "python" ]
QTreeWidget turn off selection
2,035,049
<p>By default a <code>QTreeWidget</code> manages the selection of rows (<em>when you click a row it highlights it, when you click another row it highlights that and deselects the previous row</em>), I don't want this and cant figure out how to turn it off. </p>
1
2010-01-09T21:35:33Z
2,035,665
<p>you can use <a href="http://qt.nokia.com/doc/4.6/qabstractitemview.html#selectionMode-prop" rel="nofollow"><code>setSelectionMode</code></a> of the <code>QAbstractItemView</code> class (which <code>QTreeWidget</code> is inherited from) to set no selection mode to the component. Something like this (sorry, code in C+...
3
2010-01-10T01:09:52Z
[ "python", "qt", "pyqt", "qtreewidget" ]
If I use QT For Windows, will my application run great on Linux/Mac/Windows?
2,035,249
<p>I'm under the impressions that Python runs in the Triforce smoothly. A program that runs in Windows will run in Linux. Is this sentiment correct?</p> <p>Having said that, if I create my application in QT For Windows, will it run flawlessly in Linux/Mac as well?</p> <p>Thanks.</p>
5
2010-01-09T22:40:26Z
2,035,260
<p>Yes. The code that you write using Qt will work on Windows, Mac, Linux/X11, embedded Linux, Windows CE and Symbian without any change. You can take a <a href="http://qt.nokia.com/products/platform/platforms" rel="nofollow">look here</a>.</p>
2
2010-01-09T22:44:38Z
[ "python", "qt", "cross-platform" ]
If I use QT For Windows, will my application run great on Linux/Mac/Windows?
2,035,249
<p>I'm under the impressions that Python runs in the Triforce smoothly. A program that runs in Windows will run in Linux. Is this sentiment correct?</p> <p>Having said that, if I create my application in QT For Windows, will it run flawlessly in Linux/Mac as well?</p> <p>Thanks.</p>
5
2010-01-09T22:40:26Z
2,035,265
<p>It might run well, but it will take some testing, and of course Qt only handles the GUI portability, not the myriad of other things that might cause portability problems.</p> <p>Qt apps generally don't fit in very well on MacOS because they don't have Applescript support by default and don't necessarily have the ri...
0
2010-01-09T22:46:22Z
[ "python", "qt", "cross-platform" ]
If I use QT For Windows, will my application run great on Linux/Mac/Windows?
2,035,249
<p>I'm under the impressions that Python runs in the Triforce smoothly. A program that runs in Windows will run in Linux. Is this sentiment correct?</p> <p>Having said that, if I create my application in QT For Windows, will it run flawlessly in Linux/Mac as well?</p> <p>Thanks.</p>
5
2010-01-09T22:40:26Z
2,035,272
<p>Yes. No. Maybe. See also: Java and "write once, run anywhere".</p> <p>Filesystem layout, external utilities, anything you might do with things like dock icons, character encoding behaviors, these and more are areas you might run into some trouble.</p> <p>Using Qt and Python, and strenuously avoiding anything that ...
8
2010-01-09T22:49:27Z
[ "python", "qt", "cross-platform" ]
If I use QT For Windows, will my application run great on Linux/Mac/Windows?
2,035,249
<p>I'm under the impressions that Python runs in the Triforce smoothly. A program that runs in Windows will run in Linux. Is this sentiment correct?</p> <p>Having said that, if I create my application in QT For Windows, will it run flawlessly in Linux/Mac as well?</p> <p>Thanks.</p>
5
2010-01-09T22:40:26Z
2,035,284
<p>Generally - as long as you don't use code that is not covered by Qt classes - yes.</p> <p>I have several time just recompiled applications I wrote in Linux(64bit) under Windows, and the other way arround. It works for me every time.</p> <p>Depends on your needs, you might also find compiler problems, but I am sure...
1
2010-01-09T22:52:35Z
[ "python", "qt", "cross-platform" ]
If I use QT For Windows, will my application run great on Linux/Mac/Windows?
2,035,249
<p>I'm under the impressions that Python runs in the Triforce smoothly. A program that runs in Windows will run in Linux. Is this sentiment correct?</p> <p>Having said that, if I create my application in QT For Windows, will it run flawlessly in Linux/Mac as well?</p> <p>Thanks.</p>
5
2010-01-09T22:40:26Z
2,035,601
<p>As the others said, everything which is done using Qt-Functionality will most likely run quite flawlessly, WHEN you dont use platform specific functionality of qt.</p> <p>There isnt that much (most of it has to do with window-manager stuff) , but some things might not work on other systems. But such things are sur...
0
2010-01-10T00:47:34Z
[ "python", "qt", "cross-platform" ]
If I use QT For Windows, will my application run great on Linux/Mac/Windows?
2,035,249
<p>I'm under the impressions that Python runs in the Triforce smoothly. A program that runs in Windows will run in Linux. Is this sentiment correct?</p> <p>Having said that, if I create my application in QT For Windows, will it run flawlessly in Linux/Mac as well?</p> <p>Thanks.</p>
5
2010-01-09T22:40:26Z
2,040,550
<p>As other posters mentioned, the key issue is making sure you never touch a different non-Qt non-cross-platform API. Or really even a different non-Qt crossplatform API, if you use Qt you kind of need to commit to it, it's a comprehensive framework and for the most part sticking with Qt is easier than going to anyth...
5
2010-01-11T08:03:10Z
[ "python", "qt", "cross-platform" ]
Python synchronised reading of sorted files
2,035,285
<p>I have two groups of files that contain data in CSV format with a common key (Timestamp) - I need to walk through all the records chronologically. </p> <ul> <li><p><strong>Group A: 'Environmental Data'</strong></p> <ul> <li>Filenames are in format A_0001.csv, A_0002.csv, etc.</li> <li>Pre-sorted ascending</li> <li...
4
2010-01-09T22:52:52Z
2,035,309
<p>I would suggest pre-merge.</p> <p>Reading a file takes a lot of processor time. Reading two files, twice as much. Since your program will be dealing with a large input (lots of files, esp in Group A), I think it would be better to get it over with in one file read, and have all your relevant data in that one file. ...
0
2010-01-09T23:04:22Z
[ "python", "file", "merge", "sorting" ]
Python synchronised reading of sorted files
2,035,285
<p>I have two groups of files that contain data in CSV format with a common key (Timestamp) - I need to walk through all the records chronologically. </p> <ul> <li><p><strong>Group A: 'Environmental Data'</strong></p> <ul> <li>Filenames are in format A_0001.csv, A_0002.csv, etc.</li> <li>Pre-sorted ascending</li> <li...
4
2010-01-09T22:52:52Z
2,035,315
<p>im thinking importing it into a db (mysql, sqlite, etc) will give better performance than merging it in script. the db typically has optimized routines for loading csv and the join will be probably be as fast or much faster than merging 2 dicts (one being very large) in python.</p>
2
2010-01-09T23:05:05Z
[ "python", "file", "merge", "sorting" ]
Python synchronised reading of sorted files
2,035,285
<p>I have two groups of files that contain data in CSV format with a common key (Timestamp) - I need to walk through all the records chronologically. </p> <ul> <li><p><strong>Group A: 'Environmental Data'</strong></p> <ul> <li>Filenames are in format A_0001.csv, A_0002.csv, etc.</li> <li>Pre-sorted ascending</li> <li...
4
2010-01-09T22:52:52Z
2,035,337
<p>You could read from the files in chunks of, say, 10000 records (or whatever number further profiling tells you to be optimal) and merge on the fly. Possibly using a custom class to encapsulate the IO; the actual records could then be accessed through the generator protocol (<code>__iter__</code> + <code>next</code>)...
0
2010-01-09T23:14:00Z
[ "python", "file", "merge", "sorting" ]
Python synchronised reading of sorted files
2,035,285
<p>I have two groups of files that contain data in CSV format with a common key (Timestamp) - I need to walk through all the records chronologically. </p> <ul> <li><p><strong>Group A: 'Environmental Data'</strong></p> <ul> <li>Filenames are in format A_0001.csv, A_0002.csv, etc.</li> <li>Pre-sorted ascending</li> <li...
4
2010-01-09T22:52:52Z
2,035,469
<p>"YYYY-MM-DD HH:MM:SS" can be sorted with a simple ascii compare. How about reusing external merge logic? If the first field is the key then:</p> <pre><code>for entry in os.popen("sort -m -t, -k1,1 file1 file2"): process(entry) </code></pre>
2
2010-01-10T00:00:13Z
[ "python", "file", "merge", "sorting" ]
Python synchronised reading of sorted files
2,035,285
<p>I have two groups of files that contain data in CSV format with a common key (Timestamp) - I need to walk through all the records chronologically. </p> <ul> <li><p><strong>Group A: 'Environmental Data'</strong></p> <ul> <li>Filenames are in format A_0001.csv, A_0002.csv, etc.</li> <li>Pre-sorted ascending</li> <li...
4
2010-01-09T22:52:52Z
2,035,600
<p>This is a similar to a relational join. Since your timestamps don't have to match, it's called a non-equijoin.</p> <p>Sort-Merge is one of several popular algorithms. For non-equijoins, it works well. I think this would be what you're called "pre-merge". I don't know what you mean by "merge in real time", but I...
1
2010-01-10T00:47:20Z
[ "python", "file", "merge", "sorting" ]
Getting a list of errors in a Django form
2,035,288
<p>I'm trying to create a form in Django. That works and all, but I want all the errors to be at the top of the form, not next to each field that has the error. I tried looping over form.errors, but it only showed the name of the field that had an error, not an error message such as "Name is required."</p> <p>This is ...
19
2010-01-09T22:53:27Z
2,035,314
<p>form.errors is a dictionary. When you do <code>{% for error in form.errors %}</code> error corresponds to the key.</p> <p>Instead try</p> <pre><code>{% for field, errors in form.errors.items %} {% for error in errors %} ... </code></pre> <p>Etc.</p>
38
2010-01-09T23:05:03Z
[ "python", "django", "django-templates", "django-forms" ]
Download a webpage and media
2,035,324
<p>I need to download a webpage and all its media (like css javascript and images) to make a sort of backup (like firefox does when you click on File -> Save) with python.</p> <p>Is there any library to do that or I shall create my own one?</p>
1
2010-01-09T23:09:03Z
2,035,340
<p>It's not exactly Python, but there's a pretty standard *nix utility called <a href="http://www.gnu.org/software/wget/" rel="nofollow">wget</a> which you can call from a Python script that will do this.</p>
1
2010-01-09T23:15:00Z
[ "python" ]
Python: Why does this doc test fail?
2,035,406
<p>This code that's in the doctest works when run by itself, but in this doctest it fails in 10 places. I can't figure out why it does though. The following is the entire module:</p> <pre><code>class requireparams(object): """ &gt;&gt;&gt; @requireparams(['name', 'pass', 'code']) &gt;&gt;&gt; def complex_f...
3
2010-01-09T23:38:37Z
2,035,422
<p>doctest requires that you use <code>...</code> for continuation lines:</p> <pre><code>&gt;&gt;&gt; @requireparams(['name', 'pass', 'code']) ... def complex_function(params): ... print(params['name']) ... print(params['pass']) ... print(params['code']) ... &gt;&gt;&gt; params = { ... 'name': 'John Do...
7
2010-01-09T23:43:50Z
[ "python", "doctest", "docstring" ]
Python: Why does this doc test fail?
2,035,406
<p>This code that's in the doctest works when run by itself, but in this doctest it fails in 10 places. I can't figure out why it does though. The following is the entire module:</p> <pre><code>class requireparams(object): """ &gt;&gt;&gt; @requireparams(['name', 'pass', 'code']) &gt;&gt;&gt; def complex_f...
3
2010-01-09T23:38:37Z
2,035,424
<p>Try pasting the code exactly from the python prompt. That means it will contain some <code>...</code> as well as <code>&gt;&gt;&gt;</code>. Otherwise the doctest parser won't know when there's a multiline expression.</p> <p><em>On preview: What Greg said.</em></p>
1
2010-01-09T23:44:46Z
[ "python", "doctest", "docstring" ]
Python: Why does this doc test fail?
2,035,406
<p>This code that's in the doctest works when run by itself, but in this doctest it fails in 10 places. I can't figure out why it does though. The following is the entire module:</p> <pre><code>class requireparams(object): """ &gt;&gt;&gt; @requireparams(['name', 'pass', 'code']) &gt;&gt;&gt; def complex_f...
3
2010-01-09T23:38:37Z
2,035,473
<p>Here's my module after I corrected it (it works now):</p> <pre><code>class requiresparams(object): """ Used as a decorator with an iterable passed in, this will look for each item in the iterable given as a key in the params argument of the function being decorated. It was built for a series of Pay...
0
2010-01-10T00:00:40Z
[ "python", "doctest", "docstring" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,431
<p>If you want to refer to the same object, just use 'self':</p> <pre><code>class A: def some_func(self): another_func(self) </code></pre> <p>If you want to create a new object of the same class, just do it:</p> <pre><code>class A: def some_func(self): foo = A() </code></pre> <p>If you want ...
5
2010-01-09T23:48:18Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,434
<p>Most code in the class will be inside method definitions, in which case you can simply use the name <code>A</code>.</p>
-1
2010-01-09T23:48:30Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,438
<p>What do you want to achieve? It's possible to access a class to tweak its definition using a metaclass, but it's not recommended.</p> <p>Your code sample can be written simply as:</p> <pre><code>class A(object): pass some_func(A) </code></pre>
0
2010-01-09T23:49:21Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,441
<p>There isn't a way to do that within the class scope, not unless A was defined to be something else first (and then some_func(A) will do something entirely different from what you expect)</p> <p>Unless you're doing some sort of stack inspection to add bits to the class, it seems odd why you'd want to do that. Why no...
1
2010-01-09T23:50:23Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,443
<p>Nope. It works in a function because the function contents are executed at call-time. But the class contents are executed at define-time, at which point the class doesn't exist yet.</p> <p>It's not normally a problem because you can hack further members into the class after defining it, so you can split up a class ...
0
2010-01-09T23:50:40Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,463
<p>It's ok to reference the name of the class inside its body (like inside method definitions) if it's actually in scope... Which it will be if it's defined at top level. (In other cases probably not, due to Python scoping quirks!).</p> <p>For on illustration of the scoping gotcha, try to instantiate Foo:</p> <pre><c...
0
2010-01-09T23:58:59Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,812
<p>You can't with the specific syntax you're describing due to the time at which they are evaluated. The reason the example function given works is that the call to <em>f(i-1)</em> within the function body is because the name resolution of <em>f</em> is not performed until the function is actually called. At this poi...
2
2010-01-10T02:19:07Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,904
<p>If you want to do just a little hacky thing do</p> <pre><code>class A(object): ... some_func(A) </code></pre> <p>If you want to do something more sophisticated you can use a metaclass. A metaclass is responsible for manipulating the class object before it gets fully created. A template would be:</p> <pre><cod...
1
2010-01-10T02:50:58Z
[ "python", "class" ]
python: how to refer to the class from within it ( like the recursive function)
2,035,423
<p>For a recursive function we can do:</p> <pre><code>def f(i): if i&lt;0: return print i f(i-1) f(10) </code></pre> <p>However is there a way to do the following thing?</p> <pre><code>class A: # do something some_func(A) # ... </code></pre>
8
2010-01-09T23:44:12Z
2,035,992
<p>In Python you cannot reference the class in the class body, although in languages like Ruby you can do it.</p> <p>In Python instead you can use a class decorator but that will be called once the class has initialized. Another way could be to use metaclass but it depends on what you are trying to achieve.</p>
10
2010-01-10T03:45:25Z
[ "python", "class" ]
I just installed QT for Windows but I can't find the control toolbox anywhere. Where do I drag controls to a form?
2,035,459
<p>I opened a starter application to see how it works but I only see C++ files, nothing in Python. How can I configure QT to work for Python? :S</p> <p>Also, where can I find the visual form?</p>
0
2010-01-09T23:57:00Z
2,035,556
<p>For python support see <a href="http://wiki.python.org/moin/PyQt" rel="nofollow">PyQt</a>.</p> <p>I'm not quite sure what you mean by "visual form". If you want a GUI editor try <a href="http://qt.nokia.com/products/developer-tools" rel="nofollow">qtcreator</a> </p>
2
2010-01-10T00:29:29Z
[ "python", "qt", "qt4" ]
I just installed QT for Windows but I can't find the control toolbox anywhere. Where do I drag controls to a form?
2,035,459
<p>I opened a starter application to see how it works but I only see C++ files, nothing in Python. How can I configure QT to work for Python? :S</p> <p>Also, where can I find the visual form?</p>
0
2010-01-09T23:57:00Z
2,037,059
<p>Qt comes with Qt Designer which you can use to create forms visually (like in Visual Studio). Designer creates XML ".ui" files that are then fed into Qt's UIC tool. That tool then generates C++ header files that define a class with the UI components. <a href="http://doc.trolltech.com/4.6/designer-using-a-ui-file.htm...
1
2010-01-10T13:03:43Z
[ "python", "qt", "qt4" ]
Python UDP socket options for multiple & concurrent clients
2,035,542
<p>Let me explain a bit the app i'm doing.</p> <p>I'm creating a central UDP (needs to be UDP) server for multiple and concurrent clients that also "talk" between them. I do a check into a dict of known clients addresses and create a client handler thread if "i dont know" the client. Else, the thread receives the data...
1
2010-01-10T00:25:21Z
2,035,596
<p>The 'socket reset' happens because the client sent an ICMP port-unreachable in response to the datagram sent to a socket that wasn't there any more. Perfectly reasonable way to express that in the API, so you're just going to have to handle it. But if you just ignore the exception, the socket should still be worki...
1
2010-01-10T00:46:39Z
[ "python", "sockets", "concurrency", "clients" ]
Coming from a Visual C# Express IDE/C# programming background, is there a tutorial for creating python applications?
2,035,599
<p>It's very overwhelming coming from something that helps you create applications straight forward to something with somewhat convoluted documentation.</p> <p>Can someone <strong>please</strong> share a tutorial on how to create a simple Hello World application using Python. No, I don't mean command line. I mean a ph...
1
2010-01-10T00:47:01Z
2,035,707
<p>Here's a great tutorial for wxPython (my GUI API of choice: extremely powerful, good community/mailing list, and cross-platform (it wraps the native platform's widgets))</p> <p><a href="http://wiki.wxpython.org/Getting%20Started" rel="nofollow">http://wiki.wxpython.org/Getting%20Started</a></p> <p>Installing wxpyt...
1
2010-01-10T01:26:37Z
[ "python" ]
What is my current desktop environment?
2,035,657
<p>How can I get to know what my desktop environment is using Python? I like the result to be <em>gnome</em> or <em>KDE</em> or else.</p>
4
2010-01-10T01:06:41Z
2,035,664
<p>Tested in Ubuntu 9.10:</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.environ.get('DESKTOP_SESSION') 'gnome' </code></pre> <p>Edit: As mentioned in comments below, this approach will not work for more some OSes. The other two answers provide workarounds.</p>
6
2010-01-10T01:09:23Z
[ "python", "linux", "environment" ]
What is my current desktop environment?
2,035,657
<p>How can I get to know what my desktop environment is using Python? I like the result to be <em>gnome</em> or <em>KDE</em> or else.</p>
4
2010-01-10T01:06:41Z
2,035,666
<p>You might try this:</p> <pre><code>def detect_desktop_environment(): desktop_environment = 'generic' if os.environ.get('KDE_FULL_SESSION') == 'true': desktop_environment = 'kde' elif os.environ.get('GNOME_DESKTOP_SESSION_ID'): desktop_environment = 'gnome' else: try: ...
4
2010-01-10T01:11:24Z
[ "python", "linux", "environment" ]
What is my current desktop environment?
2,035,657
<p>How can I get to know what my desktop environment is using Python? I like the result to be <em>gnome</em> or <em>KDE</em> or else.</p>
4
2010-01-10T01:06:41Z
2,035,693
<p>Sometimes people run a mix of desktop environments. Make your app desktop-agnostic using <em>xdg-utils</em>; that means using <code>xdg-open</code> to open a file or url, using <code>xdg-user-dir DOCUMENTS</code> to find the docs folder, <code>xdg-email</code> to send e-mail, and so on.</p>
4
2010-01-10T01:22:04Z
[ "python", "linux", "environment" ]
What is my current desktop environment?
2,035,657
<p>How can I get to know what my desktop environment is using Python? I like the result to be <em>gnome</em> or <em>KDE</em> or else.</p>
4
2010-01-10T01:06:41Z
21,213,358
<p>I use this in one of my projects:</p> <pre><code> def get_desktop_environment(self): #From http://stackoverflow.com/questions/2035657/what-is-my-current-desktop-environment # and http://ubuntuforums.org/showthread.php?t=652320 # and http://ubuntuforums.org/showthread.php?t=652320 ...
8
2014-01-19T04:53:06Z
[ "python", "linux", "environment" ]
purpose of '"sss".decode("base64").decode("zlib")'
2,035,727
<pre><code>ACTIVATE_THIS = """ eJx1UsGOnDAMvecrIlYriDRlKvU20h5aaY+teuilGo1QALO4CwlKAjP8fe1QGGalRoLEefbzs+Mk Sb7NcvRo3iTcoGqwgyy06As+HWSNVciKaBTFywYoJWc7yit2ndBVwEkHkIzKCV0YdQdmkvShs6YH E3IhfjFaaSNLoHxQy2sLJrL0ow98JQmEG/rAYn7OobVGogngBgf0P0hjgwgt7HOUaI5DdBVJkggR 3HwSktaqWcCtgiHIH7qHV+esW2CnkRJ+9R5cQGsikkWEV/J7leVGs9TV4T...
1
2010-01-10T01:35:00Z
2,035,729
<p>The data in the strings is encoded and compressed binary data. The <code>.decode("base64").decode("zlib")</code> unencodes and decompresses it.</p> <p>The error you got was because 'dsss' decoded from base64 is not valid zlib compressed data.</p>
4
2010-01-10T01:36:47Z
[ "python" ]
purpose of '"sss".decode("base64").decode("zlib")'
2,035,727
<pre><code>ACTIVATE_THIS = """ eJx1UsGOnDAMvecrIlYriDRlKvU20h5aaY+teuilGo1QALO4CwlKAjP8fe1QGGalRoLEefbzs+Mk Sb7NcvRo3iTcoGqwgyy06As+HWSNVciKaBTFywYoJWc7yit2ndBVwEkHkIzKCV0YdQdmkvShs6YH E3IhfjFaaSNLoHxQy2sLJrL0ow98JQmEG/rAYn7OobVGogngBgf0P0hjgwgt7HOUaI5DdBVJkggR 3HwSktaqWcCtgiHIH7qHV+esW2CnkRJ+9R5cQGsikkWEV/J7leVGs9TV4T...
1
2010-01-10T01:35:00Z
2,035,763
<p><code>.decode('base64')</code> can be called only on a string that's encoded as "base-64, in order to retrieve the byte sequence that was there encoded. Presumably that byte sequence, in the example you bring, was zlib-compressed, and so the <code>.decode('zlib')</code> part decompresses it.</p> <p>Now, for your c...
1
2010-01-10T01:52:18Z
[ "python" ]
purpose of '"sss".decode("base64").decode("zlib")'
2,035,727
<pre><code>ACTIVATE_THIS = """ eJx1UsGOnDAMvecrIlYriDRlKvU20h5aaY+teuilGo1QALO4CwlKAjP8fe1QGGalRoLEefbzs+Mk Sb7NcvRo3iTcoGqwgyy06As+HWSNVciKaBTFywYoJWc7yit2ndBVwEkHkIzKCV0YdQdmkvShs6YH E3IhfjFaaSNLoHxQy2sLJrL0ow98JQmEG/rAYn7OobVGogngBgf0P0hjgwgt7HOUaI5DdBVJkggR 3HwSktaqWcCtgiHIH7qHV+esW2CnkRJ+9R5cQGsikkWEV/J7leVGs9TV4T...
1
2010-01-10T01:35:00Z
2,035,764
<p>It is the reverse of:</p> <pre><code>original_message.encode('zlib').encode('base64') </code></pre> <p>zlib is a binary compression algorithm. base64 is a text encoding of binary data, which is useful to send binary message through text protocols like SMTP.</p> <p>After 'dsss' was decoded from base64 (the three ...
1
2010-01-10T01:52:36Z
[ "python" ]
purpose of '"sss".decode("base64").decode("zlib")'
2,035,727
<pre><code>ACTIVATE_THIS = """ eJx1UsGOnDAMvecrIlYriDRlKvU20h5aaY+teuilGo1QALO4CwlKAjP8fe1QGGalRoLEefbzs+Mk Sb7NcvRo3iTcoGqwgyy06As+HWSNVciKaBTFywYoJWc7yit2ndBVwEkHkIzKCV0YdQdmkvShs6YH E3IhfjFaaSNLoHxQy2sLJrL0ow98JQmEG/rAYn7OobVGogngBgf0P0hjgwgt7HOUaI5DdBVJkggR 3HwSktaqWcCtgiHIH7qHV+esW2CnkRJ+9R5cQGsikkWEV/J7leVGs9TV4T...
1
2010-01-10T01:35:00Z
2,035,939
<p>What is the purpose of <code>x.decode(”base64”).decode(”zlib”) for x in ("sss", "dsss", random_garbage)</code>? Excuse me, you should know; you are the one who is doing it!</p> <p><strong>Edit after OP's addition of various puzzles</strong></p> <p><strong>Puzzle 1</strong></p> <pre><code>a='dsss'.encode('...
3
2010-01-10T03:06:55Z
[ "python" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
2,035,748
<p>Presumably the best way to "merge" varies, attributes by attributes. For example, given several tuples (from the <code>INSTALLED_APPS</code> of various submodules), you might simply concatenate them into a new tuple (for the <code>INSTALLED_APPS</code> attribute of the package as a whole), or, if possible duplicati...
0
2010-01-10T01:44:19Z
[ "python", "django" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
2,035,765
<p>"When you install a new django application, you have to add/modify your settings.py module."</p> <p>I think this is fine as is. </p> <p>I don't see any reason to change or modify this at all.</p> <p>What we do, however, is to "subclass" the core settings module.</p> <p>Our developer-specific and installation-spe...
6
2010-01-10T01:53:55Z
[ "python", "django" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
2,036,247
<p>You might be interested in <a href="http://code.djangoproject.com/wiki/SplitSettings#UsingalistofconffilesTransifex" rel="nofollow">this solution</a>; uses execfile() to load a series of settings files in order, where each file has full access to settings from previously-loaded files, to update, modify, etc.</p>
4
2010-01-10T05:43:30Z
[ "python", "django" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
2,086,802
<p>I've used this work-around:</p> <p><strong>settings.py</strong>:</p> <pre><code>INSTALLED_APPS = ('whatever',) import more_settings more_settings.modify(globals()) </code></pre> <p><strong>more_settings.py</strong>:</p> <pre><code>def modify(settings): settings['INSTALLED_APPS'] += ('another_app',) </code></...
4
2010-01-18T14:53:08Z
[ "python", "django" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
2,086,835
<p>If you prefer more magic than in my previous <code>more_settings.modify()</code> approach, try this:</p> <p><strong>settings.py</strong>:</p> <pre><code>INSTALLED_APPS = ('whatever',) import more_settings more_settings.modify(globals()) </code></pre> <p><strong>more_settings.py</strong>:</p> <pre><code>def confi...
0
2010-01-18T14:56:54Z
[ "python", "django" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
3,119,942
<p>just put</p> <pre><code>from base import * from admin import * ... </code></pre> <p>in ur <strong>init</strong>.py that should work</p> <p>i used it for different sites</p> <pre><code>base/settings.py # common settings: db, apps, ... base/sites/website1/settings.py # site_id, custom middleware base/sites/websit...
-1
2010-06-25T17:06:07Z
[ "python", "django" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
6,561,943
<p>I have the same structure of settings files and I do the following to import the settings of the submodules:</p> <pre><code>def load_settings_file(file): file = open(os.path.join(INSTALL_DIR, '&lt;projectname&gt;', 'settings', file + '.py')) content = file.read() file.close() return content for sub...
1
2011-07-03T08:47:07Z
[ "python", "django" ]
how to modularize django settings.py?
2,035,733
<p>When you install a new django application, you have to add/modify your settings.py module.</p> <p>For a project I'm trying to make that module a python subpackage and create a module for each application:</p> <pre><code>settings\ __init__.py base.py admin.py feincms.py ... </code></pre> <p>The...
16
2010-01-10T01:37:16Z
7,440,753
<p>I created <a href="https://code.djangoproject.com/wiki/SplitSettings#SettingInheritancewithHierarchy" rel="nofollow">https://code.djangoproject.com/wiki/SplitSettings#SettingInheritancewithHierarchy</a> as my preferred solution. Allows for inheritance from a common file in any deployment environment. </p>
1
2011-09-16T06:02:26Z
[ "python", "django" ]
Why does this use of Smooth cause Python to crash?
2,035,842
<p>I'm using Python 2.6 against OpenCV 2.0. I've started a file capture and pulled frames. I've displayed the image to make sure it's valid. When I call this routine, python crashes:</p> <pre><code>def SmoothImage(self,SmoothingMaskSize=3): temp=cv.CreateImage(cv.GetSize(self._lpImage),self._lpImage.depth,self....
1
2010-01-10T02:31:54Z
2,058,451
<p>The bindings that come with the OpenCV 2.0 installer are buggy; I had similar problem where some very simple operations triggered crashes. Compiling from the source should fix it.</p>
0
2010-01-13T16:39:18Z
[ "python", "opencv" ]
Why does this use of Smooth cause Python to crash?
2,035,842
<p>I'm using Python 2.6 against OpenCV 2.0. I've started a file capture and pulled frames. I've displayed the image to make sure it's valid. When I call this routine, python crashes:</p> <pre><code>def SmoothImage(self,SmoothingMaskSize=3): temp=cv.CreateImage(cv.GetSize(self._lpImage),self._lpImage.depth,self....
1
2010-01-10T02:31:54Z
2,224,637
<p>If you don't need access to the object-oriented parts of OpenCV, you should take a look at ctypes-opencv, which is a better set of python bindings. It is lovingly hand-crafted, in contrast to the SWIG-generated bindings that come with OpenCV, and I have never found any bugs in it.</p> <p><a href="http://code.google...
0
2010-02-08T20:29:43Z
[ "python", "opencv" ]
Why does this use of Smooth cause Python to crash?
2,035,842
<p>I'm using Python 2.6 against OpenCV 2.0. I've started a file capture and pulled frames. I've displayed the image to make sure it's valid. When I call this routine, python crashes:</p> <pre><code>def SmoothImage(self,SmoothingMaskSize=3): temp=cv.CreateImage(cv.GetSize(self._lpImage),self._lpImage.depth,self....
1
2010-01-10T02:31:54Z
4,802,693
<p>Can you isolate the problem by removing the class definition? I get this working:</p> <pre><code>planes = [cv.CreateImage(cv.GetSize(image), cv.IPL_DEPTH_32F, 1) for i in range(3)] cv.Split(image, planes[0], planes[1], planes[2], None) for plane in planes: cv.Smooth(plane, plane, smoothtype=cv.CV_GAUSSIAN, para...
0
2011-01-26T08:54:19Z
[ "python", "opencv" ]
Raise and lower QTreeWidgetItem in a QTreeWidget?
2,035,932
<p>Question says it all how do you raise and lower [change the positions of ] QTreeWidgetItems in a QtreeWidget ,</p>
3
2010-01-10T03:01:41Z
2,036,331
<p>I believe you would need to use model object to be able to manipulate items positions (if this what you want to do). Please check an example below; it moves the first item of the abstract model to the bottom.</p> <pre><code>QAbstractItemModel* model = your_tree_view-&gt;model(); QModelIndex index0 = model-&gt;inde...
4
2010-01-10T06:24:52Z
[ "python", "qt", "pyqt", "qtreewidget" ]
Raise and lower QTreeWidgetItem in a QTreeWidget?
2,035,932
<p>Question says it all how do you raise and lower [change the positions of ] QTreeWidgetItems in a QtreeWidget ,</p>
3
2010-01-10T03:01:41Z
10,741,940
<p>I found serge's solution to be quite complicated as well for a simple move up / move down. There's actually a quite easier solution to this issue since you're using QTreeWidget :</p> <pre><code>QTreeWidgetItem* item = your_qtreewidget-&gt;currentItem(); int row = your_qtreewidget-&gt;currentIndex().ro...
4
2012-05-24T16:53:28Z
[ "python", "qt", "pyqt", "qtreewidget" ]
How to mock users and requests in django
2,036,202
<p>I have django code that interacts with request objects or user objects. For instance something like:</p> <pre><code>foo_model_instance = models.get_or_create_foo_from_user(request.user) </code></pre> <p>If you were going to test with the django python shell or in a unittest, what would you pass in there? Here simp...
39
2010-01-10T05:20:46Z
2,036,294
<p>Read about mock objects here<br> <a href="http://en.wikipedia.org/wiki/Mock_object" rel="nofollow">http://en.wikipedia.org/wiki/Mock_object</a><br> <a href="http://www.mockobjects.com/" rel="nofollow">http://www.mockobjects.com/</a></p> <p>And use this python lib to mock a user<br> <a href="http://python-mock.sourc...
6
2010-01-10T06:05:41Z
[ "python", "django", "unit-testing", "mocking" ]
How to mock users and requests in django
2,036,202
<p>I have django code that interacts with request objects or user objects. For instance something like:</p> <pre><code>foo_model_instance = models.get_or_create_foo_from_user(request.user) </code></pre> <p>If you were going to test with the django python shell or in a unittest, what would you pass in there? Here simp...
39
2010-01-10T05:20:46Z
2,036,644
<blockquote> <p>How do you mock users?</p> </blockquote> <p>Initialise a <code>django.contrib.auth.models.User</code> object. <a href="http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/models.py#L105"><code>User.objects.create_user</code></a> makes this easy.</p> <blockquote> <p>How do you mo...
36
2010-01-10T09:59:04Z
[ "python", "django", "unit-testing", "mocking" ]
How to mock users and requests in django
2,036,202
<p>I have django code that interacts with request objects or user objects. For instance something like:</p> <pre><code>foo_model_instance = models.get_or_create_foo_from_user(request.user) </code></pre> <p>If you were going to test with the django python shell or in a unittest, what would you pass in there? Here simp...
39
2010-01-10T05:20:46Z
2,036,677
<p>You don't need to mock Users, as you can just create one within your test - the database is destroyed after the test is finished.</p> <p>To mock requests, use <a href="http://www.djangosnippets.org/snippets/963/" rel="nofollow">this snippet</a> from Simon Willison.</p>
3
2010-01-10T10:18:27Z
[ "python", "django", "unit-testing", "mocking" ]
How to mock users and requests in django
2,036,202
<p>I have django code that interacts with request objects or user objects. For instance something like:</p> <pre><code>foo_model_instance = models.get_or_create_foo_from_user(request.user) </code></pre> <p>If you were going to test with the django python shell or in a unittest, what would you pass in there? Here simp...
39
2010-01-10T05:20:46Z
2,036,865
<p>You can either roll your own mocks, as Anurag Uniyal has suggested, or you can use a mocking framework.</p> <p>In response to those saying you can just create an ordinary user as you would anyway in Django... I would suggest this defeats the point of the unit test. A unit test shouldn't touch the database, but by c...
5
2010-01-10T11:43:56Z
[ "python", "django", "unit-testing", "mocking" ]
How to mock users and requests in django
2,036,202
<p>I have django code that interacts with request objects or user objects. For instance something like:</p> <pre><code>foo_model_instance = models.get_or_create_foo_from_user(request.user) </code></pre> <p>If you were going to test with the django python shell or in a unittest, what would you pass in there? Here simp...
39
2010-01-10T05:20:46Z
25,835,403
<p>For request, I would use <a href="https://docs.djangoproject.com/en/stable/topics/testing/advanced/#the-request-factory">RequestFactory</a> included with Django.</p> <pre><code>from django.test.client import RequestFactory rf = RequestFactory() get_request = rf.get('/hello/') post_request = rf.post('/submit/', {'fo...
27
2014-09-14T16:24:02Z
[ "python", "django", "unit-testing", "mocking" ]
Tips on how to parse custom file format
2,036,236
<p>Sorry about the vague title, but I really don't know how to describe this problem concisely.</p> <p>I've created a (more or less) simple <a href="http://en.wikipedia.org/wiki/Domain-specific_language" rel="nofollow">domain-specific language</a> that I will to use to specify what validation rules to apply to differe...
2
2010-01-10T05:39:37Z
2,036,276
<p>First off, if you want to learn about parsing, then write your own recursive descent parser. The language you've defined only requires a handful of productions. I suggest using Python's <code>tokenize</code> library to spare yourself the boring task of converting a stream of bytes into a stream of tokens.</p> <p>Fo...
8
2010-01-10T05:58:27Z
[ "python", "parsing", "file-format" ]
Tips on how to parse custom file format
2,036,236
<p>Sorry about the vague title, but I really don't know how to describe this problem concisely.</p> <p>I've created a (more or less) simple <a href="http://en.wikipedia.org/wiki/Domain-specific_language" rel="nofollow">domain-specific language</a> that I will to use to specify what validation rules to apply to differe...
2
2010-01-10T05:39:37Z
2,036,324
<p>There are libraries and tools to make parsing easier. One of the more well known is lex / yacc. There's a python library called '<a href="http://www.dabeaz.com/ply/" rel="nofollow">lex</a>' and a <a href="http://www.dalkescientific.com/writings/NBN/parsing_with_ply.html" rel="nofollow">tutorial</a> on using it.</p>
0
2010-01-10T06:18:55Z
[ "python", "parsing", "file-format" ]
Tips on how to parse custom file format
2,036,236
<p>Sorry about the vague title, but I really don't know how to describe this problem concisely.</p> <p>I've created a (more or less) simple <a href="http://en.wikipedia.org/wiki/Domain-specific_language" rel="nofollow">domain-specific language</a> that I will to use to specify what validation rules to apply to differe...
2
2010-01-10T05:39:37Z
2,036,327
<p>As 'Marcelo Cantos' suggested you can use python dict, benefit is that you do not have to parse any thing, you can use same rules on server side as python dict and on client side using javascript objects, and can pass them from server to client or viceversa as JSON.</p> <p>If you really want to do parsing yourself...
1
2010-01-10T06:20:51Z
[ "python", "parsing", "file-format" ]
Tips on how to parse custom file format
2,036,236
<p>Sorry about the vague title, but I really don't know how to describe this problem concisely.</p> <p>I've created a (more or less) simple <a href="http://en.wikipedia.org/wiki/Domain-specific_language" rel="nofollow">domain-specific language</a> that I will to use to specify what validation rules to apply to differe...
2
2010-01-10T05:39:37Z
2,036,330
<p>The language you've shown an example for is probably too complex to write a simple (and bug-free) parsing function for. I'd suggest reading up on parsing techniques such as recursive-descent or table-driven parsing such as LL(1), LL(k), etc.</p> <p>But that may be too general and/or complicated. It might be easier ...
1
2010-01-10T06:23:55Z
[ "python", "parsing", "file-format" ]
Tips on how to parse custom file format
2,036,236
<p>Sorry about the vague title, but I really don't know how to describe this problem concisely.</p> <p>I've created a (more or less) simple <a href="http://en.wikipedia.org/wiki/Domain-specific_language" rel="nofollow">domain-specific language</a> that I will to use to specify what validation rules to apply to differe...
2
2010-01-10T05:39:37Z
2,036,393
<p>If your goal is to learn about parsing, I'd highly recommend an OO style library like <a href="http://pyparsing.wikispaces.com/" rel="nofollow">PyParsing</a>. They are not as fast as the more sophisticated antler, lex, yac options, but you get started with the parsing right away. </p>
2
2010-01-10T07:01:41Z
[ "python", "parsing", "file-format" ]
Tips on how to parse custom file format
2,036,236
<p>Sorry about the vague title, but I really don't know how to describe this problem concisely.</p> <p>I've created a (more or less) simple <a href="http://en.wikipedia.org/wiki/Domain-specific_language" rel="nofollow">domain-specific language</a> that I will to use to specify what validation rules to apply to differe...
2
2010-01-10T05:39:37Z
2,036,394
<p>what is the motivation for the customized file structure? Would it be possible to remodel your data into a better known structure like XML? If so you could use one of a multitude to parse your file. Using an accepted parsing tool may save you a lot of time debugging, and it may make your file more readable if that...
0
2010-01-10T07:02:57Z
[ "python", "parsing", "file-format" ]
Tips on how to parse custom file format
2,036,236
<p>Sorry about the vague title, but I really don't know how to describe this problem concisely.</p> <p>I've created a (more or less) simple <a href="http://en.wikipedia.org/wiki/Domain-specific_language" rel="nofollow">domain-specific language</a> that I will to use to specify what validation rules to apply to differe...
2
2010-01-10T05:39:37Z
2,359,991
<p>Again not teaching you about parsing, but your format is so close to legal <a href="http://www.yaml.org/" rel="nofollow">YAML</a> that you might want to just redefine your language as a subset of YAML and use a <a href="http://pyyaml.org/" rel="nofollow">standard YAML parser</a>.</p>
3
2010-03-01T23:48:39Z
[ "python", "parsing", "file-format" ]
Python: Decorators: How does the following code work?
2,036,288
<p><strong>Are the comments in the following code correct? Particularly the "instance =..." one?</strong></p> <pre><code># This does nothing. class donothing(object): def __init__(self, func): """ The 'func' argument is the function being decorated because in this case, we're not instantia...
1
2010-01-10T06:02:41Z
2,036,347
<p>Yes perfect description, decorator <code>donothing</code> decorates the function <code>printer</code> and returns a object of class <code>donothing</code>, so yes decorator simply boils down to this </p> <pre><code>x = donothing(func) # donothing is a class not function </code></pre> <p>and you can use it like thi...
2
2010-01-10T06:32:34Z
[ "python", "decorator" ]
Using savepoints in python sqlite3
2,036,378
<p>I'm attempting to use savepoints with the sqlite3 module built into python 2.6. Every time I try to release or rollback a savepoint, I always recieve an <code>OperationalError: no such savepoint</code>. What am I missing?</p> <pre><code>python version: 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) [GCC 4.0.1 (Apple...
4
2010-01-10T06:53:13Z
2,036,477
<p>This appears to be a result of how the sqlite3 module behaves with that isolation level.</p> <p>This works, notice the two changes:</p> <pre><code>import sys import sqlite3 print 'python version:', sys.version print 'PySQLite version:', sqlite3.version print 'sqlite3 version:', sqlite3.sqlite_version print conn ...
2
2010-01-10T08:14:36Z
[ "python", "sqlite3", "savepoints" ]
Using savepoints in python sqlite3
2,036,378
<p>I'm attempting to use savepoints with the sqlite3 module built into python 2.6. Every time I try to release or rollback a savepoint, I always recieve an <code>OperationalError: no such savepoint</code>. What am I missing?</p> <pre><code>python version: 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) [GCC 4.0.1 (Apple...
4
2010-01-10T06:53:13Z
14,521,679
<p>This is a bug in pysqlite, see <a href="http://code.google.com/p/pysqlite/issues/detail?id=24" rel="nofollow">the pysql issue tracker</a> and <a href="http://bugs.python.org/issue10740" rel="nofollow">the python issue tracker</a>.</p>
1
2013-01-25T12:18:08Z
[ "python", "sqlite3", "savepoints" ]
Model sys's python implementation
2,036,392
<p><a href="http://codespeak.net/pypy/dist/pypy/doc/" rel="nofollow">pypy</a></p> <p>has many built-in function use python implementation.example:<a href="http://stackoverflow.com/questions/2032677/functools-module">link</a></p> <p>but,i can't find model 'sys' implementation.</p> <p>how can i get it.</p> <pre><co...
0
2010-01-10T07:01:31Z
2,036,575
<p>The sys module is implemented in C: <a href="http://svn.python.org/view/python/trunk/Python/sysmodule.c?view=markup" rel="nofollow">http://svn.python.org/view/python/trunk/Python/sysmodule.c?view=markup</a></p> <p>There is no Python source for it, because it's entirely operating system interfaces that cannot be imp...
2
2010-01-10T09:16:18Z
[ "python", "model", "pypy" ]
Model sys's python implementation
2,036,392
<p><a href="http://codespeak.net/pypy/dist/pypy/doc/" rel="nofollow">pypy</a></p> <p>has many built-in function use python implementation.example:<a href="http://stackoverflow.com/questions/2032677/functools-module">link</a></p> <p>but,i can't find model 'sys' implementation.</p> <p>how can i get it.</p> <pre><co...
0
2010-01-10T07:01:31Z
2,036,697
<p>Abstraction can only be taken so far, Python strives to be a system/platform independent language and the sys module being what it is has to be platform specific and cannot be implemented in pure python.</p>
0
2010-01-10T10:26:25Z
[ "python", "model", "pypy" ]
PIP complains when I try to install a module into another virtualenv
2,036,462
<p>I have a module installed in the main python install, however, I'd like to install this module into my virtualenv and I'd like it to be portable, how can I do that?</p> <p>I'm getting this error:</p> <pre><code>(v_env)[nubela@nubela-desktop zine-ified]$ pip -E v_env install pyfacebook Requirement already satisfied...
2
2010-01-10T07:57:38Z
2,037,129
<p>To force pip installing a package when it's already been detected, you need to use the <code>-I</code> or <code>--ignore-installed</code> flag. In your case, the command would be:</p> <pre><code>pip -E v_env install -I pyfacebook </code></pre> <p>pip will then install it into your virtualenv.</p>
6
2010-01-10T13:34:09Z
[ "python" ]
How to do related questions autopopulate
2,036,688
<p>I want to get a related [things/questions] in my app, similar to what StackOverflow does, when you tab out of the Title field.</p> <p>I can think of only one way to do it, which i think might be fast enough</p> <ol> <li>Do a search for the title in corpus of titles of all [things], and return first x matches. We c...
4
2010-01-10T10:24:21Z
2,037,175
<p>You're looking at a content-based recommendation algorithm. AFAICT StackOverflow's looks at the tags and the words in the title, and finds questions that share some of these. It can be implemented as a nearest neighbour search in a space where documents are represented as <a href="http://en.wikipedia.org/wiki/Vector...
1
2010-01-10T13:50:59Z
[ "python", "django", "algorithm", "information-retrieval" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,036,783
<p>One way to modify your code would be to use a local function as follows:</p> <pre><code>def countSubStringMatchRecursive(target,key): def countit(target,key,count): index=find(target,key) if index&gt;=0: target=target[index+len(key):] count += countit(target,key,count) + ...
11
2010-01-10T11:01:02Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,036,811
<p>Another way could be to have a third optional parameter on the <code>countSubStringMatchRecursive</code> function called count that is originally set to <code>0</code>. That way you could keep track of the count. This would expose the count variable to the outside world which might not be desirable, but since it's n...
0
2010-01-10T11:21:10Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,036,833
<p>Your recursive function has O(n^2) performance because it copies the remaining contents of the string each time it finds a match. This is slower than the iterative solution O(n) and unnecessarily so.</p> <p>You can easily rewrite it to be faster, and at the same time simplify the code and extend its functionality b...
8
2010-01-10T11:33:40Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,036,836
<p>How about this?</p> <pre><code>def count_it(target, key): index = target.find(key) if index &gt;= 0: return 1 + count_it(target[index+len(key):], key) else: return 0 print count_it("aaa bbb aaa ccc aaa", "aaa") </code></pre> <p>Output:</p> <pre><code>3 </code></pre>
1
2010-01-10T11:34:06Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,036,848
<p>Here's something similar to Greg Hewgill's answer. However, instead we pass along the current count each time we call the function, and then return the count when there are no more matches to be made. While I suspect it makes no difference in Python, in languages that implement tail-call recursion, this allows each ...
5
2010-01-10T11:38:00Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,036,856
<p><strong>Not</strong> untested ...</p> <p>code:</p> <pre><code>def countSubStringMatchRecursive(target, key, count=0): #### index = find(target, key) # HUH? index = target.find(key) if index &gt;= 0: count += 1 target = target[index+len(key):] count = countSubStringMatchRecursive...
0
2010-01-10T11:40:52Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,037,936
<p>Just a side note: all solutions presented (from the original Q to all the As) are solving a problem that's different than the specifically stated one (I imagine that's a bug in the specific problem statement, but, worth fixing if so;-). Consider:</p> <pre><code>&gt;&gt;&gt; 'banana'.count('ana') 1 &gt;&gt;&gt; sum...
5
2010-01-10T18:06:26Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
2,190,415
<pre><code>def countSubStringMatchRecursive(target,key): index = string.find(target, key) if index == -1: return 0 else: return 1 + countSubStringMatchRecursive(target[index+len(key):],key) </code></pre>
1
2010-02-03T07:51:53Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
5,963,554
<p>I'm doing this course on OpenCourseware, it's great. Anyways, this is what I did. I took inspiration from adamse above.</p> <pre><code>def countSubStringMatchRecursive(target, key, counter = 0): if find(target,key) == 0: countSubStringMatchRecursive(target[1:], key, counter + 1) elif find(target,key...
2
2011-05-11T11:35:22Z
[ "python", "recursion" ]
How to keep count in a recursive function? [python]
2,036,772
<p>I wrote a recursive function to find the no. of instances of a substring in the parent string. The way I am keeping count is by declaring/initialising count as a global variable outside the function's scope. Problem is, it'll give me correct results only the first time the function is run, because after that count !...
11
2010-01-10T10:57:12Z
9,249,369
<p>Taking into account overlapping occurrences and maintaining the original definition from <a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset3.pdf" rel="nofollow">MIT</a> this is the simpler and more compact c...
2
2012-02-12T14:02:20Z
[ "python", "recursion" ]
How to get started building a Mac application
2,036,844
<p>I am a Python/web programmer.</p> <p>Now, I would like to transition to building applications for the Mac.<br> Please tell me--what do I have to learn to get started? What books would you recommend?</p>
2
2010-01-10T11:35:55Z
2,036,861
<p>The programming language of choice for building OS X gui applications is Objective-C with Cocoa, I would recommend that you check out some books on that. There are python bindings for Cocoa but they are not optimal.</p> <p>You should check out <a href="http://stackoverflow.com/search?q=learning+cocoa">previous ques...
2
2010-01-10T11:41:55Z
[ "python", "osx" ]
How to get started building a Mac application
2,036,844
<p>I am a Python/web programmer.</p> <p>Now, I would like to transition to building applications for the Mac.<br> Please tell me--what do I have to learn to get started? What books would you recommend?</p>
2
2010-01-10T11:35:55Z
2,037,121
<p>Assuming that you included the "python" tag after considering that it will be interpreted as applying to the question and not the questioner, you must be interested in writing <em>Python</em> applications for the Mac, right? After all, you didn't include "web" as one of the tags too.</p> <p>If that's true, I'm not...
3
2010-01-10T13:32:08Z
[ "python", "osx" ]
Problem with sqlalchemy, reflected table and defaults for string fields
2,036,996
<p>hmm, is there any reason why sa tries to add Nones to for varchar columns that have defaults set in in database schema ?, it doesnt do that for floats or ints (im using reflection).</p> <p>so when i try to add new row : like u = User() u.foo = 'a' u.bar = 'b'</p> <p>sa issues a query that has a lot more cols with ...
0
2010-01-10T12:28:39Z
2,037,291
<p>I've found its a bug in sa, this happens only for string fields, they dont get server_default property for some unknow reason, filed a ticket for this already</p>
0
2010-01-10T14:35:22Z
[ "python", "sqlalchemy" ]
Problem with sqlalchemy, reflected table and defaults for string fields
2,036,996
<p>hmm, is there any reason why sa tries to add Nones to for varchar columns that have defaults set in in database schema ?, it doesnt do that for floats or ints (im using reflection).</p> <p>so when i try to add new row : like u = User() u.foo = 'a' u.bar = 'b'</p> <p>sa issues a query that has a lot more cols with ...
0
2010-01-10T12:28:39Z
2,037,676
<p>What version do you use and what is actual code? Below is a sample code showing that <code>server_default</code> parameter works fine for string fields:</p> <pre><code>from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker metadata = MetaData() Base...
2
2010-01-10T16:46:12Z
[ "python", "sqlalchemy" ]
Different results from yield vs return
2,037,267
<p>I don't really understand how <code>yield</code> statement works in this situation. The problem says that given an expression without parentheses, write a function to generate all possible fully parenthesized (FP) expressions. Say, the input is <code>'1+2+3+4'</code> which should be generated to 5 FP expressions:</p...
5
2010-01-10T14:27:28Z
2,037,390
<p>The problem is you're iterating over generators instead of lists in the yield version, specifically <em>secondG</em> which is exhausted after one loop. Change the line to this and it works:</p> <pre><code>firstG, secondG = f(first), list(f(second)) </code></pre> <p>Or, you can change your loop:</p> <pre><code>fo...
4
2010-01-10T15:05:45Z
[ "python", "recursion", "yield" ]
Listing buildout configuration variables
2,037,290
<p>I'd like to find out, exactly what variables are available when using zc.buildout. I can always look at the source, but ideally I'd find a list somewhere, or be able to query buildout to find out what <strong>it</strong> thinks are the variables available at any one time. Is this possible?</p>
6
2010-01-10T14:35:11Z
2,037,871
<p>It is not the prettiest list, but you can look at <code>.installed.cfg</code> in your buildout's directory.</p> <p>For every part, it shows which options it knows about. (For some reason several parts are often shown multiple times).</p>
1
2010-01-10T17:44:47Z
[ "python", "buildout" ]
Listing buildout configuration variables
2,037,290
<p>I'd like to find out, exactly what variables are available when using zc.buildout. I can always look at the source, but ideally I'd find a list somewhere, or be able to query buildout to find out what <strong>it</strong> thinks are the variables available at any one time. Is this possible?</p>
6
2010-01-10T14:35:11Z
2,038,773
<p>I found from the <a href="http://pypi.python.org/pypi/zc.buildout#annotated-sections">buildout docs</a> that </p> <p><code>bin/buildout annotate</code> </p> <p>was what I was looking for.</p>
14
2010-01-10T21:47:50Z
[ "python", "buildout" ]
Translating function for finding all partitions of a set from Python to Ruby
2,037,327
<p>I have the following python function to recursively find all partitions of a set:</p> <pre><code>def partitions(set_): if not set_: yield [] return for i in xrange(2**len(set_)/2): parts = [set(), set()] for item in set_: parts[i&amp;1].add(item) i &gt...
5
2010-01-10T14:45:55Z
2,037,372
<p>You'll have to think of Ruby's <code>yield</code> like a call to a user-defined operation.</p> <pre><code>def twice yield yield end twice { puts "Hello" } </code></pre> <p>So whenever your code yields a value, a processing function for this element will be called.</p> <pre><code>partitions([1, 2, 3, 4]....
0
2010-01-10T14:59:58Z
[ "python", "ruby" ]
Translating function for finding all partitions of a set from Python to Ruby
2,037,327
<p>I have the following python function to recursively find all partitions of a set:</p> <pre><code>def partitions(set_): if not set_: yield [] return for i in xrange(2**len(set_)/2): parts = [set(), set()] for item in set_: parts[i&amp;1].add(item) i &gt...
5
2010-01-10T14:45:55Z
2,037,581
<pre><code>#!/usr/bin/ruby1.8 def partitions(set) yield [] if set.empty? (0 ... 2 ** set.size / 2).each do |i| parts = [[], []] set.each do |item| parts[i &amp; 1] &lt;&lt; item i &gt;&gt;= 1 end partitions(parts[1]) do |b| result = [parts[0]] + b result = result.reject do |...
3
2010-01-10T16:16:26Z
[ "python", "ruby" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
2,037,384
<p>See <a href="http://docs.djangoproject.com/en/1.1/topics/testing/#id1" rel="nofollow">http://docs.djangoproject.com/en/1.1/topics/testing/#id1</a></p> <p>The most common reason for tests not running is that your settings aren't right, and your module is not in INSTALLED_APPS.</p> <p>We use <code>django.test.TestCa...
2
2010-01-10T15:03:44Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
2,039,219
<p>Worked it out.</p> <p>It turns out I had done <code>django-admin.py startproject pyDietTracker</code> but not <code>python manage.py startapp myApp</code>. After going back and doing this, it did work as documented. It would appear I have a lot to learn about reading and the difference between a site and an app i...
9
2010-01-11T00:10:50Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
4,747,444
<p>I had the same issue but my problem was different.</p> <p>I was getting 0 tests Ran as OP.</p> <p>But it turns out the test methods inside your test class must start with keyword 'test' to run. </p> <p>Example:</p> <pre><code>from django.test import TestCase class FooTest(TestCase): def setUp(self): ...
61
2011-01-20T13:03:25Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
9,987,699
<p>I had this happen when I had a test.py file, and a test/ subdirectory, in the same Django app directory. I guess I'm confusing python or the test runner whether I'm looking for a test module (in test.py) or a test package (in test/ subdir).</p>
3
2012-04-03T05:44:00Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
13,834,340
<p>If you are trying to run a test in your main app, such as my_app/my_app/ make sure you have the following checked:</p> <ol> <li>App name is listed in INSTALLED_APPS inside <code>settings.py</code></li> <li>Make sure your <code>DATABASES['default']</code> inside <code>settings.py</code> is set properly</li> <li>The ...
1
2012-12-12T06:50:32Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
15,961,499
<p>This also happens if you have a syntax error in your tests.py.</p>
5
2013-04-12T01:12:46Z
[ "python", "django", "unit-testing" ]
Django test runner not finding tests
2,037,364
<p>I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses ...
23
2010-01-10T14:57:35Z
25,820,203
<p>if you're using a <code>yourapp/tests</code> package/style for unittests, make sure theres a <code>__init__.py</code> in there (since thats what makes it a python module!)</p>
12
2014-09-13T05:43:59Z
[ "python", "django", "unit-testing" ]