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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
How does indexing a list with a tuple work? | 1,614,613 | <p>I am learning Python and came across this example:</p>
<pre><code>W = ((0,1,2),(3,4,5),(0,4,8),(2,4,6))
b = ['a','b','c','d','e','f','g','h','i']
for row in W:
print b[row[0]], b[row[1]], b[row[2]]
</code></pre>
<p>which prints:</p>
<p>a b c</p>
<p>d e f</p>
<p>a e i</p>
<p>c e g</p>
<p>I am trying to fig... | 4 | 2009-10-23T16:40:58Z | 1,614,637 | <p>In shot, the <code>(0,1,2)</code> does nothing. Its a tuple and can be indexed just like a list, so <code>b[(0,1,2)[0]]</code> becomes <code>b[0]</code> since <code>(0,1,2)[0] == 0</code>.</p>
<p>In the first step Python does <code>b[row[0]]</code> â <code>b[(0,1,2)[0]]</code> â <code>b[0]</code> â <code>'a'<... | 4 | 2009-10-23T16:44:42Z | [
"python",
"list",
"indexing",
"tuples"
] |
How does indexing a list with a tuple work? | 1,614,613 | <p>I am learning Python and came across this example:</p>
<pre><code>W = ((0,1,2),(3,4,5),(0,4,8),(2,4,6))
b = ['a','b','c','d','e','f','g','h','i']
for row in W:
print b[row[0]], b[row[1]], b[row[2]]
</code></pre>
<p>which prints:</p>
<p>a b c</p>
<p>d e f</p>
<p>a e i</p>
<p>c e g</p>
<p>I am trying to fig... | 4 | 2009-10-23T16:40:58Z | 1,614,642 | <p>Indexing a tuple just extracts the nth element, just as when indexing an array. That is, the expanded version</p>
<pre><code>print b[(0,1,2)[0]], b[(0,1,2)[1]], b[(0,1,2)[2]]
</code></pre>
<p>is equal to</p>
<pre><code>print b[0], b[1], b[2]
</code></pre>
<p>IE, the 0th element of the (0, 1, 2) tuple (<code>(0, ... | 0 | 2009-10-23T16:45:46Z | [
"python",
"list",
"indexing",
"tuples"
] |
How does indexing a list with a tuple work? | 1,614,613 | <p>I am learning Python and came across this example:</p>
<pre><code>W = ((0,1,2),(3,4,5),(0,4,8),(2,4,6))
b = ['a','b','c','d','e','f','g','h','i']
for row in W:
print b[row[0]], b[row[1]], b[row[2]]
</code></pre>
<p>which prints:</p>
<p>a b c</p>
<p>d e f</p>
<p>a e i</p>
<p>c e g</p>
<p>I am trying to fig... | 4 | 2009-10-23T16:40:58Z | 1,614,643 | <p>it iterates over a tuple of tuples, each <code>row</code> is a three-element tuple, when printing it accesses three elements of the <code>b</code> list by index, which is what <code>row</code> tuple contains.</p>
<p>probably, a slightly less cluttered way to do this is:</p>
<pre><code>for f, s, t in W:
print b... | 4 | 2009-10-23T16:45:59Z | [
"python",
"list",
"indexing",
"tuples"
] |
How does indexing a list with a tuple work? | 1,614,613 | <p>I am learning Python and came across this example:</p>
<pre><code>W = ((0,1,2),(3,4,5),(0,4,8),(2,4,6))
b = ['a','b','c','d','e','f','g','h','i']
for row in W:
print b[row[0]], b[row[1]], b[row[2]]
</code></pre>
<p>which prints:</p>
<p>a b c</p>
<p>d e f</p>
<p>a e i</p>
<p>c e g</p>
<p>I am trying to fig... | 4 | 2009-10-23T16:40:58Z | 1,614,649 | <p><code>for row in W:</code></p>
<p>first tuple placed into <code>row</code> is <code>(0,1,2)</code></p>
<p>in other words, <code>W[0] == (0,1,2)</code></p>
<pre><code>Therefore, since `row` == (0,1,2), then row[0] == 0
</code></pre>
<p>So the <code>[0]th element of b == 'a'</code></p>
<pre><code>b[0] == 'a'
</co... | 0 | 2009-10-23T16:46:10Z | [
"python",
"list",
"indexing",
"tuples"
] |
How does indexing a list with a tuple work? | 1,614,613 | <p>I am learning Python and came across this example:</p>
<pre><code>W = ((0,1,2),(3,4,5),(0,4,8),(2,4,6))
b = ['a','b','c','d','e','f','g','h','i']
for row in W:
print b[row[0]], b[row[1]], b[row[2]]
</code></pre>
<p>which prints:</p>
<p>a b c</p>
<p>d e f</p>
<p>a e i</p>
<p>c e g</p>
<p>I am trying to fig... | 4 | 2009-10-23T16:40:58Z | 1,614,656 | <p>Try to write down the values of all variables in each step: the result you get is right.</p>
<p>interaction 1:</p>
<ul>
<li>row is (0,1,2)</li>
<li><em>b[row[0]], b[row[1]], b[row[2]]</em> is b[(0,1,2)[0], (0,1,2)[1], (0,1,2)[2]], == b[0], b[1], b[2]</li>
</ul>
<p>interaction 2:</p>
<ul>
<li><em>row</em> is (3,4... | 0 | 2009-10-23T16:47:56Z | [
"python",
"list",
"indexing",
"tuples"
] |
How does indexing a list with a tuple work? | 1,614,613 | <p>I am learning Python and came across this example:</p>
<pre><code>W = ((0,1,2),(3,4,5),(0,4,8),(2,4,6))
b = ['a','b','c','d','e','f','g','h','i']
for row in W:
print b[row[0]], b[row[1]], b[row[2]]
</code></pre>
<p>which prints:</p>
<p>a b c</p>
<p>d e f</p>
<p>a e i</p>
<p>c e g</p>
<p>I am trying to fig... | 4 | 2009-10-23T16:40:58Z | 1,614,661 | <p>A Python interactive shell will help you see what is going on:</p>
<pre><code>In [78]: W = ((0,1,2),(3,4,5),(0,4,8),(2,4,6))
In [79]: b = ['a','b','c','d','e','f','g','h','i']
In [81]: row=W[0] # The first time throught the for-loop, row equals W[0]
In [82]: row
Out[82]: (0, 1, 2)
In [83]: row[0]
Out[83]:... | 0 | 2009-10-23T16:49:00Z | [
"python",
"list",
"indexing",
"tuples"
] |
ImportError: No module named Foundation | 1,614,648 | <p>I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:</p>
<p><hr /></p>
<p>Here's what I have done to get PyObjC working in Snow Leopard:</p>
<ul>
<li><p>Using the Finder, I we... | 13 | 2009-10-23T16:46:08Z | 1,614,668 | <p>One of two things:</p>
<ul>
<li>Either the Fundation module doesn't exists</li>
<li>Or Python interpretor doesn't know when to find this file</li>
</ul>
<p>Python looks for modules in the PythonPath</p>
<p>See this <a href="http://stackoverflow.com/questions/1538725/cant-import-gdal-in-python">SO question</a> for... | 2 | 2009-10-23T16:50:19Z | [
"python",
"xcode",
"osx-snow-leopard",
"pyobjc"
] |
ImportError: No module named Foundation | 1,614,648 | <p>I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:</p>
<p><hr /></p>
<p>Here's what I have done to get PyObjC working in Snow Leopard:</p>
<ul>
<li><p>Using the Finder, I we... | 13 | 2009-10-23T16:46:08Z | 1,614,718 | <p>Run <code>python -v</code> to trace import statements, this work for interactive mode too.</p>
| 1 | 2009-10-23T17:00:28Z | [
"python",
"xcode",
"osx-snow-leopard",
"pyobjc"
] |
ImportError: No module named Foundation | 1,614,648 | <p>I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:</p>
<p><hr /></p>
<p>Here's what I have done to get PyObjC working in Snow Leopard:</p>
<ul>
<li><p>Using the Finder, I we... | 13 | 2009-10-23T16:46:08Z | 1,616,361 | <p>Okay, it turned out that, amending mjv's answer, I was able to get it working by typing</p>
<pre><code>export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/PyObjC/"
</code></pre>
<p>before executing the <code>./project-tool.py</code> line. I still find it ridiculous that... | 5 | 2009-10-23T23:03:55Z | [
"python",
"xcode",
"osx-snow-leopard",
"pyobjc"
] |
ImportError: No module named Foundation | 1,614,648 | <p>I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:</p>
<p><hr /></p>
<p>Here's what I have done to get PyObjC working in Snow Leopard:</p>
<ul>
<li><p>Using the Finder, I we... | 13 | 2009-10-23T16:46:08Z | 3,325,899 | <p>It's because PyObjC is there :
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC</p>
<p>Edit :
I found how to make "import objc" work, just :
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/"</p>
<p>It will add all the directories to the... | 4 | 2010-07-24T16:33:33Z | [
"python",
"xcode",
"osx-snow-leopard",
"pyobjc"
] |
ImportError: No module named Foundation | 1,614,648 | <p>I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:</p>
<p><hr /></p>
<p>Here's what I have done to get PyObjC working in Snow Leopard:</p>
<ul>
<li><p>Using the Finder, I we... | 13 | 2009-10-23T16:46:08Z | 18,043,508 | <p>I had the same problem. Mine was caused I think by using <a href="http://brew.sh">homebrew</a> to install my own Python to tinker with.</p>
<p>Because I was worried about mixing python versions, rather than creating the link as described above, I installed a new pyobjc using:</p>
<pre><code>$ pip install pyobjc
</... | 14 | 2013-08-04T13:35:44Z | [
"python",
"xcode",
"osx-snow-leopard",
"pyobjc"
] |
ImportError: No module named Foundation | 1,614,648 | <p>I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:</p>
<p><hr /></p>
<p>Here's what I have done to get PyObjC working in Snow Leopard:</p>
<ul>
<li><p>Using the Finder, I we... | 13 | 2009-10-23T16:46:08Z | 22,748,228 | <p>for python 2.7</p>
<p>export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/"</p>
| 1 | 2014-03-30T18:45:58Z | [
"python",
"xcode",
"osx-snow-leopard",
"pyobjc"
] |
Copying values from a dictionary into an object in Python | 1,614,804 | <p>I have a dictionary that I would like to iterate through and copy the key-value pairs into an object in Python. The dictionary is POST, and the object is a Model (in Django, perhaps Django has better way to do this).</p>
<p>In PHP, I'd be able to use variable assignments:</p>
<pre><code>foreach($post as $key =>... | 0 | 2009-10-23T17:15:52Z | 1,614,813 | <p>You can use setattr, but it's likely the wrong way to do it in your context. You should look at Django's <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/" rel="nofollow">ModelForms documentation</a> first.</p>
| 4 | 2009-10-23T17:18:08Z | [
"python",
"django"
] |
Copying values from a dictionary into an object in Python | 1,614,804 | <p>I have a dictionary that I would like to iterate through and copy the key-value pairs into an object in Python. The dictionary is POST, and the object is a Model (in Django, perhaps Django has better way to do this).</p>
<p>In PHP, I'd be able to use variable assignments:</p>
<pre><code>foreach($post as $key =>... | 0 | 2009-10-23T17:15:52Z | 1,614,818 | <pre><code>for key, value in post.iteritems():
setattr(my_model, key, value)
</code></pre>
| 5 | 2009-10-23T17:19:24Z | [
"python",
"django"
] |
How do I do 'from foo import *' using Python's __import__ function | 1,614,884 | <p>I want to replace <code>settings.py</code> in my Django system with a module implemented as a directory <code>settings</code> containing <code>__init__.py</code>. This will try to import a module named after the server, thus allowing for per-server settings.</p>
<p>If I don't know the name of a module before I impo... | 1 | 2009-10-23T17:29:50Z | 1,615,076 | <p>For similar situation where based on lang setting I import different messages in messages.py module it is something like</p>
<pre><code># set values in current namespace
for name in vars(messages):
v = getattr(messages, name)
globals()[name] = v
</code></pre>
<p>Btw why do you want to create a package for ... | 1 | 2009-10-23T18:12:02Z | [
"python",
"import"
] |
Running Python from the Windows Command Line | 1,614,898 | <p>How do I run a Python file from the Windows Command Line (<code>cmd.exe</code>) so that I won't have to re-enter the code each time?</p>
| 1 | 2009-10-23T17:33:07Z | 1,614,906 | <p>Open a command prompt, by pressing <code>Win+R</code> and writing <code>cmd</code> in that , navigate to the script directory , and write : <code>python script.py</code></p>
| 0 | 2009-10-23T17:34:43Z | [
"python",
"windows"
] |
Running Python from the Windows Command Line | 1,614,898 | <p>How do I run a Python file from the Windows Command Line (<code>cmd.exe</code>) so that I won't have to re-enter the code each time?</p>
| 1 | 2009-10-23T17:33:07Z | 1,614,908 | <p>If you put the Python executable (python.exe) on your path, you can invoke your script using <code>python script.py</code> where script.py is the Python file that you want to execute.</p>
| 2 | 2009-10-23T17:34:54Z | [
"python",
"windows"
] |
Running Python from the Windows Command Line | 1,614,898 | <p>How do I run a Python file from the Windows Command Line (<code>cmd.exe</code>) so that I won't have to re-enter the code each time?</p>
| 1 | 2009-10-23T17:33:07Z | 1,614,911 | <p>Wouldn't you simply save your Python code into a file, and then execute that file using Python?</p>
<p>Save your code into a file called <code>Test.py</code>.</p>
<p>And then run it?</p>
<pre><code>$ C:\Python24\Python.exe C:\Temp\Test.py
</code></pre>
| 9 | 2009-10-23T17:35:40Z | [
"python",
"windows"
] |
Running Python from the Windows Command Line | 1,614,898 | <p>How do I run a Python file from the Windows Command Line (<code>cmd.exe</code>) so that I won't have to re-enter the code each time?</p>
| 1 | 2009-10-23T17:33:07Z | 1,614,915 | <p>In DOS you can use <code>edit</code> to create/modify text files, then execute them by typing <code>python [yourfile]</code></p>
| 0 | 2009-10-23T17:37:07Z | [
"python",
"windows"
] |
Running Python from the Windows Command Line | 1,614,898 | <p>How do I run a Python file from the Windows Command Line (<code>cmd.exe</code>) so that I won't have to re-enter the code each time?</p>
| 1 | 2009-10-23T17:33:07Z | 1,615,021 | <p>If you don't want to install an IDE, you can also use IDLE which includes a Python editor and a console to test things out, this is part of the standard installation.</p>
<p>If you installed the python.org version, you will see an <code>IDLE (Python GUI)</code> in your start menu. I would recommend adding it to you... | 5 | 2009-10-23T17:58:08Z | [
"python",
"windows"
] |
Running Python from the Windows Command Line | 1,614,898 | <p>How do I run a Python file from the Windows Command Line (<code>cmd.exe</code>) so that I won't have to re-enter the code each time?</p>
| 1 | 2009-10-23T17:33:07Z | 1,906,056 | <p>A good tool to have is the <a href="http://ipython.scipy.org/moin/Documentation" rel="nofollow">IPython shell</a>. Not only can it run your program (%run command), but it offers also many tools for using Python interactively in an efficient manner (automatic completion, syntax coloring, quick access to the document... | 1 | 2009-12-15T08:52:02Z | [
"python",
"windows"
] |
Running Python from the Windows Command Line | 1,614,898 | <p>How do I run a Python file from the Windows Command Line (<code>cmd.exe</code>) so that I won't have to re-enter the code each time?</p>
| 1 | 2009-10-23T17:33:07Z | 8,796,361 | <p>You need to create environment variables. Follow the instructions here: <a href="http://www.voidspace.org.uk/python/articles/command_line.shtml#environment-variables" rel="nofollow">http://www.voidspace.org.uk/python/articles/command_line.shtml#environment-variables</a></p>
| 1 | 2012-01-09T22:56:19Z | [
"python",
"windows"
] |
Running commands from a file in PDB | 1,614,983 | <p>I would like to run a set of python commands from a file in the PDB debugger.
Related to this, can I set up a file that is automatically run when PDB starts?</p>
| 0 | 2009-10-23T17:49:42Z | 1,615,937 | <p>make a subclass of <code>pdb.Pdb</code> and put a call to your extra stuff in the <code>__init__</code></p>
<p>alternatively</p>
<p>pdb.Pdb() looks for a <code>.pdbrc</code> file, so you may be able to put your stuff in there</p>
<pre><code> # Read $HOME/.pdbrc and ./.pdbrc
self.rcLines = []
if 'HOME' ... | 1 | 2009-10-23T21:17:24Z | [
"python",
"debugging",
"pdb"
] |
Python strategy for extracting text from malformed html pages | 1,615,072 | <p>I'm trying to extract text from arbitrary html pages. Some of the pages (which I have no control over) have malformed html or scripts which make this difficult. Also I'm on a shared hosting environment, so I can install any python lib, but I can't just install anything I want on the server. </p>
<p>pyparsing and ht... | 5 | 2009-10-23T18:11:41Z | 1,615,153 | <p>Try not to laugh, but:</p>
<pre><code>class TextFormatter:
def __init__(self,lynx='/usr/bin/lynx'):
self.lynx = lynx
def html2text(self, unicode_html_source):
"Expects unicode; returns unicode"
return Popen([self.lynx,
'-assume-charset=UTF-8',
... | 5 | 2009-10-23T18:26:02Z | [
"python",
"html",
"text",
"html-content-extraction"
] |
Python strategy for extracting text from malformed html pages | 1,615,072 | <p>I'm trying to extract text from arbitrary html pages. Some of the pages (which I have no control over) have malformed html or scripts which make this difficult. Also I'm on a shared hosting environment, so I can install any python lib, but I can't just install anything I want on the server. </p>
<p>pyparsing and ht... | 5 | 2009-10-23T18:11:41Z | 1,615,168 | <p>Well, it depends how good the solution has to be. I had a similar problem, importing hundreds of old html pages into a new website. I basically did</p>
<pre><code># remove all that crap around the body and let BS fix the tags
newhtml = "<html><body>%s</body></html>" % (
u''.join( unicode... | 0 | 2009-10-23T18:29:37Z | [
"python",
"html",
"text",
"html-content-extraction"
] |
Python strategy for extracting text from malformed html pages | 1,615,072 | <p>I'm trying to extract text from arbitrary html pages. Some of the pages (which I have no control over) have malformed html or scripts which make this difficult. Also I'm on a shared hosting environment, so I can install any python lib, but I can't just install anything I want on the server. </p>
<p>pyparsing and ht... | 5 | 2009-10-23T18:11:41Z | 1,617,219 | <p>BeautifulSoup will do bad with malformed HTML. What about some regex-fu?</p>
<pre><code>>>> import re
>>>
>>> html = """<p>This is paragraph with a bunch of lines
... from a news story.</p>"""
>>>
>>> pattern = re.compile('(?<=p>).+(?=</p)', re.DOT... | 0 | 2009-10-24T06:51:08Z | [
"python",
"html",
"text",
"html-content-extraction"
] |
Python POST XML not executed | 1,615,115 | <p>The Headers post fine but the associated XML seems to be taken as string data only, XML is not processed.
XML string is of the form:</p>
<pre><code>params = '''<?xml version="1.0" encoding"="UTF-8 "?>
<MainRequest>
<requestEnvelope><errorLanguage>en_US</errorLanguage>
</requestEnvel... | 0 | 2009-10-23T18:18:43Z | 1,615,287 | <p>Are you adding a content-type header? To tell the server your request is XML, add the following before sending the request:</p>
<pre><code>request.add_header('Content-Type', 'text/xml')
</code></pre>
| 2 | 2009-10-23T18:53:22Z | [
"python",
"xmlhttprequest"
] |
Python POST XML not executed | 1,615,115 | <p>The Headers post fine but the associated XML seems to be taken as string data only, XML is not processed.
XML string is of the form:</p>
<pre><code>params = '''<?xml version="1.0" encoding"="UTF-8 "?>
<MainRequest>
<requestEnvelope><errorLanguage>en_US</errorLanguage>
</requestEnvel... | 0 | 2009-10-23T18:18:43Z | 1,616,843 | <p>Take out the "urllib.quote()" call. That's what created the string which starts "%3C%3Fxml". If you want to POST XML then just send that XML string as the data, along with the Content-Type that ataylor mentioned. (But in most cases that doesn't make a difference.)</p>
| 0 | 2009-10-24T03:26:18Z | [
"python",
"xmlhttprequest"
] |
What is causing "unbound method __init__() must be called with instance as first argument" from this Python code? | 1,615,148 | <p>I have this class:</p>
<pre><code>from threading import Thread
import time
class Timer(Thread):
def __init__(self, interval, function, *args, **kwargs):
Thread.__init__()
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
... | 6 | 2009-10-23T18:24:04Z | 1,615,165 | <p>This is a frequently asked question at SO, but the answer, in brief, is that the way you call your superclass's constructor is like:</p>
<pre><code>super(Timer,self).__init__()
</code></pre>
| 8 | 2009-10-23T18:29:06Z | [
"python",
"init"
] |
What is causing "unbound method __init__() must be called with instance as first argument" from this Python code? | 1,615,148 | <p>I have this class:</p>
<pre><code>from threading import Thread
import time
class Timer(Thread):
def __init__(self, interval, function, *args, **kwargs):
Thread.__init__()
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
... | 6 | 2009-10-23T18:24:04Z | 1,615,169 | <p>You are doing:</p>
<pre><code>Thread.__init__()
</code></pre>
<p>Use:</p>
<pre><code>Thread.__init__(self)
</code></pre>
<p>Or, rather, use <code>super()</code></p>
| 13 | 2009-10-23T18:29:40Z | [
"python",
"init"
] |
What is causing "unbound method __init__() must be called with instance as first argument" from this Python code? | 1,615,148 | <p>I have this class:</p>
<pre><code>from threading import Thread
import time
class Timer(Thread):
def __init__(self, interval, function, *args, **kwargs):
Thread.__init__()
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
... | 6 | 2009-10-23T18:24:04Z | 1,615,170 | <p>You just need to pass 'self' as an argument to 'Thread.<strong>init</strong>'. After that, it works on my machines.</p>
| 1 | 2009-10-23T18:29:54Z | [
"python",
"init"
] |
What is causing "unbound method __init__() must be called with instance as first argument" from this Python code? | 1,615,148 | <p>I have this class:</p>
<pre><code>from threading import Thread
import time
class Timer(Thread):
def __init__(self, interval, function, *args, **kwargs):
Thread.__init__()
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
... | 6 | 2009-10-23T18:24:04Z | 33,506,632 | <p>First, the reason you must use:</p>
<pre><code>Thread.__init__(self)
</code></pre>
<p>instead of </p>
<pre><code>Thread.__init__()
</code></pre>
<p>is because you are using the class name, and not an object (an instance of the class), so you cannot call a method in the same way as an object.</p>
<p>Second, if y... | 0 | 2015-11-03T18:39:03Z | [
"python",
"init"
] |
In Python, can I print 3 lists in order by index number? | 1,615,289 | <p>So I have three lists:</p>
<pre><code>['this', 'is', 'the', 'first', 'list']
[1, 2, 3, 4, 5]
[0.01, 0.2, 0.3, 0.04, 0.05]
</code></pre>
<p>Is there a way that would allow me to print the values in these lists in order by index? </p>
<p>e.g.</p>
<pre><code>this, 1, 0.01 (all items at list[0])
is, 2, 0.2 (all item... | 6 | 2009-10-23T18:53:32Z | 1,615,298 | <p>Use <code>zip</code></p>
<pre><code>for items in zip(L1, L2, L3):
print items
</code></pre>
<p><code>items</code> will be a tuple with a value from each list, in order.</p>
| 3 | 2009-10-23T18:55:51Z | [
"python",
"list"
] |
In Python, can I print 3 lists in order by index number? | 1,615,289 | <p>So I have three lists:</p>
<pre><code>['this', 'is', 'the', 'first', 'list']
[1, 2, 3, 4, 5]
[0.01, 0.2, 0.3, 0.04, 0.05]
</code></pre>
<p>Is there a way that would allow me to print the values in these lists in order by index? </p>
<p>e.g.</p>
<pre><code>this, 1, 0.01 (all items at list[0])
is, 2, 0.2 (all item... | 6 | 2009-10-23T18:53:32Z | 1,615,300 | <p>What you are probably looking for is called <code>zip</code>:</p>
<pre><code>>>> x = ['this', 'is', 'the', 'first', 'list']
>>> y = [1, 2, 3, 4, 5]
>>> z = [0.01, 0.2, 0.3, 0.04, 0.05]
>>> zip(x,y,z)
[('this', 1, 0.01), ('is', 2, 0.20000000000000001), ('the', 3, 0.299999999999999... | 7 | 2009-10-23T18:55:53Z | [
"python",
"list"
] |
In Python, can I print 3 lists in order by index number? | 1,615,289 | <p>So I have three lists:</p>
<pre><code>['this', 'is', 'the', 'first', 'list']
[1, 2, 3, 4, 5]
[0.01, 0.2, 0.3, 0.04, 0.05]
</code></pre>
<p>Is there a way that would allow me to print the values in these lists in order by index? </p>
<p>e.g.</p>
<pre><code>this, 1, 0.01 (all items at list[0])
is, 2, 0.2 (all item... | 6 | 2009-10-23T18:53:32Z | 1,615,303 | <pre><code>lists = ( ['this', 'is', 'the', 'first', 'list'],
[1, 2, 3, 4, 5],
[0.01, 0.2, 0.3, 0.04, 0.05])
print zip(*lists)
</code></pre>
<p>zips the lists together and stops when the shortest list runs out of items.</p>
| 0 | 2009-10-23T18:56:26Z | [
"python",
"list"
] |
In Python, can I print 3 lists in order by index number? | 1,615,289 | <p>So I have three lists:</p>
<pre><code>['this', 'is', 'the', 'first', 'list']
[1, 2, 3, 4, 5]
[0.01, 0.2, 0.3, 0.04, 0.05]
</code></pre>
<p>Is there a way that would allow me to print the values in these lists in order by index? </p>
<p>e.g.</p>
<pre><code>this, 1, 0.01 (all items at list[0])
is, 2, 0.2 (all item... | 6 | 2009-10-23T18:53:32Z | 1,615,304 | <p>This is the most immediately obvious way (to a python newb), and there is likely a better way, but here goes:</p>
<pre><code>#Your list of lists.
uberlist = ( list1, list2, list3 )
#No sense in duplicating this definition multiple times.
#Define it up front.
uberRange = range( len( uberList ) );
#Since each will ... | 0 | 2009-10-23T18:56:52Z | [
"python",
"list"
] |
Pasting multiple lines into IDLE | 1,615,379 | <p>Is there a way to paste a block of code into IDLE? Pasting line by line works, but sometimes I'd like to paste many lines at once. When I try, IDLE reads the first line and ignores the rest.</p>
<pre><code>>>> a = 1
b = 2
c = 3
>>>
>>> a
1
>>> b
Traceback (most recent call las... | 16 | 2009-10-23T19:15:46Z | 1,615,535 | <p>Probably not the most beautiful procedure, but this works:</p>
<pre><code>cmds = '''
</code></pre>
<p>paste your commands, followed by <code>'''</code>:</p>
<pre><code>a = 1
b = 2
c = 3
'''
</code></pre>
<p>Then <code>exec(cmds)</code> will execute them. </p>
<p>Or more directly,</p>
<pre><code>exec('''
</code... | 15 | 2009-10-23T19:48:47Z | [
"python",
"python-idle"
] |
Pasting multiple lines into IDLE | 1,615,379 | <p>Is there a way to paste a block of code into IDLE? Pasting line by line works, but sometimes I'd like to paste many lines at once. When I try, IDLE reads the first line and ignores the rest.</p>
<pre><code>>>> a = 1
b = 2
c = 3
>>>
>>> a
1
>>> b
Traceback (most recent call las... | 16 | 2009-10-23T19:15:46Z | 9,868,250 | <p><a href="http://idlex.sourceforge.net">IdleX</a> provides the PastePyShell.py extension for IDLE which allows pasting of multiple lines into the shell for execution.</p>
| 5 | 2012-03-26T07:34:27Z | [
"python",
"python-idle"
] |
Python dictionary creation error | 1,615,501 | <p>I am trying to create a Python dictionary from a stored list. This first method works</p>
<pre><code>>>> myList = []
>>> myList.append('Prop1')
>>> myList.append('Prop2')
>>> myDict = dict([myList])
</code></pre>
<p>However, the following method does not work</p>
<pre><code>>... | 5 | 2009-10-23T19:42:16Z | 1,615,546 | <p>You're doing it wrong.</p>
<p>The <code>dict()</code> constructor doesn't take a list of items (much less a list containing a single list of items), it takes an iterable of 2-element iterables. So if you changed your code to be:</p>
<pre><code>myList = []
myList.append(["mykey1", "myvalue1"])
myList.append(["myke... | 13 | 2009-10-23T19:50:10Z | [
"python",
"python-2.5"
] |
How to get duration of video flash file? | 1,615,690 | <p>On Linux, YouTube places temporary flash files in /tmp. Nautilus can display the duration (Minutes:Seconds) of them, but I haven't found a way to extract the duration using python.'
The fewer dependencies your method requires the better.</p>
<p>Thanks in advance.</p>
| 2 | 2009-10-23T20:21:31Z | 1,617,438 | <p>One way it can be done using ffmpeg. ffmpeg needs to be installed with h.264 and h.263 codec support. Then following is the command to retrieve the video duration, which can be called via python <code>system(command)</code>.<br>
<code>ffmpeg -i flv_file 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//</code>... | 3 | 2009-10-24T09:07:00Z | [
"python",
"flash"
] |
How to get duration of video flash file? | 1,615,690 | <p>On Linux, YouTube places temporary flash files in /tmp. Nautilus can display the duration (Minutes:Seconds) of them, but I haven't found a way to extract the duration using python.'
The fewer dependencies your method requires the better.</p>
<p>Thanks in advance.</p>
| 2 | 2009-10-23T20:21:31Z | 8,070,345 | <p>While this example may seem overly complicated, I did it as an exercise to better understand Python and it makes dealing with the atomic parts of the file's duration easier.</p>
<pre><code>#!/usr/bin/env python
"""
duration
=========
Display the duration of a video file. Utilizes ffmpeg to retrieve tha... | 1 | 2011-11-09T19:20:25Z | [
"python",
"flash"
] |
Engines built on pygame | 1,615,693 | <p>I am currently writing an RTS for pygame and have written a number of modules on top of pygame for common things, such as efficient collision detection, a state system and more featured sprites. Now while writing games, except for Rect and Surface, I barely write any calls to Pygame itself.</p>
<p>When Googling a... | 2 | 2009-10-23T20:22:03Z | 1,615,715 | <p>Well Pygame itself is essentially a Python wrapper to SDL calls. I think in essence you would just be wrapping a wrapper.</p>
<p>You could always build your own adapter API, but what in particular about Pygame's API do you dislike so much that you feel you need to separate it from your code?</p>
<p>I think your ge... | 5 | 2009-10-23T20:27:02Z | [
"python",
"pygame"
] |
Setting an object in the Django cache API fails due to pickle error | 1,615,721 | <p>I'm trying to manually set an object in the Django cache API but it fails (i think due to pickling?)
The object is given to me by a third party, my code is:</p>
<pre><code>def index(request, template_name="mytemplate.htm"):
user_list = cache.get("user_list_ds")
if user_list is None:
# this is th... | 2 | 2009-10-23T20:28:24Z | 1,615,743 | <p>It appears that you need to install <a href="http://effbot.org/zone/element-index.htm" rel="nofollow"><code>ElementTree</code></a>, because the <code>pickle</code> operation tries and fails to import the <code>etree</code> module.</p>
<p>UPDATE: Looking at it further, are you actually trying to cache document nodes... | 2 | 2009-10-23T20:34:44Z | [
"python",
"django",
"memcached",
"pickle"
] |
How to use C++ classes with ctypes? | 1,615,813 | <p>I'm just getting started with ctypes and would like to use a C++ class that I have exported in a dll file from within python using ctypes.
So lets say my C++ code looks something like this:</p>
<pre class="lang-c++ prettyprint-override"><code>class MyClass {
public:
int test();
...
</code></pre>
<p>I would k... | 30 | 2009-10-23T20:51:00Z | 1,616,143 | <p>The short story is that there is no standard binary interface for C++ in the way that there is for C. Different compilers output different binaries for the same C++ dynamic libraries, due to name mangling and different ways to handle the stack between library function calls.</p>
<p>So, unfortunately, there really ... | 25 | 2009-10-23T21:59:45Z | [
"c++",
"python",
"ctypes"
] |
How to use C++ classes with ctypes? | 1,615,813 | <p>I'm just getting started with ctypes and would like to use a C++ class that I have exported in a dll file from within python using ctypes.
So lets say my C++ code looks something like this:</p>
<pre class="lang-c++ prettyprint-override"><code>class MyClass {
public:
int test();
...
</code></pre>
<p>I would k... | 30 | 2009-10-23T20:51:00Z | 7,061,012 | <p>Besides Boost.Python(which is probably a more friendly solution for larger projects that require one-to-one mapping of C++ classes to python classes), you could provide on the C++ side a C interface. It's one solution of many so it has its own trade offs, but I will present it for the benefit of those who aren't fam... | 26 | 2011-08-15T01:44:32Z | [
"c++",
"python",
"ctypes"
] |
How to use C++ classes with ctypes? | 1,615,813 | <p>I'm just getting started with ctypes and would like to use a C++ class that I have exported in a dll file from within python using ctypes.
So lets say my C++ code looks something like this:</p>
<pre class="lang-c++ prettyprint-override"><code>class MyClass {
public:
int test();
...
</code></pre>
<p>I would k... | 30 | 2009-10-23T20:51:00Z | 7,139,512 | <p>I found this very interesting: <a href="http://www.haskell.org/haskellwiki/CPlusPlus_from_Haskell" rel="nofollow">Calling C++ from Haskell - "The Hard Way"</a></p>
| 0 | 2011-08-21T16:24:35Z | [
"c++",
"python",
"ctypes"
] |
How to use C++ classes with ctypes? | 1,615,813 | <p>I'm just getting started with ctypes and would like to use a C++ class that I have exported in a dll file from within python using ctypes.
So lets say my C++ code looks something like this:</p>
<pre class="lang-c++ prettyprint-override"><code>class MyClass {
public:
int test();
...
</code></pre>
<p>I would k... | 30 | 2009-10-23T20:51:00Z | 21,808,137 | <p>This is a short explanation on how to use c and c++ with C_types in python.
<a href="http://wolfprojects.altervista.org/articles/dll-in-c-for-python/" rel="nofollow">How to write a DLL/SO in C++ for Python</a></p>
| 1 | 2014-02-16T06:35:50Z | [
"c++",
"python",
"ctypes"
] |
Python to Postgres interface with real prepared statements? | 1,616,106 | <p>I've been trying to find a postgres interface for python 2.x that supports real prepared statements, but can't seem to find anything. I don't want one that just escapes quotes in the params you pass in and then interpolates them into the query before executing it. Anyone have any suggestions?</p>
| 4 | 2009-10-23T21:51:12Z | 1,617,497 | <p>have a look at web.py's <a href="http://github.com/webpy/webpy/blob/master/web/db.py" rel="nofollow">db module</a> </p>
<p>examples can be found at </p>
<ol>
<li><a href="http://webpy.org/cookbook/select" rel="nofollow">http://webpy.org/cookbook/select</a></li>
<li><a href="http://webpy.org/cookbook/update" rel="n... | 0 | 2009-10-24T09:36:43Z | [
"python",
"postgresql"
] |
Python to Postgres interface with real prepared statements? | 1,616,106 | <p>I've been trying to find a postgres interface for python 2.x that supports real prepared statements, but can't seem to find anything. I don't want one that just escapes quotes in the params you pass in and then interpolates them into the query before executing it. Anyone have any suggestions?</p>
| 4 | 2009-10-23T21:51:12Z | 1,621,371 | <p>Either <a href="http://python.projects.postgresql.org/" rel="nofollow">py-postgresql</a> for Python3 or <a href="http://python.projects.postgresql.org/old/project/pg%5Fproboscis.html" rel="nofollow">pg_proboscis</a> for Python2 will do this.</p>
<p><a href="http://pypi.python.org/pypi/python-pgsql/" rel="nofollow">... | 1 | 2009-10-25T16:48:23Z | [
"python",
"postgresql"
] |
Python to Postgres interface with real prepared statements? | 1,616,106 | <p>I've been trying to find a postgres interface for python 2.x that supports real prepared statements, but can't seem to find anything. I don't want one that just escapes quotes in the params you pass in and then interpolates them into the query before executing it. Anyone have any suggestions?</p>
| 4 | 2009-10-23T21:51:12Z | 9,841,662 | <p>These links hint at the answer when using psycopg2. You don't need special API extensions.</p>
<ul>
<li><a href="http://archives.postgresql.org/message-id/200805051446.28085.micah@yoderdev.com" rel="nofollow">Re: psycopg2 and prepared statements</a></li>
<li><a href="http://groups.google.com/group/sqlalchemy/browse... | 0 | 2012-03-23T15:11:21Z | [
"python",
"postgresql"
] |
PyQT GUI Testing | 1,616,228 | <p>Does anyone know of a automated GUI testing package for that works with PyQT besides Squish? Nothing against Squish I am just looking for other packages. It would be cool if there were an open source package. I am doing my testing under Linux.</p>
| 9 | 2009-10-23T22:19:41Z | 1,751,114 | <p>You should be able to use pyunit in conjunction with PyQT. </p>
<p><a href="http://pyunit.sourceforge.net/" rel="nofollow">http://pyunit.sourceforge.net/</a></p>
| 0 | 2009-11-17T19:17:58Z | [
"python",
"testing",
"pyqt"
] |
PyQT GUI Testing | 1,616,228 | <p>Does anyone know of a automated GUI testing package for that works with PyQT besides Squish? Nothing against Squish I am just looking for other packages. It would be cool if there were an open source package. I am doing my testing under Linux.</p>
| 9 | 2009-10-23T22:19:41Z | 1,813,924 | <p><a href="http://www.tizmoi.net/watsup/intro.html" rel="nofollow">WATSUP</a> has worked for me.</p>
| 2 | 2009-11-28T22:07:26Z | [
"python",
"testing",
"pyqt"
] |
PyQT GUI Testing | 1,616,228 | <p>Does anyone know of a automated GUI testing package for that works with PyQT besides Squish? Nothing against Squish I am just looking for other packages. It would be cool if there were an open source package. I am doing my testing under Linux.</p>
| 9 | 2009-10-23T22:19:41Z | 1,829,332 | <p>It looks like PyQT4 includes a QtTest object that can be used for unit testing.</p>
| 3 | 2009-12-01T22:16:51Z | [
"python",
"testing",
"pyqt"
] |
Are there any problems with this symlink traversal code for Windows? | 1,616,245 | <p>In my efforts to resolve <a href="http://bugs.python.org/issue1578269" rel="nofollow">Python issue 1578269</a>, I've been working on trying to resolve the target of a symlink in a robust way. I started by using GetFinalPathNameByHandle as recommended <a href="http://stackoverflow.com/questions/221417/how-do-i-progra... | 2 | 2009-10-23T22:24:18Z | 1,617,645 | <p>Unfortunately I can't test with Vista until next week, but GetFinalPathNameByHandle should work, even for files in use - what's the problem you noticed?
In your code above, you forget to close the file handle.</p>
| 0 | 2009-10-24T10:46:31Z | [
"python",
"windows",
"winapi",
"filesystems",
"symlink-traversal"
] |
Navigating in the python terminal | 1,616,321 | <p>I want a 64-bit python interpreter on my Mac so I had to rebuild from source. However, with my own custom build interpreter I run into issues when I try to navigate when I run the interpreter from inside a shell. Typing python into the bash shell results in the familiar:</p>
<pre><code>Python 2.6.3 (r263:75183, Oct... | 0 | 2009-10-23T22:50:36Z | 1,616,334 | <p>Sounds like your custom build didn't include readline. Should be a simple config change and rebuild, check <a href="http://bytes.com/topic/python/answers/30809-linux-python-arrow-key-problem-when-interactive-interpreter" rel="nofollow">here</a> for more info.</p>
| 6 | 2009-10-23T22:55:55Z | [
"python",
"shell",
"navigation"
] |
Navigating in the python terminal | 1,616,321 | <p>I want a 64-bit python interpreter on my Mac so I had to rebuild from source. However, with my own custom build interpreter I run into issues when I try to navigate when I run the interpreter from inside a shell. Typing python into the bash shell results in the familiar:</p>
<pre><code>Python 2.6.3 (r263:75183, Oct... | 0 | 2009-10-23T22:50:36Z | 1,616,405 | <p>Installing the GNU readline library from <a href="http://tiswww.case.edu/php/chet/readline/rltop.html" rel="nofollow">here</a>, and rebuilding python fixes the problem.</p>
| 0 | 2009-10-23T23:20:17Z | [
"python",
"shell",
"navigation"
] |
Best way to extract .ico from .exe and paint with PyQt? | 1,616,342 | <p>I am looking for a way to extract an icon from a .exe file using Python. I know that you can use win32gui's ExtractIconEx function to grab the icon of a .exe but this returns a HIcon resource handle which is no good because I want to paint the icon using PyQt.</p>
<p>Also the only example I have seen using win32gui... | 2 | 2009-10-23T22:59:24Z | 1,617,382 | <p>There is a method to create <code>QPixmap</code> from a <code>HBITMAP</code>, so the only problem is how to convert <code>HICON</code> to <code>HBITMAP</code>. This can be done using <code>GetIconInfo</code>.</p>
<pre><code>icons = win32gui.ExtractIconEx('C:/Program Files/Internet Explorer/iexplore.exe', 0, 10)
inf... | 1 | 2009-10-24T08:40:25Z | [
"python",
"pyqt",
"pywin32"
] |
Trying to position subplots next to each other | 1,616,427 | <p>I am trying to position two subplots next to each other (as opposed to under each other). I am expecting to see [sp1] [sp2]<br />
Instead, only the second plot [sp2] is getting displayed. </p>
<pre><code>from matplotlib import pyplot
x = [0, 1, 2]
pyplot.figure()
# sp1
pyplot.subplot(211)
pyplot.bar(x, x)
# sp2... | 3 | 2009-10-23T23:25:05Z | 1,616,475 | <p>The 3 numbers are rows, columns, and plot #. What you're doing is respecifying the number of columns in your second call to subplot, which in turn changes the configuration and causes pyplot to start over.</p>
<p>What you mean is:</p>
<pre><code>subplot(211)
...
subplot(212)
</code></pre>
| 4 | 2009-10-23T23:38:28Z | [
"python",
"matplotlib"
] |
Trying to position subplots next to each other | 1,616,427 | <p>I am trying to position two subplots next to each other (as opposed to under each other). I am expecting to see [sp1] [sp2]<br />
Instead, only the second plot [sp2] is getting displayed. </p>
<pre><code>from matplotlib import pyplot
x = [0, 1, 2]
pyplot.figure()
# sp1
pyplot.subplot(211)
pyplot.bar(x, x)
# sp2... | 3 | 2009-10-23T23:25:05Z | 1,616,508 | <pre><code>from matplotlib import pyplot
x = [0, 1, 2]
pyplot.figure()
# sp1
pyplot.subplot(121)
pyplot.bar(x, x)
# sp2
pyplot.subplot(122)
pyplot.plot(x, x)
pyplot.show()
</code></pre>
| 3 | 2009-10-23T23:53:05Z | [
"python",
"matplotlib"
] |
Installing mod_python on Snow Leopard | 1,616,431 | <p>I'd rather not use Macports. Simply cause Macport replaces (installs another Apache in /opt/local/bin) the default installation of Apache. And that would mean having ports install/replace PHP too. I'd rather use the default installation included in Snow Leopard.</p>
<p>Been searching the net, and all I get is old i... | 0 | 2009-10-23T23:25:49Z | 1,616,494 | <p><a href="http://www.finkproject.org/" rel="nofollow">fink</a> is the alternative distribution to <a href="http://www.macports.org/" rel="nofollow">MacPorts</a>. Given you're installing a module, it would most likely update your Apache instance as well.</p>
<p>Sounds like you'll probably need to build Apache (to ge... | 0 | 2009-10-23T23:44:54Z | [
"python",
"osx-snow-leopard",
"mod-python"
] |
Installing mod_python on Snow Leopard | 1,616,431 | <p>I'd rather not use Macports. Simply cause Macport replaces (installs another Apache in /opt/local/bin) the default installation of Apache. And that would mean having ports install/replace PHP too. I'd rather use the default installation included in Snow Leopard.</p>
<p>Been searching the net, and all I get is old i... | 0 | 2009-10-23T23:25:49Z | 1,707,521 | <p>First of all, it seems that the mod_python development has somewhat stalled. I've read comments that, for wsgi-capable applications like Trac or Django, <a href="http://code.google.com/p/modwsgi/" rel="nofollow">mod_wsgi</a> is sufficient. Mod_wsgi compiles without problems on Snow Leopard (of course you need the De... | 2 | 2009-11-10T12:14:08Z | [
"python",
"osx-snow-leopard",
"mod-python"
] |
Installing mod_python on Snow Leopard | 1,616,431 | <p>I'd rather not use Macports. Simply cause Macport replaces (installs another Apache in /opt/local/bin) the default installation of Apache. And that would mean having ports install/replace PHP too. I'd rather use the default installation included in Snow Leopard.</p>
<p>Been searching the net, and all I get is old i... | 0 | 2009-10-23T23:25:49Z | 2,419,160 | <p>If you still want to avoid macports, I recommend checking out the mod_python trunk. I was actually able to build it with apache2 and Python 2.5 successfully without having to tweak the source of any of all the previously reported issues</p>
<p>svn co <a href="https://svn.apache.org/repos/asf/quetzalcoatl/mod_python... | 0 | 2010-03-10T17:39:57Z | [
"python",
"osx-snow-leopard",
"mod-python"
] |
writing a font viewer - getting font properties, loading ttf dynamically | 1,616,505 | <p>I'm trying to write a font viewer for TrueType / OpenType fonts with VB6 / VB5 code (under Windows).</p>
<p>it is surprisingly difficult:</p>
<p>1) in VB / winAPI, i did not find how to extract the font's name, or font properties in general.</p>
<p>2) i can install the font (using AddFontResource API function), b... | 2 | 2009-10-23T23:49:33Z | 1,616,567 | <p>It indeed is. I have faced the same problem myself (see my <a href="http://stackoverflow.com/questions/615479/corrupt-truetype-font-detection">question</a>). I ended up writing my own parser though because I needed to detect if the font was corrupt or not. There is a <a href="http://msdn.microsoft.com/en-us/library/... | 0 | 2009-10-24T00:21:30Z | [
"python",
"vb6",
"true-type-fonts"
] |
writing a font viewer - getting font properties, loading ttf dynamically | 1,616,505 | <p>I'm trying to write a font viewer for TrueType / OpenType fonts with VB6 / VB5 code (under Windows).</p>
<p>it is surprisingly difficult:</p>
<p>1) in VB / winAPI, i did not find how to extract the font's name, or font properties in general.</p>
<p>2) i can install the font (using AddFontResource API function), b... | 2 | 2009-10-23T23:49:33Z | 1,616,598 | <p>You could use the <a href="http://www.freetype.org" rel="nofollow">FreeType library</a>.</p>
| 1 | 2009-10-24T00:36:33Z | [
"python",
"vb6",
"true-type-fonts"
] |
Python: Xlib -- How can I raise(bring to top) windows? | 1,616,628 | <p>I've tried using:</p>
<pre><code> win.configure(stack_mode=X.TopIf)
win.set_input_focus(X.RevertToParent, X.CurrentTime)
</code></pre>
<p>However even without any focus loss prevention on my window manager this does not work, does anyone know of another way to do this? Xlib or not.</p>
| 4 | 2009-10-24T00:49:18Z | 1,652,847 | <p>Perhaps this is the solution:<br />
<a href="http://lists.freedesktop.org/archives/xorg/2008-August/037684.html" rel="nofollow">[Xlib] Force Raise/Map/Focus a given Window</a></p>
<p>A solution given (follow the thread) involves using wnck, which in Python is a part of the Gtk+ bindings.</p>
| 0 | 2009-10-30T23:50:57Z | [
"python",
"linux",
"xlib"
] |
Python: Xlib -- How can I raise(bring to top) windows? | 1,616,628 | <p>I've tried using:</p>
<pre><code> win.configure(stack_mode=X.TopIf)
win.set_input_focus(X.RevertToParent, X.CurrentTime)
</code></pre>
<p>However even without any focus loss prevention on my window manager this does not work, does anyone know of another way to do this? Xlib or not.</p>
| 4 | 2009-10-24T00:49:18Z | 1,653,185 | <p>There is a command-line tool called <a href="http://tripie.sweb.cz/utils/wmctrl/" rel="nofollow">wmctrl</a> which allows you to interact with EWMH/NetWM-compatible X window managers.</p>
<p>For example,</p>
<pre><code>wmctrl -l
</code></pre>
<p>lists all the windows managed by the window manager, and</p>
<pre><c... | 3 | 2009-10-31T02:15:56Z | [
"python",
"linux",
"xlib"
] |
Python: Xlib -- How can I raise(bring to top) windows? | 1,616,628 | <p>I've tried using:</p>
<pre><code> win.configure(stack_mode=X.TopIf)
win.set_input_focus(X.RevertToParent, X.CurrentTime)
</code></pre>
<p>However even without any focus loss prevention on my window manager this does not work, does anyone know of another way to do this? Xlib or not.</p>
| 4 | 2009-10-24T00:49:18Z | 3,297,152 | <p>Try this:</p>
<pre><code>window=Display().screen().root.query_pointer().child
window.set_input_focus(X.RevertToParent, X.CurrentTime)
window.configure(stack_mode=X.Above)
</code></pre>
| 0 | 2010-07-21T07:40:57Z | [
"python",
"linux",
"xlib"
] |
PIL Best Way To Replace Color? | 1,616,767 | <p>I am trying to remove a certain color from my image however it's not working as well as I'd hoped. I tried to do the same thing as seen here <a href="http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-transparent">http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-... | 11 | 2009-10-24T02:42:12Z | 1,616,893 | <p>You'll need to represent the image as a 2-dimensional array. This means either making a list of lists of pixels, or viewing the 1-dimensional array as a 2d one with some clever math. Then, for each pixel that is targeted, you'll need to find all surrounding pixels. You could do this with a python generator thus:<... | 4 | 2009-10-24T03:51:21Z | [
"python",
"image",
"replace",
"colors",
"python-imaging-library"
] |
PIL Best Way To Replace Color? | 1,616,767 | <p>I am trying to remove a certain color from my image however it's not working as well as I'd hoped. I tried to do the same thing as seen here <a href="http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-transparent">http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-... | 11 | 2009-10-24T02:42:12Z | 1,617,014 | <p>If the pixels are not easily identifiable e.g you say (r < 100 and g < 100 and b < 100) also doesn't match correctly the black region, it means you have lots of noise.</p>
<p>Best way would be to identify a region and fill it with color you want, you can identify the region manually or may be by edge detec... | 3 | 2009-10-24T05:02:24Z | [
"python",
"image",
"replace",
"colors",
"python-imaging-library"
] |
PIL Best Way To Replace Color? | 1,616,767 | <p>I am trying to remove a certain color from my image however it's not working as well as I'd hoped. I tried to do the same thing as seen here <a href="http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-transparent">http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-... | 11 | 2009-10-24T02:42:12Z | 1,617,909 | <p>The best way to do it is to use the "color to alpha" algorithm used in <a href="http://www.gimp.org/tutorials/Changing%5FBackground%5FColor%5F1/">Gimp</a> to replace a color. It will work perfectly in your case. I reimplemented this algorithm using PIL for an open source python photo processor <a href="http://photob... | 20 | 2009-10-24T12:36:50Z | [
"python",
"image",
"replace",
"colors",
"python-imaging-library"
] |
PIL Best Way To Replace Color? | 1,616,767 | <p>I am trying to remove a certain color from my image however it's not working as well as I'd hoped. I tried to do the same thing as seen here <a href="http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-transparent">http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-... | 11 | 2009-10-24T02:42:12Z | 3,169,874 | <p>Using numpy and PIL: </p>
<p>This loads the image into a numpy array of shape <code>(W,H,3)</code>, where <code>W</code> is the
width and <code>H</code> is the height. The third axis of the array represents the 3 color
channels, <code>R,G,B</code>.</p>
<pre><code>import Image
import numpy as np
orig_color = (255,... | 7 | 2010-07-03T00:55:01Z | [
"python",
"image",
"replace",
"colors",
"python-imaging-library"
] |
PIL Best Way To Replace Color? | 1,616,767 | <p>I am trying to remove a certain color from my image however it's not working as well as I'd hoped. I tried to do the same thing as seen here <a href="http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-transparent">http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-... | 11 | 2009-10-24T02:42:12Z | 3,850,345 | <pre><code>#!/usr/bin/python
from PIL import Image
import sys
img = Image.open(sys.argv[1])
img = img.convert("RGBA")
pixdata = img.load()
# Clean the background noise, if color != white, then set to black.
# change with your color
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x,... | 8 | 2010-10-03T15:24:43Z | [
"python",
"image",
"replace",
"colors",
"python-imaging-library"
] |
IN clause with integers in sqlalchemy/psycopg2 | 1,617,076 | <p>Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of:</p>
<pre><code>SELECT * FROM table WHERE pk_table_id IN ()
</code></pre>
<p>For the example below I tried <code>self.ids</code> as a tuple containing string or integer... | 7 | 2009-10-24T05:43:24Z | 1,617,098 | <p>The <code>%s</code> placeholder in <code>execute</code> expects a scalar, not a tuple. You either need to replace it with <code>','.join(('%s',) * len(mytuple))</code>, or use string substitution instead!</p>
| 3 | 2009-10-24T05:57:54Z | [
"python",
"sql",
"postgresql"
] |
IN clause with integers in sqlalchemy/psycopg2 | 1,617,076 | <p>Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of:</p>
<pre><code>SELECT * FROM table WHERE pk_table_id IN ()
</code></pre>
<p>For the example below I tried <code>self.ids</code> as a tuple containing string or integer... | 7 | 2009-10-24T05:43:24Z | 1,617,923 | <p>if self.ids is an array, you will have a problem doing the conversion within the execute statement. Instead, you should do it as a string operation before calling the execute statement. </p>
<p>Try this:</p>
<pre><code>my_connection.execute('SELECT * FROM public.table WHERE pk_table_id IN (%s)' %
... | 1 | 2009-10-24T12:43:29Z | [
"python",
"sql",
"postgresql"
] |
IN clause with integers in sqlalchemy/psycopg2 | 1,617,076 | <p>Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of:</p>
<pre><code>SELECT * FROM table WHERE pk_table_id IN ()
</code></pre>
<p>For the example below I tried <code>self.ids</code> as a tuple containing string or integer... | 7 | 2009-10-24T05:43:24Z | 1,646,829 | <p>I ended up ditching SqlAlchemy for straight psycopg2, so I don't know if it applies 100%. What I found out was that psycopg2 will correctly compile the IN clause if you pass it a tuple rather than an array/list. I passed a tuple of integers and it worked just fine.</p>
| 5 | 2009-10-29T21:56:35Z | [
"python",
"sql",
"postgresql"
] |
IN clause with integers in sqlalchemy/psycopg2 | 1,617,076 | <p>Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of:</p>
<pre><code>SELECT * FROM table WHERE pk_table_id IN ()
</code></pre>
<p>For the example below I tried <code>self.ids</code> as a tuple containing string or integer... | 7 | 2009-10-24T05:43:24Z | 10,445,238 | <p>You should convert list of ids to the string and change second param of <code>execute</code> method to tuple with empty tail:</p>
<pre><code>ids = ",".join(self.ids)
my_connection.execute('SELECT * FROM public.table WHERE pk_table_id IN (%s)' % (ids,))
</code></pre>
| -3 | 2012-05-04T08:21:40Z | [
"python",
"sql",
"postgresql"
] |
IN clause with integers in sqlalchemy/psycopg2 | 1,617,076 | <p>Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of:</p>
<pre><code>SELECT * FROM table WHERE pk_table_id IN ()
</code></pre>
<p>For the example below I tried <code>self.ids</code> as a tuple containing string or integer... | 7 | 2009-10-24T05:43:24Z | 13,941,863 | <p>You can use the <a href="http://initd.org/psycopg/docs/usage.html#adapt-tuple">cur.mogrify</a> method:</p>
<pre><code>cur = my_connection.cursor()
cur.execute(cur.mogrify('SELECT * FROM public.table WHERE pk_table_id IN %s', (tuple(self.ids),)))
</code></pre>
| 7 | 2012-12-18T21:34:55Z | [
"python",
"sql",
"postgresql"
] |
IN clause with integers in sqlalchemy/psycopg2 | 1,617,076 | <p>Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of:</p>
<pre><code>SELECT * FROM table WHERE pk_table_id IN ()
</code></pre>
<p>For the example below I tried <code>self.ids</code> as a tuple containing string or integer... | 7 | 2009-10-24T05:43:24Z | 28,216,397 | <p>if your ids are in a list you can use list adaptation:</p>
<pre><code>my_connection.execute('SELECT * FROM public.table WHERE pk_table_id = ANY(%s)', (self.ids,))
</code></pre>
<p>Taken from <a href="http://initd.org/psycopg/docs/usage.html#lists-adaptation" rel="nofollow">lists-adaptation</a></p>
| 2 | 2015-01-29T13:50:43Z | [
"python",
"sql",
"postgresql"
] |
OrderedDict for older versions of python | 1,617,078 | <p>Ordered dictionaries are extremely useful structures, but unfortunately these are quite recent only working in versions from <a href="http://docs.python.org/dev/py3k/library/collections.html#ordereddict-objects">3.1</a> and <a href="http://docs.python.org/dev/whatsnew/2.7.html#pep-372-adding-an-ordered-dictionary-to... | 52 | 2009-10-24T05:44:33Z | 1,617,087 | <p>According to the <a href="http://docs.python.org/dev/py3k/library/collections.html#collections.OrderedDict">documentation</a>, for Python versions 2.4 or later <a href="http://code.activestate.com/recipes/576693/">this code</a> should be used. There is also some <a href="http://code.activestate.com/recipes/576669/">... | 21 | 2009-10-24T05:49:26Z | [
"python"
] |
OrderedDict for older versions of python | 1,617,078 | <p>Ordered dictionaries are extremely useful structures, but unfortunately these are quite recent only working in versions from <a href="http://docs.python.org/dev/py3k/library/collections.html#ordereddict-objects">3.1</a> and <a href="http://docs.python.org/dev/whatsnew/2.7.html#pep-372-adding-an-ordered-dictionary-to... | 52 | 2009-10-24T05:44:33Z | 6,852,800 | <p>I installed ordereddict on python 2.6 with pip</p>
<pre><code>pip install ordereddict
</code></pre>
| 56 | 2011-07-28T00:20:51Z | [
"python"
] |
OrderedDict for older versions of python | 1,617,078 | <p>Ordered dictionaries are extremely useful structures, but unfortunately these are quite recent only working in versions from <a href="http://docs.python.org/dev/py3k/library/collections.html#ordereddict-objects">3.1</a> and <a href="http://docs.python.org/dev/whatsnew/2.7.html#pep-372-adding-an-ordered-dictionary-to... | 52 | 2009-10-24T05:44:33Z | 31,097,407 | <p>To import a OrderedDict class for different versions of Python, consider this snippet:</p>
<pre><code>try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
# Now use it from any version of Python
mydict = OrderedDict()
</code></pre>
<p>Versions older than Python ... | 3 | 2015-06-28T08:00:55Z | [
"python"
] |
OrderedDict for older versions of python | 1,617,078 | <p>Ordered dictionaries are extremely useful structures, but unfortunately these are quite recent only working in versions from <a href="http://docs.python.org/dev/py3k/library/collections.html#ordereddict-objects">3.1</a> and <a href="http://docs.python.org/dev/whatsnew/2.7.html#pep-372-adding-an-ordered-dictionary-to... | 52 | 2009-10-24T05:44:33Z | 31,828,282 | <p>in python2.6 gave to me:</p>
<pre><code>$ pip install ordereddict
Could not find a version that satisfies the requirement from (from versions:)
No matching distribution found for from
</code></pre>
<p>but </p>
<pre><code>$ easy_install ordereddict
install_dir /usr/local/lib/python2.6/dist-packages/
Searching fo... | 0 | 2015-08-05T09:18:05Z | [
"python"
] |
OrderedDict for older versions of python | 1,617,078 | <p>Ordered dictionaries are extremely useful structures, but unfortunately these are quite recent only working in versions from <a href="http://docs.python.org/dev/py3k/library/collections.html#ordereddict-objects">3.1</a> and <a href="http://docs.python.org/dev/whatsnew/2.7.html#pep-372-adding-an-ordered-dictionary-to... | 52 | 2009-10-24T05:44:33Z | 33,879,049 | <p>For those who can't depend on the user having pip for some reason, here is a <strong>really terrible</strong> implementaiton of OrderedDict (it is immutable, has most of the features but none of the performance boost).</p>
<pre><code>class OrderedDict(tuple):
'''A really terrible implementation of OrderedDict (... | 0 | 2015-11-23T19:29:06Z | [
"python"
] |
OrderedDict for older versions of python | 1,617,078 | <p>Ordered dictionaries are extremely useful structures, but unfortunately these are quite recent only working in versions from <a href="http://docs.python.org/dev/py3k/library/collections.html#ordereddict-objects">3.1</a> and <a href="http://docs.python.org/dev/whatsnew/2.7.html#pep-372-adding-an-ordered-dictionary-to... | 52 | 2009-10-24T05:44:33Z | 37,220,589 | <p>Also, you could just program your way around it if your situation allows:</p>
<pre><code>def doSomething(strInput): return [ord(x) for x in strInput]
things = ['first', 'second', 'third', 'fourth']
oDict = {}
orderedKeys = []
for thing in things:
oDict[thing] = doSomething(thing)
orderedKeys.append(thing)... | 0 | 2016-05-13T23:06:56Z | [
"python"
] |
Which key:value store to use with Python? | 1,617,309 | <p>So I'm looking at various key:value (where value is either strictly a single value or possibly an object) stores for use with Python, and have found a few promising ones. I have no specific requirement as of yet because I am in the evaluation phase. I'm looking for what's good, what's bad, what are the corner cases ... | 11 | 2009-10-24T07:48:35Z | 1,617,371 | <p>How about Amazon's SimpleDB?</p>
<p>There is an open-source python library called boto for python interfacing Amazon web services.</p>
| -1 | 2009-10-24T08:34:38Z | [
"python",
"memcached",
"couchdb",
"tokyo-tyrant"
] |
Which key:value store to use with Python? | 1,617,309 | <p>So I'm looking at various key:value (where value is either strictly a single value or possibly an object) stores for use with Python, and have found a few promising ones. I have no specific requirement as of yet because I am in the evaluation phase. I'm looking for what's good, what's bad, what are the corner cases ... | 11 | 2009-10-24T07:48:35Z | 1,618,306 | <p>That mostly depends on your need.</p>
<p>Read <a href="http://jan.prima.de/plok/archives/176-Caveats-of-Evaluating-Databases.html">Caveats of Evaluating Databases</a> to understand how to evaluate them. </p>
| 6 | 2009-10-24T15:39:07Z | [
"python",
"memcached",
"couchdb",
"tokyo-tyrant"
] |
Which key:value store to use with Python? | 1,617,309 | <p>So I'm looking at various key:value (where value is either strictly a single value or possibly an object) stores for use with Python, and have found a few promising ones. I have no specific requirement as of yet because I am in the evaluation phase. I'm looking for what's good, what's bad, what are the corner cases ... | 11 | 2009-10-24T07:48:35Z | 1,618,593 | <p>shelve (storing dictonaris in file / standard python module) </p>
<p>ZODB - persisatnce object database (python objects database, no SQL)</p>
<p>More persistance tools:
<a href="http://wiki.python.org/moin/PersistenceTools" rel="nofollow">http://wiki.python.org/moin/PersistenceTools</a></p>
| 3 | 2009-10-24T17:40:51Z | [
"python",
"memcached",
"couchdb",
"tokyo-tyrant"
] |
Which key:value store to use with Python? | 1,617,309 | <p>So I'm looking at various key:value (where value is either strictly a single value or possibly an object) stores for use with Python, and have found a few promising ones. I have no specific requirement as of yet because I am in the evaluation phase. I'm looking for what's good, what's bad, what are the corner cases ... | 11 | 2009-10-24T07:48:35Z | 1,620,222 | <p>My 5 cents:</p>
<p>Do you need distributed systems with tera byte sized data or massive write performance? </p>
<p>Well, they you need one of the big key:value/BigTable/Dynamo type things. That would by Cassandra, Tokyo Tyrant, Redis, etc. You need to make sure that the client library supports sharding so you can ... | 3 | 2009-10-25T07:02:56Z | [
"python",
"memcached",
"couchdb",
"tokyo-tyrant"
] |
Vim Python omni-completion failing to work on system modules | 1,617,415 | <p>I'm noticing that even for system modules, code completion doesn't work too well.</p>
<p>For example, if I have a simple file that does:</p>
<pre><code>import re
p = re.compile(pattern)
m = p.search(line)
</code></pre>
<p>If I type p., I don't get completion for methods I'd expect to see (I don't see search() for... | 2 | 2009-10-24T08:55:05Z | 1,618,429 | <p>Completion for this kind of things is tricky, because it would need to execute the actual code to work.</p>
<p>For example p.search() could return None or a MatchObject, depending on the data that is passed to it.</p>
<p>This is why omni-completion does not work here, and probably never will. It works for things t... | 2 | 2009-10-24T16:21:55Z | [
"python",
"vim",
"omnicomplete"
] |
Vim Python omni-completion failing to work on system modules | 1,617,415 | <p>I'm noticing that even for system modules, code completion doesn't work too well.</p>
<p>For example, if I have a simple file that does:</p>
<pre><code>import re
p = re.compile(pattern)
m = p.search(line)
</code></pre>
<p>If I type p., I don't get completion for methods I'd expect to see (I don't see search() for... | 2 | 2009-10-24T08:55:05Z | 1,618,466 | <p>I never got the builtin omnicomplete to work for any languages. I had the most success with <a href="http://code.google.com/p/pysmell/" rel="nofollow">pysmell</a> (which seems to have been updated slightly more recently on <a href="http://github.com/orestis/pysmell" rel="nofollow">github</a> than in the official rep... | 0 | 2009-10-24T16:35:15Z | [
"python",
"vim",
"omnicomplete"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,617,503 | <p>Use grep:</p>
<p><code>grep -rn print .</code></p>
| 4 | 2009-10-24T09:41:57Z | [
"python"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,617,508 | <p>Using grep with a cleverly constructed regex (does not begin or end with quotes) seems to be your best bet.</p>
| 1 | 2009-10-24T09:43:51Z | [
"python"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,617,515 | <p><a href="http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing%5Fpython%5Fcode.html">This article</a> can prove very valuable in doing that. Look for the <code>line</code> events and extract the method name from the frame ( if I remember correctly ). More information can be found <a href="http://d... | 5 | 2009-10-24T09:49:16Z | [
"python"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,617,554 | <p>The easiest way would be to use a "debug_print" function instead of plain "print".</p>
<p>That way you could just redefine the function and be sure you did not miss one...
and still have them handy if you need to debug that code again instead of editing your code back and forth each time.</p>
<p>(Yes leaving debug... | 2 | 2009-10-24T10:03:22Z | [
"python"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,617,725 | <p>This probably doesnt answer your question directly, but you can get away with tons of print statements if you use pdb (python debugger) in a way to effectively debug and write code.</p>
<p>I know it works, because 99% of time you simple dont wanna print stuff, but you wanna set a breakpoint somewhere and see what t... | 0 | 2009-10-24T11:24:13Z | [
"python"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,617,841 | <p>I typically do this in my code:</p>
<p>(near the top):</p>
<blockquote>
<pre><code>debug=True
</code></pre>
</blockquote>
<p>(later on)</p>
<blockquote>
<p>if debug: print "This is a debug statement. x=",x</p>
</blockquote>
<p>Then, when I want to take out all of the debugging statement, I change the debug to... | 1 | 2009-10-24T12:13:03Z | [
"python"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,617,979 | <p>Use a printf function instead. The following is from <a href="http://norvig.com/python-iaq.html" rel="nofollow">Infrequently Answered Python Questions</a></p>
<pre><code>def printf(format, *args):
"""Format args with the first argument as format string, and print.
If the format is not a string, it is conve... | 2 | 2009-10-24T13:11:23Z | [
"python"
] |
Finding a print statement in Python | 1,617,494 | <p>Sometimes I leave debugging printing statements in my project and it is difficult to find it. Is there any way to find out what line is printing something in particular?</p>
<p><strong>Sidenote</strong></p>
<p>It appears that searching smart can solve the majority of cases. In Pydev (and other IDEs) there is a Sea... | 9 | 2009-10-24T09:36:07Z | 1,620,686 | <p>You asked about static solutions. Here's a dynamic one. Suppose you run the code and see an errant print or write to sys.stdout, and want to know where it comes from. You can replace sys.stdout and let the exception traceback help you:</p>
<pre><code>>>> import sys
>>> def go():
... sys.stdout =... | 19 | 2009-10-25T11:38:30Z | [
"python"
] |
Python's MySqlDB not getting updated row | 1,617,637 | <p>I have a script that waits until some row in a db is updated:</p>
<pre><code>con = MySQLdb.connect(server, user, pwd, db)
</code></pre>
<p>When the script starts the row's value is <code>"running"</code>, and it waits for the value to become <code>"finished"</code></p>
<pre><code>while(True):
sql = '''select ... | 10 | 2009-10-24T10:43:14Z | 1,617,662 | <p>This is an InnoDB table, right? InnoDB is transactional storage engine. Setting autocommit to true will probably fix this behavior for you.</p>
<pre><code>conn.autocommit(True)
</code></pre>
<p>Alternatively, you could change the transaction isolation level. You can read more about this here:
<a href="http://dev.m... | 15 | 2009-10-24T10:56:58Z | [
"python",
"mysql"
] |
Python's MySqlDB not getting updated row | 1,617,637 | <p>I have a script that waits until some row in a db is updated:</p>
<pre><code>con = MySQLdb.connect(server, user, pwd, db)
</code></pre>
<p>When the script starts the row's value is <code>"running"</code>, and it waits for the value to become <code>"finished"</code></p>
<pre><code>while(True):
sql = '''select ... | 10 | 2009-10-24T10:43:14Z | 7,675,517 | <p>I worked around this by running</p>
<pre><code>c.execute("""set session transaction isolation level READ COMMITTED""")
</code></pre>
<p>early on in my reading session. Updates from other threads do come through now.</p>
<p>In my instance I was keeping connections open for a long time (inside mod_python) and so ... | 3 | 2011-10-06T14:10:39Z | [
"python",
"mysql"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.