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
ValueError: no such test method in <class 'myapp.tests.SessionTestCase'>: runTest
2,090,479
<p>I have a test case:</p> <pre><code>class LoginTestCase(unittest.TestCase): ... </code></pre> <p>I'd like to use it in a different test case:</p> <pre><code>class EditProfileTestCase(unittest.TestCase): def __init__(self): self.t = LoginTestCase() self.t.login() </code></pre> <p>This raises:</p> <p...
9
2010-01-19T01:29:46Z
2,090,534
<p><code>unittest</code> does deep black magic -- if you choose to use it to run your unit-tests (I do, since this way I can use a very powerful battery of test runners &amp;c integrated into the build system at my workplace, but there are definitely worthwhile alternatives), you'd better play by its rules.</p> <p>In ...
2
2010-01-19T01:44:52Z
[ "python", "unit-testing" ]
ValueError: no such test method in <class 'myapp.tests.SessionTestCase'>: runTest
2,090,479
<p>I have a test case:</p> <pre><code>class LoginTestCase(unittest.TestCase): ... </code></pre> <p>I'd like to use it in a different test case:</p> <pre><code>class EditProfileTestCase(unittest.TestCase): def __init__(self): self.t = LoginTestCase() self.t.login() </code></pre> <p>This raises:</p> <p...
9
2010-01-19T01:29:46Z
16,211,735
<p>The confusion with "runTest" is mostly based on the fact that this works:</p> <pre><code>class MyTest(unittest.TestCase): def test_001(self): print "ok" if __name__ == "__main__": unittest.main() </code></pre> <p>So there is no "runTest" in that class and all of the test-functions are being called...
21
2013-04-25T09:57:20Z
[ "python", "unit-testing" ]
ValueError: no such test method in <class 'myapp.tests.SessionTestCase'>: runTest
2,090,479
<p>I have a test case:</p> <pre><code>class LoginTestCase(unittest.TestCase): ... </code></pre> <p>I'd like to use it in a different test case:</p> <pre><code>class EditProfileTestCase(unittest.TestCase): def __init__(self): self.t = LoginTestCase() self.t.login() </code></pre> <p>This raises:</p> <p...
9
2010-01-19T01:29:46Z
26,504,058
<p>Guido's answer is almost there, however it doesn't explain the thing. I needed to look to <code>unittest</code> code to grasp the flow.</p> <p>Say you have the following.</p> <pre><code>import unittest class MyTestCase(unittest.TestCase): def testA(self): pass def testB(self): pass </code></pre> <p...
2
2014-10-22T09:14:43Z
[ "python", "unit-testing" ]
ValueError: no such test method in <class 'myapp.tests.SessionTestCase'>: runTest
2,090,479
<p>I have a test case:</p> <pre><code>class LoginTestCase(unittest.TestCase): ... </code></pre> <p>I'd like to use it in a different test case:</p> <pre><code>class EditProfileTestCase(unittest.TestCase): def __init__(self): self.t = LoginTestCase() self.t.login() </code></pre> <p>This raises:</p> <p...
9
2010-01-19T01:29:46Z
26,900,524
<p>Here's some '<strong>deep black magic</strong>':</p> <pre><code>suite = unittest.TestLoader().loadTestsFromTestCase(Test_MyTests) unittest.TextTestRunner(verbosity=3).run(suite) </code></pre> <p>Very handy if you just want to test run your unit tests from a shell (i.e., <a href="http://ipython.org/">IPython</a>).<...
10
2014-11-13T02:49:35Z
[ "python", "unit-testing" ]
ValueError: no such test method in <class 'myapp.tests.SessionTestCase'>: runTest
2,090,479
<p>I have a test case:</p> <pre><code>class LoginTestCase(unittest.TestCase): ... </code></pre> <p>I'd like to use it in a different test case:</p> <pre><code>class EditProfileTestCase(unittest.TestCase): def __init__(self): self.t = LoginTestCase() self.t.login() </code></pre> <p>This raises:</p> <p...
9
2010-01-19T01:29:46Z
28,612,437
<p>If you don't mind editing unit test module code directly, the simple fix is to add under <strong>case.py</strong> class <strong>TestCase</strong> a new method called runTest that does nothing.</p> <p>The file to edit sits under pythoninstall\Lib\unittest\case.py</p> <pre><code>def runTest(self): pass </code></...
2
2015-02-19T17:05:42Z
[ "python", "unit-testing" ]
Python dictionary key order when printing
2,090,564
<pre><code>s={ 'userName': "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf", 'userNameMin': "\u4e0d\u80fd\u5c0f\u4e8e4\u4e2a\u5b57", 'userNameMax': "\u4e0d\u80fd\u8d85\u8fc712\u4e2a\u5b57", 'userNameExist': "\u8be5\u7528\u6237\u540d\u5df2\u88ab\u6ce8\u518c\u...
1
2010-01-19T01:55:17Z
2,090,569
<p>Use tuple <code>()</code> or array <code>[]</code> instead of dictionary/map <code>{}</code> - tuples and arrays keep their sequence but do not allow using keys, dictionaries do not keep their sequence but allow using keys.</p> <pre><code>s=( ('userName', "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u5...
0
2010-01-19T01:57:14Z
[ "python" ]
Python dictionary key order when printing
2,090,564
<pre><code>s={ 'userName': "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf", 'userNameMin': "\u4e0d\u80fd\u5c0f\u4e8e4\u4e2a\u5b57", 'userNameMax': "\u4e0d\u80fd\u8d85\u8fc712\u4e2a\u5b57", 'userNameExist': "\u8be5\u7528\u6237\u540d\u5df2\u88ab\u6ce8\u518c\u...
1
2010-01-19T01:55:17Z
2,090,571
<p>dicts are unsorted. If you need keys to be output in a specific order then use a list to hold them, then index the dict by each of the keys in order.</p>
2
2010-01-19T01:57:17Z
[ "python" ]
Python dictionary key order when printing
2,090,564
<pre><code>s={ 'userName': "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf", 'userNameMin': "\u4e0d\u80fd\u5c0f\u4e8e4\u4e2a\u5b57", 'userNameMax': "\u4e0d\u80fd\u8d85\u8fc712\u4e2a\u5b57", 'userNameExist': "\u8be5\u7528\u6237\u540d\u5df2\u88ab\u6ce8\u518c\u...
1
2010-01-19T01:55:17Z
2,090,572
<p>Use <a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">OrderedDict</a> on python 2.7+</p> <p>Or change dict to tuple or list, something like this</p> <pre><code>[ ('userName', "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf"), ('userNameMin', "\u4e0d\u80fd\u5c0f...
5
2010-01-19T01:57:47Z
[ "python" ]
Python dictionary key order when printing
2,090,564
<pre><code>s={ 'userName': "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf", 'userNameMin': "\u4e0d\u80fd\u5c0f\u4e8e4\u4e2a\u5b57", 'userNameMax': "\u4e0d\u80fd\u8d85\u8fc712\u4e2a\u5b57", 'userNameExist': "\u8be5\u7528\u6237\u540d\u5df2\u88ab\u6ce8\u518c\u...
1
2010-01-19T01:55:17Z
2,090,888
<p>you could always do a sort before you print ?</p> <pre><code>for k in sorted(s.keys()): print k,s[k].decode('unicode-escape') </code></pre>
1
2010-01-19T03:34:16Z
[ "python" ]
Problems enabling a quit function in Python
2,090,582
<p>I'm pretty new to programming in general and I'm creating a small game for my younger sister...</p> <p>I have a while loop in which I want to have an option to quit the game, but none of the quitting techniques I know of seem to work:</p> <pre><code>#main game: while 1: input_event_1 = gui.buttonbox( m...
0
2010-01-19T01:59:48Z
2,090,599
<p>I think this is your problem:</p> <pre><code>if input_quit == 'Quit': input_quit = gui.ynbox( msg = 'Are you sure you want to quit?', </code></pre> <p>should be</p> <pre><code>if input_event_1 == 'Quit': input_quit = gui.ynbox( msg = 'Are you sure you want to quit?', </code></pre> ...
2
2010-01-19T02:04:28Z
[ "python", "quit" ]
Problems enabling a quit function in Python
2,090,582
<p>I'm pretty new to programming in general and I'm creating a small game for my younger sister...</p> <p>I have a while loop in which I want to have an option to quit the game, but none of the quitting techniques I know of seem to work:</p> <pre><code>#main game: while 1: input_event_1 = gui.buttonbox( m...
0
2010-01-19T01:59:48Z
2,090,601
<p>It is more elegant this way:</p> <pre><code>she_wants_to_play = true while she_wants_to_play: ask input if input == quit: she_wants_to_play = false </code></pre> <p>So you nicely quit the while loop, instead of hitting the system with a 10000 Ton weight.</p>
0
2010-01-19T02:04:35Z
[ "python", "quit" ]
Problems enabling a quit function in Python
2,090,582
<p>I'm pretty new to programming in general and I'm creating a small game for my younger sister...</p> <p>I have a while loop in which I want to have an option to quit the game, but none of the quitting techniques I know of seem to work:</p> <pre><code>#main game: while 1: input_event_1 = gui.buttonbox( m...
0
2010-01-19T01:59:48Z
2,090,605
<p>Few checkpoints</p> <ul> <li>Did you import sys?</li> <li><code>if input_event_quit == 'Quit':</code> should be if <code>input_quit == 'Quit':</code></li> </ul>
0
2010-01-19T02:05:38Z
[ "python", "quit" ]
Problems enabling a quit function in Python
2,090,582
<p>I'm pretty new to programming in general and I'm creating a small game for my younger sister...</p> <p>I have a while loop in which I want to have an option to quit the game, but none of the quitting techniques I know of seem to work:</p> <pre><code>#main game: while 1: input_event_1 = gui.buttonbox( m...
0
2010-01-19T01:59:48Z
2,090,607
<p>I think maybe your code</p> <pre><code> if input_quit == 'Quit': </code></pre> <p>should be</p> <pre><code> if input_event_1 == 'Quit': </code></pre> <p>just like your other checks? I'm not familiar with that <code>buttonbox</code> thingy but the discrepancy between this one check and the others is immediately ...
2
2010-01-19T02:05:44Z
[ "python", "quit" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
2,090,825
<p>The latest 2.6. Don't worry about 3.x; there isn't <em>that</em> much to learn.</p>
6
2010-01-19T03:18:07Z
[ "python" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
2,090,826
<p>Start with Python3. See <a href="http://diveintopython3.org/" rel="nofollow">http://diveintopython3.org/</a> for a great introduction.</p>
0
2010-01-19T03:18:21Z
[ "python" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
2,090,833
<p>one <a href="http://stackoverflow.com/questions/170921/to-learn-python-2-then-3-or-3-from-the-start">thread</a> in SO you can take reference. Search SO for more if you have to.</p> <p>I wouldn't worry too much on function differences. What's more important right now is to learn the language well. Read the documents...
2
2010-01-19T03:19:33Z
[ "python" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
2,090,836
<p>It's really going to depend on what you want to do. Generally speaking Python 3 "isn't ready yet", in the sense that few libraries support Python 3. This will end up greatly limiting what you can accomplish with the language as a beginner.</p> <p>On the other hand, if you think you'll be spending your time on mor...
12
2010-01-19T03:20:40Z
[ "python" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
2,090,843
<p>Python 2.6 (and 2.5, 2.4) are what you will find installed on most machines (Linux) and what you will <strong>find most code written in</strong>. Therefore I'd start with Python 2.6.</p>
18
2010-01-19T03:21:49Z
[ "python" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
2,091,413
<p><code>#python</code> IRC Channel says:</p> <blockquote> <p>It's too early to use Python 3.x</p> </blockquote> <p>If you are a beginner I would suggest start learning with Python 2.6</p>
0
2010-01-19T05:51:33Z
[ "python" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
2,098,857
<p>Directly from python.org:</p> <blockquote> <p>If you don't know which version to use, start with Python 2.6.4; more existing third party software is compatible with Python 2 than Python 3 right now.</p> </blockquote> <p>If Guido is recommending it, I'd follow him :)</p>
0
2010-01-20T03:26:44Z
[ "python" ]
What version of Python should I use if I'm a new to Python?
2,090,820
<p>If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc:</p> <blockquote> <p>What version of Python should I use?</p> </blockquote> <p>I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn so...
18
2010-01-19T03:15:32Z
26,802,439
<p>I would recommend to go with Python 2.7 (32-bit would be favorable). Most of the libraries are available for 2.7 version of Python than any other version. I personally use Python 2.7 (32-bit). </p> <ul> <li>Most of the tutorial are available in Python 2.7. </li> <li>Most of the Linux distributions come with pre-i...
0
2014-11-07T13:32:35Z
[ "python" ]
python datetime localization
2,090,840
<p>What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call:</p> <pre><code>datetime.date(2009,1,16).strftime("%A %Y-%b-%d") </code></pre> <p>instead of getting:</p> <pre><code>Out[20]: 'Friday 2009-Jan-16' </code></pre> <p>i get spanish/french/german/... output</p> <pre><code>Out...
7
2010-01-19T03:21:25Z
2,090,861
<p><a href="http://docs.python.org/library/locale.html#locale.setlocale"><code>locale.setlocale()</code></a></p>
7
2010-01-19T03:28:10Z
[ "python" ]
python datetime localization
2,090,840
<p>What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call:</p> <pre><code>datetime.date(2009,1,16).strftime("%A %Y-%b-%d") </code></pre> <p>instead of getting:</p> <pre><code>Out[20]: 'Friday 2009-Jan-16' </code></pre> <p>i get spanish/french/german/... output</p> <pre><code>Out...
7
2010-01-19T03:21:25Z
2,090,873
<p>After setting your locale (with <code>locale.setlocale</code>) You can use the <code>locale</code> modules' <code>nl_langinfo</code> method like so:</p> <pre><code>time.strftime(locale.nl_langinfo(locale.D_T_FMT), time.localtime()) </code></pre>
2
2010-01-19T03:31:25Z
[ "python" ]
python datetime localization
2,090,840
<p>What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call:</p> <pre><code>datetime.date(2009,1,16).strftime("%A %Y-%b-%d") </code></pre> <p>instead of getting:</p> <pre><code>Out[20]: 'Friday 2009-Jan-16' </code></pre> <p>i get spanish/french/german/... output</p> <pre><code>Out...
7
2010-01-19T03:21:25Z
2,091,994
<p>Also, have a look at the <a href="http://babel.edgewall.org/" rel="nofollow">babel</a> project.</p>
2
2010-01-19T08:09:35Z
[ "python" ]
python datetime localization
2,090,840
<p>What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call:</p> <pre><code>datetime.date(2009,1,16).strftime("%A %Y-%b-%d") </code></pre> <p>instead of getting:</p> <pre><code>Out[20]: 'Friday 2009-Jan-16' </code></pre> <p>i get spanish/french/german/... output</p> <pre><code>Out...
7
2010-01-19T03:21:25Z
36,259,353
<p>On Ubuntu,</p> <pre><code>$&gt; sudo locale-gen es_ES.UTF-8 $&gt; sudo dpkg-reconfigure locales $&gt; python &gt;&gt;&gt; import locale &gt;&gt;&gt; locale.setlocale(locale.LC_TIME, 'es_ES.UTF-8') </code></pre>
0
2016-03-28T09:20:36Z
[ "python" ]
Change keyboard input method to unicode?
2,090,886
<p>I am going to create an application called 'khmer keyboard input method' the khmer just come in unicode standard (Range: 1780–17FF).</p> <p>reference <a href="http://www.unicode.org/charts/PDF/U1780.pdf" rel="nofollow">http://www.unicode.org/charts/PDF/U1780.pdf</a></p> <p>this application it will allow cambodia...
2
2010-01-19T03:33:06Z
2,090,909
<p>There is no single way. Each IME has its own way of picking a different engine/method.</p>
1
2010-01-19T03:41:13Z
[ "python" ]
How to set value of current Numbers cell using Py-Appscript
2,090,921
<p>This seems like a straightforward operation but I am stumped.</p> <p>How do you set value of current Numbers cell using Py-Appscript?</p>
0
2010-01-19T03:46:40Z
2,091,013
<p>Pretty tediously, but working:</p> <pre><code>&gt;&gt;&gt; from appscript import * &gt;&gt;&gt; app('Numbers').documents.first.sheets.first.tables.first.selection_range.cells.first.value.set(to=42) </code></pre> <p>That's assuming a simple document. More generally, you can select items by name:</p> <pre><code>&g...
2
2010-01-19T04:13:13Z
[ "python", "iwork", "appscript" ]
unidentified com_error in python
2,090,950
<p>I've encountered the following error while scripting in Python.</p> <p>ERROR Tue 19. Jan 14:51:21 2010 C:\Python24\Lib\site-packages\win32com\client\util.py:0: Script Error com_error: (-2147217385, 'OLE error 0x80041017', None, None)</p> <p>Unfortunately, I don't know what it means, or even what other informa...
1
2010-01-19T03:56:20Z
2,091,103
<p>Here's a page at the <a href="http://msdn.microsoft.com/en-us/library/aa394559%28VS.85%29.aspx" rel="nofollow">Microsoft site</a> which might shed some light:</p> <pre> WBEM_E_INVALID_QUERY 2147749911 (0x80041017) Query was not syntactically valid. </pre>
1
2010-01-19T04:36:38Z
[ "python", "com" ]
unidentified com_error in python
2,090,950
<p>I've encountered the following error while scripting in Python.</p> <p>ERROR Tue 19. Jan 14:51:21 2010 C:\Python24\Lib\site-packages\win32com\client\util.py:0: Script Error com_error: (-2147217385, 'OLE error 0x80041017', None, None)</p> <p>Unfortunately, I don't know what it means, or even what other informa...
1
2010-01-19T03:56:20Z
2,091,963
<p>When doing python COM programming, I sometimes use VBA (in Excel) to test code that gives errors.</p> <p>That way, I can see if the problem is in the Python-COM layer, or if I get the same error when using VBA. I have sometimes seen that the error messages in VBA have descriptions that the Python exception lacks.<...
0
2010-01-19T08:01:20Z
[ "python", "com" ]
What is the maximum packet size a python socket can handle?
2,091,097
<p>Hey hi guys, i am new to network programming in python. I wanted to know that what is the maximum size packet we can transmit or receive on python socket? and how to find out it?</p>
4
2010-01-19T04:35:22Z
2,091,135
<p>The actual amount of data that can be sent in a single packet depends on what the Maximum Transmission Unit (<a href="http://en.wikipedia.org/wiki/Maximum_transmission_unit" rel="nofollow">MTU</a>) is for the protocol you're using. Read the Wikipedia article for more information.</p> <p>This is generally something ...
4
2010-01-19T04:46:20Z
[ "python", "sockets", "network-programming" ]
What is the maximum packet size a python socket can handle?
2,091,097
<p>Hey hi guys, i am new to network programming in python. I wanted to know that what is the maximum size packet we can transmit or receive on python socket? and how to find out it?</p>
4
2010-01-19T04:35:22Z
2,091,144
<p>i think they are not at the same level, if you want to manipulate the raw package, take a look at <a href="http://code.google.com/p/dpkt/" rel="nofollow">dpkt</a> &amp; <a href="http://www.secdev.org/projects/scapy/index.html" rel="nofollow">scapy</a>.</p>
0
2010-01-19T04:47:50Z
[ "python", "sockets", "network-programming" ]
What is the maximum packet size a python socket can handle?
2,091,097
<p>Hey hi guys, i am new to network programming in python. I wanted to know that what is the maximum size packet we can transmit or receive on python socket? and how to find out it?</p>
4
2010-01-19T04:35:22Z
2,091,157
<p>I don't think there's any Python-specific limits. UDP packets have a theoretical limit of circa 65kb and TCP no upper limit, but you'll have flow control problems if you use packets much more than a few kilobytes.</p>
1
2010-01-19T04:50:38Z
[ "python", "sockets", "network-programming" ]
Run a C++ Program from Django Framework
2,091,294
<p>I need to run a C++ Program from Django Framework. In a sense, I get inputs from UI in views.py . Once I have these inputs, I need to process the input using my C++ program and use those results. Is it possible ?</p>
2
2010-01-19T05:27:42Z
2,091,306
<p>Compile that C++ program to executable and call with <a href="http://docs.python.org/library/subprocess.html">subprocess</a> module from python</p>
9
2010-01-19T05:30:06Z
[ "c++", "python", "django" ]
Run a C++ Program from Django Framework
2,091,294
<p>I need to run a C++ Program from Django Framework. In a sense, I get inputs from UI in views.py . Once I have these inputs, I need to process the input using my C++ program and use those results. Is it possible ?</p>
2
2010-01-19T05:27:42Z
2,091,309
<p>You can use swig to create a C++ module that can be imported in python. An alternative is boost::python (but personnaly, I prefer swig).</p>
1
2010-01-19T05:31:12Z
[ "c++", "python", "django" ]
Run a C++ Program from Django Framework
2,091,294
<p>I need to run a C++ Program from Django Framework. In a sense, I get inputs from UI in views.py . Once I have these inputs, I need to process the input using my C++ program and use those results. Is it possible ?</p>
2
2010-01-19T05:27:42Z
2,091,342
<p>One way of doing this would be to use <a href="http://docs.python.org/library/os.html#os.popen" rel="nofollow">os.popen</a>. Assuming your C++ executable is in the system wide path and is named <code>mycpp</code>, you would do something like:</p> <pre><code>results = os.popen('mycpp %s' % user_input).read() </code>...
0
2010-01-19T05:36:13Z
[ "c++", "python", "django" ]
Run a C++ Program from Django Framework
2,091,294
<p>I need to run a C++ Program from Django Framework. In a sense, I get inputs from UI in views.py . Once I have these inputs, I need to process the input using my C++ program and use those results. Is it possible ?</p>
2
2010-01-19T05:27:42Z
2,092,407
<p>Assuming you are on *nix, compile your C++ program and store it somewhere on your system, say /home/rishabh/myexe.</p> <p>Now from your django app call the executable using commands module:</p> <pre><code>import commands status, res = commands.getstatusoutput("/home/rishabh/myexe") # status contains process stat...
0
2010-01-19T09:26:28Z
[ "c++", "python", "django" ]
Regular expression for urlpattern
2,091,449
<p>I need a regexp for a URL like:</p> <pre><code>/slug/#slug/slug/ </code></pre> <p>I know it should be something like:</p> <pre><code>r'^(?P&lt;slug1&gt;[-\w]+)/#(?P&lt;slug2&gt;[-\w]+)/(?P&lt;slug3&gt;[-\w]+)/$' </code></pre> <p>But I am having problems with the character <code>#</code></p>
4
2010-01-19T06:02:42Z
2,091,461
<p>Parameter after # character is not send to server, so cannot catch in server side script like django.</p>
5
2010-01-19T06:05:45Z
[ "python", "regex", "django", "django-urls" ]
Regular expression for urlpattern
2,091,449
<p>I need a regexp for a URL like:</p> <pre><code>/slug/#slug/slug/ </code></pre> <p>I know it should be something like:</p> <pre><code>r'^(?P&lt;slug1&gt;[-\w]+)/#(?P&lt;slug2&gt;[-\w]+)/(?P&lt;slug3&gt;[-\w]+)/$' </code></pre> <p>But I am having problems with the character <code>#</code></p>
4
2010-01-19T06:02:42Z
2,091,463
<p>The URL fragment (everything after the <code>#</code>) is not sent to the server in a request.</p>
2
2010-01-19T06:06:03Z
[ "python", "regex", "django", "django-urls" ]
How should you interpret the PyStone value across machines?
2,091,508
<p>I have three different laptops with Python2.5 on it. If I run Pystone I get essentially the same values.</p> <ul> <li>Intel Pentium M @1.80GHz - 1.5GB RAM</li> <li>Intel T2300 @1.66GHz - 1GB RAM</li> <li>Intel Pentium Dual T2370 @1.73Ghz - 2GB RAM</li> </ul> <p>These are their respective Pystone values:</p> <ul> ...
3
2010-01-19T06:17:48Z
2,091,690
<p>Your CPUs score 442, 806, and 869 respectively on <a href="http://www.cpubenchmark.net/cpu_list.php">Passmark's list of CPU benchmarks</a>. When running on a single core, your dual-core CPUs should perform roughly equivalent to a CPU with half their score. The single-core scores then are about 442, 403, 434 (i.e., a...
5
2010-01-19T07:00:24Z
[ "python", "performance" ]
How should you interpret the PyStone value across machines?
2,091,508
<p>I have three different laptops with Python2.5 on it. If I run Pystone I get essentially the same values.</p> <ul> <li>Intel Pentium M @1.80GHz - 1.5GB RAM</li> <li>Intel T2300 @1.66GHz - 1GB RAM</li> <li>Intel Pentium Dual T2370 @1.73Ghz - 2GB RAM</li> </ul> <p>These are their respective Pystone values:</p> <ul> ...
3
2010-01-19T06:17:48Z
2,091,858
<p>PyStone is not a good or reliable benchmark, so you should probably not interpret them at all. But, no, higher is better, not the other way around. Also be sure to run it multiple times after each other, many CPU's slow down when idle today.</p>
2
2010-01-19T07:39:33Z
[ "python", "performance" ]
How should you interpret the PyStone value across machines?
2,091,508
<p>I have three different laptops with Python2.5 on it. If I run Pystone I get essentially the same values.</p> <ul> <li>Intel Pentium M @1.80GHz - 1.5GB RAM</li> <li>Intel T2300 @1.66GHz - 1GB RAM</li> <li>Intel Pentium Dual T2370 @1.73Ghz - 2GB RAM</li> </ul> <p>These are their respective Pystone values:</p> <ul> ...
3
2010-01-19T06:17:48Z
22,354,756
<p>pystones is a benchmark, but it's not a benchmark of the underlying hardware, is meant more as a benchmark to compare python implementations.</p> <p>That being so, comparing pystones on different hardware makes not much sense.</p>
0
2014-03-12T14:33:14Z
[ "python", "performance" ]
Opening remote documents in Python
2,091,598
<pre><code>from xml.dom.minidom import parse, parseString datasource = open('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml') dom = parse(datasource) print dom </code></pre> <p>... the above code throws an <code>IOError: 2, 'No such file or directory'</code>. Python doesn't read remote doc like PHP? Wh...
1
2010-01-19T06:39:18Z
2,091,607
<p>Use <a href="http://docs.python.org/library/urllib.html#urllib.urlopen" rel="nofollow"><code>urllib.urlopen()</code></a>.</p>
0
2010-01-19T06:41:27Z
[ "python", "xml", "parsing", "document" ]
Opening remote documents in Python
2,091,598
<pre><code>from xml.dom.minidom import parse, parseString datasource = open('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml') dom = parse(datasource) print dom </code></pre> <p>... the above code throws an <code>IOError: 2, 'No such file or directory'</code>. Python doesn't read remote doc like PHP? Wh...
1
2010-01-19T06:39:18Z
2,091,622
<p>The <a href="http://docs.python.org/library/urllib.html#urllib.urlopen" rel="nofollow">urllib.urlopen()</a> method returns a <a href="http://docs.python.org/library/stdtypes.html#bltin-file-objects" rel="nofollow">File Object</a>. So you can directly pass it to your <code>parse()</code> method</p>
0
2010-01-19T06:45:27Z
[ "python", "xml", "parsing", "document" ]
Opening remote documents in Python
2,091,598
<pre><code>from xml.dom.minidom import parse, parseString datasource = open('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml') dom = parse(datasource) print dom </code></pre> <p>... the above code throws an <code>IOError: 2, 'No such file or directory'</code>. Python doesn't read remote doc like PHP? Wh...
1
2010-01-19T06:39:18Z
2,091,626
<p><code>open</code> is used to open a file on a local filesystem. It cannot open URLs. You have to use <code>urllib.urlopen</code> which returns a file like object that supports a subset of the API. </p>
1
2010-01-19T06:46:11Z
[ "python", "xml", "parsing", "document" ]
Opening remote documents in Python
2,091,598
<pre><code>from xml.dom.minidom import parse, parseString datasource = open('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml') dom = parse(datasource) print dom </code></pre> <p>... the above code throws an <code>IOError: 2, 'No such file or directory'</code>. Python doesn't read remote doc like PHP? Wh...
1
2010-01-19T06:39:18Z
2,091,638
<p>Using <a href="http://docs.python.org/library/urllib2.html#urllib2.urlopen" rel="nofollow"><code>urllib2.urlopen()</code></a>:</p> <pre><code>&gt;&gt;&gt; import urllib2 &gt;&gt;&gt; from xml.dom.minidom import parse, parseString &gt;&gt;&gt; u1=urllib2.urlopen('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-da...
4
2010-01-19T06:48:17Z
[ "python", "xml", "parsing", "document" ]
Opening remote documents in Python
2,091,598
<pre><code>from xml.dom.minidom import parse, parseString datasource = open('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml') dom = parse(datasource) print dom </code></pre> <p>... the above code throws an <code>IOError: 2, 'No such file or directory'</code>. Python doesn't read remote doc like PHP? Wh...
1
2010-01-19T06:39:18Z
21,500,524
<pre><code> import urllib.request from xml.dom import minidom response = urllib.request.urlopen('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml') results = response.read() #print(results) xmldoc = minidom.parseString(results) itemlist = xmldoc.getElementsByTagName('Cube...
0
2014-02-01T16:27:04Z
[ "python", "xml", "parsing", "document" ]
how to erase lines with wxpython
2,091,999
<p>hello <br> I'm trying to make a paint tool in wxpython. and i couldn't find a way to make an ( Eraser ) . how can i make an eraser tool - just like the one in windows paint - in wxpython ? please help .<br> the idea or small code sample would be very helpful </p> <p><br> thanks in advance</p>
0
2010-01-19T08:10:19Z
2,093,523
<p>Have you made a Pen tool? Just set its colour to the canvas' background colour ;)</p> <p>by the way I actively develop my own wxpython painting program that you may want to check out; see <a href="http://code.google.com/p/whyteboard/" rel="nofollow">http://code.google.com/p/whyteboard/</a></p>
3
2010-01-19T12:49:06Z
[ "python", "wxpython", "device-context" ]
How do I access an object's properties by name?
2,092,002
<pre><code>class a(type): def __str__(self): return 'aaa' def __new__(cls, name, bases, attrs): attrs['cool']='cool!!!!' new_class = super(a,cls).__new__(cls, name, bases, attrs) #if 'media' not in attrs: #new_class.media ='media' return new_cl...
2
2010-01-19T08:11:11Z
2,092,011
<pre><code>print "cool!!!" </code></pre> <p>Or did I miss something?</p>
1
2010-01-19T08:13:24Z
[ "python" ]
How do I access an object's properties by name?
2,092,002
<pre><code>class a(type): def __str__(self): return 'aaa' def __new__(cls, name, bases, attrs): attrs['cool']='cool!!!!' new_class = super(a,cls).__new__(cls, name, bases, attrs) #if 'media' not in attrs: #new_class.media ='media' return new_cl...
2
2010-01-19T08:11:11Z
2,092,025
<pre><code>print b().cool </code></pre> <p><code>attrs</code> in your <code>__new__</code> method becomes the object's dictionary. Properties of Python objects are referenced with the <code>.</code> syntax.</p>
5
2010-01-19T08:15:25Z
[ "python" ]
Variables as a part of calling a method in python
2,092,059
<p>I'm pretty new to programming and I'm creating a python game for my little sister.</p> <p>I'm having trouble, because I want the variable value to be a part of the method name Is there any way this is possible?</p> <pre><code>def play_with_toy(self): toy = gui.buttonbox( msg = 'Choose a toy for your po...
2
2010-01-19T08:21:11Z
2,092,072
<pre><code>method = getattr(myPotatoHead, 'play_' + toy) method() </code></pre>
3
2010-01-19T08:23:09Z
[ "python", "function" ]
Variables as a part of calling a method in python
2,092,059
<p>I'm pretty new to programming and I'm creating a python game for my little sister.</p> <p>I'm having trouble, because I want the variable value to be a part of the method name Is there any way this is possible?</p> <pre><code>def play_with_toy(self): toy = gui.buttonbox( msg = 'Choose a toy for your po...
2
2010-01-19T08:21:11Z
2,092,076
<pre><code>getattr(myPotatoHead,"play_"+toy)() </code></pre>
1
2010-01-19T08:24:20Z
[ "python", "function" ]
Variables as a part of calling a method in python
2,092,059
<p>I'm pretty new to programming and I'm creating a python game for my little sister.</p> <p>I'm having trouble, because I want the variable value to be a part of the method name Is there any way this is possible?</p> <pre><code>def play_with_toy(self): toy = gui.buttonbox( msg = 'Choose a toy for your po...
2
2010-01-19T08:21:11Z
2,092,079
<p>Try this: </p> <pre><code>method = getAttr(myPotatoHead, 'play_' + toy) method() </code></pre> <p>(sorry about the semi-colons! I was programming in javascript all day). </p>
1
2010-01-19T08:24:47Z
[ "python", "function" ]
Equivalent to django Form to show object contents
2,092,242
<p>Is there any Django class used to show the contents of an object model in a non-modifiable way? Something like this for forms to edit the objects from a model:</p> <pre><code>class TestForm(forms.ModelForm): class Meta: model = models.Test </code></pre> <p>using it as:</p> <pre><code>def generic_view(...
2
2010-01-19T08:58:47Z
2,092,253
<p>Calling <code>repr()</code> against the model instance will get you a (admittedly ugly) representation of the instance fields.</p>
0
2010-01-19T09:00:49Z
[ "python", "django" ]
Equivalent to django Form to show object contents
2,092,242
<p>Is there any Django class used to show the contents of an object model in a non-modifiable way? Something like this for forms to edit the objects from a model:</p> <pre><code>class TestForm(forms.ModelForm): class Meta: model = models.Test </code></pre> <p>using it as:</p> <pre><code>def generic_view(...
2
2010-01-19T08:58:47Z
2,092,581
<p>I would take a look at the source of <a href="http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/" rel="nofollow">Databrowse</a> to see how it does it. It introspects models and displays the data of objects with minimal configuration, so it probably has a component that does what you want.</p>
0
2010-01-19T09:57:26Z
[ "python", "django" ]
Uploading files in RESTful way?
2,092,249
<p>I'm designing a RESTful API that should handle binary file uploads.<br> Should this be done the same way as html form upload or is there a better way?</p>
8
2010-01-19T08:59:30Z
2,092,284
<p>Take a look at the Amazon api for an idea. It uses a PUT query and then through sendREST it sends the content. <a href="http://www.anyexample.com/programming/php/uploading_files_to_amazon_s3_with_rest_api.xml" rel="nofollow">Uploading files to Amazon S3 with REST API</a></p>
3
2010-01-19T09:05:17Z
[ "java", "python", "file", "rest", "file-upload" ]
Uploading files in RESTful way?
2,092,249
<p>I'm designing a RESTful API that should handle binary file uploads.<br> Should this be done the same way as html form upload or is there a better way?</p>
8
2010-01-19T08:59:30Z
2,092,343
<p>A good way is to upload the binary information using streams. You could have a look at the JeCARS client project. To be exact the <a href="http://kenai.com/svn/jecars~jecars-repository/jecars/jecars_client/src/org/jecars/client/JC_RESTComm.java" rel="nofollow">JC_RESTComm.java</a> class performs the upload.</p>
1
2010-01-19T09:15:54Z
[ "java", "python", "file", "rest", "file-upload" ]
How do I get js and css to display in Django?
2,092,346
<p>I've got a template, a.html, which looks like this:</p> <pre><code>&lt;script type="text/javascript" src="jquery-1.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="reg.js"&gt;&lt;/script&gt; </code></pre> <p>Why doesn't this work?</p>
0
2010-01-19T09:16:58Z
2,092,355
<p>Because you didn't set up your web server to alias those to their corresponding static media.</p>
0
2010-01-19T09:18:52Z
[ "python", "django" ]
How do I get js and css to display in Django?
2,092,346
<p>I've got a template, a.html, which looks like this:</p> <pre><code>&lt;script type="text/javascript" src="jquery-1.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="reg.js"&gt;&lt;/script&gt; </code></pre> <p>Why doesn't this work?</p>
0
2010-01-19T09:16:58Z
2,092,362
<p>Since your URLs can have arbitrary path depths, you need to get absolute path to your JS. e.g.</p> <pre><code>&lt;script type="text/javascript" src="/js/jquery-1.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/js/reg.js"&gt;&lt;/script&gt; </code></pre>
0
2010-01-19T09:19:51Z
[ "python", "django" ]
How do I get js and css to display in Django?
2,092,346
<p>I've got a template, a.html, which looks like this:</p> <pre><code>&lt;script type="text/javascript" src="jquery-1.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="reg.js"&gt;&lt;/script&gt; </code></pre> <p>Why doesn't this work?</p>
0
2010-01-19T09:16:58Z
2,092,374
<p>Try:</p> <pre><code>&lt;script type="text/javascript" src="{{ MEDIA_URL }}jquery-1.4.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="{{ MEDIA_URL }}reg.js"&gt;&lt;/script&gt; </code></pre> <p>You'll need to make sure you're <a href="http://docs.djangoproject.com/en/dev/howto/static-files/" rel="n...
3
2010-01-19T09:21:44Z
[ "python", "django" ]
Categorize a list of lists by 1 element in python
2,092,380
<p>An example list of lists:</p> <pre><code>[ ["url","name","date","category"] ["hello","world","2010","one category"] ["foo","bar","2010","another category"] ["asdfasdf","adfasdf","2010","one category"] ["qwer","req","2010","another category"] ] </code></pre> <p>What I wish do to is create a dictionary -> category :...
1
2010-01-19T09:22:43Z
2,092,409
<pre><code>dict((category, list(l)) for category, l in itertools.groupby(l, operator.itemgetter(3)) </code></pre> <p>The main thing here is the usage of <code>itertools.groupby</code>. It simply returns iterables instead of lists, which is why there's a call for <code>list(l)</code>, which means that if you're o...
7
2010-01-19T09:26:53Z
[ "python", "list", "dictionary", "map", "sorting" ]
Categorize a list of lists by 1 element in python
2,092,380
<p>An example list of lists:</p> <pre><code>[ ["url","name","date","category"] ["hello","world","2010","one category"] ["foo","bar","2010","another category"] ["asdfasdf","adfasdf","2010","one category"] ["qwer","req","2010","another category"] ] </code></pre> <p>What I wish do to is create a dictionary -> category :...
1
2010-01-19T09:22:43Z
2,092,410
<pre><code>newdict = collections.defaultdict(list) for entry in biglist: newdict[entry[3]].append(entry) </code></pre>
5
2010-01-19T09:27:38Z
[ "python", "list", "dictionary", "map", "sorting" ]
Categorize a list of lists by 1 element in python
2,092,380
<p>An example list of lists:</p> <pre><code>[ ["url","name","date","category"] ["hello","world","2010","one category"] ["foo","bar","2010","another category"] ["asdfasdf","adfasdf","2010","one category"] ["qwer","req","2010","another category"] ] </code></pre> <p>What I wish do to is create a dictionary -> category :...
1
2010-01-19T09:22:43Z
2,092,434
<pre><code>list_of_lists=[ ["url","name","date","category"], ["hello","world","2010","one category"], ["foo","bar","2010","another category"], ["asdfasdf","adfasdf","2010","one category"], ["qwer","req","2010","another category"] ] d={} for li in list_of_lists: d.setdefault(li[-1], []) d[ li[-1] ].append(li) fo...
1
2010-01-19T09:33:36Z
[ "python", "list", "dictionary", "map", "sorting" ]
Categorize a list of lists by 1 element in python
2,092,380
<p>An example list of lists:</p> <pre><code>[ ["url","name","date","category"] ["hello","world","2010","one category"] ["foo","bar","2010","another category"] ["asdfasdf","adfasdf","2010","one category"] ["qwer","req","2010","another category"] ] </code></pre> <p>What I wish do to is create a dictionary -> category :...
1
2010-01-19T09:22:43Z
2,092,436
<pre><code> d = {} for e in l: if e[3] in d: d[e[3]].append(e) else: d[e[3]] = [e] </code></pre>
1
2010-01-19T09:33:53Z
[ "python", "list", "dictionary", "map", "sorting" ]
Categorize a list of lists by 1 element in python
2,092,380
<p>An example list of lists:</p> <pre><code>[ ["url","name","date","category"] ["hello","world","2010","one category"] ["foo","bar","2010","another category"] ["asdfasdf","adfasdf","2010","one category"] ["qwer","req","2010","another category"] ] </code></pre> <p>What I wish do to is create a dictionary -> category :...
1
2010-01-19T09:22:43Z
2,092,485
<pre><code>&gt;&gt;&gt; l = [ ... ["url","name","date","category"], ... ["hello","world","2010","one category"], ... ["foo","bar","2010","another category"], ... ["asdfasdf","adfasdf","2010","one category"], ... ["qwer","req","2010","another category"], ... ] #Intermediate list to generate a more dictionary oriented da...
-2
2010-01-19T09:39:34Z
[ "python", "list", "dictionary", "map", "sorting" ]
Categorize a list of lists by 1 element in python
2,092,380
<p>An example list of lists:</p> <pre><code>[ ["url","name","date","category"] ["hello","world","2010","one category"] ["foo","bar","2010","another category"] ["asdfasdf","adfasdf","2010","one category"] ["qwer","req","2010","another category"] ] </code></pre> <p>What I wish do to is create a dictionary -> category :...
1
2010-01-19T09:22:43Z
2,092,680
<p>A variation on ghostdog74's answer, which fully uses the semantics of setdefaults:</p> <pre><code>result={} for li in list_of_lists: result.setdefault(li[-1], []).append(li) </code></pre>
2
2010-01-19T10:14:47Z
[ "python", "list", "dictionary", "map", "sorting" ]
website containing forum and chat should be devloped in Java or Python or PHP?
2,092,455
<p>I want to develop a website that contains a forum and live chat and some chatrooms. Now, should I develop it using Java or Python? I have experience in Java and PHP, but are JSP webpages slower compared to others? My web application will also contain some live chat and chat rooms. Now, there will be a load on the s...
0
2010-01-19T09:36:06Z
2,092,466
<p>In forum applications the bottleneck will be the database, not the language. So yes, pick the one you're familiar with. Unless you don't want to, in which case you should pick something else.</p>
0
2010-01-19T09:38:01Z
[ "java", "php", "python" ]
website containing forum and chat should be devloped in Java or Python or PHP?
2,092,455
<p>I want to develop a website that contains a forum and live chat and some chatrooms. Now, should I develop it using Java or Python? I have experience in Java and PHP, but are JSP webpages slower compared to others? My web application will also contain some live chat and chat rooms. Now, there will be a load on the s...
0
2010-01-19T09:36:06Z
2,092,486
<p>Find an open source implementation of a site that is close to what you need, and modify it where necessary. Don't be too disappointed if it is written in a language you already know!</p>
1
2010-01-19T09:39:42Z
[ "java", "php", "python" ]
website containing forum and chat should be devloped in Java or Python or PHP?
2,092,455
<p>I want to develop a website that contains a forum and live chat and some chatrooms. Now, should I develop it using Java or Python? I have experience in Java and PHP, but are JSP webpages slower compared to others? My web application will also contain some live chat and chat rooms. Now, there will be a load on the s...
0
2010-01-19T09:36:06Z
2,092,833
<p>Unless you are looking for a project to broaden your knowledge, stick with what you know. Java and Python are excellent Web programming tools, but PHP is more wide-used and is gaining more and more grounds in Java's domain. Just look at Zend and IBM.</p> <p>As of speed; look here: <a href="http://rochakchauhan.com/...
0
2010-01-19T10:44:27Z
[ "java", "php", "python" ]
How do I write a Django view that can be called by jQuery's $.getJSON()?
2,092,566
<p>The javascript:</p> <pre><code>$.getJSON('/jsonView', { tag: "userName", userName: 'zjm1126' }, function (H) { if (H.result == "successName") { F.showOk(h.ok); } else { if (H.result == "existName") { F.showErr(h.userNameExist); } } }); </code></pre> <p>The vi...
0
2010-01-19T09:53:49Z
2,092,586
<p>I suggest you work your way through James Bennett's tutorial on using <a href="http://www.b-list.org/weblog/2006/jul/31/django-tips-simple-ajax-example-part-1/" rel="nofollow">AJAX with Django</a> - he includes details on writing views that return JSON.</p>
2
2010-01-19T09:58:13Z
[ "python", "django" ]
How do I write a Django view that can be called by jQuery's $.getJSON()?
2,092,566
<p>The javascript:</p> <pre><code>$.getJSON('/jsonView', { tag: "userName", userName: 'zjm1126' }, function (H) { if (H.result == "successName") { F.showOk(h.ok); } else { if (H.result == "existName") { F.showErr(h.userNameExist); } } }); </code></pre> <p>The vi...
0
2010-01-19T09:53:49Z
2,093,099
<p>It's pretty simple:</p> <ol> <li>Retrieve GET data from request.GET</li> <li>Do stuff</li> <li>Return a response with mimetype <code>application/javascript</code></li> </ol> <p>1 and 2 are like any other view. If you don't know how to do 3, check out <a href="http://code.djangoproject.com/browser/django/trunk/djan...
0
2010-01-19T11:35:02Z
[ "python", "django" ]
How do I write a Django view that can be called by jQuery's $.getJSON()?
2,092,566
<p>The javascript:</p> <pre><code>$.getJSON('/jsonView', { tag: "userName", userName: 'zjm1126' }, function (H) { if (H.result == "successName") { F.showOk(h.ok); } else { if (H.result == "existName") { F.showErr(h.userNameExist); } } }); </code></pre> <p>The vi...
0
2010-01-19T09:53:49Z
2,094,288
<p>This is relatively straightforward</p> <pre><code>def json_view(request): username=request.GET.get('username') result='successName' if username: try: user=User.objects.get(username=username) result='existName' except User.DoesNotExist: pass return HttpResponse(simplejson.dumps({'...
1
2010-01-19T14:50:59Z
[ "python", "django" ]
Error handling in the RequestHandler without embedding in URI
2,092,708
<p>When a user sends a filled form, I want to print an error message in case there is an input error. One of the GAE sample codes does this by embedding the error message in the URI.</p> <p>Inside the form handler (get):</p> <pre><code>self.redirect('/compose?error_message=%s' % message) </code></pre> <p>and in the ...
0
2010-01-19T10:20:20Z
2,097,617
<p>Is the <code>values</code> dict being rendered by the template engine? If so, you can pass the error string directly like this:</p> <pre><code>values = { 'error_message': 'there is an error', ... </code></pre>
1
2010-01-19T22:22:47Z
[ "python", "google-app-engine", "web-applications" ]
Getting the module file path of a derived class via inheritance
2,092,752
<p>Suppose you have the following:</p> <pre><code>$ more a.py import os class A(object): def getfile(self): return os.path.abspath(__file__) </code></pre> <p>-</p> <pre><code>$ more b.py import a class B(a.A): pass </code></pre> <p>-</p> <pre><code>&gt;&gt;&gt; import b &gt;&gt;&gt; x=b.B() &gt;&...
2
2010-01-19T10:30:57Z
2,092,800
<pre><code>sys.modules[self.__class__.__module__].__file__ </code></pre>
5
2010-01-19T10:37:21Z
[ "python" ]
Getting the module file path of a derived class via inheritance
2,092,752
<p>Suppose you have the following:</p> <pre><code>$ more a.py import os class A(object): def getfile(self): return os.path.abspath(__file__) </code></pre> <p>-</p> <pre><code>$ more b.py import a class B(a.A): pass </code></pre> <p>-</p> <pre><code>&gt;&gt;&gt; import b &gt;&gt;&gt; x=b.B() &gt;&...
2
2010-01-19T10:30:57Z
36,000,291
<p>Was able to get this working in python 3 as follows:</p> <pre><code>import os class Parent: def __init__(self, filename=__file__): self.filename = filename def current_path(self): pth, _ = os.path.split(os.path.abspath(self.filename)) return pth </code></pre> <p>Then in a differe...
0
2016-03-14T23:57:22Z
[ "python" ]
Python and SQLite: insert into table
2,092,757
<p>I have a list that has 3 rows each representing a table row:</p> <pre><code>&gt;&gt;&gt; print list [laks,444,M] [kam,445,M] [kam,445,M] </code></pre> <p>How to insert this list into a table?</p> <p>My table structure is:</p> <pre> tablename(name varchar[100], age int, sex char[1]) </pre> <p>Or should I use som...
25
2010-01-19T10:31:36Z
2,092,775
<p>Adapted from <a href="http://docs.python.org/library/sqlite3.html" rel="nofollow">http://docs.python.org/library/sqlite3.html</a>:</p> <pre><code># Larger example for t in [('2006-03-28', 'BUY', 'IBM', 1000, 45.00), ('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00), ('2006-04-06', 'SELL', 'IBM', 500, ...
6
2010-01-19T10:34:05Z
[ "python", "sqlite", "list", "insert" ]
Python and SQLite: insert into table
2,092,757
<p>I have a list that has 3 rows each representing a table row:</p> <pre><code>&gt;&gt;&gt; print list [laks,444,M] [kam,445,M] [kam,445,M] </code></pre> <p>How to insert this list into a table?</p> <p>My table structure is:</p> <pre> tablename(name varchar[100], age int, sex char[1]) </pre> <p>Or should I use som...
25
2010-01-19T10:31:36Z
2,092,785
<pre><code>conn = sqlite3.connect('/path/to/your/sqlite_file.db') c = conn.cursor() for item in my_list: c.execute('insert into tablename values (?,?,?)', item) </code></pre>
22
2010-01-19T10:36:03Z
[ "python", "sqlite", "list", "insert" ]
Python and SQLite: insert into table
2,092,757
<p>I have a list that has 3 rows each representing a table row:</p> <pre><code>&gt;&gt;&gt; print list [laks,444,M] [kam,445,M] [kam,445,M] </code></pre> <p>How to insert this list into a table?</p> <p>My table structure is:</p> <pre> tablename(name varchar[100], age int, sex char[1]) </pre> <p>Or should I use som...
25
2010-01-19T10:31:36Z
6,019,743
<p>there's a better way </p> <pre><code># Larger example rows = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00), ('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00), ('2006-04-06', 'SELL', 'IBM', 500, 53.00)] c.executemany('insert into stocks values (?,?,?,?,?)', rows) connection.commit() </code></pre>
44
2011-05-16T15:35:37Z
[ "python", "sqlite", "list", "insert" ]
Python and SQLite: insert into table
2,092,757
<p>I have a list that has 3 rows each representing a table row:</p> <pre><code>&gt;&gt;&gt; print list [laks,444,M] [kam,445,M] [kam,445,M] </code></pre> <p>How to insert this list into a table?</p> <p>My table structure is:</p> <pre> tablename(name varchar[100], age int, sex char[1]) </pre> <p>Or should I use som...
25
2010-01-19T10:31:36Z
36,678,361
<p>Not a direct answer, but here is a function to insert a row with column-value pairs into sqlite table:</p> <pre><code>def sqlite_insert(conn, table, row): cols = ', '.join('"{}"'.format(col) for col in row.keys()) vals = ', '.join(':{}'.format(col) for col in row.keys()) sql = 'INSERT INTO "{0}" ({1}) V...
2
2016-04-17T15:17:57Z
[ "python", "sqlite", "list", "insert" ]
How to know requested module name in Django
2,092,920
<p>In Django if a request is made to another module. Can we know where the request has made from through the request variable...</p> <p>In the below example I have to know that the request was made from a.html ort that corresponding module</p> <p>Ex: a.html</p> <pre><code>&lt;html&gt; &lt;form onsubmit=/b&gt; &lt;/...
1
2010-01-19T11:01:02Z
2,092,940
<p>In your view code you can do something like this:</p> <pre><code>def my_view(request) referer = request.META.get('HTTP_REFERER', '') if referer == 'absolute/path/to/somepage.html': # do something ... else: # do something else ... </code></pre> <p>Note that you probably want to avoid hard-codi...
1
2010-01-19T11:04:38Z
[ "python", "django" ]
Python RegEx Discrepancy vs Kodos and RegExr: Can't Filter Specific Character in Python
2,092,956
<p>I'm using Python 2.6.3. When I do:</p> <pre><code>import re, urllib f = urllib.urlopen(website) z = f.read() a = re.findall(r'(\b\d*\SLegos\b)[^\\/bLegos\b]', z) print a </code></pre> <p>I get:</p> <pre><code>['/Legos', '/Legos', '525Legos', '53Legos', '11Legos', '8Legos', '10Legos', '2Legos', '0Legos', '0Legos',...
0
2010-01-19T11:08:13Z
2,092,975
<p>your regex is too complicated and erroneous, you could just use:</p> <pre><code>\b(\d+Legos)\b </code></pre> <p>if you don't really need <code>Legos</code> in your output, you could of course simply move it out of the brackets:</p> <pre><code>\b(\d+)Legos\b </code></pre>
3
2010-01-19T11:11:32Z
[ "python", "regex" ]
Django/GAE anonymous users data
2,093,115
<p>in my application I have per-user models, let me explain with a simple example:</p> <pre><code>class Item(db.Model): master = db.ReferenceProperty(User,collection_name="items") name = db.StringProperty() description = db.StringProperty() value = db.StringProperty() def __unicode__(self): return u"%s"%self.name...
0
2010-01-19T11:37:02Z
2,093,627
<p>You could create an <code>Item</code>-like lightweight class and store instances of it in the session. If the user registers later on and you want to sync with what you have in the database, you can pick up what you've stored in the session and convert to the <em>real</em> <code>Item</code> objects (and then <code>s...
0
2010-01-19T13:09:44Z
[ "python", "django", "google-app-engine", "authentication" ]
Python functional programming snippets
2,093,388
<p>I've seen some elegant python snippets using list comprehension and map reduce. Can you share some of these code or a web site.</p> <p>Thanks. </p>
9
2010-01-19T12:24:55Z
2,093,402
<p>There are some nice functional style snippets in here: <a href="http://docs.python.org/dev/howto/functional" rel="nofollow">Functional Programming HOWTO</a></p>
5
2010-01-19T12:26:58Z
[ "python", "functional-programming" ]
Python functional programming snippets
2,093,388
<p>I've seen some elegant python snippets using list comprehension and map reduce. Can you share some of these code or a web site.</p> <p>Thanks. </p>
9
2010-01-19T12:24:55Z
2,093,844
<p>Here is quick sort:</p> <pre><code>def qsort (list): if (len(list) &gt; 1): list = qsort(filter (lambda x: x &lt;= list[0], list[1:])) + [list[0]] + qsort(filter (lambda x: x &gt; list[0], list[1:])) return list </code></pre> <p>This one is a solution to a programming puzzle of finding a missing n...
2
2010-01-19T13:42:30Z
[ "python", "functional-programming" ]
Python functional programming snippets
2,093,388
<p>I've seen some elegant python snippets using list comprehension and map reduce. Can you share some of these code or a web site.</p> <p>Thanks. </p>
9
2010-01-19T12:24:55Z
2,093,942
<p>Python is not lisp. Please don't try to make it look that way. It only reduces one of python's biggest strengths, which is its readability and understandability later on.</p> <p>If you like functional programming, learn <a href="http://haskell.org/">Haskell</a>, <a href="http://en.wikipedia.org/wiki/ML_%28programm...
7
2010-01-19T13:59:41Z
[ "python", "functional-programming" ]
Python functional programming snippets
2,093,388
<p>I've seen some elegant python snippets using list comprehension and map reduce. Can you share some of these code or a web site.</p> <p>Thanks. </p>
9
2010-01-19T12:24:55Z
2,095,178
<p>Be careful when programming python in functional style. The only reason to ever do so is for readability. If the algorithm is more elegantly expressed functionally than imperatively, and it doesn't cause performance problems (it usually doesn't), then go right ahead.</p> <p>However, python does not optimize tail re...
3
2010-01-19T16:47:34Z
[ "python", "functional-programming" ]
How to create twisted.words.xish.domish.Element entirely from raw XML
2,093,400
<p>I was surprised that XML basic object (twisted.words.xish.domish.Element) could not be created entirely from XML string. The most alike way is:</p> <pre><code>msg = "&lt;iq to='juick@juick.com' id='id123' type='get'&gt; \ &lt;query xmlns='http://juick.com/query#messages' mid='123456'/&gt; \ &lt;/...
0
2010-01-19T12:26:28Z
2,095,942
<p>This is what I use for fragments, adapted from something found on the web somewhere.</p> <pre><code>from twisted.words.xish import domish class ElementParser(object): "callable class to parse XML string into Element" def __call__(self, s): self.result = None def onStart(el): se...
1
2010-01-19T18:25:11Z
[ "python", "xml", "twisted", "twisted.words" ]
C++ I/O with Python
2,093,411
<p>I am writing a module in Python which runs a C++ Program using subprocess module. Once I get the output from C++, I need to store the that in Python List . How do I do that ?</p>
1
2010-01-19T12:28:32Z
2,093,422
<p>one dirty method:</p> <p>You can use Python to read (raw_input) from stdin (if there is not input, it will wait). the C++ program writes to stdout. </p>
2
2010-01-19T12:32:13Z
[ "c++", "python" ]
C++ I/O with Python
2,093,411
<p>I am writing a module in Python which runs a C++ Program using subprocess module. Once I get the output from C++, I need to store the that in Python List . How do I do that ?</p>
1
2010-01-19T12:28:32Z
2,093,476
<p>Based upon your comment, assuming <code>data</code> contains the output:</p> <pre><code>numbers = [int(x) for x in data.split()] </code></pre> <p>I am assuming that the numbers are separated by whitespace, and that you already got the string in Python from your C++ program (i.e., you know how to use the <code>subp...
1
2010-01-19T12:40:51Z
[ "c++", "python" ]
C++ I/O with Python
2,093,411
<p>I am writing a module in Python which runs a C++ Program using subprocess module. Once I get the output from C++, I need to store the that in Python List . How do I do that ?</p>
1
2010-01-19T12:28:32Z
2,093,483
<p>Here is a quick and dirty method that I have used. </p> <pre><code>def run_cpp_thing(parameters): proc = subprocess.Popen('mycpp' + parameters, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subpr...
6
2010-01-19T12:41:40Z
[ "c++", "python" ]
C++ I/O with Python
2,093,411
<p>I am writing a module in Python which runs a C++ Program using subprocess module. Once I get the output from C++, I need to store the that in Python List . How do I do that ?</p>
1
2010-01-19T12:28:32Z
2,093,491
<p>In the command for the process you could do a redirect to a temporary file. Then read that file when the process returns.</p>
0
2010-01-19T12:42:47Z
[ "c++", "python" ]
Is it possible to implement a "change password at next logon" type feature in the django admin?
2,093,593
<p>I want to be able to set an option in the user's settings that forces them to change their password upon the next login to the admin interface. Is this possible? How would it go about being implemented? I'm using the default auth model right now but not opposed to modifying or changing it. Thanks for any help.</p>
12
2010-01-19T13:04:53Z
2,093,644
<p>From a thread on the <a href="http://osdir.com/ml/DjangoUsers/2009-07/msg01205.html" rel="nofollow">Django Users mailing list</a>:</p> <blockquote> <p>This isn't ideal, but it should work (or prompt someone to propose something better).</p> <p>Add a one-to-one table for the user, with a field containi...
1
2010-01-19T13:12:48Z
[ "python", "django" ]
Is it possible to implement a "change password at next logon" type feature in the django admin?
2,093,593
<p>I want to be able to set an option in the user's settings that forces them to change their password upon the next login to the admin interface. Is this possible? How would it go about being implemented? I'm using the default auth model right now but not opposed to modifying or changing it. Thanks for any help.</p>
12
2010-01-19T13:04:53Z
5,570,717
<p>I'm actually in the process of doing this myself. You need three components: a user profile (if not already in use on your site), a middleware component, and a pre_save signal.</p> <p>My code for this is in an app named 'accounts'.</p> <pre><code># myproject/accounts/models.py from django.db import models from dj...
18
2011-04-06T17:46:27Z
[ "python", "django" ]
Is it possible to implement a "change password at next logon" type feature in the django admin?
2,093,593
<p>I want to be able to set an option in the user's settings that forces them to change their password upon the next login to the admin interface. Is this possible? How would it go about being implemented? I'm using the default auth model right now but not opposed to modifying or changing it. Thanks for any help.</p>
12
2010-01-19T13:04:53Z
13,138,005
<p>I have used Chris Pratt's solution, with a little change: instead of using a middleware, that'd be executed for every page with the consequent resource use, I figured I'd just intercept the login view.</p> <p>In my urls.py I have added this to my urlpatterns:</p> <pre><code>url(r'^accounts/login/$', 'userbase.view...
8
2012-10-30T11:26:43Z
[ "python", "django" ]
Python readline on a pipe that has been opened as non-blocking
2,093,788
<p>I have a Linux fifo that has been opened in non-blocking mode. As expected, when I call read on the file object, it returns immediately. I use select to make sure there is no busy waiting, but that my program is still notified when there is any data available. Out of curiosity, I tried the readline function and was ...
3
2010-01-19T13:32:22Z
2,097,905
<p>The core part of Python's readline is in fileobject.c:get_line and is</p> <pre><code>FILE_BEGIN_ALLOW_THREADS(f) FLOCKFILE(fp); while ((c = GETC(fp)) != EOF &amp;&amp; (*buf++ = c) != '\n' &amp;&amp; buf != end) ; FUNLOCKFILE(fp); FILE_END_ALLOW_THREADS(f) </code></pre> <p>where</p> <pre><co...
1
2010-01-19T23:05:43Z
[ "python", "file", "pipe", "readline", "nonblocking" ]
Extracting Values from a String
2,093,812
<p>I am trying to extract values from a string, I have tried to get <code>re.match</code> working but have not had any luck. The string is:</p> <pre><code>'/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' </code></pre> <p>I have tried:</p> <pre><code> map(int,re.search("Value\s*=\s*")...
4
2010-01-19T13:36:01Z
2,093,845
<pre><code>&gt;&gt;&gt; s = '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' &gt;&gt;&gt; bits = s.split('\r\n') &gt;&gt;&gt; val, max_val, step = [int(bits[i].partition(' = ')[2]) for i in [1, 3, 4]] &gt;&gt;&gt; val 1800 &gt;&gt;&gt; max_val 3600 &gt;&gt;&gt; step 1 </code></pre>
3
2010-01-19T13:42:36Z
[ "python", "string" ]
Extracting Values from a String
2,093,812
<p>I am trying to extract values from a string, I have tried to get <code>re.match</code> working but have not had any luck. The string is:</p> <pre><code>'/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' </code></pre> <p>I have tried:</p> <pre><code> map(int,re.search("Value\s*=\s*")...
4
2010-01-19T13:36:01Z
2,093,866
<p>For that <em>particular</em> string, the following parses it into a dictionary:</p> <pre><code>s = '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' d = {} for pair in [val.split('=') for val in s.split('\r\n')[1:-1]]: d[pair[0]] = int(pair[1]) </code></pre>
6
2010-01-19T13:45:25Z
[ "python", "string" ]
Extracting Values from a String
2,093,812
<p>I am trying to extract values from a string, I have tried to get <code>re.match</code> working but have not had any luck. The string is:</p> <pre><code>'/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' </code></pre> <p>I have tried:</p> <pre><code> map(int,re.search("Value\s*=\s*")...
4
2010-01-19T13:36:01Z
2,093,870
<pre><code>s = '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' data = {} for l in s.split('\r\n'): if " = " in l: k,v = l.split(" = ") data[k] = int(v) print data </code></pre>
0
2010-01-19T13:46:02Z
[ "python", "string" ]
Extracting Values from a String
2,093,812
<p>I am trying to extract values from a string, I have tried to get <code>re.match</code> working but have not had any luck. The string is:</p> <pre><code>'/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' </code></pre> <p>I have tried:</p> <pre><code> map(int,re.search("Value\s*=\s*")...
4
2010-01-19T13:36:01Z
2,093,884
<p>You are trying to use regexp, but I think you can simply split it by <code>\r\n</code> and then use values with <code>=</code>.</p> <p>Something like:</p> <pre><code>s = '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' dct = {} arr = [ss for ss in s.split('\r\n') if '=' in ss] for ...
0
2010-01-19T13:49:14Z
[ "python", "string" ]
Chat application using django
2,093,822
<p>If i devlop a chat application using django will it have some performance problem? Can i do server push in django? I want to have PM and room discussions as well.</p>
8
2010-01-19T13:37:41Z
2,094,031
<p><a href="http://grono.net" rel="nofollow">grono.net</a> has chat and PMs (although there are no rooms) and is built on django. Performance is pretty well, so I believe you should be able achieve the same performance. It depends, on how much connections you are expecting. grono.net is pretty big and it uses some cach...
1
2010-01-19T14:13:30Z
[ "python", "django", "performance", "chat", "private-messaging" ]
Chat application using django
2,093,822
<p>If i devlop a chat application using django will it have some performance problem? Can i do server push in django? I want to have PM and room discussions as well.</p>
8
2010-01-19T13:37:41Z
2,094,368
<p>I think for a chat application you can use other technologies, such as AMQP(RabbitMQ, etc), Comet, etc. But, for develop user profile, PMs, and other you can use Django. </p> <p>Do not forget that performance still depends on server configuration (web server software, cache, db)</p>
1
2010-01-19T15:01:37Z
[ "python", "django", "performance", "chat", "private-messaging" ]