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
opengl set texture color with vertex color
244,720
<p>Because I need to display a <a href="http://codeflow.org/ubuntu.png" rel="nofollow">huge number of labels</a> that <a href="http://www.youtube.com/watch?v=A_ah-SE-cNY" rel="nofollow">move independently</a>, I need to render a label in <a href="http://pyglet.org" rel="nofollow">pyglet</a> to a texture (otherwise upda...
1
2008-10-28T20:25:55Z
405,855
<p>You want to set <code>glEnable(GL_COLOR_MATERIAL)</code>. This makes the texture color mix with the current OpenGL color. You can also use the <code>glColorMaterial</code> function to specify whether the front/back/both of each polygon should be affected. Docs <a href="http://www.glprogramming.com/blue/ch05.html#id3...
2
2009-01-02T02:00:08Z
[ "python", "opengl", "pyglet" ]
AJAX console window with ANSI/VT100 support?
244,750
<p>I'm planning to write gateway web application, which would need "terminal window" with VT100/ANSI escape code support. Are there any AJAX based alternatives for such a task?</p> <p>I'm thinking something like this: <a href="http://tryruby.hobix.com/">http://tryruby.hobix.com/</a></p> <p>My preferred backend for th...
8
2008-10-28T20:32:24Z
244,817
<p>AjaxTerm has a terminal, with mostly felicitous terminal emulation, done on the Python backend (it just pushes display updates to the client Javascript).</p> <p>The <a href="http://antony.lesuisse.org/qweb/trac/wiki/AjaxTerm" rel="nofollow">AjaxTerm</a> website has been down for some time, but you can still find it...
3
2008-10-28T20:47:37Z
[ "python", "ajax", "vt100" ]
AJAX console window with ANSI/VT100 support?
244,750
<p>I'm planning to write gateway web application, which would need "terminal window" with VT100/ANSI escape code support. Are there any AJAX based alternatives for such a task?</p> <p>I'm thinking something like this: <a href="http://tryruby.hobix.com/">http://tryruby.hobix.com/</a></p> <p>My preferred backend for th...
8
2008-10-28T20:32:24Z
244,823
<p>Try</p> <p><a href="http://wiki.kartbuilding.net/index.php/Anyterm">AnyTerm</a></p> <p><a href="http://wiki.kartbuilding.net/index.php/Ajaxterm">AjaxTerm</a></p> <p><a href="http://www-personal.umich.edu/~mressl/webshell/">WebShell</a></p>
9
2008-10-28T20:49:22Z
[ "python", "ajax", "vt100" ]
AJAX console window with ANSI/VT100 support?
244,750
<p>I'm planning to write gateway web application, which would need "terminal window" with VT100/ANSI escape code support. Are there any AJAX based alternatives for such a task?</p> <p>I'm thinking something like this: <a href="http://tryruby.hobix.com/">http://tryruby.hobix.com/</a></p> <p>My preferred backend for th...
8
2008-10-28T20:32:24Z
963,694
<p>There's also <a href="http://shellinabox.com">Shell In A Box</a>.</p>
7
2009-06-08T06:47:26Z
[ "python", "ajax", "vt100" ]
Porting MATLAB functions to Scilab. How do I use symbolic?
244,803
<p>I'm porting some <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> functions to <a href="https://en.wikipedia.org/wiki/Scilab" rel="nofollow">Scilab</a>. The cool thing is that there is a <a href="http://ralyx.inria.fr/2004/Raweb/scilab/uid96.html" rel="nofollow">conversion toolbox</a> that mak...
3
2008-10-28T20:44:25Z
245,207
<p>Not to discourage your project, but if you just want a <em>free</em> and <em>open source</em> alternative to <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a>, have you looked at the <a href="http://en.wikipedia.org/wiki/GNU_Octave" rel="nofollow">Octave</a> project? Contributing there might be...
1
2008-10-28T23:04:13Z
[ "python", "matlab", "porting", "scilab", "sympy" ]
Porting MATLAB functions to Scilab. How do I use symbolic?
244,803
<p>I'm porting some <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> functions to <a href="https://en.wikipedia.org/wiki/Scilab" rel="nofollow">Scilab</a>. The cool thing is that there is a <a href="http://ralyx.inria.fr/2004/Raweb/scilab/uid96.html" rel="nofollow">conversion toolbox</a> that mak...
3
2008-10-28T20:44:25Z
246,449
<p>See <a href="http://vnoel.wordpress.com/2008/05/03/bye-matlab-hello-python-thanks-sage/" rel="nofollow">Bye MATLAB, hello Python, thanks Sage</a> for a first-hand experience of migrating from <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> to Python.</p>
3
2008-10-29T11:24:13Z
[ "python", "matlab", "porting", "scilab", "sympy" ]
Upgrading Google Application Engine program to use unicode
245,094
<p>I have a simple Google App Engine app, that I wrote using ordinary strings. I realize I want to make it handle unicode. Are there any gotchas with this? I'm thinking of all the strings that I currently already have in the live database. (From real users who I don't want to upset.)</p>
3
2008-10-28T22:20:23Z
245,159
<p>The datastore internally keeps all strings <a href="http://code.google.com/appengine/docs/datastore/typesandpropertyclasses.html#str" rel="nofollow">in unicode</a>.</p>
1
2008-10-28T22:43:27Z
[ "python", "google-app-engine", "unicode" ]
Upgrading Google Application Engine program to use unicode
245,094
<p>I have a simple Google App Engine app, that I wrote using ordinary strings. I realize I want to make it handle unicode. Are there any gotchas with this? I'm thinking of all the strings that I currently already have in the live database. (From real users who I don't want to upset.)</p>
3
2008-10-28T22:20:23Z
245,172
<p><a href="http://stackoverflow.com/questions/245094/upgrading-google-application-engine-program-to-use-unicode#245159">Alexander Kojevnikov</a> said: "The datastore internally keeps all strings in unicode."</p> <p>In other words, your application is already using unicode everywhere. Thank the google folks for a sens...
2
2008-10-28T22:53:14Z
[ "python", "google-app-engine", "unicode" ]
Upgrading Google Application Engine program to use unicode
245,094
<p>I have a simple Google App Engine app, that I wrote using ordinary strings. I realize I want to make it handle unicode. Are there any gotchas with this? I'm thinking of all the strings that I currently already have in the live database. (From real users who I don't want to upset.)</p>
3
2008-10-28T22:20:23Z
1,515,542
<p>When storing to a db.TextProperty() you need to use db.Text() like:</p> <p><code>instance.xml = db.Text(xml_string, encoding="utf_8")</code></p> <p>And specify the correct encoding if the string doesn't have a BOM on it. Like if you get unexpected unicode data from an XML stream.</p> <p>This happened to me when ...
1
2009-10-04T03:53:15Z
[ "python", "google-app-engine", "unicode" ]
What are "first class" objects?
245,192
<p>When are objects or something else said to be "first class" in a given programming language, and why? In what do they differ from languages where they are not?</p> <p>EDIT. When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?</p>
85
2008-10-28T22:58:47Z
245,208
<p>In short, it means there are no restrictions on the object's use. It's the same as any other object.</p> <p>A first class object is an entity that can be dynamically created, destroyed, passed to a function, returned as a value, and have all the rights as other variables in the programming language have. </p> <bl...
82
2008-10-28T23:04:22Z
[ "python", "language-agnostic" ]
What are "first class" objects?
245,192
<p>When are objects or something else said to be "first class" in a given programming language, and why? In what do they differ from languages where they are not?</p> <p>EDIT. When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?</p>
85
2008-10-28T22:58:47Z
245,209
<p>“First class” means you can operate on them in the usual manner. Most of the times, this just means you can pass these first-class citizens as arguments to functions, or return them from functions.</p> <p>This is self-evident for objects but not always so evident for functions, or even classes:</p> <pre><code>...
14
2008-10-28T23:04:36Z
[ "python", "language-agnostic" ]
What are "first class" objects?
245,192
<p>When are objects or something else said to be "first class" in a given programming language, and why? In what do they differ from languages where they are not?</p> <p>EDIT. When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?</p>
85
2008-10-28T22:58:47Z
245,238
<p>IMO this is one of those metaphors used to describe things in a natural language. The term is essentially used in context of describing functions as first class objects. </p> <p>If you consider a object oriented language, we can impart various features to objects for eg: inheritance, class definition, ability to pa...
0
2008-10-28T23:16:37Z
[ "python", "language-agnostic" ]
What are "first class" objects?
245,192
<p>When are objects or something else said to be "first class" in a given programming language, and why? In what do they differ from languages where they are not?</p> <p>EDIT. When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?</p>
85
2008-10-28T22:58:47Z
245,295
<p>"When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?"</p> <p>Yes.</p> <p>Everything in Python is a proper object. Even things that are "primitive types" in other languages.</p> <p>You find that an object like <code>2</code> actually has a fairly rich an...
9
2008-10-28T23:49:30Z
[ "python", "language-agnostic" ]
What are "first class" objects?
245,192
<p>When are objects or something else said to be "first class" in a given programming language, and why? In what do they differ from languages where they are not?</p> <p>EDIT. When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?</p>
85
2008-10-28T22:58:47Z
417,721
<p>From a slide in <a href="http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/">Structure and Interpretation of Computer Programs</a>, lecture 2A (1986), which in turns quotes <a href="http://en.wikipedia.org/wiki/Christopher_Strachey">Christopher Stracey</a>:</p> <p><strong>The rights and privile...
7
2009-01-06T19:03:53Z
[ "python", "language-agnostic" ]
Which library should I use to write an XLS from Linux / Python?
245,225
<p>I'd love a <em>good</em> native Python library to write XLS, but it doesn't seem to exist. Happily, Jython does.</p> <p>So I'm trying to decide between jexcelapi and Apache HSSF: <a href="http://www.andykhan.com/jexcelapi/tutorial.html#writing">http://www.andykhan.com/jexcelapi/tutorial.html#writing</a> <a href="h...
7
2008-10-28T23:11:54Z
245,267
<p>Excel exposes the same OLE automation API used by VBA to anything that supports COM. You can use win32com (which is included with ActiveState Python by default) to manipulate spreadsheets in much the same way that you would do in VBA.</p>
0
2008-10-28T23:33:20Z
[ "java", "python", "xls", "jexcelapi", "hssf" ]
Which library should I use to write an XLS from Linux / Python?
245,225
<p>I'd love a <em>good</em> native Python library to write XLS, but it doesn't seem to exist. Happily, Jython does.</p> <p>So I'm trying to decide between jexcelapi and Apache HSSF: <a href="http://www.andykhan.com/jexcelapi/tutorial.html#writing">http://www.andykhan.com/jexcelapi/tutorial.html#writing</a> <a href="h...
7
2008-10-28T23:11:54Z
245,272
<p>I'd use JExcelApi, but only because I've used it before. Never have touched HSSF. Biggest show-stopper I can recall is JExcelApi doesn't support multiple formats in one cell (e.g. half the text in bold, the other half in italic or something like that). I think in general JExcelApi is more limited than HSSF, but the ...
1
2008-10-28T23:34:49Z
[ "java", "python", "xls", "jexcelapi", "hssf" ]
Which library should I use to write an XLS from Linux / Python?
245,225
<p>I'd love a <em>good</em> native Python library to write XLS, but it doesn't seem to exist. Happily, Jython does.</p> <p>So I'm trying to decide between jexcelapi and Apache HSSF: <a href="http://www.andykhan.com/jexcelapi/tutorial.html#writing">http://www.andykhan.com/jexcelapi/tutorial.html#writing</a> <a href="h...
7
2008-10-28T23:11:54Z
245,275
<p>What's wrong with <a href="http://pypi.python.org/pypi/xlwt">xlwt</a>?</p>
16
2008-10-28T23:37:26Z
[ "java", "python", "xls", "jexcelapi", "hssf" ]
Which library should I use to write an XLS from Linux / Python?
245,225
<p>I'd love a <em>good</em> native Python library to write XLS, but it doesn't seem to exist. Happily, Jython does.</p> <p>So I'm trying to decide between jexcelapi and Apache HSSF: <a href="http://www.andykhan.com/jexcelapi/tutorial.html#writing">http://www.andykhan.com/jexcelapi/tutorial.html#writing</a> <a href="h...
7
2008-10-28T23:11:54Z
245,591
<p>+1 for xlwt. See Matt Harrison's blog for posts on <a href="http://panela.blog-city.com/pyexcelerator_xlwt_cheatsheet_create_native_excel_from_pu.htm" rel="nofollow">how to use xlwt</a> and <a href="http://panela.blog-city.com/creating_large_excel_spreadsheets_xlwt_in_python.htm" rel="nofollow">how to deal with larg...
3
2008-10-29T02:14:27Z
[ "java", "python", "xls", "jexcelapi", "hssf" ]
Which library should I use to write an XLS from Linux / Python?
245,225
<p>I'd love a <em>good</em> native Python library to write XLS, but it doesn't seem to exist. Happily, Jython does.</p> <p>So I'm trying to decide between jexcelapi and Apache HSSF: <a href="http://www.andykhan.com/jexcelapi/tutorial.html#writing">http://www.andykhan.com/jexcelapi/tutorial.html#writing</a> <a href="h...
7
2008-10-28T23:11:54Z
1,158,884
<p>i personally dis-advise JExcel if you intent to use anything more then very simple text to excel and vice versa.</p> <p>the more advanced features are abstracted very leaky from the underlying (basically undocumented) low-level code / (documented) Excel specs.</p> <p>another problem we ran into is jexcel fails fat...
1
2009-07-21T12:26:55Z
[ "java", "python", "xls", "jexcelapi", "hssf" ]
Running Django with FastCGI or with mod_python
245,237
<p>which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?</p>
20
2008-10-28T23:16:23Z
245,259
<p>Personally I've had it working with FastCGI for some time now (6 months or so) and the response times 'seem' quicker when loading a page that way vs mod___python. The critical reason for me though is that I couldn't see an obvious way to do multiple sites from the same apache / mod_python install whereas FastCGI was...
2
2008-10-28T23:29:58Z
[ "python", "django", "apache", "fastcgi" ]
Running Django with FastCGI or with mod_python
245,237
<p>which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?</p>
20
2008-10-28T23:16:23Z
245,264
<p>lighttpd with FastCGI will be nominally faster, but really the time it takes to run your python code and any database hits it does is going to absolutely dwarf any performance benefit you get between web servers.</p> <p>mod_python and apache will give you a bit more flexibility feature-wise if you want to write cod...
6
2008-10-28T23:32:27Z
[ "python", "django", "apache", "fastcgi" ]
Running Django with FastCGI or with mod_python
245,237
<p>which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?</p>
20
2008-10-28T23:16:23Z
245,464
<p>I'm using it with nginx. not sure if it's really faster, but certainly less RAM/CPU load. Also it's easier to run several Django processes and have nginx map each URL prefix to a different socket. still not taking full advantage of nginx's memcached module, but first tests show <em>huge</em> speed advantage.</p>
2
2008-10-29T01:14:18Z
[ "python", "django", "apache", "fastcgi" ]
Running Django with FastCGI or with mod_python
245,237
<p>which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?</p>
20
2008-10-28T23:16:23Z
245,484
<p>There's also mod_wsgi, it seems to be faster than mod_python and the daemon mode operates similar to FastCGI</p>
2
2008-10-29T01:25:43Z
[ "python", "django", "apache", "fastcgi" ]
Running Django with FastCGI or with mod_python
245,237
<p>which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?</p>
20
2008-10-28T23:16:23Z
245,660
<p>I've done both, and Apache/mod_python tended to be easier to work with and more stable. But these days I've jumped over to Apache/mod_wsgi, which is everything I've ever wanted and more:</p> <ul> <li>Easy management of daemon processes.</li> <li>As a result, <strong>much</strong> better process isolation (running m...
21
2008-10-29T03:06:03Z
[ "python", "django", "apache", "fastcgi" ]
Running Django with FastCGI or with mod_python
245,237
<p>which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?</p>
20
2008-10-28T23:16:23Z
258,159
<p>Nginx with mod_wsgi</p>
5
2008-11-03T08:51:51Z
[ "python", "django", "apache", "fastcgi" ]
Running Django with FastCGI or with mod_python
245,237
<p>which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?</p>
20
2008-10-28T23:16:23Z
304,369
<p>I'd recommend WSGI configurations; I keep meaning to ditch apache, but there is always some legacy app on the server that seems to require it. Additionally, the WSGI app ecology is very diverse, and it allows neat tricks such as daisy-chaining WSGI "middleware" between the server and the app.</p> <p>However, there ...
2
2008-11-20T05:01:46Z
[ "python", "django", "apache", "fastcgi" ]
How do I get the name of a function or method from within a Python function or method?
245,304
<p>I feel like I should know this, but I haven't been able to figure it out...</p> <p>I want to get the name of a method--which happens to be an integration test--from inside it so it can print out some diagnostic text. I can, of course, just hard-code the method's name in the string, but I'd like to make the test a ...
36
2008-10-28T23:52:09Z
245,314
<p>I think the <a href="http://www.python.org/doc/2.5.2/lib/module-traceback.html" rel="nofollow"><code>traceback</code></a> module might have what you're looking for. In particular, the <code>extract_stack</code> function looks like it will do the job.</p>
3
2008-10-28T23:56:35Z
[ "python" ]
How do I get the name of a function or method from within a Python function or method?
245,304
<p>I feel like I should know this, but I haven't been able to figure it out...</p> <p>I want to get the name of a method--which happens to be an integration test--from inside it so it can print out some diagnostic text. I can, of course, just hard-code the method's name in the string, but I'd like to make the test a ...
36
2008-10-28T23:52:09Z
245,333
<p>This decorator makes the name of the method available inside the function by passing it as a keyword argument.</p> <pre><code>from functools import wraps def pass_func_name(func): "Name of decorated function will be passed as keyword arg _func_name" @wraps(func) def _pass_name(*args, **kwds): kw...
15
2008-10-29T00:07:24Z
[ "python" ]
How do I get the name of a function or method from within a Python function or method?
245,304
<p>I feel like I should know this, but I haven't been able to figure it out...</p> <p>I want to get the name of a method--which happens to be an integration test--from inside it so it can print out some diagnostic text. I can, of course, just hard-code the method's name in the string, but I'd like to make the test a ...
36
2008-10-28T23:52:09Z
245,346
<p>This seems to be the simplest way using module <code>inspect</code>:</p> <pre><code>import inspect def somefunc(a,b,c): print "My name is: %s" % inspect.stack()[0][3] </code></pre> <p>You could generalise this with:</p> <pre><code>def funcname(): return inspect.stack()[1][3] def somefunc(a,b,c): prin...
52
2008-10-29T00:13:35Z
[ "python" ]
How do I get the name of a function or method from within a Python function or method?
245,304
<p>I feel like I should know this, but I haven't been able to figure it out...</p> <p>I want to get the name of a method--which happens to be an integration test--from inside it so it can print out some diagnostic text. I can, of course, just hard-code the method's name in the string, but I'd like to make the test a ...
36
2008-10-28T23:52:09Z
245,561
<pre><code># file "foo.py" import sys import os def LINE( back = 0 ): return sys._getframe( back + 1 ).f_lineno def FILE( back = 0 ): return sys._getframe( back + 1 ).f_code.co_filename def FUNC( back = 0): return sys._getframe( back + 1 ).f_code.co_name def WHERE( back = 0 ): frame = sys._getframe( b...
10
2008-10-29T01:58:33Z
[ "python" ]
How do I get the name of a function or method from within a Python function or method?
245,304
<p>I feel like I should know this, but I haven't been able to figure it out...</p> <p>I want to get the name of a method--which happens to be an integration test--from inside it so it can print out some diagnostic text. I can, of course, just hard-code the method's name in the string, but I'd like to make the test a ...
36
2008-10-28T23:52:09Z
245,581
<p>The answers involving introspection via <code>inspect</code> and the like are reasonable. But there may be another option, depending on your situation:</p> <p>If your integration test is written with the <a href="http://docs.python.org/library/unittest.html">unittest</a> module, then you could use <code>self.id()<...
21
2008-10-29T02:09:48Z
[ "python" ]
How do I draw text at an angle using python's PIL?
245,447
<p>Using Python I want to be able to draw text at different angles using PIL.</p> <p>For example, imagine you were drawing the number around the face of a clock. The number <strong>3</strong> would appear as expected whereas <strong>12</strong> would we drawn rotated counter-clockwise 90 degrees.</p> <p>Therefore, I...
15
2008-10-29T01:04:48Z
245,837
<p>I'm not saying this is going to be easy, or that this solution will necessarily be perfect for you, but look at the documentation here:<p> <a href="http://effbot.org/imagingbook/pil-index.htm" rel="nofollow"><a href="http://effbot.org/imagingbook/pil-index.htm" rel="nofollow">http://effbot.org/imagingbook/pil-index....
2
2008-10-29T04:55:33Z
[ "python", "python-imaging-library", "imaging" ]
How do I draw text at an angle using python's PIL?
245,447
<p>Using Python I want to be able to draw text at different angles using PIL.</p> <p>For example, imagine you were drawing the number around the face of a clock. The number <strong>3</strong> would appear as expected whereas <strong>12</strong> would we drawn rotated counter-clockwise 90 degrees.</p> <p>Therefore, I...
15
2008-10-29T01:04:48Z
245,892
<p>Draw text into a temporary blank image, rotate that, then paste that onto the original image. You could wrap up the steps in a function. Good luck figuring out the exact coordinates to use - my cold-fogged brain isn't up to it right now. </p> <p>This demo writes yellow text on a slant over an image:</p> <pre...
22
2008-10-29T05:31:25Z
[ "python", "python-imaging-library", "imaging" ]
How do I draw text at an angle using python's PIL?
245,447
<p>Using Python I want to be able to draw text at different angles using PIL.</p> <p>For example, imagine you were drawing the number around the face of a clock. The number <strong>3</strong> would appear as expected whereas <strong>12</strong> would we drawn rotated counter-clockwise 90 degrees.</p> <p>Therefore, I...
15
2008-10-29T01:04:48Z
741,592
<p>It's also usefull to know our text's size in pixels before we create an Image object. I used such code when drawing graphs. Then I got no problems e.g. with alignment of data labels (the image is exactly as big as the text).</p> <pre><code>(...) img_main = Image.new("RGB", (200, 200)) font = ImageFont.load_default(...
7
2009-04-12T10:48:23Z
[ "python", "python-imaging-library", "imaging" ]
How do I draw text at an angle using python's PIL?
245,447
<p>Using Python I want to be able to draw text at different angles using PIL.</p> <p>For example, imagine you were drawing the number around the face of a clock. The number <strong>3</strong> would appear as expected whereas <strong>12</strong> would we drawn rotated counter-clockwise 90 degrees.</p> <p>Therefore, I...
15
2008-10-29T01:04:48Z
35,586,716
<p>Here is a working version, inspired by the answer, but it works without opening or saving images.</p> <p>The two images have colored background and alpha channel different from zero to show what's going on. Changing the two alpha channels from 92 to 0 will make them completely transparent.</p> <pre><code>from PIL ...
1
2016-02-23T19:44:14Z
[ "python", "python-imaging-library", "imaging" ]
Upload a file in Django and then send it somewhere else through REST?
245,725
<p>I am building a simple Django app that will use scribd to display documents. I would like to have a page where the administrator can upload documents to scribd through the website, since I need to know a few things about it before it gets to scribd. What is the best/easiest way to do this, display an upload page and...
1
2008-10-29T03:45:09Z
245,815
<p>What you want to do (at least from what I read here and on the Django documentation site) is create a <a href="http://docs.djangoproject.com/en/dev/howto/custom-file-storage/#howto-custom-file-storage" rel="nofollow">custom storage system.</a></p> <p>This should give you exactly what you need - it's the motivation ...
1
2008-10-29T04:41:23Z
[ "python", "django", "api", "rest", "scribd" ]
Upload a file in Django and then send it somewhere else through REST?
245,725
<p>I am building a simple Django app that will use scribd to display documents. I would like to have a page where the administrator can upload documents to scribd through the website, since I need to know a few things about it before it gets to scribd. What is the best/easiest way to do this, display an upload page and...
1
2008-10-29T03:45:09Z
245,821
<p>That is quite a few questions. </p> <p>Handling the file upload is pretty straight-forward with Django, see the <a href="http://docs.djangoproject.com/en/dev/topics/http/file-uploads/" rel="nofollow">File Uploads documentation</a> for examples. In short you can access the uploaded file via <code>request.FILES['file...
3
2008-10-29T04:45:06Z
[ "python", "django", "api", "rest", "scribd" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
245,797
<p>You should never favor <a href="http://docs.python.org/2/library/functions.html#zip" rel="nofollow"><code>zip</code></a> over <a href="http://docs.python.org/2/library/itertools.html#itertools.izip" rel="nofollow"><code>izip</code></a>, <code>range</code> over <code>xrange</code>, or list comprehensions over generat...
16
2008-10-29T04:28:58Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
245,816
<p>In general, don't use a generator when you need list operations, like len(), reversed(), and so on.</p> <p>There may also be times when you don't want lazy evaluation (e.g. to do all the calculation up front so you can release a resource). In that case, a list expression might be better.</p>
33
2008-10-29T04:42:05Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
246,155
<p>As you mention, "This especially makes sense for large datasets", I think this answers your question.</p> <p>If your not hitting any walls, performance-wise, I would stick to lists and standard functions. Then when you run into problems with performance make the switch.</p>
3
2008-10-29T08:50:47Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
246,481
<p>Profile, Profile, Profile.</p> <p>Profiling your code is the only way to know if what you're doing has any effect at all.</p> <p>Most usages of xrange, generators, etc are over static size, small datasets. It's only when you get to large datasets that it really makes a difference. range() vs. xrange() is mostly ju...
21
2008-10-29T11:37:31Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
246,494
<p>As far as performance is concerned, I can't think of any times that you would want to use a list over a generator.</p>
2
2008-10-29T11:44:06Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
247,527
<p>I've never found a situation where generators would hinder what you're trying to do. There are, however, plenty of instances where using generators would not help you any more than not using them.</p> <p>For example:</p> <pre><code>sorted(xrange(5)) </code></pre> <p>Does not offer any improvement over:</p> <pre>...
2
2008-10-29T16:44:36Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
255,570
<p>Regarding performance: if using psyco, lists can be quite a bit faster than generators. In the example below, lists are almost 50% faster when using psyco.full()</p> <pre><code>import psyco import time import cStringIO def time_func(func): """The amount of time it requires func to run""" start = time.clock...
5
2008-11-01T05:53:31Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
256,272
<p>You should prefer list comprehensions if you need to keep the values around for something else later and the size of your set is not too large.</p> <p>For example: you are creating a list that you will loop over several times later in your program. </p> <p>To some extent you can think of generators as a replaceme...
2
2008-11-01T23:49:09Z
[ "python", "optimization", "iterator", "generator" ]
When is not a good time to use python generators?
245,792
<p>This is rather the inverse of <a href="http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for">What can you use Python generator functions for?</a>: python generators, generator expressions, and the <code>itertools</code> module are some of my favorite features of python these days...
55
2008-10-29T04:25:02Z
26,635,939
<p><strong>Use a list instead of a generator when:</strong></p> <p>1) You need to access the data <strong>multiple</strong> times (i.e. cache the results instead of recomputing them):</p> <pre><code>for i in outer: # used once, okay to be a generator or return a list for j in inner: # used multipl...
24
2014-10-29T16:36:57Z
[ "python", "optimization", "iterator", "generator" ]
HTTP compliance testing
246,123
<p>What would you use to perform a compliance testing of an HTTP proxy? I've seen two projects so far:</p> <ul> <li><a href="http://www.web-polygraph.org/" rel="nofollow">Web Polygraph</a> (the feedback I got from a coworker is mostly negative)</li> <li><a href="http://funkload.nuxeo.com/" rel="nofollow">Funkload</a><...
1
2008-10-29T08:29:59Z
248,806
<p>Take a look here: <a href="http://www.measurement-factory.com/" rel="nofollow">http://www.measurement-factory.com/</a></p> <p>The Co-Advisor product might be what you are after. Note that this is by the same mob that created Web-Polygraph/</p>
0
2008-10-29T23:36:02Z
[ "python", "http", "testing", "standards-compliance" ]
Can I call and set the Python gettext module in a library and a module using it at the same time?
246,137
<p>Im a coding a library inluding textual feedback that I need to translate.</p> <p>I put the following lines in a _config.py module that I import everywhere in my app :</p> <pre><code>import gettext, os, sys pathname = os.path.dirname(sys.argv[0]) localdir = os.path.abspath(pathname) + "/locale" gettext.install("mes...
2
2008-10-29T08:40:36Z
246,254
<p>You can only gettext.install() once. In general it's useless for library work -- gettext.install() will only do the right thing if the module calling it is in charge of the whole program, since it will only provide you with one catalog to load from. Library code should do something akin to what Mailman does: have th...
1
2008-10-29T09:43:07Z
[ "python", "internationalization", "gettext" ]
Can I call and set the Python gettext module in a library and a module using it at the same time?
246,137
<p>Im a coding a library inluding textual feedback that I need to translate.</p> <p>I put the following lines in a _config.py module that I import everywhere in my app :</p> <pre><code>import gettext, os, sys pathname = os.path.dirname(sys.argv[0]) localdir = os.path.abspath(pathname) + "/locale" gettext.install("mes...
2
2008-10-29T08:40:36Z
398,420
<p>You can use the class based gettext api to isolate message catalogs. This is also what is recommended in the <a href="http://docs.python.org/library/gettext.html#class-based-api" rel="nofollow">python gettext documentation</a>.</p> <p>The drawback is that you, or the other dev, will have to use the gettext method o...
2
2008-12-29T19:29:16Z
[ "python", "internationalization", "gettext" ]
How can I draw a bezier curve using Python's PIL?
246,525
<p>I'm using Python's Imaging Library and I would like to draw some bezier curves. I guess I could calculate pixel by pixel but I'm hoping there is something simpler.</p>
11
2008-10-29T11:59:08Z
246,628
<p>A bezier curve isn't that hard to draw yourself. Given three points <code>A</code>, <code>B</code>, <code>C</code> you require three linear interpolations in order to draw the curve. We use the scalar <code>t</code> as the parameter for the linear interpolation:</p> <pre><code>P0 = A * t + (1 - t) * B P1 = B * t + ...
10
2008-10-29T12:39:15Z
[ "python", "python-imaging-library", "bezier", "imaging" ]
How can I draw a bezier curve using Python's PIL?
246,525
<p>I'm using Python's Imaging Library and I would like to draw some bezier curves. I guess I could calculate pixel by pixel but I'm hoping there is something simpler.</p>
11
2008-10-29T11:59:08Z
246,933
<p>You can use the <a href="http://effbot.org/zone/aggdraw-index.htm">aggdraw</a> on top of PIL, bezier curves are <a href="http://effbot.org/zone/pythondoc-aggdraw.htm#aggdraw.Path-class">supported</a>.</p> <p><strong>EDIT:</strong></p> <p>I made an example only to discover there is a bug in the <code>Path</code> cl...
7
2008-10-29T14:09:59Z
[ "python", "python-imaging-library", "bezier", "imaging" ]
How can I draw a bezier curve using Python's PIL?
246,525
<p>I'm using Python's Imaging Library and I would like to draw some bezier curves. I guess I could calculate pixel by pixel but I'm hoping there is something simpler.</p>
11
2008-10-29T11:59:08Z
2,292,690
<pre><code>def make_bezier(xys): # xys should be a sequence of 2-tuples (Bezier control points) n = len(xys) combinations = pascal_row(n-1) def bezier(ts): # This uses the generalized formula for bezier curves # http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Generalization result...
16
2010-02-18T22:23:02Z
[ "python", "python-imaging-library", "bezier", "imaging" ]
How can I draw a bezier curve using Python's PIL?
246,525
<p>I'm using Python's Imaging Library and I would like to draw some bezier curves. I guess I could calculate pixel by pixel but I'm hoping there is something simpler.</p>
11
2008-10-29T11:59:08Z
21,416,678
<p>Although bezier curveto paths don't work with Aggdraw, as mentioned by @ToniRuža, there is another way to do this in Aggdraw. The benefit of using Aggdraw instead of PIL or your own bezier functions is that Aggdraw will antialias the image making it look smoother (see pic at bottom).</p> <p><strong>Aggdraw Symbols...
3
2014-01-28T20:58:36Z
[ "python", "python-imaging-library", "bezier", "imaging" ]
How do I add tab completion to the Python shell?
246,725
<p>When starting a django application using <code>python manage.py shell</code>, I get an InteractiveConsole shell - I can use tab completion, etc.</p> <pre><code>Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more in...
55
2008-10-29T13:09:10Z
246,774
<p>I think django does something like <a href="https://docs.python.org/library/rlcompleter.html">https://docs.python.org/library/rlcompleter.html</a></p> <p>If you want to have a really good interactive interpreter have a look at <a href="http://ipython.scipy.org/">http://ipython.scipy.org/</a>.</p>
30
2008-10-29T13:21:43Z
[ "python", "shell", "interpreter" ]
How do I add tab completion to the Python shell?
246,725
<p>When starting a django application using <code>python manage.py shell</code>, I get an InteractiveConsole shell - I can use tab completion, etc.</p> <pre><code>Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more in...
55
2008-10-29T13:09:10Z
246,779
<p>I may have found a way to do it.</p> <p>Create a file .pythonrc</p> <pre><code># ~/.pythonrc # enable syntax completion try: import readline except ImportError: print("Module readline not available.") else: import rlcompleter readline.parse_and_bind("tab: complete") </code></pre> <p>then in your ....
91
2008-10-29T13:24:39Z
[ "python", "shell", "interpreter" ]
How do I add tab completion to the Python shell?
246,725
<p>When starting a django application using <code>python manage.py shell</code>, I get an InteractiveConsole shell - I can use tab completion, etc.</p> <pre><code>Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more in...
55
2008-10-29T13:09:10Z
247,513
<p>For the record, this is covered in the tutorial: <a href="http://docs.python.org/tutorial/interactive.html">http://docs.python.org/tutorial/interactive.html</a></p>
21
2008-10-29T16:39:03Z
[ "python", "shell", "interpreter" ]
How do I add tab completion to the Python shell?
246,725
<p>When starting a django application using <code>python manage.py shell</code>, I get an InteractiveConsole shell - I can use tab completion, etc.</p> <pre><code>Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more in...
55
2008-10-29T13:09:10Z
32,135,426
<p>I use ptpython. <a href="https://github.com/jonathanslenders/ptpython/" rel="nofollow">https://github.com/jonathanslenders/ptpython/</a></p> <p>ptpython is a wonderful tool autocomplete shell cmd. install ptpython is very easy,use pip tool</p> <blockquote> <p>pip install ptpython</p> </blockquote> <p><strong>an...
1
2015-08-21T08:11:38Z
[ "python", "shell", "interpreter" ]
How can I launch an instance of an application using Python?
247,724
<p>I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that in my script?</p>
11
2008-10-29T17:40:12Z
247,730
<p>os.system("open file.xls")</p>
0
2008-10-29T17:41:19Z
[ "python", "scripting", "ipc" ]
How can I launch an instance of an application using Python?
247,724
<p>I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that in my script?</p>
11
2008-10-29T17:40:12Z
247,740
<p>or </p> <pre><code>os.system("start excel.exe &lt;path/to/file&gt;") </code></pre> <p>(presuming it's in the path, and you're on windows)</p> <p>and also on Windows, just <code>start &lt;filename&gt;</code> works, too - if it's an associated extension already (as xls would be)</p>
8
2008-10-29T17:44:31Z
[ "python", "scripting", "ipc" ]
How can I launch an instance of an application using Python?
247,724
<p>I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that in my script?</p>
11
2008-10-29T17:40:12Z
247,761
<p>I like popen2 for the ability to monitor the process.</p> <pre><code>excelProcess = popen2.Popen4("start excel %s" % (excelFile)) status = excelProcess.wait() </code></pre> <p><a href="http://www.python.org/doc/2.5.2/lib/module-popen2.html" rel="nofollow">http://www.python.org/doc/2.5.2/lib/module-popen2.html</a><...
6
2008-10-29T17:50:13Z
[ "python", "scripting", "ipc" ]
How can I launch an instance of an application using Python?
247,724
<p>I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that in my script?</p>
11
2008-10-29T17:40:12Z
248,080
<p>While the <code>Popen</code> answers are reasonable for the general case, I would recommend <code>win32api</code> for this specific case, if you want to do something useful with it:</p> <p>It goes something like this:</p> <pre><code>from win32com.client import Dispatch xl = Dispatch('Excel.Application') wb = xl.Wo...
10
2008-10-29T19:22:09Z
[ "python", "scripting", "ipc" ]
How can I launch an instance of an application using Python?
247,724
<p>I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that in my script?</p>
11
2008-10-29T17:40:12Z
249,571
<p>The <strong>subprocess</strong> module intends to replace several other, older modules and functions, such as:</p> <ul> <li>os.system</li> <li>os.spawn*</li> <li>os.popen*</li> <li>popen2.*</li> <li>commands.*</li> </ul> <p>.</p> <pre><code>import subprocess process_one = subprocess.Popen(['gqview', '/home/toto/...
5
2008-10-30T08:27:03Z
[ "python", "scripting", "ipc" ]
How can I launch an instance of an application using Python?
247,724
<p>I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that in my script?</p>
11
2008-10-29T17:40:12Z
6,351,029
<p>As others have stated, I would suggest os.system. In case anyone is looking for a Mac-compatible solution, here is an example:</p> <pre><code>import os os.system("open /Applications/Safari.app") </code></pre>
1
2011-06-14T22:42:54Z
[ "python", "scripting", "ipc" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
248,066
<p>This was trivial.</p> <p>Each module has a <code>__file__</code> variable that shows its relative path from where you are right now.</p> <p>Therefore, getting a directory for the module to notify it is simple as:</p> <pre><code>os.path.dirname(__file__) </code></pre>
13
2008-10-29T19:18:15Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
248,862
<pre><code>import a_module print a_module.__file__ </code></pre> <p>Will actually give you the path to the .pyc file that was loaded, at least on Mac OS X. So I guess you can do</p> <pre><code>import os path = os.path.dirname(amodule.__file__) </code></pre> <p>You can also try</p> <pre><code>path = os.path.abspath(...
385
2008-10-29T23:57:13Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
4,431,672
<pre><code>import os path = os.path.abspath(__file__) dir_path = os.path.dirname(path) </code></pre>
12
2010-12-13T17:35:17Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
6,416,114
<p>As the other answers have said, the best way to do this is with <code>__file__</code> (demonstrated again below). However, there is an important caveat, which is that <code>__file__</code> does NOT exist if you are running the module on its own (i.e. as <code>__main__</code>).</p> <p>For example, say you have two ...
49
2011-06-20T19:05:40Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
9,759,993
<p>So I spent a fair amount of time trying to do this with py2exe The problem was to get the base folder of the script whether it was being run as a python script or as a py2exe executable. Also to have it work whether it was being run from the current folder, another folder or (this was the hardest) from the system's ...
6
2012-03-18T16:28:43Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
12,154,601
<p>There is <code>inspect</code> module in python.</p> <h2><a href="http://docs.python.org/library/inspect.html">Official documentation</a></h2> <blockquote> <p>The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, traceback...
121
2012-08-28T07:24:09Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
16,826,913
<p>I will try tackling a few variations on this question as well:</p> <ol> <li>finding the path of the called script </li> <li>finding the path of the currently executing script </li> <li>finding the directory of the called script</li> </ol> <p>(Some of these questions have been asked on SO, but have been closed as...
22
2013-05-30T02:15:40Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
25,319,974
<p>If the only caveat of using <code>__file__</code> is when current, relative directory is blank (ie, when running as a script from the same directory where the script is), then a trivial solution is:</p> <pre class="lang-py prettyprint-override"><code>import os.path mydir = os.path.dirname(__file__) or '.' full = o...
2
2014-08-15T01:22:39Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
25,344,804
<blockquote> <p>Packages support one more special attribute, <code>__path__</code>. This is initialized to be a list containing the name of the directory holding the package’s <code>__init__.py</code> before the code in that file is executed. This variable can be modified; doing so affects future searches for...
3
2014-08-16T23:04:03Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
27,934,408
<p>If you wish to do this dynamically in a "program" try this code:<br> My point is, you may not know the exact name of the module to "hardcode" it. It may be selected from a list or may not be currently running to use __file__.</p> <p>(I know, it will not work in Python 3)</p> <pre><code>global modpath modname = 'os...
0
2015-01-14T01:23:25Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
28,976,381
<p>I don't get why no one is talking about this, but to me the simplest solution is using <strong>imp.find_module("modulename")</strong> (documentation <a href="https://docs.python.org/2/library/imp.html?highlight=import#module-imp">here</a>):</p> <pre><code>import imp imp.find_module("os") </code></pre> <p>It gives ...
10
2015-03-11T00:10:44Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
30,192,316
<p>From within modules of a python package I had to refer to a file that resided in the same directory as package. Ex.</p> <pre><code>some_dir/ maincli.py top_package/ __init__.py level_one_a/ __init__.py my_lib_a.py level_two/ __init__.py hello_world.py level_one_b/ ...
0
2015-05-12T13:27:01Z
[ "python", "module", "inotify" ]
Retrieving python module path
247,770
<p>I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from.</p> <p>How do I retrieve a module's path in python?</p>
351
2008-10-29T17:52:40Z
32,026,782
<h2>Command Line Utility</h2> <p>You can tweak it to a command line utility,</p> <pre><code>python-which &lt;package name&gt; </code></pre> <p><a href="http://i.stack.imgur.com/pjVSO.png" rel="nofollow"><img src="http://i.stack.imgur.com/pjVSO.png" alt="enter image description here"></a></p> <hr> <p>Create <code>/...
1
2015-08-15T16:27:18Z
[ "python", "module", "inotify" ]
Is it possible to get the value of an item contained in Django's "changed_data" list?
247,922
<p>I have the following code in my Django application:</p> <pre><code>if 'book' in authorForm.changed_data: #Do something here... </code></pre> <p>I realize Django can tell me which values have changed in my form by utilizing the "changed_data" list object, but I'd like to know the new values of the fields that ha...
0
2008-10-29T18:38:46Z
248,200
<p>Hmm... Try this:</p> <pre><code>if authorForm.is_valid() and 'book' in authorForm.changed_data: new_value = authorForm.cleaned_data['book'] </code></pre>
2
2008-10-29T19:58:24Z
[ "python", "django" ]
Is it possible to get the value of an item contained in Django's "changed_data" list?
247,922
<p>I have the following code in my Django application:</p> <pre><code>if 'book' in authorForm.changed_data: #Do something here... </code></pre> <p>I realize Django can tell me which values have changed in my form by utilizing the "changed_data" list object, but I'd like to know the new values of the fields that ha...
0
2008-10-29T18:38:46Z
3,086,204
<p>The short answer to my original question is "No".</p>
0
2010-06-21T15:56:26Z
[ "python", "django" ]
Is there something between a normal user account and root?
248,730
<p>I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and...
3
2008-10-29T23:02:30Z
248,743
<p>There's no single user that is halfway between a "normal" user and root. You have root, and then you have users; users can have differing levels of capabilities. If you want something that's more powerful than a "normal" user but not as powerful as root, you just create a new user with the capabilities you want, but...
0
2008-10-29T23:06:28Z
[ "python", "linux", "root" ]
Is there something between a normal user account and root?
248,730
<p>I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and...
3
2008-10-29T23:02:30Z
248,756
<p>You could create and distribute a selinux policy for your application. Selinux allows the kind of fine-grained access that you need. If you can't or won't use selinux, then the daemon is the way to go.</p>
1
2008-10-29T23:10:17Z
[ "python", "linux", "root" ]
Is there something between a normal user account and root?
248,730
<p>I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and...
3
2008-10-29T23:02:30Z
248,757
<p>I would not run the application full time as root, but you might want to explore making your application setuid root, or setuid to some id that can become root using something like sudo for particular applications. You might be able to set up an account that cannot login, use setuid to change your program's id (te...
1
2008-10-29T23:10:23Z
[ "python", "linux", "root" ]
Is there something between a normal user account and root?
248,730
<p>I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and...
3
2008-10-29T23:02:30Z
248,758
<p>Your idea about the daemon has much merit, despite the complexity it introduces. As long as the actions don't require some user interface interaction <em>as root</em>, a daemon allows you to control what operations are allowed and disallowed.</p> <p>However, you can use SUDO to create a controlled compromise betwee...
7
2008-10-29T23:11:01Z
[ "python", "linux", "root" ]
Is there something between a normal user account and root?
248,730
<p>I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and...
3
2008-10-29T23:02:30Z
248,759
<p>What you want is a "Group"</p> <p>You create a group, specify that the account wanting to do the action belongs to the group, then you specify that the resource you want access to is a member of that group.</p> <p>Sometimes group management can be kind of irritating, but it should allow you to do anything you want...
3
2008-10-29T23:11:35Z
[ "python", "linux", "root" ]
Is there something between a normal user account and root?
248,730
<p>I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and...
3
2008-10-29T23:02:30Z
248,874
<p>I'm not familiar enough with Python to tell you what the necessary commands would be in that language, but you should be able to accomplish this by forking and using a pipe to communicate between the parent and child processes. Something along the lines of:</p> <ul> <li>Run the program as root via sudo or suid</li...
0
2008-10-30T00:04:26Z
[ "python", "linux", "root" ]
Is there something between a normal user account and root?
248,730
<p>I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and...
3
2008-10-29T23:02:30Z
248,882
<p>The traditional way would be to create and use a setuid helper to do whatever you need. Note that, however, properly writing a setuid helper is tricky (there are several attack vectors you have to protect against).</p> <p>The modern way would be to use a daemon (running as root, started on boot) which listens to re...
1
2008-10-30T00:08:28Z
[ "python", "linux", "root" ]
Python: using a recursive algorithm as a generator
248,830
<p>Recently I wrote a function to generate certain sequences with nontrivial constraints. The problem came with a natural recursive solution. Now it happens that, even for relatively small input, the sequences are several thousands, thus I would prefer to use my algorithm as a generator instead of using it to fill a li...
79
2008-10-29T23:45:56Z
248,854
<pre><code>def getPermutations(string, prefix=""): if len(string) == 1: yield prefix + string else: for i in xrange(len(string)): for perm in getPermutations(string[:i] + string[i+1:], prefix+string[i]): yield perm </code></pre> <p>Or without an accumulator:</p> <pr...
96
2008-10-29T23:53:47Z
[ "python", "recursion", "generator" ]
Python: using a recursive algorithm as a generator
248,830
<p>Recently I wrote a function to generate certain sequences with nontrivial constraints. The problem came with a natural recursive solution. Now it happens that, even for relatively small input, the sequences are several thousands, thus I would prefer to use my algorithm as a generator instead of using it to fill a li...
79
2008-10-29T23:45:56Z
248,857
<p>The interior call to getPermutations -- it's a generator, too.</p> <pre><code>def getPermutations(string, prefix=""): if len(string) == 1: yield prefix + string else: for i in range(len(string)): getPermutations(string[:i]+string[i+1:], prefix+string[i]) # &lt;----- </code></...
19
2008-10-29T23:54:51Z
[ "python", "recursion", "generator" ]
Python: using a recursive algorithm as a generator
248,830
<p>Recently I wrote a function to generate certain sequences with nontrivial constraints. The problem came with a natural recursive solution. Now it happens that, even for relatively small input, the sequences are several thousands, thus I would prefer to use my algorithm as a generator instead of using it to fill a li...
79
2008-10-29T23:45:56Z
252,199
<p>This avoids the <code>len(string)</code>-deep recursion, and is in general a nice way to handle generators-inside-generators:</p> <pre><code>from types import GeneratorType def flatten(*stack): stack = list(stack) while stack: try: x = stack[0].next() except StopIteration: stack...
24
2008-10-31T00:05:38Z
[ "python", "recursion", "generator" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,075
<p>Almost no problem <strong>requires</strong> a specific programming language, that's just not how things work.</p> <p>The easiest way to get a new language into an environment like yours is to start a new work project in your own time in the new language. Make it do something you need doing, and write it on your ow...
12
2008-10-30T02:04:09Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,101
<p>"Can you guys help me think of something to finally convince my boss to really learn Python and start using it on projects?"</p> <p>Nope. </p> <p>Nothing succeeds like success. Use Python. Be successful. Make people jealous. </p> <p>When asked why you're successful, you can talk about Python. Not before.</p>...
28
2008-10-30T02:12:10Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,113
<blockquote> <p>Can you guys help me think of something to finally convince my boss to really learn Python and start using it on projects?</p> </blockquote> <p>Unfortunately, the answer is no. As Harley said, no problem is going to <strong>require</strong> a specific language. The approach Harley suggested is ...
3
2008-10-30T02:21:05Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,118
<p>Take a step back, and look at your approach. "I know what I want the answer to be, but I can't find any evidence to support it." </p> <p>Despite the fact that Python is my current first choice language, I am afraid I find myself on the side of your boss! Sorry.</p> <p>I think you should open your mind and consider...
3
2008-10-30T02:23:40Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,125
<p>Sneaking a language in is often done by automating tedious manual tasks (especially dynamic/scripting languages like Python/Ruby etc). Set it up so something like deploying builds, or shuffling backups, or whatever is done with Python.</p> <p>Then casually slip in how easy it was to do, and try to spread some of th...
6
2008-10-30T02:28:20Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,143
<p>The best leverage you're likely going to have is tools and libraries; as others have pointed out, no language is <em>required</em> to solve any particular program. So let's look at Things You Can Leverage Using Python:</p> <ul> <li>Google App Engine</li> <li>SciPy</li> <li>pywinauto</li> <li>django</li> </ul> <p>...
2
2008-10-30T02:46:42Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,258
<p>Well, <a href="http://www.paulgraham.com/pypar.html" rel="nofollow">here's a view</a> of why Python programmers make better Java programmers; the concepts are much the same as for your situation.</p> <p>Essentially, people who learn a language because they want to show that they enjoy programming, like to learn new...
1
2008-10-30T04:16:21Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
249,277
<p>The language is almost never the key to success. Good programmers can be successful in a variety of languages, and you'll find successful projects in almost any language. You won't find the failures that much because those projects just go away never to be heard of again. If you're looking for a new language because...
1
2008-10-30T04:27:55Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
251,632
<p>Python got a good start in the Java world as Jython for unit testing. In fact many Java people started using it first that way. Its dynamic scripting nature makes it a great fit for unit tests. Just yesterday I was wishing I could use it or something like it for the unit tests I was writing for a VB.Net project. ...
1
2008-10-30T20:24:07Z
[ "python" ]
I need a really good reason to use Python
249,064
<p>I have been trying to make a case for using Python at my work. We use C# and ASP.NET for basically all of our development. 80% or more of our projects are web applications. It seems natural that we would look at some of the nice dynamic web languages (Ruby, Python, etc), and with things like <a href="http://en.wikip...
10
2008-10-30T01:59:48Z
37,058,004
<p>I am pretty sure (100%) that you don't need to use Python for MS Windows at least.</p> <p>In cases of other platforms you can use any language you like.</p>
0
2016-05-05T18:44:23Z
[ "python" ]
Django: Arbitrary number of unnamed urls.py parameters
249,110
<p>I have a Django model with a large number of fields and 20000+ table rows. To facilitate human readable URLs and the ability to break down the large list into arbitrary sublists, I would like to have a URL that looks like this:</p> <pre><code>/browse/&lt;name1&gt;/&lt;value1&gt;/&lt;name2&gt;/&lt;value2&gt;/ .... ...
16
2008-10-30T02:18:32Z
249,524
<p>A possibility that you might consider is matching the entire string of possible values within the url pattern portion and pull out the specific pieces within your view. As an example:</p> <pre><code>urlpatterns = patterns('', url(r'^browse/(?P&lt;match&gt;.+)/$', 'app.views.view', name='model_browse'), ) def ...
11
2008-10-30T07:52:30Z
[ "python", "django", "django-urls" ]
Django: Arbitrary number of unnamed urls.py parameters
249,110
<p>I have a Django model with a large number of fields and 20000+ table rows. To facilitate human readable URLs and the ability to break down the large list into arbitrary sublists, I would like to have a URL that looks like this:</p> <pre><code>/browse/&lt;name1&gt;/&lt;value1&gt;/&lt;name2&gt;/&lt;value2&gt;/ .... ...
16
2008-10-30T02:18:32Z
251,253
<p>I agree with Adam, but I think the pattern in urls.py should be:</p> <pre><code>... r'^browse/(?P&lt;match&gt;.+)/$' ... </code></pre> <p>The '\w' will only match 'word' characters, but the '.' will match anything.</p>
3
2008-10-30T18:32:46Z
[ "python", "django", "django-urls" ]