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
PyQt, click action on Qwidget
1,996,511
<p>I've this simple problem, I can grab the event of a click on button, but now I need to handle a click over a widget, here is part of the code:</p> <pre><code>self.widget = QtGui.QWidget(self) self.widget.setStyleSheet("QWidget { background-color: %s }" % color.name()) self.widget.setGeometry(150, 22, 50, 50) self.c...
5
2010-01-03T22:05:55Z
1,996,779
<p>See <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#connecting-signals-using-keyword-arguments" rel="nofollow">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#connecting-signals-using-keyword-arguments</a></p> <pre><code>self.widget.click.connect(self.onWidgetClick) ...
-1
2010-01-03T23:31:56Z
[ "python", "qt4", "click", "pyqt" ]
PyQt, click action on Qwidget
1,996,511
<p>I've this simple problem, I can grab the event of a click on button, but now I need to handle a click over a widget, here is part of the code:</p> <pre><code>self.widget = QtGui.QWidget(self) self.widget.setStyleSheet("QWidget { background-color: %s }" % color.name()) self.widget.setGeometry(150, 22, 50, 50) self.c...
5
2010-01-03T22:05:55Z
2,002,617
<p>Use mousePressEvent instead.</p> <pre><code>import sys from PyQt4.QtGui import QWidget, QApplication class MyWidget(QWidget): def mousePressEvent(self, event): print "clicked" app = QApplication(sys.argv) widget = MyWidget() widget.show() app.exec_() </code></pre>
5
2010-01-04T22:07:45Z
[ "python", "qt4", "click", "pyqt" ]
PyQt, click action on Qwidget
1,996,511
<p>I've this simple problem, I can grab the event of a click on button, but now I need to handle a click over a widget, here is part of the code:</p> <pre><code>self.widget = QtGui.QWidget(self) self.widget.setStyleSheet("QWidget { background-color: %s }" % color.name()) self.widget.setGeometry(150, 22, 50, 50) self.c...
5
2010-01-03T22:05:55Z
29,253,724
<p>you can try this i found this from <a href="http://popdevelop.com/2010/05/an-example-on-how-to-make-qlabel-clickable/" rel="nofollow">this blog site's comment box from Jared Glass</a> It was working fine for me </p> <pre><code>self.widget.mouseReleaseEvent=self.myfunction </code></pre> <p>or </p> <pre><code>self....
3
2015-03-25T10:57:24Z
[ "python", "qt4", "click", "pyqt" ]
Python string function isidentifier()
1,996,517
<p>I'm working through a Python 3 book and came across the string function isidentifier(). The text description is "s.isidentifier() : Returns True if s is non empty and is a valid identifier". I tested it in the Python Shell like this:</p> <pre><code>&gt;&gt;&gt; s = 'test' &gt;&gt;&gt; s.isidentifier() True &gt;&g...
2
2010-01-03T22:07:05Z
1,996,522
<blockquote> <p>Returns True if s is non empty and is a <strong>valid</strong> identifier.</p> </blockquote> <p>What they mean is that s <em>could</em> be valid as an identifier. It doesn't imply that it is an identifier that's in use.</p> <p>Your first example is showing the same thing: 'test' (what <code>isidenti...
9
2010-01-03T22:09:02Z
[ "python", "string" ]
Python string function isidentifier()
1,996,517
<p>I'm working through a Python 3 book and came across the string function isidentifier(). The text description is "s.isidentifier() : Returns True if s is non empty and is a valid identifier". I tested it in the Python Shell like this:</p> <pre><code>&gt;&gt;&gt; s = 'test' &gt;&gt;&gt; s.isidentifier() True &gt;&g...
2
2010-01-03T22:07:05Z
1,996,535
<p>"isidentifier" doesn't say anything about the "variable" the string being tested is referenced by. So</p> <pre><code>'blah'.isidentifier() </code></pre> <p>is identical to</p> <pre><code>s = 'blah' s.isidentifier() </code></pre> <p>In Python, it's never (or rarely) about the "variable" (Python doesn't have vari...
5
2010-01-03T22:13:18Z
[ "python", "string" ]
Python string function isidentifier()
1,996,517
<p>I'm working through a Python 3 book and came across the string function isidentifier(). The text description is "s.isidentifier() : Returns True if s is non empty and is a valid identifier". I tested it in the Python Shell like this:</p> <pre><code>&gt;&gt;&gt; s = 'test' &gt;&gt;&gt; s.isidentifier() True &gt;&g...
2
2010-01-03T22:07:05Z
1,996,551
<p>Python doesn't have "variables". It is more helpful to think in terms of <em>objects</em>.</p> <p><code>'blah'</code> definitely exists at the time <code>'blah'.isidentifier()</code> is called (after all it means that "call <code>isidentifier()</code> method of the string object <code>'blah'</code>").</p> <p>So i...
4
2010-01-03T22:16:19Z
[ "python", "string" ]
Retrieving the output of subprocess.call()
1,996,518
<p>How can I get the output of a process run using subprocess.call()?</p> <p>Passing a StringIO.StringIO object to stdout gives this error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subpro...
121
2010-01-03T22:07:05Z
1,996,540
<p>Output from <code>subprocess.call()</code> should only be redirected to files.</p> <p>You should use <code>subprocess.Popen()</code> instead. Then you can pass <code>subprocess.PIPE</code> for the stderr, stdout, and/or stdin parameters and read from the pipes by using the <code>communicate()</code> method:</p> <p...
81
2010-01-03T22:13:40Z
[ "python", "pipe", "subprocess", "stringio" ]
Retrieving the output of subprocess.call()
1,996,518
<p>How can I get the output of a process run using subprocess.call()?</p> <p>Passing a StringIO.StringIO object to stdout gives this error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subpro...
121
2010-01-03T22:07:05Z
3,247,271
<p>I recently just figured out how to do this, and here's some example code from a current project of mine:</p> <pre><code>#Getting the random picture. #First find all pictures: import shlex, subprocess cmd = 'find ../Pictures/ -regex ".*\(JPG\|NEF\|jpg\)" ' #cmd = raw_input("shell:") args = shlex.split(cmd) output,er...
22
2010-07-14T14:42:34Z
[ "python", "pipe", "subprocess", "stringio" ]
Retrieving the output of subprocess.call()
1,996,518
<p>How can I get the output of a process run using subprocess.call()?</p> <p>Passing a StringIO.StringIO object to stdout gives this error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subpro...
121
2010-01-03T22:07:05Z
8,700,414
<p>If you have Python version >= 2.7, you can use <a href="http://docs.python.org/library/subprocess.html#subprocess.check_output">subprocess.check_output</a> which basically does exactly what you want (it returns standard output as string).</p> <p>As commented below you can find sample code and a more detailed explan...
115
2012-01-02T11:45:57Z
[ "python", "pipe", "subprocess", "stringio" ]
Retrieving the output of subprocess.call()
1,996,518
<p>How can I get the output of a process run using subprocess.call()?</p> <p>Passing a StringIO.StringIO object to stdout gives this error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subpro...
121
2010-01-03T22:07:05Z
21,000,308
<p>I have the following solution. It captures the exit code, the stdout, and the stderr too of the executed external command:</p> <pre><code>import shlex from subprocess import Popen, PIPE def get_exitcode_stdout_stderr(cmd): """ Execute the external command and get its exitcode, stdout and stderr. """ ...
26
2014-01-08T15:50:06Z
[ "python", "pipe", "subprocess", "stringio" ]
Retrieving the output of subprocess.call()
1,996,518
<p>How can I get the output of a process run using subprocess.call()?</p> <p>Passing a StringIO.StringIO object to stdout gives this error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subpro...
121
2010-01-03T22:07:05Z
32,413,478
<p>In <code>Ipython</code> shell:</p> <pre><code>In [8]: import subprocess In [9]: s=subprocess.check_output(["echo", "Hello World!"]) In [10]: s Out[10]: 'Hello World!\n' </code></pre> <p>Based on sargue's answer. Credit to sargue.</p>
3
2015-09-05T13:14:48Z
[ "python", "pipe", "subprocess", "stringio" ]
Retrieving the output of subprocess.call()
1,996,518
<p>How can I get the output of a process run using subprocess.call()?</p> <p>Passing a StringIO.StringIO object to stdout gives this error:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subpro...
121
2010-01-03T22:07:05Z
34,873,354
<p>For python 3.5+ it is recommended that you use the <a href="https://docs.python.org/3/library/subprocess.html#subprocess.run">run function from the subprocess module</a>. This returns a <code>CompletedProcess</code> object, from which you can easily obtain the output as well as return code.</p> <pre><code>from subp...
7
2016-01-19T09:44:30Z
[ "python", "pipe", "subprocess", "stringio" ]
How can I get the depth of a jpg file?
1,996,577
<p>I want to retrieve the bit depth for a jpeg file using Python.</p> <p>Using the Python Imaging Library:</p> <pre><code>import Image data = Image.open('file.jpg') print data.depth </code></pre> <p>However, this gives me a depth of 8 for an obviously 24-bit image. Am I doing something wrong? Is there some way to do...
4
2010-01-03T22:24:09Z
1,996,592
<p>Jpeg files don't <em>have</em> bit depth in the same manner as GIF or PNG files. The transform used to create the Jpeg data renders a continuous color spectrum on decompression.</p>
5
2010-01-03T22:31:22Z
[ "python", "jpeg", "imaging" ]
How can I get the depth of a jpg file?
1,996,577
<p>I want to retrieve the bit depth for a jpeg file using Python.</p> <p>Using the Python Imaging Library:</p> <pre><code>import Image data = Image.open('file.jpg') print data.depth </code></pre> <p>However, this gives me a depth of 8 for an obviously 24-bit image. Am I doing something wrong? Is there some way to do...
4
2010-01-03T22:24:09Z
1,996,609
<p>I don't see the <code>depth</code> attribute documented anywhere in the <a href="http://www.pythonware.com/library/pil/handbook/index.htm">Python Imaging Library handbook</a>. However, it looks like only a limited number of <a href="http://www.pythonware.com/library/pil/handbook/concepts.htm">modes</a> are supporte...
7
2010-01-03T22:35:40Z
[ "python", "jpeg", "imaging" ]
How can I get the depth of a jpg file?
1,996,577
<p>I want to retrieve the bit depth for a jpeg file using Python.</p> <p>Using the Python Imaging Library:</p> <pre><code>import Image data = Image.open('file.jpg') print data.depth </code></pre> <p>However, this gives me a depth of 8 for an obviously 24-bit image. Am I doing something wrong? Is there some way to do...
4
2010-01-03T22:24:09Z
1,996,610
<p>PIL is reporting bit depth per "band". I don't actually see <code>depth</code> as a documented property in the PIL docs, however, I think you want this:</p> <pre><code>data.depth * len(data.getbands()) </code></pre> <p>Or better yet:</p> <pre><code>data.mode </code></pre> <p>See <a href="http://www.pythonware.co...
3
2010-01-03T22:35:46Z
[ "python", "jpeg", "imaging" ]
How can I get the depth of a jpg file?
1,996,577
<p>I want to retrieve the bit depth for a jpeg file using Python.</p> <p>Using the Python Imaging Library:</p> <pre><code>import Image data = Image.open('file.jpg') print data.depth </code></pre> <p>However, this gives me a depth of 8 for an obviously 24-bit image. Am I doing something wrong? Is there some way to do...
4
2010-01-03T22:24:09Z
1,996,653
<p>I was going to say that JPG images are 24 bit by definition. They normally consist of three 8 bit colour channels, one for each of red, green and blue making 24 bits per pixel. However, I've just found <a href="http://www.connectedphotographer.com/issues/issue200512/00001686001.html" rel="nofollow">this page</a> whi...
0
2010-01-03T22:48:01Z
[ "python", "jpeg", "imaging" ]
How to get a Blob size? (Python Google App Engine)
1,996,591
<p><a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#Blob" rel="nofollow">http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#Blob</a></p>
2
2010-01-03T22:31:19Z
1,996,616
<p>Try <code>blob.getSize()</code></p>
-1
2010-01-03T22:37:10Z
[ "python", "google-app-engine", "blob" ]
How to get a Blob size? (Python Google App Engine)
1,996,591
<p><a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#Blob" rel="nofollow">http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#Blob</a></p>
2
2010-01-03T22:31:19Z
1,996,851
<p><code>{{ theblob|length }}</code> if you're using a Django template (as you seem to indicate in a comment, although you give absolutely no indication of this in your question -- I suggest editing the question to add that crucial bit of info!-).</p>
3
2010-01-04T00:04:08Z
[ "python", "google-app-engine", "blob" ]
Reference function or create a new function that only calls another?
1,996,680
<pre><code>def a(something): return something*something #Case I - referencing b = a #Case II - creating a new function to call the first def b(something): return a(something) </code></pre> <p>Which is better style? Are there drawbacks to either?</p>
1
2010-01-03T22:58:04Z
1,996,683
<p>First doesn't generate a new function, should be better.</p>
0
2010-01-03T22:59:41Z
[ "python", "function", "coding-style" ]
Reference function or create a new function that only calls another?
1,996,680
<pre><code>def a(something): return something*something #Case I - referencing b = a #Case II - creating a new function to call the first def b(something): return a(something) </code></pre> <p>Which is better style? Are there drawbacks to either?</p>
1
2010-01-03T22:58:04Z
1,996,691
<p>Function call creates overhead. Case I is faster. Case II creates new function unrelated function.</p> <p>Why would you need Case II?</p>
0
2010-01-03T23:02:13Z
[ "python", "function", "coding-style" ]
Reference function or create a new function that only calls another?
1,996,680
<pre><code>def a(something): return something*something #Case I - referencing b = a #Case II - creating a new function to call the first def b(something): return a(something) </code></pre> <p>Which is better style? Are there drawbacks to either?</p>
1
2010-01-03T22:58:04Z
1,996,704
<p>Depends on what you need.</p> <pre><code>def a(something): return something*something b = a def a(something): return something+something &gt;&gt;&gt; b(3) 9 &gt;&gt;&gt; a(3) 7 </code></pre> <p>Whereas if you did:</p> <pre><code>b = lambda x:a(x) </code></pre> <p>b and a will always returns the same</...
5
2010-01-03T23:06:21Z
[ "python", "function", "coding-style" ]
Reference function or create a new function that only calls another?
1,996,680
<pre><code>def a(something): return something*something #Case I - referencing b = a #Case II - creating a new function to call the first def b(something): return a(something) </code></pre> <p>Which is better style? Are there drawbacks to either?</p>
1
2010-01-03T22:58:04Z
1,996,848
<p><code>b = a</code> means calls to <code>b</code> will be faster (no overhead), but introspection (e.g. <code>help(b)</code>) will show the name <code>a</code>, and <code>a</code>'s docstring. Unless the latter issues are a killer for your specific application (some kind of tutorial, for example), the speed advantag...
2
2010-01-04T00:00:15Z
[ "python", "function", "coding-style" ]
Error in imitating memoize() from django.utils.functional.py
1,997,094
<pre><code>def a(): print 'aa' def b(): print 'bb' def c(*x): print x def d(x,y): c(*(x+y)) d(a,b) Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 15, in &lt;module&gt; d(a,b) File "D:\zjm_code\mysite\zjmbooks\a.py", line 13, in d c(*(x+y)) TypeError: uns...
0
2010-01-04T01:33:19Z
1,997,115
<p>Your code (in <code>x+y</code>, where <code>x</code> is <code>a</code> and <code>y</code> is <code>b</code>) is trying to sum two functions (instead of calling them and summing their results, for example): function objects cannot be summed, so your code raises an exeption.</p> <p>The code you quote, in <code>args+m...
3
2010-01-04T01:39:59Z
[ "python", "caching" ]
How to get something to appear on every page in Django?
1,997,109
<p>I'm curious as to the best-practise way to handle having something appear on every page, or on a number of pages without having to assign the data manually to every page like so:</p> <pre><code># views.py def page0(request): return render_to_response( "core/index.html", { "locality"...
3
2010-01-04T01:38:00Z
1,997,112
<p>use inheritance in the templating engine:</p> <p>have a base.html that includes the common code:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &...
3
2010-01-04T01:39:50Z
[ "python", "django" ]
How to get something to appear on every page in Django?
1,997,109
<p>I'm curious as to the best-practise way to handle having something appear on every page, or on a number of pages without having to assign the data manually to every page like so:</p> <pre><code># views.py def page0(request): return render_to_response( "core/index.html", { "locality"...
3
2010-01-04T01:38:00Z
1,997,121
<p>Middleware is one option or your could write a custom <a href="http://docs.djangoproject.com/en/1.1/howto/custom-template-tags/#howto-custom-template-tags" rel="nofollow">template tag</a>.</p>
2
2010-01-04T01:41:34Z
[ "python", "django" ]
How to get something to appear on every page in Django?
1,997,109
<p>I'm curious as to the best-practise way to handle having something appear on every page, or on a number of pages without having to assign the data manually to every page like so:</p> <pre><code># views.py def page0(request): return render_to_response( "core/index.html", { "locality"...
3
2010-01-04T01:38:00Z
1,997,127
<p>You want a <a href="http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/">context processor</a>. The data they generate is included in every context created as a <code>RequestContext</code>. They are perfect for this.</p> <p>Combined with base templates that show common things, you ca...
16
2010-01-04T01:43:48Z
[ "python", "django" ]
How to get something to appear on every page in Django?
1,997,109
<p>I'm curious as to the best-practise way to handle having something appear on every page, or on a number of pages without having to assign the data manually to every page like so:</p> <pre><code># views.py def page0(request): return render_to_response( "core/index.html", { "locality"...
3
2010-01-04T01:38:00Z
1,997,132
<p>To do exactly what you request, I'd simply define a function:</p> <pre><code>def foobar(req): return render_to_response( "core/index.html", { "locality": getCityForm(req.user), }, context_instance=RequestContext(req) ) </code></pre> <p>put it in some module <code...
0
2010-01-04T01:45:17Z
[ "python", "django" ]
Can't find thread.py
1,997,244
<p>What does this code mean?</p> <pre><code>try: import thread except ImportError: del _sys.modules[__name__]#why raise </code></pre> <p>But I can't find thread.py.</p> <p>why,<code>del _sys.modules[__name__]</code></p>
2
2010-01-04T02:37:37Z
1,997,251
<p>That code from Python's <code>threading.py</code> is trying to load the C implementation of the <code>thread</code> module. If it fails (for some reason this hasn't been compiled, as it would be with all Python distributions) then it deletes itself from the list of modules so that <code>threading</code> doesn't sho...
5
2010-01-04T02:40:15Z
[ "python" ]
Can't find thread.py
1,997,244
<p>What does this code mean?</p> <pre><code>try: import thread except ImportError: del _sys.modules[__name__]#why raise </code></pre> <p>But I can't find thread.py.</p> <p>why,<code>del _sys.modules[__name__]</code></p>
2
2010-01-04T02:37:37Z
1,997,255
<p>Must be some custom logic - keeping track of what is imported and where. In regular Python 3.1 this standalone code does not work:</p> <pre><code>&gt;&gt;&gt; try: import thread except: del _sys.modules[__name__] raise Traceback (most recent call last): File "&lt;pyshell#10&gt;", line 4, in &lt;modul...
0
2010-01-04T02:41:30Z
[ "python" ]
Am I using the webbrowser.open() wrong, or does it not work as advertised? (Python)
1,997,327
<p>Given this python code:</p> <pre><code>import webbrowser webbrowser.open("http://slashdot.org",new=0) webbrowser.open("http://cnn.com",new=0) </code></pre> <p>I would expect a browser to open up, load the first website, then load the second website <em>in the same window</em>. However, it opens up in a new window...
2
2010-01-04T03:09:26Z
1,997,349
<p>Note that the documentation specifically avoids guarantees with the language <em>if possible</em>: <a href="http://docs.python.org/library/webbrowser.html#webbrowser.open" rel="nofollow">http://docs.python.org/library/webbrowser.html#webbrowser.open</a></p> <p>Most browser settings by default specify tab behavior a...
2
2010-01-04T03:16:38Z
[ "python" ]
How does Gedit expose its api to python for plugins?
1,997,427
<p>I'm starting a medium (academic) project in C++ for which I need users to be able to write small scripts, which interact directly with the main program. My first thought as an aproach to this was to make something like Gedit does with it's plugins (in fact I thought about it because it is something very similar to w...
2
2010-01-04T03:53:25Z
1,997,438
<p>Fortunately, gedit's plugin framework can be used. You could use <a href="http://git.dronelabs.com/ethos/about/" rel="nofollow">Ethos</a>, which is the same plugin framework gedit uses, only without gedit.</p>
3
2010-01-04T03:57:54Z
[ "c++", "python", "plugins", "gedit" ]
Find which python modules are being imported
1,997,449
<p>What's an easy way of finding all the python modules from a particular package that are being used in an application?</p>
33
2010-01-04T04:01:56Z
1,997,461
<p><code>sys.modules</code> is a dictionary mapping module names to modules. You can examine its keys to see imported modules.</p>
29
2010-01-04T04:07:10Z
[ "python", "package" ]
Find which python modules are being imported
1,997,449
<p>What's an easy way of finding all the python modules from a particular package that are being used in an application?</p>
33
2010-01-04T04:01:56Z
1,997,465
<p>You could use <code>python -v</code>, which will emit messages about <em>every</em> imported module:</p> <pre><code>$ echo 'print "hello world"' &gt; helo.py $ python -v helo.py # installing zipimport hook import zipimport # builtin # installed zipimport hook # /System/Library/Frameworks/Python.framework/Versions/2...
27
2010-01-04T04:09:47Z
[ "python", "package" ]
Find which python modules are being imported
1,997,449
<p>What's an easy way of finding all the python modules from a particular package that are being used in an application?</p>
33
2010-01-04T04:01:56Z
1,997,472
<p>I think <a href="http://docs.python.org/library/modulefinder.html" rel="nofollow">modulefinder</a> is what you're looking for. You can use <code>modulefinder.py</code> directly, running it as a script as is described there, or you can <a href="http://docs.python.org/library/modulefinder.html#example-usage-of-modulef...
1
2010-01-04T04:11:53Z
[ "python", "package" ]
Find which python modules are being imported
1,997,449
<p>What's an easy way of finding all the python modules from a particular package that are being used in an application?</p>
33
2010-01-04T04:01:56Z
1,997,473
<p>A real simple method is to delete all .pyc files from the package or folder, and then run the application. Once you've played a bit, do a directory listing and see which files have .pyc files now. Those are modules which were imported by the application.</p> <p>(Note: the <code>__main__</code> module, whichever ...
0
2010-01-04T04:15:02Z
[ "python", "package" ]
Sanitizing user-provided SQL with Python?
1,997,468
<p>I'm working on a small app which will help browse the data generated by <a href="http://wolever.net/~wolever/wiki/vim-logging" rel="nofollow">vim-logging</a>, and I'd like to allow people to run arbitrary SQL queries against the datasets.</p> <p>How can I do that safely?</p> <p>For example, I'd like to let someone...
1
2010-01-04T04:10:09Z
1,997,477
<p>Allowing expressive power while preventing destruction is a difficult job. If you let them enter "SELECT .." themselves, you need to prevent them from entering "DELETE .." instead. You can require the statement to begin with "SELECT", but then you also have to be sure it doesn't contain "; DELETE" somewhere in the...
3
2010-01-04T04:16:48Z
[ "python", "sql" ]
Sanitizing user-provided SQL with Python?
1,997,468
<p>I'm working on a small app which will help browse the data generated by <a href="http://wolever.net/~wolever/wiki/vim-logging" rel="nofollow">vim-logging</a>, and I'd like to allow people to run arbitrary SQL queries against the datasets.</p> <p>How can I do that safely?</p> <p>For example, I'd like to let someone...
1
2010-01-04T04:10:09Z
1,997,481
<p>In MySQL, you can create a <a href="http://dev.mysql.com/doc/refman/5.1/en/adding-users.html" rel="nofollow">limited user</a> (create new user and grant limited access), which can only access certain table.</p>
2
2010-01-04T04:18:10Z
[ "python", "sql" ]
Sanitizing user-provided SQL with Python?
1,997,468
<p>I'm working on a small app which will help browse the data generated by <a href="http://wolever.net/~wolever/wiki/vim-logging" rel="nofollow">vim-logging</a>, and I'd like to allow people to run arbitrary SQL queries against the datasets.</p> <p>How can I do that safely?</p> <p>For example, I'd like to let someone...
1
2010-01-04T04:10:09Z
1,997,532
<p>Consider using SQLAlchemy. While SQLAlchemy is arguably the greatest Object Relational Mapper ever, you certainly don't need to use any of the ORM stuff to take advantage of all of the great Python/SQL work that's been done.</p> <p>As the introductory documentation suggests:</p> <blockquote> <p>Most importantly...
0
2010-01-04T04:38:25Z
[ "python", "sql" ]
Sanitizing user-provided SQL with Python?
1,997,468
<p>I'm working on a small app which will help browse the data generated by <a href="http://wolever.net/~wolever/wiki/vim-logging" rel="nofollow">vim-logging</a>, and I'd like to allow people to run arbitrary SQL queries against the datasets.</p> <p>How can I do that safely?</p> <p>For example, I'd like to let someone...
1
2010-01-04T04:10:09Z
12,810,497
<p>Do this:</p> <pre><code>cmd = "update people set name=%s where id=%s" curs.execute(cmd, (name, id)) </code></pre> <p>Note that the placeholder syntax depends on the database you are using.</p> <p>Source and more info here:</p> <p><a href="http://bobby-tables.com/python.html" rel="nofollow">http://bobby-tables.co...
3
2012-10-10T00:56:00Z
[ "python", "sql" ]
Qt Python Combo-Box "currentIndexChanged" firing twice
1,997,478
<p>I have a combo, which is showing some awkward behavior. Given a list of options from the combo-box, the user should pick the name of a city clicking with the mouse. Here is the code:</p> <pre><code>QtCore.QObject.connect(self.comboCity, QtCore.SIGNAL("currentIndexChanged(QString)"), self.checkChosenCity) ...
0
2010-01-04T04:17:20Z
1,997,807
<p>Thanks Eli..</p> <p>Here is what I have:</p> <pre><code>combo1 : [customernames] - pick a customer. combo2 : [cityList] - pick a city for the chosen customer. combo3 : [emploeeList] - load employees for that city, given the chosen customer. </code></pre> <p>What I find out is that, even when no city is chosen, th...
0
2010-01-04T06:25:30Z
[ "python", "qt", "combobox", "pyqt" ]
Qt Python Combo-Box "currentIndexChanged" firing twice
1,997,478
<p>I have a combo, which is showing some awkward behavior. Given a list of options from the combo-box, the user should pick the name of a city clicking with the mouse. Here is the code:</p> <pre><code>QtCore.QObject.connect(self.comboCity, QtCore.SIGNAL("currentIndexChanged(QString)"), self.checkChosenCity) ...
0
2010-01-04T04:17:20Z
3,883,230
<p>I had exactly the same problem. After some debugging it turned out that using </p> <p>currentIndexChanged(int)</p> <p>instead of</p> <p>currentIndexChanged(QString)</p> <p>fixed it for me.</p> <p>It still don't understand why the former fires twice.</p>
0
2010-10-07T15:27:46Z
[ "python", "qt", "combobox", "pyqt" ]
Determining the number of possible combinations
1,997,614
<p>I'm trying to figure out how many possible ways there are to combine various elements form this string.</p> <pre><code>"{Hello|Hi|Hey} {world|earth}{!|.|?}" </code></pre> <p>Where one item (separated by a pipe/|) is selected at random from each group ({}) and combined into a single string.</p> <p>So the above "te...
1
2010-01-04T05:11:19Z
1,997,624
<p>Well, there are 3 x 2 x 3 = 18 combinations in your first example.</p> <p>Your second example is 3 x 4 x 2 x 3 = 72 combinations. </p> <p>I'm not entirely sure what you mean by <code>{a|b}|{c|d}</code> though, I'm assuming you mean pick one of either (a or b) or (c or d), which is 4 choices. </p> <p>You might wan...
6
2010-01-04T05:17:29Z
[ "python", "math", "statistics", "combinatorics" ]
Determining the number of possible combinations
1,997,614
<p>I'm trying to figure out how many possible ways there are to combine various elements form this string.</p> <pre><code>"{Hello|Hi|Hey} {world|earth}{!|.|?}" </code></pre> <p>Where one item (separated by a pipe/|) is selected at random from each group ({}) and combined into a single string.</p> <p>So the above "te...
1
2010-01-04T05:11:19Z
1,997,673
<p>The problem breaks down to two simple sub-problems:</p> <ol> <li>count how many combinations are within braces and separated within vbars, for each braces pair</li> <li>multiply those numbers</li> </ol> <p>So for <code>1</code> I'd go with a plain regular expression + looping approach:</p> <pre><code>import re d...
0
2010-01-04T05:38:30Z
[ "python", "math", "statistics", "combinatorics" ]
sharing objects between module in GAE
1,997,663
<p>To share a state(e.g. user) between a module in django people sometime use thread local storage, but as google app engine follows CGI standard and keeps state of a request in os.environ , can I share objects between two modules just by setting it e.g.</p> <p>mod1.my_data = {} and now any other module can get handle...
1
2010-01-04T05:37:01Z
1,997,676
<p>Later requests that happen to be served on the same process (you can't control that) would access just the same <code>mod1.my_data</code> object (unless you take pains to reassign it as a fresh object at the start of each request, of course).</p>
0
2010-01-04T05:40:42Z
[ "python", "google-app-engine" ]
Faster method of reading screen pixel in Python than PIL?
1,997,678
<p>Currently I'm using a pixel reader via AutoItv3 to perform some actions in a program that is running direct X; A game. Right now the program works fine but as an exercise I've been rewriting it in python. Right now I can do:</p> <pre><code>import ImageGrab # Part of PIL image = ImageGrab.grab() #Define an ar...
7
2010-01-04T05:41:27Z
1,997,747
<p>You might be able to do it via SDL (?). Based on <a href="http://stackoverflow.com/questions/1934151/direct-screen-pixel-framebuffer-access">this question</a>, SDL can access the screen. And it has python bindings.</p> <p>Might be worth a shot? If it worked it would certainly be faster than doing a full screen capt...
3
2010-01-04T06:04:42Z
[ "python", "windows", "winapi", "directx", "python-imaging-library" ]
Faster method of reading screen pixel in Python than PIL?
1,997,678
<p>Currently I'm using a pixel reader via AutoItv3 to perform some actions in a program that is running direct X; A game. Right now the program works fine but as an exercise I've been rewriting it in python. Right now I can do:</p> <pre><code>import ImageGrab # Part of PIL image = ImageGrab.grab() #Define an ar...
7
2010-01-04T05:41:27Z
1,997,875
<p>This is the PIL's grabscreen source, Its does not accept any parameters, and Its grab the whole screen and convert it to bitmap.</p> <pre><code>PyImaging_GrabScreenWin32(PyObject* self, PyObject* args) { int width, height; HBITMAP bitmap; BITMAPCOREHEADER core; HDC screen, screen_copy; PyObject*...
11
2010-01-04T06:45:54Z
[ "python", "windows", "winapi", "directx", "python-imaging-library" ]
Faster method of reading screen pixel in Python than PIL?
1,997,678
<p>Currently I'm using a pixel reader via AutoItv3 to perform some actions in a program that is running direct X; A game. Right now the program works fine but as an exercise I've been rewriting it in python. Right now I can do:</p> <pre><code>import ImageGrab # Part of PIL image = ImageGrab.grab() #Define an ar...
7
2010-01-04T05:41:27Z
1,998,663
<p>Comment on S.Mark's solution: user32 library is already loaded by windll into windll.user32, so instead of the dc = ... line you can do:</p> <pre><code>def getpixel(x,y): return gdi.GetPixel(windll.user32.GetDC(0),x,y) </code></pre> <p>...or preferably:</p> <pre><code>dc= windll.user32.GetDC(0) </code></pre>
7
2010-01-04T10:25:21Z
[ "python", "windows", "winapi", "directx", "python-imaging-library" ]
Faster method of reading screen pixel in Python than PIL?
1,997,678
<p>Currently I'm using a pixel reader via AutoItv3 to perform some actions in a program that is running direct X; A game. Right now the program works fine but as an exercise I've been rewriting it in python. Right now I can do:</p> <pre><code>import ImageGrab # Part of PIL image = ImageGrab.grab() #Define an ar...
7
2010-01-04T05:41:27Z
39,221,931
<p>It's an old question, but it ranks quite highly on Google when searching for Python screen grab methods, so I think it might be useful to mention that the ImageGrab module now supports grabbing a region of the screen:</p> <pre><code>PIL.ImageGrab.grab(bbox=None) Parameters: bbox – What region to copy. Default is ...
0
2016-08-30T07:59:49Z
[ "python", "windows", "winapi", "directx", "python-imaging-library" ]
Alternative pygame resources
1,997,679
<p>I have been trying to access the pygame website for a few weeks now, and I can't get to it. I doubt it's down, so I have to conclude that it's blocked because I am in China. I have no idea why. Anyways, I want the pygame documentation, but all the download links I fond lead back to pygame.org (which I does not even ...
3
2010-01-04T05:41:35Z
1,997,724
<p>I'll upload the pygame source here <a href="http://www.cse.unsw.edu.au/~cma/pygame-1.9.1release.zip">http://www.cse.unsw.edu.au/~cma/pygame-1.9.1release.zip</a></p> <p>Unzip it and there's a folder called 'docs' all the documentation is in there. </p>
16
2010-01-04T05:54:31Z
[ "python", "pygame" ]
Alternative pygame resources
1,997,679
<p>I have been trying to access the pygame website for a few weeks now, and I can't get to it. I doubt it's down, so I have to conclude that it's blocked because I am in China. I have no idea why. Anyways, I want the pygame documentation, but all the download links I fond lead back to pygame.org (which I does not even ...
3
2010-01-04T05:41:35Z
2,748,990
<p><a href="http://pygame.seul.org/news.html" rel="nofollow">Here is Seul mirror</a> maybe it will work :), if not you can always install any Linux on VM, and than download PyGame from repos.</p>
0
2010-05-01T05:16:03Z
[ "python", "pygame" ]
Pygame error: display surface quit: Why?
1,997,710
<p>Sorry if this question is dumb, but I am writing from China and for some unfathomable reason a lot of websites having to do with pygame are blocked. I can't access pygame.org, I have not been able to download the docs or even look at message boards having to do with pygame! WEIRD!</p> <p>Anyways, I am a pygame newb...
2
2010-01-04T05:49:03Z
1,999,941
<p>From <a href="http://archives.seul.org/pygame/users/Nov-2006/msg00236.html" rel="nofollow">http://archives.seul.org/pygame/users/Nov-2006/msg00236.html</a> :</p> <p>On Thu, 2006-11-30 at 21:27 -0300, Nicolas Bischof wrote:</p> <blockquote> <p>pygame.error: display Surface quit what does that mean?, i can't fix...
0
2010-01-04T14:43:37Z
[ "python", "pygame", "documentation" ]
Pygame error: display surface quit: Why?
1,997,710
<p>Sorry if this question is dumb, but I am writing from China and for some unfathomable reason a lot of websites having to do with pygame are blocked. I can't access pygame.org, I have not been able to download the docs or even look at message boards having to do with pygame! WEIRD!</p> <p>Anyways, I am a pygame newb...
2
2010-01-04T05:49:03Z
4,317,744
<p>I had similar problem and discovered that Surface objects don't like to be deepcopied. When I used copy.deepcopy() on such object and then accessed the copy, I got that strange error message (without calling pygame.quit()). Maybe you experience similar behavior?</p>
9
2010-11-30T19:37:39Z
[ "python", "pygame", "documentation" ]
Pygame error: display surface quit: Why?
1,997,710
<p>Sorry if this question is dumb, but I am writing from China and for some unfathomable reason a lot of websites having to do with pygame are blocked. I can't access pygame.org, I have not been able to download the docs or even look at message boards having to do with pygame! WEIRD!</p> <p>Anyways, I am a pygame newb...
2
2010-01-04T05:49:03Z
9,521,984
<p>I had a similar problem in a very simple piece of code:</p> <pre><code> import sys, pygame pygame.init() size = width, height = 640, 480 speed = [2, 2] black = 0, 0, 0 screen = pygame.display.set_mode(size) ball = pygame.image.load("Golfball.png") ballrect = ball.get_rect() whil...
1
2012-03-01T18:39:04Z
[ "python", "pygame", "documentation" ]
Pygame error: display surface quit: Why?
1,997,710
<p>Sorry if this question is dumb, but I am writing from China and for some unfathomable reason a lot of websites having to do with pygame are blocked. I can't access pygame.org, I have not been able to download the docs or even look at message boards having to do with pygame! WEIRD!</p> <p>Anyways, I am a pygame newb...
2
2010-01-04T05:49:03Z
10,585,054
<p>I too had this problem, and similar to Maciej Miąsik's answer mine had to do with copy.deepcopy()-ing an image.</p> <p>I had:</p> <pre><code>import copy,pygame,sys from pygame.locals import * EMPTY_IMG= pygame.image.load('C:super/fancy/file/path/transparent.png') held_image=copy.deepcopy(EMPTY_IMG) my_rect=held_...
0
2012-05-14T14:12:53Z
[ "python", "pygame", "documentation" ]
Pygame error: display surface quit: Why?
1,997,710
<p>Sorry if this question is dumb, but I am writing from China and for some unfathomable reason a lot of websites having to do with pygame are blocked. I can't access pygame.org, I have not been able to download the docs or even look at message boards having to do with pygame! WEIRD!</p> <p>Anyways, I am a pygame newb...
2
2010-01-04T05:49:03Z
16,255,618
<p>I had this problem too, but got it from another origin.</p> <p>I had a class defined like this:</p> <pre><code>class PauseMenu(pygame.Surface) </code></pre> <p>i got the error when forgetting to initialize the pygame.Surface and trying to blit it, making pygame.screen crash and gave me this error.</p> <p>so i ju...
0
2013-04-27T18:40:21Z
[ "python", "pygame", "documentation" ]
Pygame error: display surface quit: Why?
1,997,710
<p>Sorry if this question is dumb, but I am writing from China and for some unfathomable reason a lot of websites having to do with pygame are blocked. I can't access pygame.org, I have not been able to download the docs or even look at message boards having to do with pygame! WEIRD!</p> <p>Anyways, I am a pygame newb...
2
2010-01-04T05:49:03Z
35,459,887
<pre><code>import pygame, sys running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() # quit the screen running = False sys.exit() </code></pre> <p>call sys.exit() after pygame.quit() to stop the program so you can not change the surfa...
0
2016-02-17T14:47:08Z
[ "python", "pygame", "documentation" ]
Python's mechanize proxy support
1,997,894
<p>I have a question about python mechanize's proxy support. I'm making some web client script, and I would like to insert proxy support function into my script.</p> <p>For example, if I have:</p> <pre><code>params = urllib.urlencode({'id':id, 'passwd':pw}) rq = mechanize.Request('http://www.example.com', params) rs...
9
2010-01-04T06:51:05Z
1,997,950
<p>I'm not sure whether that help or not but you can set proxy settings on <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a> proxy browser.</p> <pre><code>br = Browser() # Explicitly configure proxies (Browser will attempt to set good defaults). # Note the userinfo ("joe:password@") and port number (...
30
2010-01-04T07:11:59Z
[ "python", "mechanize" ]
Python's mechanize proxy support
1,997,894
<p>I have a question about python mechanize's proxy support. I'm making some web client script, and I would like to insert proxy support function into my script.</p> <p>For example, if I have:</p> <pre><code>params = urllib.urlencode({'id':id, 'passwd':pw}) rq = mechanize.Request('http://www.example.com', params) rs...
9
2010-01-04T06:51:05Z
2,519,023
<p>You use mechanize.Request.set_proxy(host, type) (at least as of 0.1.11)</p> <p>assuming an http proxy running at localhost:8888</p> <pre><code>req = mechanize.Request("http://www.google.com") req.set_proxy("localhost:8888","http") mechanize.urlopen(req) </code></pre> <p>Should work.</p>
9
2010-03-25T20:14:16Z
[ "python", "mechanize" ]
Is it safe to use user input for Python's regular expressions?
1,998,104
<p>I would like to let my users use regular expressions for some features. I'm curious what the implications are of passing user input to re.compile(). I assume there is no way for a user to give me a string that could let them execute arbitrary code. The dangers I have thought of are:</p> <ol> <li>The user could p...
14
2010-01-04T07:58:14Z
1,998,170
<p>I really don't think it is possible to execute code simply by passing it into an re.compile. The way I understand it, re.compile (or any regex system in any language) converts the regex string into a <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="nofollow">finite automaton</a> (DFA or NFA), and despi...
0
2010-01-04T08:17:38Z
[ "python", "regex", "user-input", "sanitize" ]
Is it safe to use user input for Python's regular expressions?
1,998,104
<p>I would like to let my users use regular expressions for some features. I'm curious what the implications are of passing user input to re.compile(). I assume there is no way for a user to give me a string that could let them execute arbitrary code. The dangers I have thought of are:</p> <ol> <li>The user could p...
14
2010-01-04T07:58:14Z
1,998,350
<p>You technically don't need to use <code>re.compile()</code> to perform a regular expression operation on a string. In fact, the compile method can often be slower if you're only executing the operation once since there's overhead associated with the initial compiling.</p> <p>If you're worried about the word "compi...
0
2010-01-04T09:06:21Z
[ "python", "regex", "user-input", "sanitize" ]
Is it safe to use user input for Python's regular expressions?
1,998,104
<p>I would like to let my users use regular expressions for some features. I'm curious what the implications are of passing user input to re.compile(). I assume there is no way for a user to give me a string that could let them execute arbitrary code. The dangers I have thought of are:</p> <ol> <li>The user could p...
14
2010-01-04T07:58:14Z
1,998,499
<p>It's not necessary to use compile() except when you need to reuse a lot of different regular expressions. The module already caches the last expressions.</p> <p>The point 2 (at execution) could be a very difficult one if you allow the user to input any regular expression. You can make a complex regexp with few char...
1
2010-01-04T09:46:50Z
[ "python", "regex", "user-input", "sanitize" ]
Is it safe to use user input for Python's regular expressions?
1,998,104
<p>I would like to let my users use regular expressions for some features. I'm curious what the implications are of passing user input to re.compile(). I assume there is no way for a user to give me a string that could let them execute arbitrary code. The dangers I have thought of are:</p> <ol> <li>The user could p...
14
2010-01-04T07:58:14Z
1,998,506
<p>Compiling the regular expression should be reasonably safe. Although what it compiles into is not strictly an NFA (backreferences mean it's not quite as clean) it should still be sort of straightforward to compile into.</p> <p>Now as to performance characteristics, this is another problem entirely. Even a small reg...
3
2010-01-04T09:48:00Z
[ "python", "regex", "user-input", "sanitize" ]
Is it safe to use user input for Python's regular expressions?
1,998,104
<p>I would like to let my users use regular expressions for some features. I'm curious what the implications are of passing user input to re.compile(). I assume there is no way for a user to give me a string that could let them execute arbitrary code. The dangers I have thought of are:</p> <ol> <li>The user could p...
14
2010-01-04T07:58:14Z
1,998,507
<p>I have worked on a program that allows users to enter their own regex and you are right - they can (and do) enter regex that can take a long time to finish - sometimes longer than than the lifetime of the universe. What is worse, while processing a regex Python holds the GIL, so it will not only hang the thread tha...
17
2010-01-04T09:48:05Z
[ "python", "regex", "user-input", "sanitize" ]
Is it safe to use user input for Python's regular expressions?
1,998,104
<p>I would like to let my users use regular expressions for some features. I'm curious what the implications are of passing user input to re.compile(). I assume there is no way for a user to give me a string that could let them execute arbitrary code. The dangers I have thought of are:</p> <ol> <li>The user could p...
14
2010-01-04T07:58:14Z
1,998,868
<p>It's much simpler for casual users to give them a subset language. The shell's globbing rules in <a href="http://docs.python.org/library/fnmatch.html">fnmatch</a>, for example. The SQL LIKE condition rules are another example.</p> <p>Translate the user's language into a proper regex for execution at runtime.</p>
5
2010-01-04T11:04:51Z
[ "python", "regex", "user-input", "sanitize" ]
How to mimic vb's control array in python for win32com?
1,998,186
<p>I need to dynamically create com objects from an activex dll and each of the objects can raise events which should be handled with event handlers.</p> <p>I can do this easily with <code>win32com.client.Dispatch</code> and <code>win32com.client.WithEvents</code> and associate a "separate" class of event handlers wit...
1
2010-01-04T08:22:23Z
1,999,710
<p>Control Arrays were removed in VB.NET so I don't think they would be supported in the win32com. Not sure if this would work for you but can you pass the index to the EventHandler class?</p> <pre><code>class MyEventHandler: def __init__(self, index): self.obj_index = index def OnEvent(self): ...
0
2010-01-04T14:04:49Z
[ "python", "win32com" ]
How to mimic vb's control array in python for win32com?
1,998,186
<p>I need to dynamically create com objects from an activex dll and each of the objects can raise events which should be handled with event handlers.</p> <p>I can do this easily with <code>win32com.client.Dispatch</code> and <code>win32com.client.WithEvents</code> and associate a "separate" class of event handlers wit...
1
2010-01-04T08:22:23Z
2,004,553
<p>It's a major flaw of win32com's event handling that you have to pass in a class object rather than a class instance.</p> <p>You can attach state to your classes using win32com, however, by creating classes dynamically using <code>new.classobj</code>:</p> <pre><code>from win32com.client import Dispatch, WithEvents ...
0
2010-01-05T06:35:00Z
[ "python", "win32com" ]
Datetime problem at start of month in Python
1,998,198
<p>I have a function that removes a file after a certain amount of time. The problem is that it works at later parts of the month, but when I try and remove 7 days from the start of the month it will not substract into the previous month. Does anyone know how to get this to work? The code is below that works out the da...
0
2010-01-04T08:26:32Z
1,998,208
<pre><code>minus_seven = today - datetime.timedelta(days = 7) </code></pre>
7
2010-01-04T08:30:12Z
[ "python" ]
Datetime problem at start of month in Python
1,998,198
<p>I have a function that removes a file after a certain amount of time. The problem is that it works at later parts of the month, but when I try and remove 7 days from the start of the month it will not substract into the previous month. Does anyone know how to get this to work? The code is below that works out the da...
0
2010-01-04T08:26:32Z
1,998,333
<p>The reason this breaks is that <code>today</code> is a <code>datetime.date</code>; and as <a href="http://docs.python.org/library/datetime.html#date-objects" rel="nofollow">the docs</a> say, that means that <code>today.day</code> is:</p> <blockquote> <p>Between 1 and the number of days in the given month of the g...
3
2010-01-04T08:59:50Z
[ "python" ]
Replace string in a specific line using python
1,998,233
<p>I'm writing a python script to replace strings from a each text file in a directory with a specific extension (.seq). The strings replaced should only be from the second line of each file, and the output is a new subdirectory (call it clean) with the same file names as the original files, but with a *.clean suffix. ...
2
2010-01-04T08:36:46Z
1,998,255
<p>line.replace is not a mutator, it leaves the original string unchanged and returns a new string with the replacements made. You'll need to change your code to <code>line = line.replace('R', 'N')</code>, etc.</p> <p>I think you also want to add a <code>break</code> statement at the end of your else clause, so that ...
0
2010-01-04T08:41:19Z
[ "python", "replace" ]
Replace string in a specific line using python
1,998,233
<p>I'm writing a python script to replace strings from a each text file in a directory with a specific extension (.seq). The strings replaced should only be from the second line of each file, and the output is a new subdirectory (call it clean) with the same file names as the original files, but with a *.clean suffix. ...
2
2010-01-04T08:36:46Z
1,998,260
<p>you need to allocate the result of the replacement back to "line" variable</p> <pre><code>line=line.replace('M', 'N') </code></pre> <p>you can also use the module fileinput for inplace edit</p> <pre><code>import os, shutil,fileinput if not os.path.exists('clean'): os.mkdir('clean') for file in os.listdir("."...
3
2010-01-04T08:42:40Z
[ "python", "replace" ]
Replace string in a specific line using python
1,998,233
<p>I'm writing a python script to replace strings from a each text file in a directory with a specific extension (.seq). The strings replaced should only be from the second line of each file, and the output is a new subdirectory (call it clean) with the same file names as the original files, but with a *.clean suffix. ...
2
2010-01-04T08:36:46Z
1,998,280
<p>You should replace <code>line.replace('M', 'N')</code> with <code>line=line.replace('M', 'N')</code>. replace returns a copy of the original string with the relevant substrings replaced.</p> <p>An even better way (IMO) is to use re.</p> <pre><code>import re line="ABCDEFGHIJKLMNOPQRSTUVWXYZ" line=re.sub("K|Y|W|M|R...
5
2010-01-04T08:46:37Z
[ "python", "replace" ]
Replace string in a specific line using python
1,998,233
<p>I'm writing a python script to replace strings from a each text file in a directory with a specific extension (.seq). The strings replaced should only be from the second line of each file, and the output is a new subdirectory (call it clean) with the same file names as the original files, but with a *.clean suffix. ...
2
2010-01-04T08:36:46Z
1,998,318
<p>Here are some general hints:</p> <ol> <li><p>Don't use <code>find</code> for checking the file extension (e.g., this would also match "<code>file1.seqdata.xls</code>"). At least use <code>file.endswith('seq')</code>, or, better yet, <code>os.path.splitext(file)[1]</code></p></li> <li><p>Actually, don't do that alto...
3
2010-01-04T08:55:21Z
[ "python", "replace" ]
Replace string in a specific line using python
1,998,233
<p>I'm writing a python script to replace strings from a each text file in a directory with a specific extension (.seq). The strings replaced should only be from the second line of each file, and the output is a new subdirectory (call it clean) with the same file names as the original files, but with a *.clean suffix. ...
2
2010-01-04T08:36:46Z
1,998,414
<p>some notes: </p> <ol> <li><code>string.replace</code> and <code>re.sub</code> are not in-place so you should be assigning the return value back to your variable.</li> <li><code>glob.glob</code> is better for finding files in a directory matching a defined pattern...</li> <li>maybe you should be checking if the dir...
3
2010-01-04T09:25:57Z
[ "python", "replace" ]
Python's Regular Expression Source String Length
1,998,261
<p>In Python Regular Expressions,</p> <pre><code>re.compile("x"*50000) </code></pre> <p>gives me <code>OverflowError: regular expression code size limit exceeded</code></p> <p>but following one does not get any error, but it hits 100% CPU, and took 1 minute in my PC</p> <pre><code>&gt;&gt;&gt; re.compile(".*?.*?.*?...
4
2010-01-04T08:42:57Z
1,998,287
<p>The difference is that <code>".*?.*?.*?.*?.*?.*?.*?.*?.*?.*?"*50000</code> can be reduced to <code>".*?"</code>, while <code>"x"*50000</code> has to generate 50000 nodes in the FSM (or a similar structure used by the regex engine).</p> <p><strong>EDIT:</strong> Ok, I was wrong. It's not that smart. The reason why <...
6
2010-01-04T08:47:48Z
[ "python", "regex" ]
Python's Regular Expression Source String Length
1,998,261
<p>In Python Regular Expressions,</p> <pre><code>re.compile("x"*50000) </code></pre> <p>gives me <code>OverflowError: regular expression code size limit exceeded</code></p> <p>but following one does not get any error, but it hits 100% CPU, and took 1 minute in my PC</p> <pre><code>&gt;&gt;&gt; re.compile(".*?.*?.*?...
4
2010-01-04T08:42:57Z
1,998,401
<p>you want to match 50000 "x"s , correct??? if so, an alternative without regex</p> <pre><code>if "x"*50000 in mystring: print "found" </code></pre> <p>if you want to match 50000 "x"s using regex, you can use range</p> <pre><code>&gt;&gt;&gt; pat=re.compile("x{50000}") &gt;&gt;&gt; pat.search(s) &lt;_sre.SRE_Ma...
1
2010-01-04T09:22:55Z
[ "python", "regex" ]
Wrong encoding of text, in Django?
1,998,362
<pre><code>"query" = джазовыми </code></pre> <p>For some reason...when I display it via:</p> <pre><code>{{ query|safe }} </code></pre> <p>I get this:</p> <pre><code>%u0434%u0436%u0430%u0437%u043E%u0432%u044B%u043C%u0438 </code></pre>
0
2010-01-04T09:08:47Z
1,998,862
<p>Would the query be set from the source, this would solve it:</p> <pre><code>query = u"джазовыми" </code></pre> <p>(provided that for example your file encoding is utf-8 and you have corresponding line</p> <pre><code># -*- coding: UTF-8 -*- </code></pre> <p>in the beginning)</p> <p>But I guess the query...
2
2010-01-04T11:04:00Z
[ "python", "django", "templates", "encoding", "utf-8" ]
Parsing XML with SAX/Python + no validation
1,998,425
<p>Hi, I am new to python and I'm trying to parse a XML file with SAX <em>without</em> validating it.</p> <p>The head of my xml file is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE n:document SYSTEM "schema.dtd"&gt; &lt;n:document.... </code></pre> <p>and I've tried to parse it with pyth...
1
2010-01-04T09:28:46Z
1,998,950
<p>expatreader considers the DTD external subset as an external general entity. So the feature you want is:</p> <pre><code>parser.setFeature(handler.feature_external_ges, False) </code></pre> <p>However, it's a bit dodgy pointing the DTD external subset to a non-existant URL; as this shows, it's not only validating p...
4
2010-01-04T11:21:12Z
[ "python", "xml", "validation", "sax" ]
Streaming the result of a command back to the browser using Twisted and Comet
1,998,556
<p>I'm writing an application that streams the output (by this I mean both sys.stdout and sys.stderr) of a python script excited on the server, in real time to the browser. </p> <p>The users on the site will be allowed to select the script to run, excite and kill their chosen script, and change some parameters, so I w...
1
2010-01-04T10:01:59Z
2,002,311
<p>An example of serving for long-polling clients with Twisted is <a href="http://github.com/dustin/slosh" rel="nofollow">slosh</a>. This might not be what you want, but because it's not a large framework, it can help you figure out how to use Twisted.</p>
0
2010-01-04T21:19:21Z
[ "python", "comet", "twisted", "stomp", "orbited" ]
Streaming the result of a command back to the browser using Twisted and Comet
1,998,556
<p>I'm writing an application that streams the output (by this I mean both sys.stdout and sys.stderr) of a python script excited on the server, in real time to the browser. </p> <p>The users on the site will be allowed to select the script to run, excite and kill their chosen script, and change some parameters, so I w...
1
2010-01-04T10:01:59Z
3,064,381
<p>Nevow Athena is a framework specifically for AJAX and COMET applications and in theory is exactly the sort of thing you are looking for.</p> <p>However, I am not sure that it is well used or supported at this time - looking at mailing list traffic and google search results suggests that it may not be.</p> <p>There...
1
2010-06-17T18:16:52Z
[ "python", "comet", "twisted", "stomp", "orbited" ]
Streaming the result of a command back to the browser using Twisted and Comet
1,998,556
<p>I'm writing an application that streams the output (by this I mean both sys.stdout and sys.stderr) of a python script excited on the server, in real time to the browser. </p> <p>The users on the site will be allowed to select the script to run, excite and kill their chosen script, and change some parameters, so I w...
1
2010-01-04T10:01:59Z
10,753,025
<p>You can implement a very simple "HTTP streaming" by keeping the http connection open and appending javascript chunks that update the dom contents. This works since the browser evaluates the "script" chunks as they arrive.</p> <p>I wrote a blog entry a while ago with a running example using twisted and very few line...
1
2012-05-25T10:44:44Z
[ "python", "comet", "twisted", "stomp", "orbited" ]
wiki/docbook/latex documentation template system
1,998,677
<p>I'm searching for a documentation template system or rather will be creating one. It should support the following features:</p> <ul> <li>Create output in PDF and HTML</li> <li>Support for large &amp; complicated (LaTeX) formulas</li> <li>References between documents</li> <li>Bibliographies</li> <li>Templates will b...
6
2010-01-04T10:28:17Z
1,998,811
<p>We use sphinx: <a href="http://sphinx.pocoo.org" rel="nofollow">http://sphinx.pocoo.org</a></p> <p>It does almost all of that.</p> <p>Your python script or your users or whomever (I can't follow the question) can create content using <a href="http://docutils.sourceforge.net/rst.html" rel="nofollow">RST markup</a...
7
2010-01-04T10:52:35Z
[ "python", "html", "latex", "documentation-generation", "docbook" ]
wiki/docbook/latex documentation template system
1,998,677
<p>I'm searching for a documentation template system or rather will be creating one. It should support the following features:</p> <ul> <li>Create output in PDF and HTML</li> <li>Support for large &amp; complicated (LaTeX) formulas</li> <li>References between documents</li> <li>Bibliographies</li> <li>Templates will b...
6
2010-01-04T10:28:17Z
2,002,991
<p>I created a LaTeX pre-processor and python module that allows you to embed python or SQL inside a LaTeX file. The python and/or SQL is executed and the output is folded in.</p> <p>With latex2html or latex2rtf you can then use the LaTeX code to produce HTM and RTF.</p> <p>I've posted it for you at <a href="http://s...
1
2010-01-04T23:14:55Z
[ "python", "html", "latex", "documentation-generation", "docbook" ]
wiki/docbook/latex documentation template system
1,998,677
<p>I'm searching for a documentation template system or rather will be creating one. It should support the following features:</p> <ul> <li>Create output in PDF and HTML</li> <li>Support for large &amp; complicated (LaTeX) formulas</li> <li>References between documents</li> <li>Bibliographies</li> <li>Templates will b...
6
2010-01-04T10:28:17Z
2,403,420
<p><a href="http://single-sourcing.com/products/arbortext/publishing.html?utm_source=stackoverflow&amp;utm_medium=comment&amp;utm_term=latex&amp;utm_content=ati&amp;utm_campaign=us" rel="nofollow">Arbortext</a> supports LaTeX natively. You can send the publishing engine or print composer LaTeX and it'll pass it through...
0
2010-03-08T17:54:30Z
[ "python", "html", "latex", "documentation-generation", "docbook" ]
wiki/docbook/latex documentation template system
1,998,677
<p>I'm searching for a documentation template system or rather will be creating one. It should support the following features:</p> <ul> <li>Create output in PDF and HTML</li> <li>Support for large &amp; complicated (LaTeX) formulas</li> <li>References between documents</li> <li>Bibliographies</li> <li>Templates will b...
6
2010-01-04T10:28:17Z
9,033,151
<p>I think that <a href="http://www.methods.co.nz/asciidoc/" rel="nofollow">Asciidoc</a> is better targeted at what you are trying to get. It is a simple markup language, it allows latex formulas in it and it generates Docbook documents from which you can further generate the readable HTML or Latex representation</p>
0
2012-01-27T12:18:33Z
[ "python", "html", "latex", "documentation-generation", "docbook" ]
sqlalchemy cascade and association objects
1,998,962
<p>My database structure is something like this (I'm using declarative style):</p> <pre><code>class Character(Base): __tablename__="characters" id = Column(Integer, primary_key=True) name = Column(String) player = Column(String) inventory = relation(Inventory) class Item(Base): __tablename__="...
0
2010-01-04T11:24:45Z
2,000,367
<p><code>Session.delete()</code> method just marks an instance as "to be deleted", so your relation won't change untill you flush changes to database independent on cascade rules. On other hand you can just remove <code>Inventory</code> instance from <code>character.inventory</code> collection, then having <code>'delet...
1
2010-01-04T15:58:12Z
[ "python", "sqlalchemy" ]
Why does it print funny characters? unicode problem?
1,998,967
<p>The user entered the word</p> <pre><code>éclair </code></pre> <p>into the search box.</p> <pre><code>Showing results 1 - 10 of about 140 for �air. </code></pre> <p>Why does it show the weird question mark? I'm using Django to display it:</p> <pre><code>Showing results 1 - 10 of about 140 for {{query|safe}} ...
2
2010-01-04T11:26:35Z
1,998,976
<p>It's an encoding problem. Most likely your form or the output page is not UTF-8 encoded.</p> <p>This article is <em>very</em> good reading on the issue: <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About U...
8
2010-01-04T11:29:26Z
[ "python", "django", "unicode", "encoding" ]
Why does it print funny characters? unicode problem?
1,998,967
<p>The user entered the word</p> <pre><code>éclair </code></pre> <p>into the search box.</p> <pre><code>Showing results 1 - 10 of about 140 for �air. </code></pre> <p>Why does it show the weird question mark? I'm using Django to display it:</p> <pre><code>Showing results 1 - 10 of about 140 for {{query|safe}} ...
2
2010-01-04T11:26:35Z
1,998,980
<p>You are serving the page with the wrong character encoding (charset). Check that you are using the same encoding throughout all your application (for example UTF-8). This includes:</p> <ul> <li>HTTP headers from web server (Content-Type: text/html;charset=utf-8)</li> <li>Communication with database (i.e SET NAMES '...
0
2010-01-04T11:30:21Z
[ "python", "django", "unicode", "encoding" ]
Why does it print funny characters? unicode problem?
1,998,967
<p>The user entered the word</p> <pre><code>éclair </code></pre> <p>into the search box.</p> <pre><code>Showing results 1 - 10 of about 140 for �air. </code></pre> <p>Why does it show the weird question mark? I'm using Django to display it:</p> <pre><code>Showing results 1 - 10 of about 140 for {{query|safe}} ...
2
2010-01-04T11:26:35Z
1,999,393
<p>It would also be good to check your browser encoding setting.</p>
0
2010-01-04T13:00:15Z
[ "python", "django", "unicode", "encoding" ]
Why does it print funny characters? unicode problem?
1,998,967
<p>The user entered the word</p> <pre><code>éclair </code></pre> <p>into the search box.</p> <pre><code>Showing results 1 - 10 of about 140 for �air. </code></pre> <p>Why does it show the weird question mark? I'm using Django to display it:</p> <pre><code>Showing results 1 - 10 of about 140 for {{query|safe}} ...
2
2010-01-04T11:26:35Z
1,999,451
<p>This is the result when you interpret data that is not encoded in UTF-8 as UTF-8 encoded.</p> <p>The interpreter expects from the code point of your first character of the word <code>éclair</code> a multibyte encoded character with a length of three characters, consumes the next two characters but can’t decode i...
1
2010-01-04T13:12:48Z
[ "python", "django", "unicode", "encoding" ]
Why does it print funny characters? unicode problem?
1,998,967
<p>The user entered the word</p> <pre><code>éclair </code></pre> <p>into the search box.</p> <pre><code>Showing results 1 - 10 of about 140 for �air. </code></pre> <p>Why does it show the weird question mark? I'm using Django to display it:</p> <pre><code>Showing results 1 - 10 of about 140 for {{query|safe}} ...
2
2010-01-04T11:26:35Z
2,002,335
<p>I second the responses above. Some other things from the top of my head:</p> <p>If you're using e.g. MySQL database, then it could be good to create your database using:</p> <p>CREATE DATABASE x CHARACTER SET UTF8</p> <p>You can also check this: <a href="http://docs.djangoproject.com/en/dev/ref/settings/#default-...
0
2010-01-04T21:23:26Z
[ "python", "django", "unicode", "encoding" ]
How do i use Django and UTF-8 content-type for template?
1,998,987
<p>When I do:</p> <pre><code>return render_to_response() </code></pre> <p>in Django. How do I set the content-type to UTF-8? So that everything displayed is UTF-8?</p>
2
2010-01-04T11:33:06Z
1,999,138
<p>django use UTF-8 as default encoding, but this can be modified with settings.DEFAULT_CHARSET.</p> <p>Be sure, in your HTML template, to set UTF-8 for the HTML page also :</p> <pre><code>&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt; </code></pre>
3
2010-01-04T12:04:31Z
[ "python", "django", "unicode", "encoding", "utf-8" ]
Determine where documents differ with Python
1,999,019
<p>I have been using the Python <a href="http://docs.python.org/library/difflib.html" rel="nofollow">difflib</a> library to find where 2 documents differ. The Differ().compare() method does this, but it is <strong>very</strong> slow - atleast 100x slower for large HTML documents compared to the <a href="http://www.comp...
3
2010-01-04T11:39:58Z
1,999,207
<p>An ugly and stupid solution: If <code>diff</code> is faster, use it; through a call from python via <code>subprocess</code>, parse the command output for the information you need. This won't be as fast as just <code>diff</code>, but maybe faster than <code>difflib</code>.</p>
1
2010-01-04T12:18:52Z
[ "python", "diff", "document", "difflib", "sequencematcher" ]
Determine where documents differ with Python
1,999,019
<p>I have been using the Python <a href="http://docs.python.org/library/difflib.html" rel="nofollow">difflib</a> library to find where 2 documents differ. The Differ().compare() method does this, but it is <strong>very</strong> slow - atleast 100x slower for large HTML documents compared to the <a href="http://www.comp...
3
2010-01-04T11:39:58Z
1,999,271
<pre><code>a = open("file1.txt").readlines() b = open("file2.txt").readlines() count = 0 pos = 0 while 1: count += 1 try: al = a.pop(0) bl = b.pop(0) if al != bl: print "files differ on line %d, byte %d" % (count,pos) pos += len(al) except IndexError: bre...
3
2010-01-04T12:30:02Z
[ "python", "diff", "document", "difflib", "sequencematcher" ]
Determine where documents differ with Python
1,999,019
<p>I have been using the Python <a href="http://docs.python.org/library/difflib.html" rel="nofollow">difflib</a> library to find where 2 documents differ. The Differ().compare() method does this, but it is <strong>very</strong> slow - atleast 100x slower for large HTML documents compared to the <a href="http://www.comp...
3
2010-01-04T11:39:58Z
1,999,452
<p>Google has a <a href="http://code.google.com/p/google-diff-match-patch/" rel="nofollow">diff library</a> for plain text with a python API, which should apply to the html documents you want to work with. I am not sure if it is suited for your particular use case where you are specifically interested in the location o...
2
2010-01-04T13:13:00Z
[ "python", "diff", "document", "difflib", "sequencematcher" ]
Understanding while loop
1,999,026
<p>I am a newbie in Python. I can understand what a for loop does, but can't really understand what a while loop does. I knew it does repeat something while the condition is true, easy to say, but it's really hard to use it as far as I think.</p> <p>Say, an example here:</p> <pre><code>while 1: rate(100) #what doe...
0
2010-01-04T11:42:30Z
1,999,059
<p><code>while 1</code> is a special case of <code>while</code> loop: It's a so-called "infinite loop".</p> <p>Of course nothing is infinite. What the code is saying is: Run the contents of this loop until something inside causes it to exit. There's no explicit test in the loop, so the exit condition must be inside.</...
2
2010-01-04T11:49:53Z
[ "python", "while-loop" ]
Understanding while loop
1,999,026
<p>I am a newbie in Python. I can understand what a for loop does, but can't really understand what a while loop does. I knew it does repeat something while the condition is true, easy to say, but it's really hard to use it as far as I think.</p> <p>Say, an example here:</p> <pre><code>while 1: rate(100) #what doe...
0
2010-01-04T11:42:30Z
1,999,061
<p>Well, <code>while 1</code> is an infinite loop that will run forever. I'm guessing here a bit but <code>rate(N)</code> looks like the sort of function that would try to do something 100 times a second (or minute or other time period), in which case it's likely to be a simple "sleep for time period divided by rate".<...
0
2010-01-04T11:50:30Z
[ "python", "while-loop" ]
Understanding while loop
1,999,026
<p>I am a newbie in Python. I can understand what a for loop does, but can't really understand what a while loop does. I knew it does repeat something while the condition is true, easy to say, but it's really hard to use it as far as I think.</p> <p>Say, an example here:</p> <pre><code>while 1: rate(100) #what doe...
0
2010-01-04T11:42:30Z
1,999,066
<p>The <code>while 1:</code> construction is a infinite loop, ie it never ends.</p>
0
2010-01-04T11:51:01Z
[ "python", "while-loop" ]
Understanding while loop
1,999,026
<p>I am a newbie in Python. I can understand what a for loop does, but can't really understand what a while loop does. I knew it does repeat something while the condition is true, easy to say, but it's really hard to use it as far as I think.</p> <p>Say, an example here:</p> <pre><code>while 1: rate(100) #what doe...
0
2010-01-04T11:42:30Z
1,999,078
<p>You have actually defined an infinite loop. <code>while 1:</code> means to run the code-block below infinite times. You can only exit from it using a <code>break</code> statement.</p> <p>The <code>rate(100)</code> calls the rate method, which must be defined somewhere. Then a try-catch block is executed. First 'som...
2
2010-01-04T11:53:38Z
[ "python", "while-loop" ]
Understanding while loop
1,999,026
<p>I am a newbie in Python. I can understand what a for loop does, but can't really understand what a while loop does. I knew it does repeat something while the condition is true, easy to say, but it's really hard to use it as far as I think.</p> <p>Say, an example here:</p> <pre><code>while 1: rate(100) #what doe...
0
2010-01-04T11:42:30Z
1,999,101
<p><code>while 1</code> is an infinite loop - it will run forever.</p> <p>The <code>while</code> loop is a statement that allows code to be run on a given boolean value.</p> <p>You can find more information <a href="http://en.wikipedia.org/wiki/While_loop" rel="nofollow">here</a>, and I've included the example given...
0
2010-01-04T11:56:44Z
[ "python", "while-loop" ]
Understanding while loop
1,999,026
<p>I am a newbie in Python. I can understand what a for loop does, but can't really understand what a while loop does. I knew it does repeat something while the condition is true, easy to say, but it's really hard to use it as far as I think.</p> <p>Say, an example here:</p> <pre><code>while 1: rate(100) #what doe...
0
2010-01-04T11:42:30Z
1,999,153
<p>Read this: <a href="http://www.cs.utexas.edu/users/EWD/transcriptions/EWD03xx/EWD316.2.html" rel="nofollow">http://www.cs.utexas.edu/users/EWD/transcriptions/EWD03xx/EWD316.2.html</a></p>
0
2010-01-04T12:08:10Z
[ "python", "while-loop" ]