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
Transitioning from desktop app written in C++ to a web-based app
1,900,868
<p>We have a mature Windows desktop application written in C++. The application's GUI sits on top of a windows DLL that does most of the work for the GUI (it's kind of the engine). It, too, is written in C++. We are considering transitioning the Windows app to be a web-based app for various reasons. </p> <p>What I ...
5
2009-12-14T13:16:34Z
1,901,640
<p>3- Python is the solution.</p> <p>Make a sigle entry point interface in python that takes only the name of the function and a list of params to pass to the function itself. You will have something to start experimenting straight away and see which functions of the DLL are really needed for the first functional web ...
4
2009-12-14T15:41:38Z
[ "c#", "c++", "python", "dll", "web-based" ]
Transitioning from desktop app written in C++ to a web-based app
1,900,868
<p>We have a mature Windows desktop application written in C++. The application's GUI sits on top of a windows DLL that does most of the work for the GUI (it's kind of the engine). It, too, is written in C++. We are considering transitioning the Windows app to be a web-based app for various reasons. </p> <p>What I ...
5
2009-12-14T13:16:34Z
1,926,142
<p>Since nobody has mentioned it, how about <a href="http://www.webtoolkit.eu/wt" rel="nofollow">Wt</a>. </p> <p>If you are not looking for a explorer-based UI, there are many C++ libraries for you to extend a local app to web-based app, <a href="http://pocoproject.org/" rel="nofollow">POCO</a> is one of them. If you ...
1
2009-12-18T03:39:59Z
[ "c#", "c++", "python", "dll", "web-based" ]
Write variable to file, including name
1,900,956
<p>Let's say I have the following dictionary in a small application. </p> <pre><code>dict = {'one': 1, 'two': 2} </code></pre> <p>What if I would like to write the exact code line, with the dict name and all, to a file. Is there a function in python that let me do it? Or do I have to convert it to a string first? Not...
7
2009-12-14T13:34:33Z
1,901,002
<p>use <code>pickle</code></p> <pre><code>import pickle dict = {'one': 1, 'two': 2} file = open('dump.txt', 'w') pickle.dump(dict, file) file.close() </code></pre> <p>and to read it again</p> <pre><code>file = open('dump.txt', 'r') dict = pickle.load(file) </code></pre> <p>EDIT: Guess I misread your question, sorry...
11
2009-12-14T13:44:18Z
[ "python" ]
Write variable to file, including name
1,900,956
<p>Let's say I have the following dictionary in a small application. </p> <pre><code>dict = {'one': 1, 'two': 2} </code></pre> <p>What if I would like to write the exact code line, with the dict name and all, to a file. Is there a function in python that let me do it? Or do I have to convert it to a string first? Not...
7
2009-12-14T13:34:33Z
1,901,009
<p>The default string representation for a dictionary seems to be just right:</p> <pre><code>&gt;&gt;&gt; a={3: 'foo', 17: 'bar' } &gt;&gt;&gt; a {17: 'bar', 3: 'foo'} &gt;&gt;&gt; print a {17: 'bar', 3: 'foo'} &gt;&gt;&gt; print "a=", a a= {17: 'bar', 3: 'foo'} </code></pre> <p>Not sure if you can get at the "variab...
0
2009-12-14T13:45:26Z
[ "python" ]
Write variable to file, including name
1,900,956
<p>Let's say I have the following dictionary in a small application. </p> <pre><code>dict = {'one': 1, 'two': 2} </code></pre> <p>What if I would like to write the exact code line, with the dict name and all, to a file. Is there a function in python that let me do it? Or do I have to convert it to a string first? Not...
7
2009-12-14T13:34:33Z
1,901,016
<p>the <code>repr</code> function will return a string which is the exact definition of your dict (except for the order of the element, dicts are unordered in python). unfortunately, i can't tell a way to automatically get a string which represent the variable name.</p> <pre><code>&gt;&gt;&gt; dict = {'one': 1, 'two':...
23
2009-12-14T13:46:03Z
[ "python" ]
Write variable to file, including name
1,900,956
<p>Let's say I have the following dictionary in a small application. </p> <pre><code>dict = {'one': 1, 'two': 2} </code></pre> <p>What if I would like to write the exact code line, with the dict name and all, to a file. Is there a function in python that let me do it? Or do I have to convert it to a string first? Not...
7
2009-12-14T13:34:33Z
1,901,030
<p>You could do:</p> <pre><code>import inspect mydict = {'one': 1, 'two': 2} source = inspect.getsourcelines(inspect.getmodule(inspect.stack()[0][0]))[0] print [x for x in source if x.startswith("mydict = ")] </code></pre> <p>Also: make sure not to shadow the dict builtin!</p>
4
2009-12-14T13:47:40Z
[ "python" ]
Write variable to file, including name
1,900,956
<p>Let's say I have the following dictionary in a small application. </p> <pre><code>dict = {'one': 1, 'two': 2} </code></pre> <p>What if I would like to write the exact code line, with the dict name and all, to a file. Is there a function in python that let me do it? Or do I have to convert it to a string first? Not...
7
2009-12-14T13:34:33Z
1,901,103
<p>Is something like this what you're looking for?</p> <pre><code>def write_vars_to_file(_f, **vars): for (name, val) in vars.items(): _f.write("%s = %s\n" % (name, repr(val))) </code></pre> <p>Usage:</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; write_vars_to_file(sys.stdout, dict={'one': 1, 'two'...
14
2009-12-14T14:01:55Z
[ "python" ]
Write variable to file, including name
1,900,956
<p>Let's say I have the following dictionary in a small application. </p> <pre><code>dict = {'one': 1, 'two': 2} </code></pre> <p>What if I would like to write the exact code line, with the dict name and all, to a file. Is there a function in python that let me do it? Or do I have to convert it to a string first? Not...
7
2009-12-14T13:34:33Z
1,902,004
<p>Do you just want to know how to write a line to a <a href="http://docs.python.org/library/stdtypes.html#file-objects" rel="nofollow">file</a>? First, you need to open the file:</p> <pre><code>f = open("filename.txt", 'w') </code></pre> <p>Then, you need to write the string to the file:</p> <pre><code>f.write("dic...
0
2009-12-14T16:42:17Z
[ "python" ]
How to avoid multiple instances of a program?
1,900,979
<p>I need to find a right way to prevent two running instances of my (Python) program. I am currently using the following method.</p> <p>On Windows,</p> <pre><code>os.popen('wmic process get caption,processid | findstr `programname.exe`') </code></pre> <p>On Linux,</p> <pre><code>os.popen('ps x | grep `programname`...
7
2009-12-14T13:39:39Z
1,900,988
<p>There are numerous ways:</p> <ol> <li>have an "instance file" in /var/run or similar (cross-platform)</li> <li>use a fixed socket (cross-platform)</li> <li>use DBus to register a name (linux)</li> </ol> <p>What you need is a service (external to your application) that manages a namespace where unique ids are avai...
5
2009-12-14T13:41:45Z
[ "python", "instance" ]
How to avoid multiple instances of a program?
1,900,979
<p>I need to find a right way to prevent two running instances of my (Python) program. I am currently using the following method.</p> <p>On Windows,</p> <pre><code>os.popen('wmic process get caption,processid | findstr `programname.exe`') </code></pre> <p>On Linux,</p> <pre><code>os.popen('ps x | grep `programname`...
7
2009-12-14T13:39:39Z
1,901,010
<p>For linux, see the answer from jldupont. For windows, use the CreateMutex-method, to create a named mutex. See: <a href="http://msdn.microsoft.com/en-us/library/ms686927%28VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms686927%28VS.85%29.aspx</a></p>
1
2009-12-14T13:45:33Z
[ "python", "instance" ]
How to avoid multiple instances of a program?
1,900,979
<p>I need to find a right way to prevent two running instances of my (Python) program. I am currently using the following method.</p> <p>On Windows,</p> <pre><code>os.popen('wmic process get caption,processid | findstr `programname.exe`') </code></pre> <p>On Linux,</p> <pre><code>os.popen('ps x | grep `programname`...
7
2009-12-14T13:39:39Z
1,901,189
<p>on Linux, I used to write a pidfile, roughly:</p> <pre><code>if (pidfile already exists) read pidfile content if (/proc/&lt;pid&gt;/exec == my executable) already running, exit else it´s a stale pidfile, delete it write my own pid to pidfile start the 'real' work </code></pre> <p>latel...
1
2009-12-14T14:19:02Z
[ "python", "instance" ]
Calling Python from JavaScript
1,901,093
<p>Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension.</p> <p>A good option to compile a pure Python library would also be great. I looked at <a href="http://en.wikipedia.org/wiki/Pyjamas_%28software%29">Pyjamas</a>, but it seems to offer only partial supp...
11
2009-12-14T14:00:18Z
1,901,175
<p>This wouldn't be done in an extension but more likely a plugin (a sometimes obscure but notable difference.) </p> <p>I'm not aware of any plugins right now that expose Python directly, but there are a couple of ways I've heard of to make it work indirectly. For example: you can get IronPython (a .Net driven version...
3
2009-12-14T14:16:42Z
[ "javascript", "python" ]
Calling Python from JavaScript
1,901,093
<p>Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension.</p> <p>A good option to compile a pure Python library would also be great. I looked at <a href="http://en.wikipedia.org/wiki/Pyjamas_%28software%29">Pyjamas</a>, but it seems to offer only partial supp...
11
2009-12-14T14:00:18Z
1,901,178
<p>I am not 100% sure, but I do know for a fact that on Google Chrome you can't: you would need either:</p> <ol> <li>an HTTP "gateway" of some sort</li> <li>an NPAPI plugin</li> </ol> <p>The situation is likely the same on the Firefox case because of security concerns.</p>
0
2009-12-14T14:17:12Z
[ "javascript", "python" ]
Calling Python from JavaScript
1,901,093
<p>Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension.</p> <p>A good option to compile a pure Python library would also be great. I looked at <a href="http://en.wikipedia.org/wiki/Pyjamas_%28software%29">Pyjamas</a>, but it seems to offer only partial supp...
11
2009-12-14T14:00:18Z
1,901,212
<p>You may wish to look at the <a href="http://www.codestrong.com/titanium/guides/python/" rel="nofollow" title="Titanium Desktop">Titanium Desktop</a>. It has a great API that allows you to call Python easily from within Javascript.</p> <p>Eg:</p> <pre><code>&lt;script type="text/python" src="myfile.py"/&gt; </code...
4
2009-12-14T14:23:11Z
[ "javascript", "python" ]
Calling Python from JavaScript
1,901,093
<p>Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension.</p> <p>A good option to compile a pure Python library would also be great. I looked at <a href="http://en.wikipedia.org/wiki/Pyjamas_%28software%29">Pyjamas</a>, but it seems to offer only partial supp...
11
2009-12-14T14:00:18Z
1,901,261
<p>You could build a native Firefox extension that uses libpython to run your python code. From that, export an interface that enables your Javascript code to call python running in your extension.</p> <p>It appears that there is a Firefox python extension that may enable you to do what you want: <a href="http://pyx...
3
2009-12-14T14:34:18Z
[ "javascript", "python" ]
Calling Python from JavaScript
1,901,093
<p>Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension.</p> <p>A good option to compile a pure Python library would also be great. I looked at <a href="http://en.wikipedia.org/wiki/Pyjamas_%28software%29">Pyjamas</a>, but it seems to offer only partial supp...
11
2009-12-14T14:00:18Z
1,901,267
<p>You would either need a browser with builtin python support (but this is not a "standard", hence it would defeat the purpose of using a webapp - if you need a special client, you can better use a classic gui), or a way to translate Python to Javascript; there three options for this at the time:</p> <ul> <li>Pyjamas...
3
2009-12-14T14:35:50Z
[ "javascript", "python" ]
Calling Python from JavaScript
1,901,093
<p>Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension.</p> <p>A good option to compile a pure Python library would also be great. I looked at <a href="http://en.wikipedia.org/wiki/Pyjamas_%28software%29">Pyjamas</a>, but it seems to offer only partial supp...
11
2009-12-14T14:00:18Z
12,710,576
<p>Take a look to the <a href="https://github.com/niedbalski/slurpy" rel="nofollow">https://github.com/niedbalski/slurpy</a> Slurpy project, it implements two way communications as RPC mechanism.</p> <pre><code> python = new Slurpy(); python.on('loaded', function(evt) { python.sum(10.5,1000,...
2
2012-10-03T14:24:56Z
[ "javascript", "python" ]
How to select many rows from a dictionary (executemany select)
1,901,337
<p>I'm using Python and its MySQLdb module, is it possible to do a "selectmany"-like from a tuple/dictionary/list in the condition</p> <p>something like this:</p> <pre><code>cursor.executemany("""SELECT * FROM customers WHERE name= %(name)s""",[d.__dict__ for d in data]) selected_rows = cursor.fecthall() </code></p...
1
2009-12-14T14:51:42Z
1,901,422
<p>You could use the "WHERE IN" sql syntax, for example,</p> <pre><code>SELECT * FROM customers WHERE name IN ('john', 'mary', 'jane'); </code></pre>
1
2009-12-14T15:06:46Z
[ "python", "select", "mysql", "executemany" ]
How to select many rows from a dictionary (executemany select)
1,901,337
<p>I'm using Python and its MySQLdb module, is it possible to do a "selectmany"-like from a tuple/dictionary/list in the condition</p> <p>something like this:</p> <pre><code>cursor.executemany("""SELECT * FROM customers WHERE name= %(name)s""",[d.__dict__ for d in data]) selected_rows = cursor.fecthall() </code></p...
1
2009-12-14T14:51:42Z
1,901,428
<p>I haven't used the <code>executemany</code> method yet, but I wonder if it's meant to be used for SELECTs. What about</p> <pre><code>... where name in (...) </code></pre> <p>instead of</p> <pre><code>... where name = ... </code></pre> <p>and inserting a tuple containing the keys of your <code>data</code> diction...
1
2009-12-14T15:07:20Z
[ "python", "select", "mysql", "executemany" ]
How to select many rows from a dictionary (executemany select)
1,901,337
<p>I'm using Python and its MySQLdb module, is it possible to do a "selectmany"-like from a tuple/dictionary/list in the condition</p> <p>something like this:</p> <pre><code>cursor.executemany("""SELECT * FROM customers WHERE name= %(name)s""",[d.__dict__ for d in data]) selected_rows = cursor.fecthall() </code></p...
1
2009-12-14T14:51:42Z
31,907,075
<p><code>executemany</code> for the most part is for insertion or update. Doesn't really work well for querying <a href="http://mysql-python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.BaseCursor-class.html#executemany" rel="nofollow">data</a>, from my experience it will only return the last set of parameters....
0
2015-08-09T17:42:44Z
[ "python", "select", "mysql", "executemany" ]
Emacs Python-Mode: Sending statements to a subprocess does not lead to REPL-style evaluation
1,901,354
<p>After selecting <code>1 + 1</code> and issuing <em>python-send-region</em>, my subprocess buffer shows no results. I have to evaluate <code>print 1 + 1</code>, instead.</p> <p>How can I force the python-send-* commands to print the value of the respective statements rather than echoing their stdout?</p>
1
2009-12-14T14:55:23Z
1,901,609
<p>It sounds like you need print; use print.</p> <p>emacs is launching a python process and getting text from its standard output, not a python value.</p>
2
2009-12-14T15:35:01Z
[ "python", "emacs" ]
Get the executing file's path from an installed package?
1,901,407
<p>If one installs a python package using setuptools, then executes a method in that package from a standard python script, is it possible to get the file path of the calling/executing file?</p> <p>For instance, the file I'm executing is <code>/usr/foo/bar.py</code>, which looks like this:</p> <pre><code>import baz b...
0
2009-12-14T15:03:34Z
1,901,481
<p>Use <code>inspect.getouterframes()</code> or <code>inspect.stack()</code>, then get the filename from the calling frame.</p>
1
2009-12-14T15:16:27Z
[ "python" ]
How to disable screen update in matplotlib
1,901,461
<p>I have a loop that is adding a line to a plot on each iteration. Right now this is horribly slow as it seems to redraw the the whole graph each time. Is it possible to disable screen updates for a graph while it is being set up then re-enable them afterwards.</p> <p>Here's the code:</p> <pre><code> for rr,dd in...
0
2009-12-14T15:13:42Z
1,902,378
<p>It sounds like you have the <a href="http://matplotlib.sourceforge.net/users/shell.html" rel="nofollow">interactive mode</a> <code>on</code>, so you should just set it to <code>off</code> using the command</p> <pre><code>ioff() </code></pre> <p>Note that when interactive mode is off, you'll need to use the command...
2
2009-12-14T17:46:10Z
[ "python", "matplotlib", "scipy" ]
youtube data api comment paging
1,901,487
<p>I'm struggling a little bit with the syntax for iterating through all comments on a youtube video. I'm using the python and have found little documentation on the <code>GetYouTubeVideoCommentFeed()</code> function.</p> <p>What I'm really trying to do is search all comments of a video for an instance of a word and i...
4
2009-12-14T15:17:39Z
2,010,597
<p>Found out how to do it. Instead of passing a video_id to the GetYouTubeVideoCommentFeed function, you can pass it a URL. You can iterate through the comments by changing the URL parameters.</p> <p>There must be an API limitation though; I can only access the last 1000 comments on the video.</p>
1
2010-01-06T02:23:28Z
[ "python", "youtube", "youtube-api" ]
youtube data api comment paging
1,901,487
<p>I'm struggling a little bit with the syntax for iterating through all comments on a youtube video. I'm using the python and have found little documentation on the <code>GetYouTubeVideoCommentFeed()</code> function.</p> <p>What I'm really trying to do is search all comments of a video for an instance of a word and i...
4
2009-12-14T15:17:39Z
4,164,589
<p>Here's the code snippet for the same: </p> <pre><code># Comment feed URL comment_feed_url = "http://gdata.youtube.com/feeds/api/videos/%s/comments" ''' Get the comment feed of a video given a video_id''' def WriteCommentFeed(video_id, data_file): url = comment_feed_url % video_id comment_feed = ...
5
2010-11-12T12:27:49Z
[ "python", "youtube", "youtube-api" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
1,901,554
<p>I don't like it, personally. There's probably no reason for my preference, other than the old Python dictum "Explicit is better than implicit". I like to know exactly what's going into my templates.</p>
11
2009-12-14T15:26:39Z
[ "python", "django" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
1,901,566
<p>I've used it without any problems (so far!).</p> <p>I'm not especially fond of typing which is why I like it. Code like</p> <pre><code>'customer' : customer, 'invoice' : invoice, 'date' : date </code></pre> <p>just looks ridiculous to me and if I can avoid it I will. One of the reasons I like Python is its lack...
3
2009-12-14T15:28:42Z
[ "python", "django" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
1,901,641
<p>I guess it depends on how many local variables you define in your function. </p> <p>If it matches exactly the number you want return to your template, or the 'extra' variables are simple structures like integers or booleans, then I guess there is no point in explicitely returning them, as this requires more work.</...
2
2009-12-14T15:41:41Z
[ "python", "django" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
1,901,720
<p>I don't like repetition -- I think "DRY", "Don't Repeat Yourself", is a key programming principle. As a consequence, I have indeed used <code>locals()</code> in similar situations. Django template rendering is far from the only situation of this kind: the general case is "a function or operator which accepts a dict...
73
2009-12-14T15:55:07Z
[ "python", "django" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
1,902,962
<p>I often thought of doing the following, but I am not sure if it is really helpful.</p> <pre><code>class MyStruct(object): pass def my_view(request, id): c = MyStruct() c.customer = .. c.invoice = .. c.date = .. return render_to_response('xxx,html',c.__dict__) </code></pre>
26
2009-12-14T19:31:33Z
[ "python", "django" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
25,063,917
<p>I agree with Alex. Don't see the point of creating a class instance (as niels suggested) when you can just do this:</p> <pre><code>def my_view(request, id): customer = .. invoice = .. date = .. return render_to_response('xxx,html', locals()) </code></pre> <p>If you want a performance reason, dotted...
0
2014-07-31T16:09:10Z
[ "python", "django" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
29,334,736
<p>I know this is an old thread...currently render_to_response is deprecated. Use render instead without locals(). Passing around all locals is a bad practice. Here is an views.py example:</p> <pre><code>from django.shortcuts import render from django.contrib.auth.decorators import login_required @login_required def ...
0
2015-03-29T20:55:53Z
[ "python", "django" ]
Django template and the locals trick
1,901,525
<p>The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary <a href="http://www.djangobook.com/en/2.0/chapter04/">http://www.djangobook.com/en/2.0/chapter04/</a></p> <p>It recommends this to lazy programmers but points out some overhead which may have an impact ...
47
2009-12-14T15:22:03Z
39,564,577
<p>This solution reduces clutter in <code>views.py</code> while keeping things explicit.</p> <p>In <code>controllers.py</code>:</p> <pre><code>import sys def auto_context(the_locals=None): # Take any variable in the locals() whose name ends with an underscore, and # put it in a dictionary with the underscore...
0
2016-09-19T02:30:30Z
[ "python", "django" ]
vim and python scripts debugging
1,901,528
<p>Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)?</p>
26
2009-12-14T13:02:33Z
1,901,529
<p>It sounds like you want to use VIM as a Python IDE.</p> <p>A quick Google search found <a href="http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/" rel="nofollow">this</a> and <a href="http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/" rel="nofollow">this</a> example, with many more.<...
-1
2009-12-14T13:11:38Z
[ "python", "vim" ]
vim and python scripts debugging
1,901,528
<p>Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)?</p>
26
2009-12-14T13:02:33Z
1,902,220
<p>Use <a href="http://docs.python.org/library/pdb.html">pdb</a>:</p> <pre><code>import pdb def main(): list = [1,2,3] pdb.set_trace() list = [2,3,4] if __name__ == '__main__': main() </code></pre> <p>Now run using <code>:!python %</code> and you'll hit your breakpoint and be able to debug interactively li...
22
2009-12-14T17:17:09Z
[ "python", "vim" ]
vim and python scripts debugging
1,901,528
<p>Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)?</p>
26
2009-12-14T13:02:33Z
1,902,702
<p>From what I know, there is one more option: You could use Eclipse + PyDev for project managing and Vim as an editor for Eclipse. That way You could use the best of both worlds. </p> <p>Also, I haven't tried it, but You could try <a href="http://www.vim.org/scripts/script.php?script%5Fid=2270" rel="nofollow">this sc...
0
2009-12-14T18:42:55Z
[ "python", "vim" ]
vim and python scripts debugging
1,901,528
<p>Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)?</p>
26
2009-12-14T13:02:33Z
1,904,268
<p>See the "Debugging" section in <a href="http://www.sontek.net/category/Vim.aspx" rel="nofollow">this</a> blog post. It shows how to setup F7 to set breakpoints and Shift+F7 to remove breakpoints. It also uses <code>pdb</code>, as mentioned before. With a little modification, you can replace the use of <code>pdb</cod...
0
2009-12-14T23:27:09Z
[ "python", "vim" ]
vim and python scripts debugging
1,901,528
<p>Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)?</p>
26
2009-12-14T13:02:33Z
9,522,651
<p>Try <a href="http://pyclewn.sourceforge.net/" rel="nofollow">pyclewn</a>. It allows to use vim as front end for pdb. You can create/delete break points, control flow of debugging process, look at values of your variables. All from vim!</p>
4
2012-03-01T19:28:28Z
[ "python", "vim" ]
vim and python scripts debugging
1,901,528
<p>Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)?</p>
26
2009-12-14T13:02:33Z
18,209,708
<p>Vim and pdb-clone is the combination I use. I use <a href="http://pyclewn.sourceforge.net/" rel="nofollow">Home - pyclewn</a> which provides a replacement for pdb called pdb-clone that is quite faster than vanilla pdb. It integrates well with vim via a plugin, and the thing I appreciate most is that it takes care of...
1
2013-08-13T12:55:39Z
[ "python", "vim" ]
vim and python scripts debugging
1,901,528
<p>Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)?</p>
26
2009-12-14T13:02:33Z
23,833,896
<p>Also try <a href="https://pypi.python.org/pypi/pudb" rel="nofollow">https://pypi.python.org/pypi/pudb</a> - its like pdb but more advanced. Contains code highlighting, stack, showing avaliable values, etc. Not only-vim solution but for me works perfectly.</p> <p>Three Steps:</p> <p>Install:</p> <blockquote> <p>...
1
2014-05-23T16:09:12Z
[ "python", "vim" ]
Solr Facet Range with Integers
1,901,567
<p>My index contains peoples information, name, age, phone email etc.</p> <p>I am faceting on Age. I group ages kinda like Date Range functionality. </p> <p>My ranges are:</p> <pre><code> 0 to 10 11 to 20 21 to 30 31 to 40 etc etc </code></pre> <p>When I do a query:</p> <pre><code> ?q=*:*&amp;fac...
2
2009-12-14T15:28:45Z
1,901,681
<p>I know nothing of solr but I would guess that it is treating your ranges as alphabetical rather than numeric.</p> <p>You may want to look at <a href="http://stackoverflow.com/questions/33956/how-to-get-facet-ranges-in-solr-results">this answer</a> which has links to various documents discussing a very similar issue...
1
2009-12-14T15:48:22Z
[ "python", "django", "solr" ]
Solr Facet Range with Integers
1,901,567
<p>My index contains peoples information, name, age, phone email etc.</p> <p>I am faceting on Age. I group ages kinda like Date Range functionality. </p> <p>My ranges are:</p> <pre><code> 0 to 10 11 to 20 21 to 30 31 to 40 etc etc </code></pre> <p>When I do a query:</p> <pre><code> ?q=*:*&amp;fac...
2
2009-12-14T15:28:45Z
1,937,367
<p>In your request, you don't have any <a href="http://wiki.apache.org/solr/SimpleFacetParameters#facet.query%5F%3A%5FArbitrary%5FQuery%5FFaceting" rel="nofollow">facet queries</a>. You are using <a href="http://wiki.apache.org/solr/SolrFacetingOverview" rel="nofollow">filter queries</a>. Which will narrow you're resul...
3
2009-12-20T22:45:30Z
[ "python", "django", "solr" ]
Solr Facet Range with Integers
1,901,567
<p>My index contains peoples information, name, age, phone email etc.</p> <p>I am faceting on Age. I group ages kinda like Date Range functionality. </p> <p>My ranges are:</p> <pre><code> 0 to 10 11 to 20 21 to 30 31 to 40 etc etc </code></pre> <p>When I do a query:</p> <pre><code> ?q=*:*&amp;fac...
2
2009-12-14T15:28:45Z
1,946,936
<p>From trawling the web I found that Solr indexes all data as strings - even when you define it as an integer. Its still a string in Solr:</p> <p><code>&lt;field name="age" type="integer" indexed="true" stored="true"/&gt;</code></p> <p>So what I needed to do was:</p> <p><code>&lt;field name="age" type="sint" indexe...
3
2009-12-22T15:07:12Z
[ "python", "django", "solr" ]
What is the standard sort order for Python release/version numbers?
1,901,612
<p>Python's <code>pip</code> and <code>easy_install</code> follow some rules to sort packages by their release numbers. What are the rules for numbering beta/release/bugfix releases so these tools will know which is the newest?</p>
3
2009-12-14T15:35:32Z
1,901,676
<p>See the <a href="http://peak.telecommunity.com/DevCenter/setuptools?action=highlight&amp;value=setuptools#specifying-your-project-s-version" rel="nofollow">documentation</a> or look at the source: doc string in pkg_resources.py function parse_version().</p>
2
2009-12-14T15:47:46Z
[ "python", "easy-install", "pip" ]
What is the standard sort order for Python release/version numbers?
1,901,612
<p>Python's <code>pip</code> and <code>easy_install</code> follow some rules to sort packages by their release numbers. What are the rules for numbering beta/release/bugfix releases so these tools will know which is the newest?</p>
3
2009-12-14T15:35:32Z
1,901,690
<p>This is a sore point for many folks. <code>setuptools</code> and <code>easy_install</code> have some rather bizarre rules in an attempt to play nice with everybody. You can read the full rules in <code>setuptools</code>'s <code>parse_version</code> method, but here's the summary:</p> <ul> <li><p>Version numbers are...
8
2009-12-14T15:49:29Z
[ "python", "easy-install", "pip" ]
What is the standard sort order for Python release/version numbers?
1,901,612
<p>Python's <code>pip</code> and <code>easy_install</code> follow some rules to sort packages by their release numbers. What are the rules for numbering beta/release/bugfix releases so these tools will know which is the newest?</p>
3
2009-12-14T15:35:32Z
1,901,724
<p>Use 1.0a1 and 1.0b2 before 1.0.</p> <p>The upcoming standard:</p> <ul> <li><a href="http://www.python.org/dev/peps/pep-0386/#the-new-versioning-algorithm" rel="nofollow">http://www.python.org/dev/peps/pep-0386/#the-new-versioning-algorithm</a></li> <li><a href="http://tarekziade.wordpress.com/2009/11/18/distutils-...
2
2009-12-14T15:55:22Z
[ "python", "easy-install", "pip" ]
A function callback every time a key is pressed (regardless of which window has focus)?
1,901,850
<p>I want to write a programme (in python) on Linux (Ubuntu Linux 9.10) that will keep track of how many key presses per second/minute I make. This includes normal letter keys, and control/shift/space/etc.</p> <p>Is there some way to hook into X so that I can say "when a key is pressed call this function?". Since I wa...
5
2009-12-14T16:16:32Z
1,901,928
<p>Take a look at what others have done already. You can take a look on how this <a href="http://sourceforge.net/projects/pykeylogger/develop">pykeylogger</a> code handles Linux in its <a href="http://pykeylogger.git.sourceforge.net/git/gitweb.cgi?p=pykeylogger/pykeylogger;a=blob%5Fplain;f=pyxhook.py;hb=HEAD">backend</...
5
2009-12-14T16:29:18Z
[ "python", "linux", "keypress", "xorg", "keylogger" ]
A function callback every time a key is pressed (regardless of which window has focus)?
1,901,850
<p>I want to write a programme (in python) on Linux (Ubuntu Linux 9.10) that will keep track of how many key presses per second/minute I make. This includes normal letter keys, and control/shift/space/etc.</p> <p>Is there some way to hook into X so that I can say "when a key is pressed call this function?". Since I wa...
5
2009-12-14T16:16:32Z
1,901,941
<p>I'd recommend that you look at the StackOverflow question: <a href="http://stackoverflow.com/questions/676713/is-there-a-cross-platform-python-low-level-api-to-capture-or-generate-keyboard-ev">Is there a cross-platform python low-level API to capture or generate keyboard events?</a></p> <p>You could also look at th...
4
2009-12-14T16:31:17Z
[ "python", "linux", "keypress", "xorg", "keylogger" ]
Python Mechanize + GAEpython code
1,902,079
<p>I am aware of previous questions regarding mechanize + Google App Engine, <a href="http://stackoverflow.com/questions/1563165/what-pure-python-library-should-i-use-to-scrape-a-website">What pure Python library should I use to scrape a website?</a> and <a href="http://stackoverflow.com/questions/1389893/mechanize-an...
5
2009-12-14T16:52:38Z
1,908,808
<p>I managed to get mechanize code that runs on GAE, many thanks to MStodd, from GAEMechanize project <a href="http://code.google.com/p/gaemechanize/" rel="nofollow">http://code.google.com/p/gaemechanize/</a> and</p> <p>If anybody needs the code, you can contact MStodd !</p> <p>ps: the code is not on google code, so...
1
2009-12-15T16:54:04Z
[ "python", "google-app-engine", "mechanize-python" ]
Python Mechanize + GAEpython code
1,902,079
<p>I am aware of previous questions regarding mechanize + Google App Engine, <a href="http://stackoverflow.com/questions/1563165/what-pure-python-library-should-i-use-to-scrape-a-website">What pure Python library should I use to scrape a website?</a> and <a href="http://stackoverflow.com/questions/1389893/mechanize-an...
5
2009-12-14T16:52:38Z
2,056,543
<p>I have solved this problem, just change the code of mechanize._http.py, about line 43, from:</p> <pre><code>try: socket._fileobject("fake socket", close=True) except TypeError: # python &lt;= 2.4 create_readline_wrapper = socket._fileobject else: def create_readline_wrapper(fh): return sock...
10
2010-01-13T12:23:29Z
[ "python", "google-app-engine", "mechanize-python" ]
Python Mechanize + GAEpython code
1,902,079
<p>I am aware of previous questions regarding mechanize + Google App Engine, <a href="http://stackoverflow.com/questions/1563165/what-pure-python-library-should-i-use-to-scrape-a-website">What pure Python library should I use to scrape a website?</a> and <a href="http://stackoverflow.com/questions/1389893/mechanize-an...
5
2009-12-14T16:52:38Z
3,996,290
<p>I've uploaded the source of the gaemechanize project to a new project: <a href="http://code.google.com/p/gaemechanize2/" rel="nofollow">http://code.google.com/p/gaemechanize2/</a></p> <p>Insert usual caveats.</p>
0
2010-10-22T11:22:27Z
[ "python", "google-app-engine", "mechanize-python" ]
How do I disable Nagle's algorithm for sockets?
1,902,325
<p>I'm writing some python and are stuck at the moment. I think this "Nagle algoritm" is the problem since my packages are delayed some time for some reason to the client.</p> <p>I've tried this on both client and server but it doesn't seems to work (or there's another problem causing it):</p> <pre><code>socketobj.se...
1
2009-12-14T17:34:59Z
1,902,437
<p>I'm not familiar with Python's sockets, but does it have a flush method? Even with Nagle's disabled, most socket implementations will buffer if you don't write X number of bytes. However, if you call flush, the bytes should be sent immediately.</p>
0
2009-12-14T17:57:46Z
[ "python", "networking", "sockets" ]
Django Admin app: building a dynamic list of admin actions
1,902,332
<p>I am trying to dynamically build a list of admin actions using the <a href="http://docs.djangoproject.com/en/1.1/ref/contrib/admin/actions/#django.contrib.admin.ModelAdmin.get_actions" rel="nofollow"><code>get_actions()</code></a> method on a <code>ModelAdmin</code>. Each action relates to a particular instance of a...
3
2009-12-14T17:35:59Z
1,902,859
<p>I am surprised that q stays the same object within the loop.</p> <p>Does it work with <code>quality=q.id</code> in your lambda?</p>
0
2009-12-14T19:09:17Z
[ "python", "django", "closures" ]
Django Admin app: building a dynamic list of admin actions
1,902,332
<p>I am trying to dynamically build a list of admin actions using the <a href="http://docs.djangoproject.com/en/1.1/ref/contrib/admin/actions/#django.contrib.admin.ModelAdmin.get_actions" rel="nofollow"><code>get_actions()</code></a> method on a <code>ModelAdmin</code>. Each action relates to a particular instance of a...
3
2009-12-14T17:35:59Z
1,903,078
<p>try </p> <pre><code> def make_action(quality): return lambda modeladmin, req, qset: qset.update(quality=quality) for q in models.Quality.objects.all(): action = make_action(q) name = "mark_%s" % (q,) yield (name, (action, name, "Mark selected as %s quality" % (q,))) </code></pre> ...
5
2009-12-14T19:53:41Z
[ "python", "django", "closures" ]
Django Admin app: building a dynamic list of admin actions
1,902,332
<p>I am trying to dynamically build a list of admin actions using the <a href="http://docs.djangoproject.com/en/1.1/ref/contrib/admin/actions/#django.contrib.admin.ModelAdmin.get_actions" rel="nofollow"><code>get_actions()</code></a> method on a <code>ModelAdmin</code>. Each action relates to a particular instance of a...
3
2009-12-14T17:35:59Z
1,903,132
<p>As I mentioned in my comment to andylei's answer, I just found a solution; using another function to create the closure seems to break the reference, meaning that now every action refers to the correct instance of <code>Quality</code>.</p> <pre><code>def create_action(quality): fun = lambda modeladmin, request,...
1
2009-12-14T20:01:00Z
[ "python", "django", "closures" ]
How to implement time event scheduler in python?
1,902,338
<p>In python how to implement a thread which runs in the background (may be when the module loads) and calls the function every minute Monday to Friday 10 AM to 3 PM. For example the function should be called at:</p> <p>10:01 AM 10:02 AM 10:03 AM . . 2:59 PM</p> <p>Any pointers?</p> <p>Environment: Django</p> <p>Th...
1
2009-12-14T17:38:08Z
1,902,471
<p>Django is a server application, which only reacts to external events.</p> <p>You should use a scheduler like <strong>cron</strong> to create events that call your django application, either calling a management subcommand or doing an HTTP request on some special page.</p>
4
2009-12-14T18:03:31Z
[ "python", "django", "multithreading", "scheduling" ]
How to implement time event scheduler in python?
1,902,338
<p>In python how to implement a thread which runs in the background (may be when the module loads) and calls the function every minute Monday to Friday 10 AM to 3 PM. For example the function should be called at:</p> <p>10:01 AM 10:02 AM 10:03 AM . . 2:59 PM</p> <p>Any pointers?</p> <p>Environment: Django</p> <p>Th...
1
2009-12-14T17:38:08Z
1,902,490
<p>Note sure how django affects threads (unless you're using App Engine where you can't do low level such), but once your thread is running you can continuously check timestamps:</p> <pre><code>from datetime import time from datetime import date time_delta = 60 while True: end_time = time.time() + time_delta w...
-1
2009-12-14T18:06:48Z
[ "python", "django", "multithreading", "scheduling" ]
How to implement time event scheduler in python?
1,902,338
<p>In python how to implement a thread which runs in the background (may be when the module loads) and calls the function every minute Monday to Friday 10 AM to 3 PM. For example the function should be called at:</p> <p>10:01 AM 10:02 AM 10:03 AM . . 2:59 PM</p> <p>Any pointers?</p> <p>Environment: Django</p> <p>Th...
1
2009-12-14T17:38:08Z
1,902,540
<p>Here is an article about scheduling tasks in cron from google code.</p> <p><a href="http://code.google.com/appengine/docs/python/config/cron.html#The%5FSchedule%5FFormat" rel="nofollow">Scheduling Tasks with Cron</a></p>
-1
2009-12-14T18:14:48Z
[ "python", "django", "multithreading", "scheduling" ]
How to implement time event scheduler in python?
1,902,338
<p>In python how to implement a thread which runs in the background (may be when the module loads) and calls the function every minute Monday to Friday 10 AM to 3 PM. For example the function should be called at:</p> <p>10:01 AM 10:02 AM 10:03 AM . . 2:59 PM</p> <p>Any pointers?</p> <p>Environment: Django</p> <p>Th...
1
2009-12-14T17:38:08Z
1,902,568
<p>The <a href="http://docs.python.org/library/threading.html?highlight=schedule#timer-objects" rel="nofollow"><code>threading.Timer</code></a> class is convenient to do such tasks. But you have to compute interval yourself.</p>
2
2009-12-14T18:20:28Z
[ "python", "django", "multithreading", "scheduling" ]
How to implement time event scheduler in python?
1,902,338
<p>In python how to implement a thread which runs in the background (may be when the module loads) and calls the function every minute Monday to Friday 10 AM to 3 PM. For example the function should be called at:</p> <p>10:01 AM 10:02 AM 10:03 AM . . 2:59 PM</p> <p>Any pointers?</p> <p>Environment: Django</p> <p>Th...
1
2009-12-14T17:38:08Z
1,903,182
<p>I think you can make a command <a href="http://docs.djangoproject.com/en/1.1/howto/custom-management-commands/#howto-custom-management-commands" rel="nofollow">http://docs.djangoproject.com/en/1.1/howto/custom-management-commands/#howto-custom-management-commands</a> and then cron it.</p>
1
2009-12-14T20:11:09Z
[ "python", "django", "multithreading", "scheduling" ]
How to properly remove a specific ManyToMany relationship?
1,902,487
<p>I have a ManyToMany relationship with one of my Models. On deleting a child, I want to remove the relationship but leave the record as it might be being used by other objects. On calling the delete view, I get an AttributeError error:</p> <blockquote> <p>Exception Value: 'QuerySet' object has no attribute 'cl...
1
2009-12-14T18:05:57Z
1,902,658
<p>Clear the fields on a Digest isntance</p> <pre><code>digest = get_object_or_404(Digest, id=id) if digest.user == request.user: digest.feeds.clear() #do your processing </code></pre> <p>In response to your comment.</p> <pre><code>digest = get_object_or_404(Digest, id=id) if digest.user == request.user: feed=...
6
2009-12-14T18:35:07Z
[ "python", "django", "django-models", "many-to-many" ]
How to add a variable to the module I import from?
1,902,656
<p>What I want to do is something like this:</p> <pre><code>template.py def dummy_func(): print(VAR) # more functions like this to follow fabfile.py # this gets called by fabric (fabfile.org) # safe to think of it as ant build.xml import template template.VAR = 'some_val' from template import * </code></pre> <...
1
2009-12-14T18:34:55Z
1,902,737
<p>I'm not sure what you mean by "a functional manner" -- do you mean, as in <a href="http://en.wikipedia.org/wiki/Functional%5Fprogramming" rel="nofollow">functional programming</a>? That's not going to happen (since you're intrinsically trying to modify an object, which is the reverse of FP). Or do you mean somethi...
4
2009-12-14T18:47:53Z
[ "python", "fabric" ]
How to add a variable to the module I import from?
1,902,656
<p>What I want to do is something like this:</p> <pre><code>template.py def dummy_func(): print(VAR) # more functions like this to follow fabfile.py # this gets called by fabric (fabfile.org) # safe to think of it as ant build.xml import template template.VAR = 'some_val' from template import * </code></pre> <...
1
2009-12-14T18:34:55Z
1,902,760
<p>If you change a property of a module in one place, it will be the same in other places too. Proof:</p> <p>Create a file '/tmp/test1.py':</p> <pre><code>imoprt os os.path = '' # set os.path (module) to a mere string os.zzz = 'zzz' </code></pre> <p>Then</p> <pre><code>cd /tmp &amp;&amp; python &gt;&gt;&gt; dir(te...
0
2009-12-14T18:51:19Z
[ "python", "fabric" ]
How to add a variable to the module I import from?
1,902,656
<p>What I want to do is something like this:</p> <pre><code>template.py def dummy_func(): print(VAR) # more functions like this to follow fabfile.py # this gets called by fabric (fabfile.org) # safe to think of it as ant build.xml import template template.VAR = 'some_val' from template import * </code></pre> <...
1
2009-12-14T18:34:55Z
1,905,157
<p>Turns out this has a fabric-centric solution.<br> So you have an abstract <strong>some__fab__template.py</strong> and a concrete <strong>fabfile.py</strong> that should 'extend' the template contributing some required variables (e.g. project name).<br> I've implemented it utilizing fab's <strong>env</strong> diction...
0
2009-12-15T04:23:00Z
[ "python", "fabric" ]
context within a query filter?
1,902,813
<p>I have a very basic contact model. The model has the following fields:</p> <pre><code>class Entry(models.Model): name = models.CharField(max_length=64, unique=False) organization = models.CharField(max_length=100, unique=False, blank=True, null=True) team = models.CharField(max_length=64, unique=False,...
0
2009-12-14T18:59:40Z
1,902,862
<p>You probably want the display_organization URL map to include a parameter for the organization:</p> <pre><code>('^organization/(?P&lt;org_name&gt;.+)$', 'myapp.views.display_organization'), </code></pre> <p>With that, your display_organization function must accept the org_name parameter too:</p> <pre><code>def di...
3
2009-12-14T19:09:45Z
[ "python", "django" ]
context within a query filter?
1,902,813
<p>I have a very basic contact model. The model has the following fields:</p> <pre><code>class Entry(models.Model): name = models.CharField(max_length=64, unique=False) organization = models.CharField(max_length=100, unique=False, blank=True, null=True) team = models.CharField(max_length=64, unique=False,...
0
2009-12-14T18:59:40Z
1,908,074
<p>You're making it quite complex by depending on the URL. It's fine if there's only one or two things that work that way.</p> <p>I'd say, keep it simple and just use request.GET</p> <pre><code>def display_organization(request): records = Entry.objects.filter(organization__iexact=request.GET['organization']) ...
0
2009-12-15T15:07:13Z
[ "python", "django" ]
Running Django Tests with a Precommit Hook
1,902,817
<p>I would like to run all my django tests using mercurial's precommit hook. Whenever a test fails the commit will be aborted.</p> <p>The goal is to block build-breaking commits as often as possible.</p> <p><strong>edit:</strong> Ended up using the external script route. Here is the reletant portion of my hgrc:</p> ...
4
2009-12-14T19:00:40Z
1,902,844
<p>It looks like Mercurial's way of importing modules is clashing with Django's somehow.</p> <p>Before trying to dive in and sort that out, is there any reason to not just run the tests with the normal command?</p> <pre><code>[hooks] precommit.runtests = python manage.py test </code></pre>
6
2009-12-14T19:06:42Z
[ "python", "django", "version-control", "mercurial", "pre-commit" ]
How do I chain object instantiation with its methods?
1,902,836
<p>For example this chunk of code:</p> <pre><code>new_log = ActivityLog(user=self.user, activity=activity) new_log.save() </code></pre> <p>Can I chain it to be like new_log = ActivityLog(...).save() ?</p> <p>I believe I tried the above, but it doesn't work. Is there a way to make it a 1 liner?<...
0
2009-12-14T19:04:25Z
1,902,841
<p>Let <code>save()</code> return <code>self</code>, such as:</p> <pre><code>class ActivityLog (object): # EDIT: OR INHERIT FROM WHATEVER OTHER CLASS, I DONT CARE ... def save(self): ... return self </code></pre> <p><strong>NOTE:</strong> This is a generic coding pattern called <a href="http:...
6
2009-12-14T19:06:32Z
[ "python" ]
How do I chain object instantiation with its methods?
1,902,836
<p>For example this chunk of code:</p> <pre><code>new_log = ActivityLog(user=self.user, activity=activity) new_log.save() </code></pre> <p>Can I chain it to be like new_log = ActivityLog(...).save() ?</p> <p>I believe I tried the above, but it doesn't work. Is there a way to make it a 1 liner?<...
0
2009-12-14T19:04:25Z
1,902,845
<p>Django provides a convenience method on the model manager for just this purpose :-)</p> <pre><code>new_log = ActivityLog.objects.create(user=self.user, activity=activity) </code></pre> <p>The docs on <a href="http://docs.djangoproject.com/en/1.1/ref/models/querysets/#create-kwargs" rel="nofollow">create are here</...
2
2009-12-14T19:06:55Z
[ "python" ]
Potential errors with my makeValidFilename function?
1,902,926
<p>It is inspired by <a href="http://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename-in-python">"How to make a valid Windows filename from an arbitrary string?"</a>, I've written a function that will take arbitrary string and make it a valid filename.</p> <p>My function should technically be an ...
0
2009-12-14T19:23:11Z
3,551,390
<p>One point I've noticed: Under NTFS, some files can not be created in specific directories. E.G. $Boot in root </p>
1
2010-08-23T20:26:49Z
[ "python", "filesystems", "sanitization", "file-rename" ]
NLTK - how to find out what corpora are installed from within python?
1,902,967
<p>I'm trying to load some corpora I installed with the NLTK installer but I got a:</p> <pre><code>&gt;&gt;&gt; from nltk.corpus import machado Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ImportError: cannot import name machado </code></pre> <p>But in the downl...
4
2009-12-14T19:32:25Z
1,903,002
<p>try</p> <pre><code>import nltk.corpus dir(nltk.corpus) </code></pre> <p>at which point, it probably told you something about <code>__LazyModule__...</code> so do <code>dir(nltk.corpus)</code> again.</p> <p>If that doesn't work, try tab-completion in iPython.</p>
7
2009-12-14T19:39:49Z
[ "python", "nlp", "nltk", "corpus" ]
NLTK - how to find out what corpora are installed from within python?
1,902,967
<p>I'm trying to load some corpora I installed with the NLTK installer but I got a:</p> <pre><code>&gt;&gt;&gt; from nltk.corpus import machado Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ImportError: cannot import name machado </code></pre> <p>But in the downl...
4
2009-12-14T19:32:25Z
20,075,588
<p>The NLTK includes a package, <code>nltk.corpus</code>, that contains definitions of corpus readers (such as <code>PlainTextCorpusReader</code>). This package also includes a large list of pre-defined access points for corpora that can be downloaded with <code>nltk.downloader()</code>. These access points (e.g., <cod...
2
2013-11-19T15:31:39Z
[ "python", "nlp", "nltk", "corpus" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,903,114
<p>If you are planning on a 'huge' website, then don't use App Engine. Simple as that. The App Engine is not built to deliver the next top 1000th website. </p> <p>Allow me to also ask what do you mean by 'huge', how many simultaneous users? Queries per second? DB load?</p>
-11
2009-12-14T19:58:37Z
[ "python", "google-app-engine", "web2py" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,903,297
<p>The AppEngine uses BigTable as it's datastore backend. Don't try to write a traditional relational-database driven application. BigTable is much more well suited for use as a highly-scalable key-value store. Avoid joins if at all possible.</p>
3
2009-12-14T20:28:53Z
[ "python", "google-app-engine", "web2py" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,904,574
<p>I wouldn't worry about any of this. After having played with Google App Engine for a while now, I've found that it scales quite well for large data sets. If your data elements are large (i.e. photos), then you'll need to integrate with another service to handle them, but that's probably going to be true no matter ...
2
2009-12-15T00:48:16Z
[ "python", "google-app-engine", "web2py" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,904,610
<p>Having developed a smallish site with GAE, I have some thoughts</p> <ul> <li><p>If you mean "huge" like "the next YouTube", then GAE might be a great fit, because of the previously mentioned scaling.</p></li> <li><p>If you mean "huge" like "massively complex, with a whole slew of screens, models, and features", the...
8
2009-12-15T01:01:00Z
[ "python", "google-app-engine", "web2py" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,905,263
<p>using web2py on Google App Engine is a great strategy. It lets you get up and running fast, and if you do outgrow the restrictions of GAE then you can move your web2py application elsewhere. </p> <p>However, keeping this portability means you should stay away from the advanced parts of GAE (Task Queues, Transaction...
5
2009-12-15T04:59:23Z
[ "python", "google-app-engine", "web2py" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,905,802
<p>Google has just released version 1.3.0 of the SDK with support with a new Blobstore API for storage of files up to 50MB. See the post "<a href="http://googleappengine.blogspot.com/2009/12/app-engine-sdk-130-released-including.html?utm%5Fsource=feedburner&amp;utm%5Fmedium=feed&amp;utm%5Fcampaign=Feed%3A+GoogleAppEngi...
1
2009-12-15T07:44:55Z
[ "python", "google-app-engine", "web2py" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,934,107
<p>My only concern would be if for a huge website (that consumes lot of bandwidth and CPU) if hosting it yourself would not be cheaper in the end. (The question is how fair are Google's quotas and if pricing is competitive at the very high-end.)</p> <p>Other than that - enable billing, and let Google do all the scalin...
0
2009-12-19T20:53:34Z
[ "python", "google-app-engine", "web2py" ]
Is Google App Engine right for me?
1,903,065
<p>I am thinking about using Google App Engine.It is going to be a huge website. In that case, what is your piece of advice using Google App Engine. I heard GAE has restrictions like we cannot store images or files more than 1MB limit(they are going to change this from what I read in the GAE roadmap),query is limited t...
9
2009-12-14T19:51:01Z
1,994,758
<p>What about Google Wave? It's being built on appengine, and once live, real-time translatable chat reaches the corporate sector... I could see it hitting top 1000th... But then again, that's an internal project that gets to do special stuff other appengine apps can't.... Like hanging threads; I think... And what...
0
2010-01-03T11:57:06Z
[ "python", "google-app-engine", "web2py" ]
Validate that atleast one modelfield has value in Django admin
1,903,158
<p>Given the following model, how do I require that atleast one of the two fields has been given a value?</p> <pre><code>class ZipUpload(models.Model): zip_file = models.FileField(upload_to="/tmp", blank=True, help_text='Select a file to upload.') zip_file_path = models.FilePath...
0
2009-12-14T20:04:23Z
1,903,210
<p>This kind of validation is what a customized Form is for. Define a Form, write validation methods in the Form. Bind the Form to the Model to create the Admin interface.</p>
3
2009-12-14T20:16:33Z
[ "python", "django", "django-models", "django-admin" ]
Are there any matrix math modules compatible with Python 3.x?
1,903,209
<p>When I began this project, I thought it would be easy to get libraries for common stuff like matrix math, so I chose to work in Python 3.1- it being the most recent, updated version of the language. Unfortunately, NumPy is only compatible with 2.5 and 2.6 and seems to be the only game in town! Even other stuff tha...
2
2009-12-14T20:16:27Z
1,903,315
<p>Given that a large portion of those interested in this sort of development are involved in NumPy, and given their <a href="http://blog.jarrodmillman.com/2009/01/when-will-numpy-and-scipy-migrate-to.html">schedule for migrating</a> I think the answer is "no, there is nothing yet".</p> <p>I would advise treating Pyth...
5
2009-12-14T20:30:59Z
[ "python", "math", "matrix" ]
Are there any matrix math modules compatible with Python 3.x?
1,903,209
<p>When I began this project, I thought it would be easy to get libraries for common stuff like matrix math, so I chose to work in Python 3.1- it being the most recent, updated version of the language. Unfortunately, NumPy is only compatible with 2.5 and 2.6 and seems to be the only game in town! Even other stuff tha...
2
2009-12-14T20:16:27Z
1,903,322
<p><strong>EDIT:</strong> <a href="http://code.google.com/p/pyeuclid/source/browse/trunk/euclid.py" rel="nofollow">PyEuclid</a> has supports matrices, vectors up to 4 dimensions and is designed for geometric operations.</p> <p>Otherwise, the answer is probably not what you want, but:</p> <ul> <li>use python 2.x inste...
1
2009-12-14T20:32:16Z
[ "python", "math", "matrix" ]
How can I "zip sort" parallel numpy arrays?
1,903,462
<p>If I have two parallel lists and want to sort them by the order of the elements in the first, it's very easy:</p> <pre><code>&gt;&gt;&gt; a = [2, 3, 1] &gt;&gt;&gt; b = [4, 6, 2] &gt;&gt;&gt; a, b = zip(*sorted(zip(a,b))) &gt;&gt;&gt; print a (1, 2, 3) &gt;&gt;&gt; print b (2, 4, 6) </code></pre> <p>How can I do t...
22
2009-12-14T21:00:03Z
1,903,579
<p><code>b[a.argsort()]</code> should do the trick.</p> <p>Here's how it works. First you need to find a permutation that sorts a. <code>argsort</code> is a method that computes this:</p> <pre><code>&gt;&gt;&gt; a = numpy.array([2, 3, 1]) &gt;&gt;&gt; p = a.argsort() &gt;&gt;&gt; p [2, 0, 1] </code></pre> <p>You can...
30
2009-12-14T21:19:39Z
[ "python", "sorting", "numpy" ]
How can I "zip sort" parallel numpy arrays?
1,903,462
<p>If I have two parallel lists and want to sort them by the order of the elements in the first, it's very easy:</p> <pre><code>&gt;&gt;&gt; a = [2, 3, 1] &gt;&gt;&gt; b = [4, 6, 2] &gt;&gt;&gt; a, b = zip(*sorted(zip(a,b))) &gt;&gt;&gt; print a (1, 2, 3) &gt;&gt;&gt; print b (2, 4, 6) </code></pre> <p>How can I do t...
22
2009-12-14T21:00:03Z
1,903,997
<p>Here's an approach that creates no intermediate Python lists, though it does require a NumPy "record array" to use for the sorting. If your two input arrays are actually related (like columns in a spreadsheet) then this might open up an advantageous way of dealing with your data in general, rather than keeping two ...
14
2009-12-14T22:35:41Z
[ "python", "sorting", "numpy" ]
How can I "zip sort" parallel numpy arrays?
1,903,462
<p>If I have two parallel lists and want to sort them by the order of the elements in the first, it's very easy:</p> <pre><code>&gt;&gt;&gt; a = [2, 3, 1] &gt;&gt;&gt; b = [4, 6, 2] &gt;&gt;&gt; a, b = zip(*sorted(zip(a,b))) &gt;&gt;&gt; print a (1, 2, 3) &gt;&gt;&gt; print b (2, 4, 6) </code></pre> <p>How can I do t...
22
2009-12-14T21:00:03Z
1,904,880
<p>This might the simplest and most general way to do what you want. (I used three arrays here, but this will work on arrays of any shape, whether two columns or two hundred).</p> <pre><code>import numpy as NP fnx = lambda : NP.random.randint(0, 10, 6) a, b, c = fnx(), fnx(), fnx() abc = NP.column_stack((a, b, c)) ke...
1
2009-12-15T02:37:14Z
[ "python", "sorting", "numpy" ]
libnet creates UDP packets with invalid checksums
1,903,500
<p>I'm using pylibnet to construct and send UDP packets. The UDP packets I construct in this way all seem to have invalid checksums. Example:</p> <pre><code># python Python 2.4.3 (#1, Sep 3 2009, 15:37:12) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more in...
1
2009-12-14T21:06:16Z
1,903,756
<p>The job of calculating checksums is usually not performed in the user-space library but at the device driver or in hardware. I believe you are seeing the result of "checksum offloading", where the physical device calculates the checksums on outgoing packets, saving CPU cycles on the host. Many (if not all) modern E...
1
2009-12-14T21:52:58Z
[ "python", "udp", "libnet" ]
libnet creates UDP packets with invalid checksums
1,903,500
<p>I'm using pylibnet to construct and send UDP packets. The UDP packets I construct in this way all seem to have invalid checksums. Example:</p> <pre><code># python Python 2.4.3 (#1, Sep 3 2009, 15:37:12) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more in...
1
2009-12-14T21:06:16Z
2,071,739
<p>It's nothing to do with tcpdump bugs or checksum offloading. Libnet calculates the checksum in user mode as well (FYI). The problem has to do with the fact that you did not specify a length for the UDP header. This is not automagically calculated in pylibnet or libnet so you have to specify it for the time being. Be...
3
2010-01-15T13:21:33Z
[ "python", "udp", "libnet" ]
libnet creates UDP packets with invalid checksums
1,903,500
<p>I'm using pylibnet to construct and send UDP packets. The UDP packets I construct in this way all seem to have invalid checksums. Example:</p> <pre><code># python Python 2.4.3 (#1, Sep 3 2009, 15:37:12) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more in...
1
2009-12-14T21:06:16Z
2,114,780
<p>I have updated pylibnet to include an auto size determination for the length fields in most headers. This way if you forget to specify the length of the header for any of the headers that require it, it will attempt to automagically determine it. Saves you the headache of figuring out why your checksum is bad;)</p>
1
2010-01-22T03:41:35Z
[ "python", "udp", "libnet" ]
How can I deal with python eggs for multiple platforms in one location?
1,903,653
<p>We have a common python installation for all of our systems in order to ensure every system has the same python installation and to ease configuration issues. This installation is located on a shared drive. We also have multiple platforms that share this installation. We get around conflicting platform-specific f...
6
2009-12-14T21:33:11Z
1,908,321
<p>Python has enough hooks to make this possible but it is probably not wise. If you really want to implement this, look at <a href="http://www.python.org/dev/peps/pep-0302/" rel="nofollow">PEP 302</a> and start hacking on the <code>easy_install</code> or <a href="http://pypi.python.org/pypi/distribute" rel="nofollow">...
1
2009-12-15T15:47:30Z
[ "python", "easy-install", "pkg-resources" ]
How can I deal with python eggs for multiple platforms in one location?
1,903,653
<p>We have a common python installation for all of our systems in order to ensure every system has the same python installation and to ease configuration issues. This installation is located on a shared drive. We also have multiple platforms that share this installation. We get around conflicting platform-specific f...
6
2009-12-14T21:33:11Z
1,909,332
<p>Try virtualenv ... <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">http://pypi.python.org/pypi/virtualenv</a> ... helps you create isolated environment with it's own python interpreter + site_packages folder. Thus you never have any conflicts with packages installed in say local path.</p>
2
2009-12-15T18:15:19Z
[ "python", "easy-install", "pkg-resources" ]
How can I deal with python eggs for multiple platforms in one location?
1,903,653
<p>We have a common python installation for all of our systems in order to ensure every system has the same python installation and to ease configuration issues. This installation is located on a shared drive. We also have multiple platforms that share this installation. We get around conflicting platform-specific f...
6
2009-12-14T21:33:11Z
1,923,715
<p>What I ended up going with was manually moving the platform-dependent egg to the platform-specific site-packages directory (as specified at <a href="http://docs.python.org/install/index.html" rel="nofollow">http://docs.python.org/install/index.html</a>). Then I made another easy-install.pth in that same directory, ...
2
2009-12-17T18:39:18Z
[ "python", "easy-install", "pkg-resources" ]
How can I deal with python eggs for multiple platforms in one location?
1,903,653
<p>We have a common python installation for all of our systems in order to ensure every system has the same python installation and to ease configuration issues. This installation is located on a shared drive. We also have multiple platforms that share this installation. We get around conflicting platform-specific f...
6
2009-12-14T21:33:11Z
2,164,148
<p>Use "easy_install -m" to install all the platform-specific packages, so that there is no default version on sys.path. That way, version resolution takes place at runtime, and platform information will be taken into consideration.</p>
0
2010-01-29T18:17:49Z
[ "python", "easy-install", "pkg-resources" ]
How to get progress of file move in python?
1,903,690
<p>I've got a little script for sorting out my dowloaded files and it works great, but I'd like to print out the progress of a file move, for when it's doing the big ones, right now I do something like:</p> <pre><code>print "moving..." os.renames(pathTofile, newName) print "done" </code></pre> <p>But I'd like to be a...
0
2009-12-14T21:40:28Z
1,903,753
<p>You won't be able to get that kind of information using os.renames. Your best bet is to replace that with a home grown file copy operation but call stat on the file beforehand in order to get the complete size so you can track how far through you are.</p> <p>Something like this:</p> <pre><code>source_size = os.st...
7
2009-12-14T21:52:34Z
[ "python" ]
How to get progress of file move in python?
1,903,690
<p>I've got a little script for sorting out my dowloaded files and it works great, but I'd like to print out the progress of a file move, for when it's doing the big ones, right now I do something like:</p> <pre><code>print "moving..." os.renames(pathTofile, newName) print "done" </code></pre> <p>But I'd like to be a...
0
2009-12-14T21:40:28Z
1,903,754
<p>There isn't any way to get a progress bar because the "rename" call that moves the file is a single OS call.</p> <p>It's worth noting that the "rename" call only takes time if the source and destination are on <em>different</em> physical volumes. If they're on the same volume, then the rename will take almost no ti...
1
2009-12-14T21:52:41Z
[ "python" ]
How to get progress of file move in python?
1,903,690
<p>I've got a little script for sorting out my dowloaded files and it works great, but I'd like to print out the progress of a file move, for when it's doing the big ones, right now I do something like:</p> <pre><code>print "moving..." os.renames(pathTofile, newName) print "done" </code></pre> <p>But I'd like to be a...
0
2009-12-14T21:40:28Z
34,425,692
<p>This example method expands on the answer by Benno by estimating the time remaining and removing the progress line when the copy is complete.</p> <pre><code>def copy_large_file(src, dst): ''' Copy a large file showing progress. ''' print('copying "{}" --&gt; "{}"'.format(src, dst)) # Start the ...
0
2015-12-22T22:44:02Z
[ "python" ]
Getting a list of all churches in a certain state using Python
1,903,966
<p>I am pretty good with Python, so pseudo-code will suffice when details are trivial. Please get me started on the task - how do go about crawling the net for the snail mail addresses of churches in my state. Once I have a one liner such as "123 Old West Road #3 Old Lyme City MD 01234", I can probably parse it into Ci...
-3
2009-12-14T22:29:44Z
1,904,007
<p>Try <code>lynx --dump &lt;url&gt;</code> to download the web pages. All the troublesome HTML tags will be stripped from the output, and all the links from the page will appear together.</p>
2
2009-12-14T22:36:49Z
[ "python", "automation", "web-crawler", "pseudocode", "street-address" ]
Getting a list of all churches in a certain state using Python
1,903,966
<p>I am pretty good with Python, so pseudo-code will suffice when details are trivial. Please get me started on the task - how do go about crawling the net for the snail mail addresses of churches in my state. Once I have a one liner such as "123 Old West Road #3 Old Lyme City MD 01234", I can probably parse it into Ci...
-3
2009-12-14T22:29:44Z
1,904,038
<p>You could use <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a>. It's a python library that simulates a browser, so you could crawl through the white pages (similarly to what you do manually).</p> <p>In order to deal with the 'html junk' python has a library for that too: <a href="h...
2
2009-12-14T22:42:54Z
[ "python", "automation", "web-crawler", "pseudocode", "street-address" ]
Getting a list of all churches in a certain state using Python
1,903,966
<p>I am pretty good with Python, so pseudo-code will suffice when details are trivial. Please get me started on the task - how do go about crawling the net for the snail mail addresses of churches in my state. Once I have a one liner such as "123 Old West Road #3 Old Lyme City MD 01234", I can probably parse it into Ci...
-3
2009-12-14T22:29:44Z
1,904,053
<p>What you're trying to do is called <em><a href="http://en.wikipedia.org/wiki/Web_scraping" rel="nofollow">Scraping</a></em> or web scraping.</p> <p>If you do some <a href="http://www.google.com/search?q=python+web+scraping" rel="nofollow">searches</a> on <a href="http://www.packtpub.com/article/web-scraping-with-py...
2
2009-12-14T22:46:32Z
[ "python", "automation", "web-crawler", "pseudocode", "street-address" ]
Getting a list of all churches in a certain state using Python
1,903,966
<p>I am pretty good with Python, so pseudo-code will suffice when details are trivial. Please get me started on the task - how do go about crawling the net for the snail mail addresses of churches in my state. Once I have a one liner such as "123 Old West Road #3 Old Lyme City MD 01234", I can probably parse it into Ci...
-3
2009-12-14T22:29:44Z
1,904,218
<p>Beautiful Soup is a no brainer. Here's a site you might start at <a href="http://www.churchangel.com/" rel="nofollow">http://www.churchangel.com/</a>. They have a huge list and the formatting is very regular -- translation: easy to setup BSoup to scrape.</p>
2
2009-12-14T23:17:01Z
[ "python", "automation", "web-crawler", "pseudocode", "street-address" ]