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 to find the sum of a ASCII value in a file to find the max number of ASCII and to print out the name of the highest sum of ASCII value | 1,293,404 | <p>Here is the code I'm working with</p>
<pre><code>def ascii_sum():
x = 0
infile = open("30075165.txt","r")
for line in infile:
return sum([ord(x) for x in line])
infile.close()
</code></pre>
<p>This code only prints out the first ASCII value in the file not the max ASCII value</p>
| -1 | 2009-08-18T11:58:13Z | 1,293,464 | <p>This is a snippet from an answer to one to of your <a href="http://stackoverflow.com/questions/1292630/how-to-open-a-file-and-find-the-longest-length-of-a-line-and-then-print-it-out/1292676#1292676">previous questions</a></p>
<pre><code>def get_file_data(filename):
def ascii_sum(line):
return sum([ord(x... | 1 | 2009-08-18T12:11:52Z | [
"python"
] |
Proxies in Python FTP application | 1,293,518 | <p>I'm developing an FTP client in Python ftplib. How do I add proxies support to it (most FTP apps I have seen seem to have it)? I'm especially thinking about SOCKS proxies, but also other types... FTP, HTTP (is it even possible to use HTTP proxies with FTP program?)</p>
<p>Any ideas how to do it?</p>
| 5 | 2009-08-18T12:28:03Z | 1,293,579 | <p>Standard module <code>ftplib</code> doesn't support proxies. It seems the only solution is to write your own customized version of the <code>ftplib</code>.</p>
| 0 | 2009-08-18T12:42:28Z | [
"python",
"proxy",
"ftp",
"ftplib"
] |
Proxies in Python FTP application | 1,293,518 | <p>I'm developing an FTP client in Python ftplib. How do I add proxies support to it (most FTP apps I have seen seem to have it)? I'm especially thinking about SOCKS proxies, but also other types... FTP, HTTP (is it even possible to use HTTP proxies with FTP program?)</p>
<p>Any ideas how to do it?</p>
| 5 | 2009-08-18T12:28:03Z | 1,293,587 | <p>As per <a href="http://mail.python.org/pipermail/python-list/2004-October/288418.html">this</a> source.</p>
<p>Depends on the proxy, but a common method is to ftp to the proxy, then use
user at real-server as the user name, and the original password</p>
<p>EG for ftp.download.com</p>
<pre><code>ftp proxyserver... | 6 | 2009-08-18T12:44:33Z | [
"python",
"proxy",
"ftp",
"ftplib"
] |
Proxies in Python FTP application | 1,293,518 | <p>I'm developing an FTP client in Python ftplib. How do I add proxies support to it (most FTP apps I have seen seem to have it)? I'm especially thinking about SOCKS proxies, but also other types... FTP, HTTP (is it even possible to use HTTP proxies with FTP program?)</p>
<p>Any ideas how to do it?</p>
| 5 | 2009-08-18T12:28:03Z | 1,293,627 | <p>You can use the <a href="http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler" rel="nofollow">ProxyHandler</a> in <code>urllib2</code>.</p>
<pre><code>ph = urllib2.ProxyHandler( { 'ftp' : proxy_server_url } )
server= urllib2.build_opener( ph )
</code></pre>
| 4 | 2009-08-18T12:52:04Z | [
"python",
"proxy",
"ftp",
"ftplib"
] |
Proxies in Python FTP application | 1,293,518 | <p>I'm developing an FTP client in Python ftplib. How do I add proxies support to it (most FTP apps I have seen seem to have it)? I'm especially thinking about SOCKS proxies, but also other types... FTP, HTTP (is it even possible to use HTTP proxies with FTP program?)</p>
<p>Any ideas how to do it?</p>
| 5 | 2009-08-18T12:28:03Z | 5,581,905 | <p>I had the same problem and needed to use the <strong>ftplib</strong> module (not to rewrite all my scripts with URLlib2).</p>
<p>I have managed to write a script that installs transparent <strong>HTTP tunneling</strong> on the socket layer (used by ftplib). </p>
<p>Now, I can do <strong>FTP over HTTP</strong> tran... | 1 | 2011-04-07T13:31:39Z | [
"python",
"proxy",
"ftp",
"ftplib"
] |
Proxies in Python FTP application | 1,293,518 | <p>I'm developing an FTP client in Python ftplib. How do I add proxies support to it (most FTP apps I have seen seem to have it)? I'm especially thinking about SOCKS proxies, but also other types... FTP, HTTP (is it even possible to use HTTP proxies with FTP program?)</p>
<p>Any ideas how to do it?</p>
| 5 | 2009-08-18T12:28:03Z | 37,144,136 | <p>Patching the builtin socket library definitely won't be an option for everyone, but my solution was to patch <code>socket.create_connection()</code> to use an HTTP proxy when the hostname matches a whitelist:</p>
<pre><code>from base64 import b64encode
from functools import wraps
import socket
_real_create_connect... | 0 | 2016-05-10T16:28:06Z | [
"python",
"proxy",
"ftp",
"ftplib"
] |
Proxies in Python FTP application | 1,293,518 | <p>I'm developing an FTP client in Python ftplib. How do I add proxies support to it (most FTP apps I have seen seem to have it)? I'm especially thinking about SOCKS proxies, but also other types... FTP, HTTP (is it even possible to use HTTP proxies with FTP program?)</p>
<p>Any ideas how to do it?</p>
| 5 | 2009-08-18T12:28:03Z | 39,295,143 | <p>Here is workaround using <code>requests</code>, tested with a squid proxy that does NOT support CONNECT tunneling:</p>
<pre><code>def ftp_fetch_file_through_http_proxy(host, user, password, remote_filepath, http_proxy, output_filepath):
"""
This function let us to make a FTP RETR query through a HTTP proxy ... | 0 | 2016-09-02T14:44:17Z | [
"python",
"proxy",
"ftp",
"ftplib"
] |
Human readable cookie information using cookielib? | 1,293,828 | <p>Is there a way to print the cookies stored in a cookielib.CookieJar in a human-readable way?</p>
<p>I'm scraping a site and I'd like to know if the same cookies are set when I use my script as when I use the browser.</p>
| 0 | 2009-08-18T13:27:55Z | 1,294,165 | <pre><code>import urllib2
from cookielib import CookieJar, DefaultCookiePolicy
policy = DefaultCookiePolicy(
rfc2965=True, strict_ns_domain=DefaultCookiePolicy.DomainStrict)
cj = CookieJar(policy)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
r = opener.open("http://somewebsite.com")
[str(i) for i in ... | 1 | 2009-08-18T14:15:11Z | [
"python",
"cookies"
] |
Sandboxing / copying a module in two separate places to prevent overwriting or monkey patching | 1,293,879 | <p>Using these four files, all in the same directory:</p>
<h3>splitter.py</h3>
<pre><code>#imagine this is a third-party library
SPLIT_CHAR = ','
class Splitter(object):
def __init__(self, s, split_char=None):
self.orig = s
if not split_char:
self.splitted = s.split(SPLIT_CHAR)
</code... | 0 | 2009-08-18T13:33:29Z | 1,293,906 | <p><strong>"Is there a way to prevent this result?"</strong></p>
<p>Yes. Find the people who monkeypatched the module and make them stop.</p>
<p>Monkeypatching doesn't require fancy code work-arounds. It requires people to simply cooperate.</p>
<p>If you write a module and some co-worker makes a mess of it, you sh... | 2 | 2009-08-18T13:37:09Z | [
"python"
] |
Sandboxing / copying a module in two separate places to prevent overwriting or monkey patching | 1,293,879 | <p>Using these four files, all in the same directory:</p>
<h3>splitter.py</h3>
<pre><code>#imagine this is a third-party library
SPLIT_CHAR = ','
class Splitter(object):
def __init__(self, s, split_char=None):
self.orig = s
if not split_char:
self.splitted = s.split(SPLIT_CHAR)
</code... | 0 | 2009-08-18T13:33:29Z | 1,293,943 | <p>How about when you instantiate the <code>Splitter</code>, you set it's default split char to whatever it is you want it to be, and make a setter for it, so that people can change it?</p>
| 1 | 2009-08-18T13:42:20Z | [
"python"
] |
Sandboxing / copying a module in two separate places to prevent overwriting or monkey patching | 1,293,879 | <p>Using these four files, all in the same directory:</p>
<h3>splitter.py</h3>
<pre><code>#imagine this is a third-party library
SPLIT_CHAR = ','
class Splitter(object):
def __init__(self, s, split_char=None):
self.orig = s
if not split_char:
self.splitted = s.split(SPLIT_CHAR)
</code... | 0 | 2009-08-18T13:33:29Z | 1,295,200 | <p>Another way to prevent that is to "hint" that splitter.SPLIT_CHAR is "private" by calling it _SPLIT_CHAR. From <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP8, the style guide for Python code</a>:</p>
<blockquote>
<p><code>_single_leading_underscore</code>: weak "internal use" indicator. ... | 1 | 2009-08-18T16:59:27Z | [
"python"
] |
Best way to obtain indexed access to a Python queue, thread-safe | 1,293,966 | <p>I have a queue (from the <code>Queue</code> module), and I want to get indexed access into it. (i.e., being able to ask for item number four in the queue, without removing it from the queue.)</p>
<p>I saw that a queue uses a deque internally, and deque has indexed access. The question is, how can I use the deque wi... | 8 | 2009-08-18T13:45:32Z | 1,294,330 | <pre><code>import Queue
class IndexableQueue(Queue):
def __getitem__(self, index):
with self.mutex:
return self.queue[index]
</code></pre>
<p>It's of course crucial to release the mutex whether the indexing succeeds or raises an IndexError, and I'm using a <code>with</code> statement for that. In older Py... | 9 | 2009-08-18T14:39:19Z | [
"python",
"multithreading",
"queue",
"deque"
] |
How do I install PyGTK / PyGobject on Windows with Python 2.6? | 1,294,272 | <p>I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute <code>import gobject</code> I get this:</p>
<pre><code>Traceback (most recent call last):
import gobject
File "C:\Python26\lib\site-packages\gtk-2.0\gobject... | 10 | 2009-08-18T14:31:08Z | 1,294,354 | <p>I have it working fine, and it didn't give me much trouble, so we know it can be done...</p>
<p>Keep in mind you will probably need all of the following installed on your Windows machine:</p>
<ul>
<li><p>PyCairo ( <a href="http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/" rel="nofollow">http://ftp.gnome.org/... | 10 | 2009-08-18T14:44:11Z | [
"python",
"pygtk",
"mingw",
"pygobject"
] |
How do I install PyGTK / PyGobject on Windows with Python 2.6? | 1,294,272 | <p>I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute <code>import gobject</code> I get this:</p>
<pre><code>Traceback (most recent call last):
import gobject
File "C:\Python26\lib\site-packages\gtk-2.0\gobject... | 10 | 2009-08-18T14:31:08Z | 1,992,519 | <p>u should have pygtk,pycairo,pygboject and the gtk+ runtime...</p>
<p>see this for an all in one installer
<a href="http://aruiz.typepad.com/siliconisland/2006/12/allinone_win32_.html" rel="nofollow">http://aruiz.typepad.com/siliconisland/2006/12/allinone_win32_.html</a></p>
| 0 | 2010-01-02T19:15:07Z | [
"python",
"pygtk",
"mingw",
"pygobject"
] |
How do I install PyGTK / PyGobject on Windows with Python 2.6? | 1,294,272 | <p>I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute <code>import gobject</code> I get this:</p>
<pre><code>Traceback (most recent call last):
import gobject
File "C:\Python26\lib\site-packages\gtk-2.0\gobject... | 10 | 2009-08-18T14:31:08Z | 5,357,523 | <p>The PyGTK all-in-one installer has been updated recently:</p>
<p><a href="http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/" rel="nofollow">http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/</a></p>
<p>This will install PyGTK, PyGObject, PyCairo, PyGtkSourceView2, PyGooCanvas, PyRsvg, the gtk+-bundl... | 4 | 2011-03-18T20:31:46Z | [
"python",
"pygtk",
"mingw",
"pygobject"
] |
How do I install PyGTK / PyGobject on Windows with Python 2.6? | 1,294,272 | <p>I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute <code>import gobject</code> I get this:</p>
<pre><code>Traceback (most recent call last):
import gobject
File "C:\Python26\lib\site-packages\gtk-2.0\gobject... | 10 | 2009-08-18T14:31:08Z | 9,947,516 | <p>for 64 bit Windows users see </p>
<p><a href="http://digitalpbk.blogspot.in/2012/03/installing-pygtk-pypango-and-pycairo-on.html" rel="nofollow">http://digitalpbk.blogspot.in/2012/03/installing-pygtk-pypango-and-pycairo-on.html</a> </p>
<p>Above steps will give Invalid DLL error on 64 bit.</p>
| 3 | 2012-03-30T17:15:01Z | [
"python",
"pygtk",
"mingw",
"pygobject"
] |
How do I install PyGTK / PyGobject on Windows with Python 2.6? | 1,294,272 | <p>I have an application which depends on PyGTK, PyGobject, and PyCairo that I built to work on Linux. I want to port it over to windows, but when I execute <code>import gobject</code> I get this:</p>
<pre><code>Traceback (most recent call last):
import gobject
File "C:\Python26\lib\site-packages\gtk-2.0\gobject... | 10 | 2009-08-18T14:31:08Z | 28,122,412 | <p>Be careful about installing PyGTK bundle pack if any one planning to run PyGTK through embedded interpreter and the C/C++ code is already using GTK. PyGTK bundle pack does not add its GTK runtime to PATH.</p>
<p>In such case possibly the C code will take GTK from PATH (as probably you have already installed GTK bu... | 0 | 2015-01-24T04:49:56Z | [
"python",
"pygtk",
"mingw",
"pygobject"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 1,294,398 | <p>Suppose you have multiple threads which don't <em>really</em> touch each other's data. Those should execute as independently as possible. If you have a "global lock" which you need to acquire in order to (say) call a function, that can end up as a bottleneck. You can wind up not getting much benefit from having mult... | 28 | 2009-08-18T14:53:04Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 1,294,402 | <p>Python's GIL is intended to serialize access to interpreter internals from different threads. On multi-core systems, it means that multiple threads can't effectively make use of multiple cores. (If the GIL didn't lead to this problem, most people wouldn't care about the GIL - it's only being raised as an issue becau... | 90 | 2009-08-18T14:53:17Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 1,294,408 | <p>Wikipedia has a nice description of a global interpreter lock</p>
<p><a href="http://en.wikipedia.org/wiki/Global%5FInterpreter%5FLock" rel="nofollow">http://en.wikipedia.org/wiki/Global%5FInterpreter%5FLock</a></p>
<p>That article links this nice article that discusses the GIL in Python.</p>
<p><a href="http://w... | 1 | 2009-08-18T14:53:44Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 1,294,430 | <p>Whenever two threads have access to the same variable you have a problem.
In C++ for instance, the way to avoid the problem is to define some mutex lock to prevent two thread to, let's say, enter the setter of an object at the same time.</p>
<p>Multithreading is possible in python, but two threads cannot be execute... | 10 | 2009-08-18T14:57:06Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 1,294,553 | <p><a href="http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2010-understanding-the-python-gil-82-3273690" rel="nofollow">Watch David Beazley</a> tell you everything you ever wanted to know about the GIL.</p>
| 7 | 2009-08-18T15:16:02Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 1,294,988 | <p>Here's a longish article talking about the GIL and threading in Python I wrote awhile back. It goes into a fair amount of detail on it:</p>
<p><a href="http://jessenoller.com/2009/02/01/python-threads-and-the-global-interpreter-lock/" rel="nofollow">http://jessenoller.com/2009/02/01/python-threads-and-the-global-in... | 3 | 2009-08-18T16:25:10Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 20,418,825 | <p>Let's first understand what the python GIL provides:</p>
<p>Any operation/instruction is executed in the interpreter. GIL ensures that interpreter is held by a single thread at <strong>a particular instant of time</strong>. And your python program with multiple threads works in a single interpreter. At any particul... | 6 | 2013-12-06T07:55:24Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 25,324,045 | <p>Here is some code demonstrating effects of GIL: <a href="https://github.com/cankav/python_gil_demonstration" rel="nofollow">https://github.com/cankav/python_gil_demonstration</a></p>
| 1 | 2014-08-15T09:19:19Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 31,306,077 | <p><strong>Why Python (CPython and others) uses the GIL</strong></p>
<p>From <a href="http://wiki.python.org/moin/GlobalInterpreterLock" rel="nofollow">http://wiki.python.org/moin/GlobalInterpreterLock</a></p>
<p>In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threads from ex... | 0 | 2015-07-09T00:18:30Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 33,493,011 | <p>I want to share an example from the book multithreading for Visual Effects. So here is a classic dead lock situation</p>
<pre><code>static void MyCallback(const Context &context){
Auto<Lock> lock(GetMyMutexFromContext(context));
...
EvalMyPythonString(str); //A function that takes the GIL
...
}
</code... | 0 | 2015-11-03T06:50:24Z | [
"python",
"gil"
] |
What is a global interpreter lock (GIL)? | 1,294,382 | <p>What is a global interpreter lock and why is that an issue?</p>
<p>A lot noise has been made around removing the GIL from Python, and I'd like to understand why that is so important. I have never written a compiler nor an interpreter myself, so don't be frugal with details, I'll probably need them to understand.</p... | 87 | 2009-08-18T14:50:06Z | 36,942,047 | <p>I find this is the best explain of GIL. Please read.</p>
<p><a href="http://www.dabeaz.com/python/UnderstandingGIL.pdf" rel="nofollow">http://www.dabeaz.com/python/UnderstandingGIL.pdf</a></p>
| 2 | 2016-04-29T15:19:29Z | [
"python",
"gil"
] |
How to insert / retrieve a file stored as a BLOB in a MySQL db using python | 1,294,385 | <p>I want to write a python script that populates a database with some information. One of the columns in my table is a BLOB that I would like to save a file to for each entry.</p>
<p>How can I read the file (binary) and insert it into the DB using python? Likewise, how can I retrieve it and write that file back to ... | 10 | 2009-08-18T14:50:58Z | 1,294,488 | <p>You can insert and read BLOBs from a DB like every other column type. From the database API's view there is nothing special about BLOBs.</p>
| 0 | 2009-08-18T15:07:42Z | [
"python",
"mysql",
"file-io",
"blob"
] |
How to insert / retrieve a file stored as a BLOB in a MySQL db using python | 1,294,385 | <p>I want to write a python script that populates a database with some information. One of the columns in my table is a BLOB that I would like to save a file to for each entry.</p>
<p>How can I read the file (binary) and insert it into the DB using python? Likewise, how can I retrieve it and write that file back to ... | 10 | 2009-08-18T14:50:58Z | 1,294,496 | <pre><code>thedata = open('thefile', 'rb').read()
sql = "INSERT INTO sometable (theblobcolumn) VALUES (%s)"
cursor.execute(sql, (thedata,))
</code></pre>
<p>That code of course works as written only if your table has just the BLOB column and what
you want to do is INSERT, but of course you could easily tweak it to add... | 12 | 2009-08-18T15:09:15Z | [
"python",
"mysql",
"file-io",
"blob"
] |
how to register more than 10 apps in Google App Engine | 1,294,618 | <p>Anyone knows any "legal" way to surpass the 10-app-limit Google imposes?
I wouldn't mind to pay, or anything, but I wasn't able to find a way to have more
than 10 apps and can't either remove one.</p>
| 13 | 2009-08-18T15:25:56Z | 1,294,678 | <p>Call or write to Google! Google's policies are very exact and very strict, because they are catering to <em>thousands</em> of developers, and thus need those standards and uniformity. But if you have a good reason for needing more than 10, and you can get a real person at the end of a telephone line, I'd think you'd... | 4 | 2009-08-18T15:35:03Z | [
"python",
"google-app-engine",
"registration"
] |
how to register more than 10 apps in Google App Engine | 1,294,618 | <p>Anyone knows any "legal" way to surpass the 10-app-limit Google imposes?
I wouldn't mind to pay, or anything, but I wasn't able to find a way to have more
than 10 apps and can't either remove one.</p>
| 13 | 2009-08-18T15:25:56Z | 1,295,100 | <p>This post in the Google App Engine group "solves" the problem:
<a href="http://groups.google.com/group/google-appengine/browse%5Fthread/thread/815d0e29076da2b1/ecc21212ed9362ab#ecc21212ed9362ab">link</a></p>
| 12 | 2009-08-18T16:43:19Z | [
"python",
"google-app-engine",
"registration"
] |
Getting DOM tree of XML document | 1,294,654 | <p>Does anyone know how I would get a DOM instance (tree) of an XML file in Python. I am trying to compare two XML documents to eachother that may have elements and attributes in different order. How would I do this?</p>
| 5 | 2009-08-18T15:31:03Z | 1,294,697 | <p>Some solutions to ponder:</p>
<ul>
<li><a href="http://docs.python.org/library/xml.dom.minidom.html" rel="nofollow">minidom</a></li>
<li><a href="http://pypi.python.org/pypi/Amara" rel="nofollow">amara</a> (xml data binding)</li>
</ul>
| 1 | 2009-08-18T15:36:42Z | [
"python",
"xml",
"dom"
] |
Getting DOM tree of XML document | 1,294,654 | <p>Does anyone know how I would get a DOM instance (tree) of an XML file in Python. I am trying to compare two XML documents to eachother that may have elements and attributes in different order. How would I do this?</p>
| 5 | 2009-08-18T15:31:03Z | 1,294,753 | <p>For comparing XML document instances, a naive compare of the parsed DOM trees will not work. You will probably need to implement your own NodeComperator that recursively compares a node and its child-nodes with some other node and its child-nodes based on your specific criteria such as:</p>
<ul>
<li>When is the ord... | 0 | 2009-08-18T15:45:54Z | [
"python",
"xml",
"dom"
] |
Getting DOM tree of XML document | 1,294,654 | <p>Does anyone know how I would get a DOM instance (tree) of an XML file in Python. I am trying to compare two XML documents to eachother that may have elements and attributes in different order. How would I do this?</p>
| 5 | 2009-08-18T15:31:03Z | 1,295,977 | <p>Personally, whenever possible, I'd start with <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">elementtree</a> (preferably the C implementation that comes with Python's standard library, or the <a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a> implementation, but that's e... | 2 | 2009-08-18T19:29:48Z | [
"python",
"xml",
"dom"
] |
Python WWW macro | 1,294,862 | <p>i need something like iMacros for Python. It would be great to have something like that:</p>
<pre><code>browse_to('www.google.com')
type_in_input('search', 'query')
click_button('search')
list = get_all('<p>')
</code></pre>
<p>Do you know something like that?</p>
<p>Thanks in advance,
Etam.</p>
| 6 | 2009-08-18T16:05:29Z | 1,294,891 | <p>Use <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a>. Other than executing JavaScript in a page, it's pretty good.</p>
| 6 | 2009-08-18T16:10:39Z | [
"python",
"screen-scraping"
] |
Python WWW macro | 1,294,862 | <p>i need something like iMacros for Python. It would be great to have something like that:</p>
<pre><code>browse_to('www.google.com')
type_in_input('search', 'query')
click_button('search')
list = get_all('<p>')
</code></pre>
<p>Do you know something like that?</p>
<p>Thanks in advance,
Etam.</p>
| 6 | 2009-08-18T16:05:29Z | 1,295,028 | <p>Almost a direct fulfillment of the wishes in the question - <a href="http://twill.idyll.org/" rel="nofollow">twill</a>.</p>
<blockquote>
<p>twill is a simple language that allows users to browse the Web from a command-line interface. With twill, you can navigate through Web sites that use forms, cookies, and most... | 7 | 2009-08-18T16:31:31Z | [
"python",
"screen-scraping"
] |
Python WWW macro | 1,294,862 | <p>i need something like iMacros for Python. It would be great to have something like that:</p>
<pre><code>browse_to('www.google.com')
type_in_input('search', 'query')
click_button('search')
list = get_all('<p>')
</code></pre>
<p>Do you know something like that?</p>
<p>Thanks in advance,
Etam.</p>
| 6 | 2009-08-18T16:05:29Z | 1,297,568 | <p>Another thing to consider is writing your own script. It's actually not too tough once you get the hang of it, and without invoking a half dozen huge libraries it might even be faster (but I'm not sure). I use a web debugger called "Charles" to surf websites that I want to scrape. It logs all outgoing/incoming http ... | 0 | 2009-08-19T02:35:16Z | [
"python",
"screen-scraping"
] |
GIS: line_locate_point() in Python | 1,295,386 | <p>I'm pretty much a beginner when it comes to GIS, but I think I understand the basics - it doesn't seem to hard. But: All these acronyms and different libraries, GEOS, GDAL, PROJ, PCL, Shaply, OpenGEO, OGR, OGC, OWS and what not, each seemingly depending on any number of others, is slightly overwhelming me.</p>
<p>H... | 2 | 2009-08-18T17:35:18Z | 1,298,837 | <p>For posterity:</p>
<p><a href="http://bitbucket.org/miracle2k/pyutils/changeset/156c60ec88f8/" rel="nofollow">http://bitbucket.org/miracle2k/pyutils/changeset/156c60ec88f8/</a></p>
| 2 | 2009-08-19T09:48:34Z | [
"python",
"postgresql",
"geometry",
"gis",
"geospatial"
] |
GIS: line_locate_point() in Python | 1,295,386 | <p>I'm pretty much a beginner when it comes to GIS, but I think I understand the basics - it doesn't seem to hard. But: All these acronyms and different libraries, GEOS, GDAL, PROJ, PCL, Shaply, OpenGEO, OGR, OGC, OWS and what not, each seemingly depending on any number of others, is slightly overwhelming me.</p>
<p>H... | 2 | 2009-08-18T17:35:18Z | 1,299,693 | <p>In another forum I suggested reimplementing the (simple) PostGIS algorithm in Python using <a href="http://pypi.python.org/pypi/Shapely/" rel="nofollow">Shapely</a>.</p>
| 2 | 2009-08-19T12:44:57Z | [
"python",
"postgresql",
"geometry",
"gis",
"geospatial"
] |
GIS: line_locate_point() in Python | 1,295,386 | <p>I'm pretty much a beginner when it comes to GIS, but I think I understand the basics - it doesn't seem to hard. But: All these acronyms and different libraries, GEOS, GDAL, PROJ, PCL, Shaply, OpenGEO, OGR, OGC, OWS and what not, each seemingly depending on any number of others, is slightly overwhelming me.</p>
<p>H... | 2 | 2009-08-18T17:35:18Z | 2,980,216 | <p>For posterity, these functions are available in Shapely 1.2</p>
| 2 | 2010-06-05T11:54:04Z | [
"python",
"postgresql",
"geometry",
"gis",
"geospatial"
] |
How to replace Python function while supporting all passed in parameters | 1,295,415 | <p>I'm looking for a way to decorate an arbitrary python function, so that an alternate function is called instead of the original, with all parameters passed as a list or dict.</p>
<p>More precisely, something like this (where f is any function, and replacement_f takes a list and a dict):</p>
<pre><code>def replace_... | 0 | 2009-08-18T17:39:40Z | 1,295,436 | <p>If I understand this correctly, you want to pass all arguments from one function to another.</p>
<p>Simply do:</p>
<pre><code>def replace_func(f, replacement_f):
def new_f(*args, **kwargs):
replacement_f(*args, **kwargs) # args & kwargs will be expanded
return new_f
</code></pre>
| 0 | 2009-08-18T17:43:27Z | [
"python",
"decorator",
"kwargs"
] |
How to replace Python function while supporting all passed in parameters | 1,295,415 | <p>I'm looking for a way to decorate an arbitrary python function, so that an alternate function is called instead of the original, with all parameters passed as a list or dict.</p>
<p>More precisely, something like this (where f is any function, and replacement_f takes a list and a dict):</p>
<pre><code>def replace_... | 0 | 2009-08-18T17:39:40Z | 1,295,443 | <p>why don't you just try:</p>
<pre><code>f = replacement_f
</code></pre>
<p><em>example</em>:</p>
<pre><code>>>> def rep(*args):
print(*args, sep=' -- ')
>>> def ori(*args):
print(args)
>>> ori('dfef', 32)
('dfef', 32)
>>> ori = rep
>>> ori('dfef', 32)
dfef -- ... | 4 | 2009-08-18T17:44:41Z | [
"python",
"decorator",
"kwargs"
] |
How to replace Python function while supporting all passed in parameters | 1,295,415 | <p>I'm looking for a way to decorate an arbitrary python function, so that an alternate function is called instead of the original, with all parameters passed as a list or dict.</p>
<p>More precisely, something like this (where f is any function, and replacement_f takes a list and a dict):</p>
<pre><code>def replace_... | 0 | 2009-08-18T17:39:40Z | 1,295,465 | <p>does this do what you mean? Untested</p>
<pre><code>def replace_func(f, replacement_f):
nonlocal replacement_f #<<<<<<<<<<<<<<<py3k magic
def new_f(*args, **kwargs):
replacement_f(*args, **kwargs) # args & kwargs will be expanded
replacement_f =... | 0 | 2009-08-18T17:48:48Z | [
"python",
"decorator",
"kwargs"
] |
How to replace Python function while supporting all passed in parameters | 1,295,415 | <p>I'm looking for a way to decorate an arbitrary python function, so that an alternate function is called instead of the original, with all parameters passed as a list or dict.</p>
<p>More precisely, something like this (where f is any function, and replacement_f takes a list and a dict):</p>
<pre><code>def replace_... | 0 | 2009-08-18T17:39:40Z | 1,295,621 | <p>Although I think SilentGhost's answer is the best solution if it works for you, for the sake of completeness, here is the correct version of what you where trying to do:</p>
<p>To define a decorator that takes an argument, you have to introduce an additional level:</p>
<pre><code>def replace_function(repl):
de... | 1 | 2009-08-18T18:17:56Z | [
"python",
"decorator",
"kwargs"
] |
HTML snippet from Python | 1,295,446 | <p>I'm new to Python and CGI, so this may be trivial. But I'd like Python to produce a block of HTML whenever a visitor loads a page.</p>
<pre><code><html>
<body>
<!-- Beautiful website with great content -->
<!-- Suddenly... -->
<h1> Here's Some Python Output </h1>
<!-- RUN PYT... | 1 | 2009-08-18T17:44:58Z | 1,295,519 | <p>Use AJAX client-side, or templates server side. </p>
<p>A template will allow you to keep most of your page static, but use a server-side scripting language (like Python) to fill in the dynamic bits. There are lots of good posts on Python template systems on Stackoverflow. <a href="http://stackoverflow.com/questi... | 3 | 2009-08-18T17:59:37Z | [
"python",
"html",
"cgi"
] |
Running a plain python interpreter in presense of ipython with manage.py shell | 1,295,492 | <p>I have ipython installed, I want to run a plain python interpreter instead with manage.py shell.</p>
<p>So I try,</p>
<pre><code>python2.5 manage.py shell --plain
</code></pre>
<p>Which gave me an error, and text which suggest that --plain was passed to ipython</p>
<p>So I read, <a href="http://docs.djangoprojec... | 1 | 2009-08-18T17:53:50Z | 1,295,585 | <p><a href="http://proteus-tech.com/blog/code-garden/bpython-django/" rel="nofollow">link to a blog post explaining the same thing for bpython</a></p>
| 0 | 2009-08-18T18:11:33Z | [
"python",
"django",
"django-manage.py"
] |
Running a plain python interpreter in presense of ipython with manage.py shell | 1,295,492 | <p>I have ipython installed, I want to run a plain python interpreter instead with manage.py shell.</p>
<p>So I try,</p>
<pre><code>python2.5 manage.py shell --plain
</code></pre>
<p>Which gave me an error, and text which suggest that --plain was passed to ipython</p>
<p>So I read, <a href="http://docs.djangoprojec... | 1 | 2009-08-18T17:53:50Z | 1,299,134 | <p>If the reason you want to use python's interpretor over iPython's is because you need to paste the doc tests, you can try typing</p>
<pre><code>%doctest_mode
</code></pre>
<p>in the ipython console instead</p>
<pre><code>In [1]: %doctest_mode
*** Pasting of code with ">>>" or "..." has been enabled.
Exce... | 1 | 2009-08-19T10:53:32Z | [
"python",
"django",
"django-manage.py"
] |
Evaluate a script (e.g. Python) in Java for Android platform | 1,295,720 | <p>Is it possible to evaluate a string of python code (or Perl) from Java when developing Android applications?</p>
<p>I am try to do something like evaluating a text-input script:</p>
<p>e.g. </p>
<pre><code>String script = text1.getText().toString();
String result = PythonRuntime.evaluate(script);
text2.setText(re... | 1 | 2009-08-18T18:39:27Z | 1,295,730 | <p><a href="http://www.jython.org/" rel="nofollow">Jython</a> and its derivatives should be able to do this. See also <a href="http://code.google.com/p/jythonroid/" rel="nofollow">Jythondroid</a>.</p>
| 4 | 2009-08-18T18:41:21Z | [
"java",
"python",
"android",
"scripting"
] |
Evaluate a script (e.g. Python) in Java for Android platform | 1,295,720 | <p>Is it possible to evaluate a string of python code (or Perl) from Java when developing Android applications?</p>
<p>I am try to do something like evaluating a text-input script:</p>
<p>e.g. </p>
<pre><code>String script = text1.getText().toString();
String result = PythonRuntime.evaluate(script);
text2.setText(re... | 1 | 2009-08-18T18:39:27Z | 1,295,810 | <p>In case you weren't aware of it, the <a href="http://code.google.com/p/android-scripting/" rel="nofollow">Android Scripting Environment</a> might be useful to you, though I don't think it does exactly what you're looking for.</p>
| 4 | 2009-08-18T18:55:41Z | [
"java",
"python",
"android",
"scripting"
] |
On Google AppEngine what is the best way to merge two tables? | 1,295,832 | <p>If I have two tables, Company and Sales, and I want to display both sets of data in a single list, how would I do this on Google App Engine using GQL?</p>
<p>The models are:</p>
<pre><code>
class Company(db.Model):
companyname = db.StringProperty()
companyid = db.StringProperty()
salesperson = ... | 0 | 2009-08-18T19:00:18Z | 1,295,986 | <p>You should use a <a href="http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html#References" rel="nofollow">ReferenceProperty</a> in your Sales model:</p>
<p><code>company = db.ReferenceProperty(Company)</code></p>
<p>An example on how to iterate through the sales for a given company:</p>
... | 0 | 2009-08-18T19:31:56Z | [
"python",
"google-app-engine"
] |
On Google AppEngine what is the best way to merge two tables? | 1,295,832 | <p>If I have two tables, Company and Sales, and I want to display both sets of data in a single list, how would I do this on Google App Engine using GQL?</p>
<p>The models are:</p>
<pre><code>
class Company(db.Model):
companyname = db.StringProperty()
companyid = db.StringProperty()
salesperson = ... | 0 | 2009-08-18T19:00:18Z | 1,297,981 | <pre><code>{%for company in companys%}
{% for sale in sales %}
{% ifequal company.companyid sales.companyid %}
</code></pre>
<p>that code is problematic. If you have 200 companies and 1000 sales, you will be running that ifequal statement 200000 times! </p>
<p>In general, if you have more than 1000 sale... | 0 | 2009-08-19T05:45:39Z | [
"python",
"google-app-engine"
] |
On Google AppEngine what is the best way to merge two tables? | 1,295,832 | <p>If I have two tables, Company and Sales, and I want to display both sets of data in a single list, how would I do this on Google App Engine using GQL?</p>
<p>The models are:</p>
<pre><code>
class Company(db.Model):
companyname = db.StringProperty()
companyid = db.StringProperty()
salesperson = ... | 0 | 2009-08-18T19:00:18Z | 1,300,954 | <p>You've said in a comment that there's a 1-1 relationship between sales and companies. So you could get the data in the same order:</p>
<pre><code>def company(request):
companys = db.GqlQuery("SELECT * FROM Company ORDER BY companyid").fetch(1000)
sales = db.GqlQuery("SELECT * FROM Sales ORDER BY companyid").fe... | 1 | 2009-08-19T16:01:52Z | [
"python",
"google-app-engine"
] |
Numpy: Is there an array size limit? | 1,295,994 | <p>I'm learning to use Numpy and I wanted to see the speed difference in the summation of a list of numbers so I made this code:</p>
<pre><code>np_array = numpy.arange(1000000)
start = time.time()
sum_ = np_array.sum()
print time.time() - start, sum_
>>> 0.0 1783293664
python_list = range(1000000)
start = t... | 3 | 2009-08-18T19:33:20Z | 1,296,017 | <p>The standard list switched over to doing arithmetic with the long type when numbers got larger than a 32-bit int.</p>
<p>The numpy array did not switch to long, and suffered from integer overflow. The price for speed is smaller range of values allowed.</p>
<pre><code>>>> 499999500000 % 2**32
1783293664L
... | 9 | 2009-08-18T19:38:08Z | [
"python",
"numpy"
] |
Numpy: Is there an array size limit? | 1,295,994 | <p>I'm learning to use Numpy and I wanted to see the speed difference in the summation of a list of numbers so I made this code:</p>
<pre><code>np_array = numpy.arange(1000000)
start = time.time()
sum_ = np_array.sum()
print time.time() - start, sum_
>>> 0.0 1783293664
python_list = range(1000000)
start = t... | 3 | 2009-08-18T19:33:20Z | 1,296,028 | <p>Numpy is creating an array of 32-bit unsigned ints.
When it sums them, it sums them into a 32-bit value.</p>
<pre><code>if 499999500000L % (2**32) == 1783293664L:
print "Overflowed a 32-bit integer"
</code></pre>
<p>You can explicitly choose the data type at array creation time:</p>
<pre><code>a = numpy.arang... | 9 | 2009-08-18T19:40:03Z | [
"python",
"numpy"
] |
Numpy: Is there an array size limit? | 1,295,994 | <p>I'm learning to use Numpy and I wanted to see the speed difference in the summation of a list of numbers so I made this code:</p>
<pre><code>np_array = numpy.arange(1000000)
start = time.time()
sum_ = np_array.sum()
print time.time() - start, sum_
>>> 0.0 1783293664
python_list = range(1000000)
start = t... | 3 | 2009-08-18T19:33:20Z | 1,296,051 | <p>Notice that <code>499999500000 % 2**32</code> equals exactly 1783293664 ... i.e., numpy is doing operations modulo 2**32, because that's the type of the numpy.array you've told it to use. </p>
<p>Make <code>np_array = numpy.arange(1000000, dtype=numpy.uint64)</code>, for example, and your sum will come out OK (alth... | 6 | 2009-08-18T19:43:12Z | [
"python",
"numpy"
] |
Tuple list from dict in Python | 1,296,042 | <p>How can I obtain a list of key-value tuples from a <a href="http://docs.python.org/2/library/stdtypes.html#dict">dict</a> in Python?</p>
| 23 | 2009-08-18T19:41:26Z | 1,296,049 | <p>For Python 2.x only (thanks Alex):</p>
<pre><code>yourdict = {}
# ...
items = yourdict.items()
</code></pre>
<p>See <a href="http://docs.python.org/library/stdtypes.html#dict.items">http://docs.python.org/library/stdtypes.html#dict.items</a> for details.</p>
<p>For Python 3.x only (taken from <a href="http://stac... | 40 | 2009-08-18T19:42:48Z | [
"python",
"list",
"dictionary",
"key-value"
] |
Tuple list from dict in Python | 1,296,042 | <p>How can I obtain a list of key-value tuples from a <a href="http://docs.python.org/2/library/stdtypes.html#dict">dict</a> in Python?</p>
| 23 | 2009-08-18T19:41:26Z | 1,296,070 | <p>For a list of of tuples:</p>
<pre><code>my_dict.items()
</code></pre>
<p>If all you're doing is iterating over the items, however, it is often preferable to use <code>dict.iteritems()</code>, which is more memory efficient because it returns only one item at a time, rather than all items at once:</p>
<pre><code>f... | 5 | 2009-08-18T19:45:09Z | [
"python",
"list",
"dictionary",
"key-value"
] |
Tuple list from dict in Python | 1,296,042 | <p>How can I obtain a list of key-value tuples from a <a href="http://docs.python.org/2/library/stdtypes.html#dict">dict</a> in Python?</p>
| 23 | 2009-08-18T19:41:26Z | 1,296,074 | <p>In Python <code>2.*</code>, <code>thedict.items()</code>, as in @Andrew's answer. In Python <code>3.*</code>, <code>list(thedict.items())</code> (since there <code>items</code> is just an iterable view, not a list, you need to call <code>list</code> on it explicitly if you need exactly a list).</p>
| 5 | 2009-08-18T19:45:45Z | [
"python",
"list",
"dictionary",
"key-value"
] |
Tuple list from dict in Python | 1,296,042 | <p>How can I obtain a list of key-value tuples from a <a href="http://docs.python.org/2/library/stdtypes.html#dict">dict</a> in Python?</p>
| 23 | 2009-08-18T19:41:26Z | 5,352,946 | <p>For Python > 2.5:</p>
<pre><code>a = {'1' : 10, '2' : 20 }
list(a.itervalues())
</code></pre>
| -2 | 2011-03-18T13:51:19Z | [
"python",
"list",
"dictionary",
"key-value"
] |
Tuple list from dict in Python | 1,296,042 | <p>How can I obtain a list of key-value tuples from a <a href="http://docs.python.org/2/library/stdtypes.html#dict">dict</a> in Python?</p>
| 23 | 2009-08-18T19:41:26Z | 11,231,128 | <blockquote>
<p>Converting from dict to list is made easy in Python. Three examples:</p>
<blockquote>
<blockquote>
<p>d = {'a': 'Arthur', 'b': 'Belling'}</p>
<p>d.items() [('a', 'Arthur'), ('b', 'Belling')]</p>
<p>d.keys() ['a', 'b']</p>
<p>d.values() ['Arthur', '... | 2 | 2012-06-27T16:40:53Z | [
"python",
"list",
"dictionary",
"key-value"
] |
How can I read a python pickle database/file from C? | 1,296,162 | <p>I am working on integrating with several music players. At the moment my favorite is exaile.</p>
<p>In the new version they are migrating the database format from SQLite3 to an internal Pickle format. I wanted to know if there is a way to access pickle format files without having to reverse engineer the format by h... | 8 | 2009-08-18T20:02:51Z | 1,296,188 | <p>You can embed a Python interpreter in a C program, but I think that the easiest solution is to write a Python script that converts "pickles" in another format, e.g. an SQLite database.</p>
| 1 | 2009-08-18T20:07:27Z | [
"python",
"c"
] |
How can I read a python pickle database/file from C? | 1,296,162 | <p>I am working on integrating with several music players. At the moment my favorite is exaile.</p>
<p>In the new version they are migrating the database format from SQLite3 to an internal Pickle format. I wanted to know if there is a way to access pickle format files without having to reverse engineer the format by h... | 8 | 2009-08-18T20:02:51Z | 1,296,612 | <p>Like Cristian told, you can rather easily embed python code in your C code, see the example here: <a href="http://docs.python.org/extending/extending.html#calling-python-functions-from-c" rel="nofollow">http://docs.python.org/extending/extending.html#calling-python-functions-from-c</a></p>
<p>Using cPickle is dead ... | 3 | 2009-08-18T21:25:52Z | [
"python",
"c"
] |
How can I read a python pickle database/file from C? | 1,296,162 | <p>I am working on integrating with several music players. At the moment my favorite is exaile.</p>
<p>In the new version they are migrating the database format from SQLite3 to an internal Pickle format. I wanted to know if there is a way to access pickle format files without having to reverse engineer the format by h... | 8 | 2009-08-18T20:02:51Z | 4,166,900 | <p><a href="http://www.picklingtools.com/">http://www.picklingtools.com/</a></p>
<p>There is a library called the PicklingTools which I help maintain which might be useful: it allows you to form data structures in C++ that you can then pickle/unpickle ... it is C++, not C, but that shouldn't be a problem these days (a... | 14 | 2010-11-12T16:37:26Z | [
"python",
"c"
] |
Bruce Eckel's code snippet from Design Pattern: I'm confused on how it works | 1,296,311 | <p>I've been reading <a href="http://www.mindview.net/Books/TIPython" rel="nofollow">Thinking in python</a> by Bruce Eckel. Currently, I'm reading the <em>Pattern Concept</em> chapter. In this chapter, Eckel shows the different implementations of Singletons in python. But I have an unclear understanding of Alex Martell... | 3 | 2009-08-18T20:28:46Z | 1,296,343 | <pre><code>class Borg:
_shared_state = {}
def __init__(self):
self.__dict__ = self._shared_state
</code></pre>
<p>1) since <code>Borg._shared_state</code> is initialized at class-level (not in <code>__init__</code>) it is effectively static, e.g. shared by all instances of the class.</p>
<p>2) <code>self.__di... | 6 | 2009-08-18T20:34:56Z | [
"python"
] |
Bruce Eckel's code snippet from Design Pattern: I'm confused on how it works | 1,296,311 | <p>I've been reading <a href="http://www.mindview.net/Books/TIPython" rel="nofollow">Thinking in python</a> by Bruce Eckel. Currently, I'm reading the <em>Pattern Concept</em> chapter. In this chapter, Eckel shows the different implementations of Singletons in python. But I have an unclear understanding of Alex Martell... | 3 | 2009-08-18T20:28:46Z | 1,296,490 | <p>Comparing to instances of a normal class may help you see what they're doing:</p>
<pre><code>>>> class NormalClass:
def __init__(self, arg):
self.x = arg
>>> a = NormalClass(1)
>>> b = NormalClass(2)
>>> a.x
1
>>> a.__dict__
{'x': 1}
>>> b.x
... | 2 | 2009-08-18T21:00:19Z | [
"python"
] |
Bruce Eckel's code snippet from Design Pattern: I'm confused on how it works | 1,296,311 | <p>I've been reading <a href="http://www.mindview.net/Books/TIPython" rel="nofollow">Thinking in python</a> by Bruce Eckel. Currently, I'm reading the <em>Pattern Concept</em> chapter. In this chapter, Eckel shows the different implementations of Singletons in python. But I have an unclear understanding of Alex Martell... | 3 | 2009-08-18T20:28:46Z | 1,297,577 | <p>Good answers so far, but let me also answer directly... <code>self.__dict__</code> holds the attributes (i.e., the state) of instance <code>self</code> (unless its class does peculiar things such as defining <code>__slots__</code>;-). So by ensuring that all instances have the same <code>__dict__</code> we're ensuri... | 9 | 2009-08-19T02:37:39Z | [
"python"
] |
Bruce Eckel's code snippet from Design Pattern: I'm confused on how it works | 1,296,311 | <p>I've been reading <a href="http://www.mindview.net/Books/TIPython" rel="nofollow">Thinking in python</a> by Bruce Eckel. Currently, I'm reading the <em>Pattern Concept</em> chapter. In this chapter, Eckel shows the different implementations of Singletons in python. But I have an unclear understanding of Alex Martell... | 3 | 2009-08-18T20:28:46Z | 31,640,691 | <p>I believe the question was this:how does <code>Borg._shared_state</code> get updated? Answer: through <code>self.__dict__</code> in every instance.
<code>self.__dict__ = self._shared_state</code> gives you access to <code>Borg._shared_state</code> through <code>self.__dict__</code> of every instance. When you change... | 0 | 2015-07-26T18:51:41Z | [
"python"
] |
simple python script to block nokia n73 screen | 1,296,359 | <p>i want that upon opening my N73's camera cover,the camera software keeps working as usual,but that it is blocked by a black screen covering the whole screen so that it appears that the camera is not working... I know my requirement is weired but i need this.. ;)</p>
<p>Can anyone guide me to write a python script t... | 1 | 2009-08-18T20:38:23Z | 1,296,689 | <p>I'm rather sceptical whether this can be achieved with PyS60. First of all, AFAIK for PyS60 program you'd need to start the interpreter environment first, autostarting when camera starts probably won't be possible.</p>
<p>Also, opening the camera cover probably does not have any callback so you won't be able to det... | 0 | 2009-08-18T21:40:04Z | [
"python",
"camera",
"pys60",
"n73"
] |
Parse Gmail with Python and mark all older than date as "read" | 1,296,446 | <p>Long story short, I created a new gmail account, and linked several other accounts to it (each with 1000s of messages), which I am importing. All imported messages arrive as unread, but I need them to appear as read.</p>
<p>I have a little experience with python, but I've only used mail and imaplib modules for send... | 4 | 2009-08-18T20:52:28Z | 1,296,465 | <p>Rather than try to parse our HTML why not just use the IMAP interface? Hook it up to a standard mail client and then just sort by date and mark whichever ones you want as read.</p>
| 1 | 2009-08-18T20:55:42Z | [
"python",
"email",
"gmail",
"imap",
"pop3"
] |
Parse Gmail with Python and mark all older than date as "read" | 1,296,446 | <p>Long story short, I created a new gmail account, and linked several other accounts to it (each with 1000s of messages), which I am importing. All imported messages arrive as unread, but I need them to appear as read.</p>
<p>I have a little experience with python, but I've only used mail and imaplib modules for send... | 4 | 2009-08-18T20:52:28Z | 1,296,476 | <p>Just go to the Gmail web interface, do an advanced search by date, then select all and mark as read.</p>
| 1 | 2009-08-18T20:57:09Z | [
"python",
"email",
"gmail",
"imap",
"pop3"
] |
Parse Gmail with Python and mark all older than date as "read" | 1,296,446 | <p>Long story short, I created a new gmail account, and linked several other accounts to it (each with 1000s of messages), which I am importing. All imported messages arrive as unread, but I need them to appear as read.</p>
<p>I have a little experience with python, but I've only used mail and imaplib modules for send... | 4 | 2009-08-18T20:52:28Z | 1,296,613 | <pre><code>typ, data = M.search(None, '(BEFORE 01-Jan-2009)')
for num in data[0].split():
M.store(num, '+FLAGS', '\\Seen')
</code></pre>
<p>This is a slight modification of the code in the <a href="http://docs.python.org/library/imaplib.html" rel="nofollow">imaplib doc page</a> for the store method. I found the se... | 8 | 2009-08-18T21:25:53Z | [
"python",
"email",
"gmail",
"imap",
"pop3"
] |
Parse Gmail with Python and mark all older than date as "read" | 1,296,446 | <p>Long story short, I created a new gmail account, and linked several other accounts to it (each with 1000s of messages), which I am importing. All imported messages arrive as unread, but I need them to appear as read.</p>
<p>I have a little experience with python, but I've only used mail and imaplib modules for send... | 4 | 2009-08-18T20:52:28Z | 8,740,548 | <p>Based on Philip T.'s answer above and <a href="http://tools.ietf.org/html/rfc3501.html" rel="nofollow">RFC 3501</a> and <a href="http://tools.ietf.org/html/rfc2822.html" rel="nofollow">RFC 2822</a>, I built some lines of code to mark mails older than 10 days as read. A static list is used for the abbreviated month ... | 2 | 2012-01-05T09:57:47Z | [
"python",
"email",
"gmail",
"imap",
"pop3"
] |
Python - Find Path to File Being Run | 1,296,501 | <p>How can I find the full path to the currently running python script? That is to say, what do I have to put to achieve this:</p>
<pre><code>Nirvana@bahamut:/tmp$ python baz.py
running from /tmp
file is baz.py
</code></pre>
| 23 | 2009-08-18T21:02:54Z | 1,296,522 | <p>This will print the directory in which the script lives (as opposed to the working directory):</p>
<pre><code>import os
dirname, filename = os.path.split(os.path.abspath(__file__))
print "running from", dirname
print "file is", filename
</code></pre>
<p>Here's how it behaves, when I put it in <code>c:\src</code>:<... | 12 | 2009-08-18T21:08:20Z | [
"python"
] |
Python - Find Path to File Being Run | 1,296,501 | <p>How can I find the full path to the currently running python script? That is to say, what do I have to put to achieve this:</p>
<pre><code>Nirvana@bahamut:/tmp$ python baz.py
running from /tmp
file is baz.py
</code></pre>
| 23 | 2009-08-18T21:02:54Z | 1,296,535 | <pre><code>import sys, os
file = sys.argv[0]
pathname = os.path.dirname(file)
print 'running from %s' % os.path.abspath(pathname)
print 'file is %s' % file
</code></pre>
<p>Check os.getcwd() (<a href="http://docs.python.org/library/os.html" rel="nofollow">docs</a>)</p>
| 2 | 2009-08-18T21:10:04Z | [
"python"
] |
Python - Find Path to File Being Run | 1,296,501 | <p>How can I find the full path to the currently running python script? That is to say, what do I have to put to achieve this:</p>
<pre><code>Nirvana@bahamut:/tmp$ python baz.py
running from /tmp
file is baz.py
</code></pre>
| 23 | 2009-08-18T21:02:54Z | 1,296,536 | <p>The script name will (always?) be the first index of sys.argv:</p>
<pre><code>import sys
print sys.argv[0]
</code></pre>
<p>An even easier way to find the path of your running script:</p>
<pre><code>os.path.basename(sys.argv[0])
</code></pre>
| 2 | 2009-08-18T21:10:11Z | [
"python"
] |
Python - Find Path to File Being Run | 1,296,501 | <p>How can I find the full path to the currently running python script? That is to say, what do I have to put to achieve this:</p>
<pre><code>Nirvana@bahamut:/tmp$ python baz.py
running from /tmp
file is baz.py
</code></pre>
| 23 | 2009-08-18T21:02:54Z | 1,296,537 | <p>The running file is always <code>__file__</code>.</p>
<p>Here's a demo script, named <code>identify.py</code></p>
<pre><code>print __file__
</code></pre>
<p>Here's the results</p>
<pre><code>MacBook-5:Projects slott$ python StackOverflow/identify.py
StackOverflow/identify.py
MacBook-5:Projects slott$ cd StackOv... | 1 | 2009-08-18T21:10:13Z | [
"python"
] |
Python - Find Path to File Being Run | 1,296,501 | <p>How can I find the full path to the currently running python script? That is to say, what do I have to put to achieve this:</p>
<pre><code>Nirvana@bahamut:/tmp$ python baz.py
running from /tmp
file is baz.py
</code></pre>
| 23 | 2009-08-18T21:02:54Z | 1,297,407 | <p><strong><code>__file__</code> is NOT what you are looking for.</strong> Don't use accidental side-effects</p>
<p><code>sys.argv[0]</code> is <strong>always</strong> the path to the script (if in fact a script has been invoked) -- see <a href="http://docs.python.org/library/sys.html#sys.argv">http://docs.python.org/... | 43 | 2009-08-19T01:29:19Z | [
"python"
] |
Python - Find Path to File Being Run | 1,296,501 | <p>How can I find the full path to the currently running python script? That is to say, what do I have to put to achieve this:</p>
<pre><code>Nirvana@bahamut:/tmp$ python baz.py
running from /tmp
file is baz.py
</code></pre>
| 23 | 2009-08-18T21:02:54Z | 1,299,299 | <p>I would suggest</p>
<pre><code>import os, sys
print os.path.split(os.path.abspath(os.path.realpath(sys.argv[0])))[0]
</code></pre>
<p>This way you can safely create symbolic links to the script executable and it will still find the correct directory.</p>
| 1 | 2009-08-19T11:24:13Z | [
"python"
] |
Efficiency of using a Python list as a queue | 1,296,511 | <p>A coworker recently wrote a program in which he used a Python list as a queue. In other words, he used <code>.append(x)</code> when needing to insert items and <code>.pop(0)</code> when needing to remove items.</p>
<p>I know that Python has <a href="http://docs.python.org/library/collections.html#collections.deque... | 34 | 2009-08-18T21:05:58Z | 1,296,523 | <p>it sounds like a bit of empirical testing might be the best thing to do here - second order issues might make one approach better in practice, even if it's not better in theory.</p>
| 2 | 2009-08-18T21:08:22Z | [
"python",
"list",
"memory-leaks"
] |
Efficiency of using a Python list as a queue | 1,296,511 | <p>A coworker recently wrote a program in which he used a Python list as a queue. In other words, he used <code>.append(x)</code> when needing to insert items and <code>.pop(0)</code> when needing to remove items.</p>
<p>I know that Python has <a href="http://docs.python.org/library/collections.html#collections.deque... | 34 | 2009-08-18T21:05:58Z | 1,296,527 | <p>You won't run out of memory using the <code>list</code> implementation, but performance will be poor. From <a href="http://docs.python.org/library/collections.html">the docs</a>:</p>
<blockquote>
<p>Though <code>list</code> objects support similar
operations, they are optimized for
fast fixed-length operation... | 23 | 2009-08-18T21:09:05Z | [
"python",
"list",
"memory-leaks"
] |
Efficiency of using a Python list as a queue | 1,296,511 | <p>A coworker recently wrote a program in which he used a Python list as a queue. In other words, he used <code>.append(x)</code> when needing to insert items and <code>.pop(0)</code> when needing to remove items.</p>
<p>I know that Python has <a href="http://docs.python.org/library/collections.html#collections.deque... | 34 | 2009-08-18T21:05:58Z | 1,296,531 | <p>Every <code>.pop(0)</code> takes N steps, since the list has to be reorganized. The required memory will not grow endlessly and only be as big as required for the items that are held.</p>
<p>I'd recommend using <code>deque</code> to get O(1) append and pop from front.</p>
| 4 | 2009-08-18T21:09:35Z | [
"python",
"list",
"memory-leaks"
] |
Efficiency of using a Python list as a queue | 1,296,511 | <p>A coworker recently wrote a program in which he used a Python list as a queue. In other words, he used <code>.append(x)</code> when needing to insert items and <code>.pop(0)</code> when needing to remove items.</p>
<p>I know that Python has <a href="http://docs.python.org/library/collections.html#collections.deque... | 34 | 2009-08-18T21:05:58Z | 1,297,464 | <p>Some answers claimed a "10x" speed advantage for deque vs list-used-as-FIFO when both have 1000 entries, but that's a bit of an overbid:</p>
<pre><code>$ python -mtimeit -s'q=range(1000)' 'q.append(23); q.pop(0)'
1000000 loops, best of 3: 1.24 usec per loop
$ python -mtimeit -s'import collections; q=collections.deq... | 60 | 2009-08-19T02:00:10Z | [
"python",
"list",
"memory-leaks"
] |
Efficiency of using a Python list as a queue | 1,296,511 | <p>A coworker recently wrote a program in which he used a Python list as a queue. In other words, he used <code>.append(x)</code> when needing to insert items and <code>.pop(0)</code> when needing to remove items.</p>
<p>I know that Python has <a href="http://docs.python.org/library/collections.html#collections.deque... | 34 | 2009-08-18T21:05:58Z | 1,297,467 | <p>From Beazley's <a href="http://rads.stackoverflow.com/amzn/click/0672329786"><em>Python Essential Reference, Fourth Edition</em></a>, p. 194:</p>
<blockquote>
<p>Some library modules provide new types
that outperform the built-ins at
certain tasks. For instance,
collections.deque type provides
similar fun... | 14 | 2009-08-19T02:00:18Z | [
"python",
"list",
"memory-leaks"
] |
Does IronPython implement python standard library? | 1,296,640 | <p>I tried IronPython some time ago and it seemed that it implements only python language, and uses .NET for libraries. Is this still the case? Can one use python modules from IronPython?</p>
| 6 | 2009-08-18T21:32:14Z | 1,296,706 | <p>(As I said <a href="http://stackoverflow.com/questions/676681/iron-python-twisted/677154#677154">here</a>:)</p>
<blockquote>
<p>I've not used it myself, but you may
get some mileage out of <a href="http://www.resolversystems.com/documentation/index.php/Ironclad.html" rel="nofollow">Ironclad</a>
- it supposedl... | 0 | 2009-08-18T21:43:36Z | [
"python",
"ironpython"
] |
Does IronPython implement python standard library? | 1,296,640 | <p>I tried IronPython some time ago and it seemed that it implements only python language, and uses .NET for libraries. Is this still the case? Can one use python modules from IronPython?</p>
| 6 | 2009-08-18T21:32:14Z | 1,296,734 | <p>You can use the Python standard library from IronPython just fine. Here's how:</p>
<ol>
<li>Install Python.</li>
<li>Setup an environment variable named IRONPYTHONPATH that points to the standard library directory. </li>
</ol>
<p>Next time ipy.exe is run, site.py is read and you're good to go.</p>
| 2 | 2009-08-18T21:49:21Z | [
"python",
"ironpython"
] |
Does IronPython implement python standard library? | 1,296,640 | <p>I tried IronPython some time ago and it seemed that it implements only python language, and uses .NET for libraries. Is this still the case? Can one use python modules from IronPython?</p>
| 6 | 2009-08-18T21:32:14Z | 1,296,770 | <p>The <a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22981">IronPython installer</a> includes the Python standard library. Otherwise, you can use the standard library from a compatible Python install (IPy 2.0 -> CPy 2.5, IPy 2.6 -> CPy 2.6). Either copy the Python Lib directory to the I... | 9 | 2009-08-18T21:55:21Z | [
"python",
"ironpython"
] |
Does IronPython implement python standard library? | 1,296,640 | <p>I tried IronPython some time ago and it seemed that it implements only python language, and uses .NET for libraries. Is this still the case? Can one use python modules from IronPython?</p>
| 6 | 2009-08-18T21:32:14Z | 1,297,357 | <p>The .msi installer for <a href="http://ironpython.codeplex.com" rel="nofollow">IronPython</a> includes all parts of the <a href="http://python.org" rel="nofollow">CPython</a> standard library that should work with IronPython. You can simply copy the standard library from a CPython install if you prefer, although yo... | 2 | 2009-08-19T01:04:37Z | [
"python",
"ironpython"
] |
Getting system status in python | 1,296,703 | <p>Is there any way to get system status in python, for example the amount of memory free, processes that are running, cpu load and so on.
I know on linux I can get this from the /proc directory, but I would like to do this on unix and windows as well.</p>
| 8 | 2009-08-18T21:42:51Z | 1,296,768 | <p>I don't think there is a cross-platform library for that yet (there definitely should be one though)</p>
<p>I can however provide you with one snippet I used to get the current CPU load from <code>/proc/stat</code> under Linux:</p>
<p><strong>Edit</strong>: replaced horrible undocumented code with slightly more py... | 5 | 2009-08-18T21:55:08Z | [
"python",
"operating-system"
] |
Getting system status in python | 1,296,703 | <p>Is there any way to get system status in python, for example the amount of memory free, processes that are running, cpu load and so on.
I know on linux I can get this from the /proc directory, but I would like to do this on unix and windows as well.</p>
| 8 | 2009-08-18T21:42:51Z | 1,296,816 | <p>I don't know of any such library/ package that currently supports both Linux and Windows. There's <a href="http://www.i-scream.org/libstatgrab/" rel="nofollow">libstatgrab</a> which doesn't seem to be very actively developed (it already supports a decent variety of Unix platforms though) and the very active <a href=... | 8 | 2009-08-18T22:03:23Z | [
"python",
"operating-system"
] |
Getting system status in python | 1,296,703 | <p>Is there any way to get system status in python, for example the amount of memory free, processes that are running, cpu load and so on.
I know on linux I can get this from the /proc directory, but I would like to do this on unix and windows as well.</p>
| 8 | 2009-08-18T21:42:51Z | 14,613,230 | <p><a href="https://pypi.python.org/pypi/psutil" rel="nofollow">https://pypi.python.org/pypi/psutil</a></p>
<pre><code>import psutil
psutil.get_pid_list()
psutil.virtual_memory()
psutil.cpu_times()
</code></pre>
<p>etc.</p>
| 4 | 2013-01-30T20:35:43Z | [
"python",
"operating-system"
] |
Match all urls that aren't wrapped into <a> tag | 1,296,778 | <p>I am seeking for a regular expression pattern that could match urls in HTML that aren't wrapped into 'a' tag, in order to wrap them into 'a' tag further (i.e. highlight all non-highlighted links).</p>
<p>Input is simple HTML with 'a', 'b', 'i', 'br', 'p' 'img' tags allowed. All other HTML tags shouldn't appear in t... | 1 | 2009-08-18T21:56:33Z | 1,296,870 | <p>You could use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> or similar to exclude all urls that are already part of links. </p>
<p>Then you can match the plain text with one of the url regular expressions that's already out there (google "url regular expression", which one... | 5 | 2009-08-18T22:15:25Z | [
"python",
"regex"
] |
Match all urls that aren't wrapped into <a> tag | 1,296,778 | <p>I am seeking for a regular expression pattern that could match urls in HTML that aren't wrapped into 'a' tag, in order to wrap them into 'a' tag further (i.e. highlight all non-highlighted links).</p>
<p>Input is simple HTML with 'a', 'b', 'i', 'br', 'p' 'img' tags allowed. All other HTML tags shouldn't appear in t... | 1 | 2009-08-18T21:56:33Z | 1,296,897 | <p>Parsing HTML with a single regex is almost impossible by definition, since regexes don't have state.</p>
<p>Build/Use a real parser instead. Maybe <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> or <a href="http://code.google.com/p/html5lib/" rel="nofollow">html5lib</a>.</p>... | 5 | 2009-08-18T22:23:58Z | [
"python",
"regex"
] |
Match all urls that aren't wrapped into <a> tag | 1,296,778 | <p>I am seeking for a regular expression pattern that could match urls in HTML that aren't wrapped into 'a' tag, in order to wrap them into 'a' tag further (i.e. highlight all non-highlighted links).</p>
<p>Input is simple HTML with 'a', 'b', 'i', 'br', 'p' 'img' tags allowed. All other HTML tags shouldn't appear in t... | 1 | 2009-08-18T21:56:33Z | 1,299,962 | <p>Thanks guys! Below is my solution:</p>
<pre><code>from django.utils.html import urlize # Yes, I am using Django's urlize to do all dirty work :)
def urlize_html(value):
"""
Urlizes text containing simple HTML tags.
"""
A_IMG_REGEX = r'(<[aA][^>]+>[^<]+</[aA]>|<[iI][mM][gG][^>... | -2 | 2009-08-19T13:34:47Z | [
"python",
"regex"
] |
Django ModelChoiceField initial data not working for ForeignKey | 1,296,938 | <p>I am filling my form with initial data using the normail:</p>
<pre><code>form = somethingForm(initial = {
'title' : something.title,
'category' : something.category_id,
})
</code></pre>
<p>The title works fine, but if the category is a Mod... | 2 | 2009-08-18T22:34:00Z | 1,297,909 | <p>You need to do this</p>
<pre><code>form = somethingForm(initial = {
'title' : something.title,
'category' : [("database value","display value")],
})
</code></pre>
<h2>Why list of tuples?</h2>
<ol>
<li><p>Because choice fields are associat... | 0 | 2009-08-19T05:13:28Z | [
"python",
"django"
] |
Django ModelChoiceField initial data not working for ForeignKey | 1,296,938 | <p>I am filling my form with initial data using the normail:</p>
<pre><code>form = somethingForm(initial = {
'title' : something.title,
'category' : something.category_id,
})
</code></pre>
<p>The title works fine, but if the category is a Mod... | 2 | 2009-08-18T22:34:00Z | 1,358,242 | <p>Perhaps try using an instance of a category rather than its ID?</p>
| 1 | 2009-08-31T16:36:14Z | [
"python",
"django"
] |
SQLAlchemy(Postgres) and transaction | 1,296,994 | <p>I want a record from a table(queue) to be selected, locked(no other process can edit this record) and updated at a later point in time.<br />
I assumed if I put the whole querying and updating in a transaction, no other process can edit/query the same record. But I am not quite able to achieve this.</p>
<pre><code>... | 2 | 2009-08-18T22:49:57Z | 1,297,946 | <p>Either make your transaction isolation level serializable, or fetch the record for updating via query.with_lockmode('update').</p>
| 1 | 2009-08-19T05:34:50Z | [
"python",
"postgresql",
"sqlalchemy"
] |
in GTK, how do I get the original normal bg color of a widget? | 1,297,169 | <p>I do this:</p>
<pre><code> self.origbg = self.style.bg[gtk.STATE_NORMAL]
</code></pre>
<p>and later in my eventboxes I change the bgcolor to it by doing:</p>
<pre><code> self.modify_bg(gtk.STATE_NORMAL, color)
</code></pre>
<p>However, the color actually <em>changes</em>! It's not the state_normal color th... | 1 | 2009-08-18T23:43:23Z | 1,310,063 | <p>Connect to the widget's "map-event" signal (which is sent when the widget is first shown in a window); this is the first time you can read the real theme colors.</p>
| 1 | 2009-08-21T04:19:22Z | [
"python",
"gtk",
"colors",
"themes"
] |
in GTK, how do I get the original normal bg color of a widget? | 1,297,169 | <p>I do this:</p>
<pre><code> self.origbg = self.style.bg[gtk.STATE_NORMAL]
</code></pre>
<p>and later in my eventboxes I change the bgcolor to it by doing:</p>
<pre><code> self.modify_bg(gtk.STATE_NORMAL, color)
</code></pre>
<p>However, the color actually <em>changes</em>! It's not the state_normal color th... | 1 | 2009-08-18T23:43:23Z | 5,381,093 | <p>If you want to avoid listening for map event you should call <code>realize()</code> and then get colors. I know this is an old issue but just wanted to contribute in case people run into it like I did. :)</p>
| 3 | 2011-03-21T17:08:20Z | [
"python",
"gtk",
"colors",
"themes"
] |
in GTK, how do I get the original normal bg color of a widget? | 1,297,169 | <p>I do this:</p>
<pre><code> self.origbg = self.style.bg[gtk.STATE_NORMAL]
</code></pre>
<p>and later in my eventboxes I change the bgcolor to it by doing:</p>
<pre><code> self.modify_bg(gtk.STATE_NORMAL, color)
</code></pre>
<p>However, the color actually <em>changes</em>! It's not the state_normal color th... | 1 | 2009-08-18T23:43:23Z | 39,064,643 | <p>I use this to get the default background color for an entry in GTK3</p>
<pre><code> context = entry.get_style_context()
default_background = context.get_background_color(Gtk.StateType.NORMAL)
</code></pre>
| 0 | 2016-08-21T13:19:30Z | [
"python",
"gtk",
"colors",
"themes"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.