title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
setting script path in a buildout using one of the distutils recipes
2,031,650
<p>I am using buildout. I am using it to install openerp. I would like the scripts that openerp creates to run itself available in ${buildout:location}/bin </p> <p>I tried <a href="http://github.com/zerok/zerokspot.recipe.distutils/" rel="nofollow">zerokspot.recipe.distutils</a> and <a href="http://pypi.python.or...
0
2010-01-09T00:03:06Z
2,037,991
<p>After some help and some research, it seems that openerp is hardly a standard distutils package. After some research and some help, I tracked down </p> <p><a href="http://pypi.python.org/pypi/cns.recipe.symlink/0.1" rel="nofollow">http://pypi.python.org/pypi/cns.recipe.symlink/0.1</a></p> <p>Which I shall use to...
0
2010-01-10T18:18:10Z
[ "python", "distutils", "buildout" ]
setting script path in a buildout using one of the distutils recipes
2,031,650
<p>I am using buildout. I am using it to install openerp. I would like the scripts that openerp creates to run itself available in ${buildout:location}/bin </p> <p>I tried <a href="http://github.com/zerok/zerokspot.recipe.distutils/" rel="nofollow">zerokspot.recipe.distutils</a> and <a href="http://pypi.python.or...
0
2010-01-09T00:03:06Z
2,195,165
<p>Did you successfuly installed openerp with buildout ?</p> <p>On my side it just cannot find these modules, but they are in my eggs dir: </p> <pre><code>Error: python module psycopg2 (PostgreSQL module) is required Error: python module libxslt (libxslt python bindings) is required Error: python module pychart (pych...
0
2010-02-03T20:26:17Z
[ "python", "distutils", "buildout" ]
Any way to set request headers when doing a request using urllib in Python 2.x?
2,031,745
<p>I am trying to make an HTTP request in Python 2.6.4, using the urllib module. Is there any way to set the request headers?</p> <p>I am sure that this is possible using urllib2, but I would prefer to use urllib since it seems simpler.</p>
0
2010-01-09T00:27:49Z
2,031,772
<p>I don't think so, but <em>urllib2</em> can. Check out the <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">documentation</a> of <em>urllib2.Request</em>.</p>
1
2010-01-09T00:33:01Z
[ "python", "http", "urllib", "python-2.6", "python-2.x" ]
Any way to set request headers when doing a request using urllib in Python 2.x?
2,031,745
<p>I am trying to make an HTTP request in Python 2.6.4, using the urllib module. Is there any way to set the request headers?</p> <p>I am sure that this is possible using urllib2, but I would prefer to use urllib since it seems simpler.</p>
0
2010-01-09T00:27:49Z
2,031,786
<p>There isn't any way to do that, which is precisely the reason <code>urllib</code> is deprecated in favour of <code>urllib2</code>. So just use <code>urllib2</code> rather than writing new code to a deprecated interface.</p>
2
2010-01-09T00:37:35Z
[ "python", "http", "urllib", "python-2.6", "python-2.x" ]
Any way to set request headers when doing a request using urllib in Python 2.x?
2,031,745
<p>I am trying to make an HTTP request in Python 2.6.4, using the urllib module. Is there any way to set the request headers?</p> <p>I am sure that this is possible using urllib2, but I would prefer to use urllib since it seems simpler.</p>
0
2010-01-09T00:27:49Z
2,031,794
<p>You could actually overwrite methods in <code>FancyURLopener</code>, but that does not seem right (see <a href="http://docs.python.org/library/urllib.html#urllib._urlopener" rel="nofollow">http://docs.python.org/library/urllib.html#urllib._urlopener</a>). You could also use <code>httplib</code> which basically is th...
1
2010-01-09T00:41:00Z
[ "python", "http", "urllib", "python-2.6", "python-2.x" ]
how can i use django.utils.safestring.py
2,031,788
<pre><code>from django.utils.safestring import * print SafeString('\u3042') print '\u3042' \u3042 \u3042 </code></pre> <p>who can give me a better example.</p> <p>thanks</p>
0
2010-01-09T00:39:29Z
2,031,866
<p>An instance of <a href="http://djangoapi.quamquam.org/trunk/django.utils.safestring-pysrc.html" rel="nofollow">django.utils.safestring.SafeString</a> is a string which has already been vetted or escaped, so it contains no characters that could give HTML a parsing problem ('&lt;', '>', '&amp;'). See <a href="http://...
2
2010-01-09T01:00:13Z
[ "python", "django" ]
Python find list lengths in a sublist
2,031,846
<p>I am trying to find out how to get the length of every list that is held within a particular list. For example:</p> <pre><code>a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) </code></pre> <p>I'd like to run a command like: </p> <pre><code>len(a[0][:]) </code></pre> <p>w...
5
2010-01-09T00:55:04Z
2,031,855
<p><code>[len(x) for x in a[0]]</code> ?</p> <pre><code>&gt;&gt;&gt; a = [] &gt;&gt;&gt; a.append([]) &gt;&gt;&gt; a[0].append([1,2,3,4,5]) &gt;&gt;&gt; a[0].append([1,2,3,4]) &gt;&gt;&gt; a[0].append([1,2,3]) &gt;&gt;&gt; [len(x) for x in a[0]] [5, 4, 3] </code></pre>
13
2010-01-09T00:57:25Z
[ "python", "list" ]
Python find list lengths in a sublist
2,031,846
<p>I am trying to find out how to get the length of every list that is held within a particular list. For example:</p> <pre><code>a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) </code></pre> <p>I'd like to run a command like: </p> <pre><code>len(a[0][:]) </code></pre> <p>w...
5
2010-01-09T00:55:04Z
2,031,864
<pre><code>[len(x) for x in a[0]] </code></pre>
3
2010-01-09T00:59:10Z
[ "python", "list" ]
Python find list lengths in a sublist
2,031,846
<p>I am trying to find out how to get the length of every list that is held within a particular list. For example:</p> <pre><code>a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) </code></pre> <p>I'd like to run a command like: </p> <pre><code>len(a[0][:]) </code></pre> <p>w...
5
2010-01-09T00:55:04Z
2,031,873
<p>This is known as <a href="http://diveintopython.net/native_data_types/mapping_lists.html" rel="nofollow">List comprehension</a> (click for more info and a description).</p> <pre><code>[len(l) for l in a[0]] </code></pre>
3
2010-01-09T01:01:07Z
[ "python", "list" ]
Python find list lengths in a sublist
2,031,846
<p>I am trying to find out how to get the length of every list that is held within a particular list. For example:</p> <pre><code>a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) </code></pre> <p>I'd like to run a command like: </p> <pre><code>len(a[0][:]) </code></pre> <p>w...
5
2010-01-09T00:55:04Z
2,031,877
<p><code>map(len, a[0])</code></p>
7
2010-01-09T01:02:05Z
[ "python", "list" ]
Python find list lengths in a sublist
2,031,846
<p>I am trying to find out how to get the length of every list that is held within a particular list. For example:</p> <pre><code>a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) </code></pre> <p>I'd like to run a command like: </p> <pre><code>len(a[0][:]) </code></pre> <p>w...
5
2010-01-09T00:55:04Z
2,031,878
<pre><code>def lens(listoflists): return [len(x) for x in listoflists] </code></pre> <p>now, just call <code>lens(a[0])</code> instead of your desired <code>len(a[0][:])</code> (you can, if you insist, add that redundant <code>[:]</code>, but that's just doing a copy for no purpose whatsoever -- waste not, want not;...
2
2010-01-09T01:03:13Z
[ "python", "list" ]
Python find list lengths in a sublist
2,031,846
<p>I am trying to find out how to get the length of every list that is held within a particular list. For example:</p> <pre><code>a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) </code></pre> <p>I'd like to run a command like: </p> <pre><code>len(a[0][:]) </code></pre> <p>w...
5
2010-01-09T00:55:04Z
2,031,898
<p>using the usual "old school" way</p> <pre><code>t=[] for item in a[0]: t.append(len(item)) print t </code></pre>
1
2010-01-09T01:10:05Z
[ "python", "list" ]
Python find list lengths in a sublist
2,031,846
<p>I am trying to find out how to get the length of every list that is held within a particular list. For example:</p> <pre><code>a = [] a.append([]) a[0].append([1,2,3,4,5]) a[0].append([1,2,3,4]) a[0].append([1,2,3]) </code></pre> <p>I'd like to run a command like: </p> <pre><code>len(a[0][:]) </code></pre> <p>w...
5
2010-01-09T00:55:04Z
38,223,853
<p>Matthew's answer does not work in Python 3. The following one works in both Python 2 and Python 3</p> <p><code>list(map(len, a[0]))</code></p>
0
2016-07-06T12:19:45Z
[ "python", "list" ]
How can i grab CData out of BeautifulSoup
2,032,172
<p>I have a website that I'm scraping that has a similar structure the following. I'd like to be able to grab the info out of the CData block. </p> <p>I'm using BeautifulSoup to pull other info off the page, so if the solution can work with that, it would help keep my learning curve down as I'm a python novice. Specif...
5
2010-01-09T02:53:22Z
2,032,225
<p>You could try this:</p> <pre><code>from BeautifulSoup import BeautifulSoup // source.html contains your html above f = open('source.html') soup = BeautifulSoup(''.join(f.readlines())) s = soup.findAll('script') cdata = s[0].contents[0] </code></pre> <p>That should give you the contents of cdata.</p> <p><strong>U...
3
2010-01-09T03:19:21Z
[ "python", "screen-scraping", "beautifulsoup", "cdata" ]
How can i grab CData out of BeautifulSoup
2,032,172
<p>I have a website that I'm scraping that has a similar structure the following. I'd like to be able to grab the info out of the CData block. </p> <p>I'm using BeautifulSoup to pull other info off the page, so if the solution can work with that, it would help keep my learning curve down as I'm a python novice. Specif...
5
2010-01-09T02:53:22Z
2,032,252
<p>BeautifulSoup sees CData as a special case (subclass) of "navigable strings". So for example:</p> <pre><code>import BeautifulSoup txt = '''&lt;foobar&gt;We have &lt;![CDATA[some data here]]&gt; and more. &lt;/foobar&gt;''' soup = BeautifulSoup.BeautifulSoup(txt) for cd in soup.findAll(text=Tr...
11
2010-01-09T03:31:41Z
[ "python", "screen-scraping", "beautifulsoup", "cdata" ]
How can i grab CData out of BeautifulSoup
2,032,172
<p>I have a website that I'm scraping that has a similar structure the following. I'd like to be able to grab the info out of the CData block. </p> <p>I'm using BeautifulSoup to pull other info off the page, so if the solution can work with that, it would help keep my learning curve down as I'm a python novice. Specif...
5
2010-01-09T02:53:22Z
23,754,419
<pre><code>import re from bs4 import BeautifulSoup soup = BeautifulSoup(content) for x in soup.find_all('item'): print re.sub('[\[CDATA\]]', '', x.string) </code></pre>
0
2014-05-20T08:16:52Z
[ "python", "screen-scraping", "beautifulsoup", "cdata" ]
Scripting Python for Linux commands
2,032,228
<p>I have a question. I have been really trying to learn Python. For a project, I want to make an ncurses GUI for my backup server. My backup server runs rdiff-backup, and I want to have the ncurses take in variable names and plug them into my script. I have been trying to do a lot of reading so I don't ask dumb q...
2
2010-01-09T03:23:17Z
2,032,240
<p>You join paths using os.path.join</p> <p>You concatenate strings like so: "".join(['a', 'b']) or ", ".join(['c', 'd'])</p> <p>Which part is difficult? I am not sure I understand the question 100%</p> <p>Is this it?</p> <pre><code>script = rdiff + " ".join(rdiffArgs) </code></pre>
3
2010-01-09T03:27:07Z
[ "python", "linux" ]
Scripting Python for Linux commands
2,032,228
<p>I have a question. I have been really trying to learn Python. For a project, I want to make an ncurses GUI for my backup server. My backup server runs rdiff-backup, and I want to have the ncurses take in variable names and plug them into my script. I have been trying to do a lot of reading so I don't ask dumb q...
2
2010-01-09T03:23:17Z
2,032,254
<p>you can use format specifiers</p> <pre><code>def runScript(): script = "%s %s %s@%s %s::%s %s" %(rdiff,rdiffVerbosity,rdiffStatistics,clientName,clientHost,clientDir,serverDir) os.system(script) </code></pre> <p>or say your rdiffArgs is already in a list</p> <pre><code>rdiffArgs = [rdiffVerbosity,rdif...
5
2010-01-09T03:31:58Z
[ "python", "linux" ]
Scripting Python for Linux commands
2,032,228
<p>I have a question. I have been really trying to learn Python. For a project, I want to make an ncurses GUI for my backup server. My backup server runs rdiff-backup, and I want to have the ncurses take in variable names and plug them into my script. I have been trying to do a lot of reading so I don't ask dumb q...
2
2010-01-09T03:23:17Z
2,032,260
<p>try to use <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess</a> module and pass arguments as list e.g.</p> <pre><code>client = clientName + '@' + clientHost + '::' + clientDir cmd = [rdiff, rdiffVerbosity, rdiffStatistics, client , serverDir] p = Popen(cmd ", shell=True) print os.w...
5
2010-01-09T03:33:31Z
[ "python", "linux" ]
ValueError in Django
2,032,360
<p>I'm getting a strange error and can't figure out why. I'd appreciate any input. I've been stuck on this for a few days. Here is my code:</p> <p>models.py</p> <pre><code>class Employee(models.Model): lastname = models.CharField(max_length=75) firstname = models.CharField(max_length=75) position = mod...
9
2010-01-09T04:37:52Z
2,032,378
<pre><code>urlpatterns = patterns('', (r'^salaries/employee/$', list_detail.object_list, 'employee_info'), ) </code></pre> <p>The third item in the tuple needs to be a dictionary, not a string. Try removing the single quotes around employee_info:</p> <pre><code>urlpatterns = patterns('', (r'^salarie...
16
2010-01-09T04:47:32Z
[ "python", "django" ]
ValueError in Django
2,032,360
<p>I'm getting a strange error and can't figure out why. I'd appreciate any input. I've been stuck on this for a few days. Here is my code:</p> <p>models.py</p> <pre><code>class Employee(models.Model): lastname = models.CharField(max_length=75) firstname = models.CharField(max_length=75) position = mod...
9
2010-01-09T04:37:52Z
15,670,508
<p>may be you mean the URL <code>name</code>:</p> <pre><code>urlpatterns = patterns('', (r'^salaries/employee/$', list_detail.object_list, name='employee_info'), ) </code></pre>
1
2013-03-27T22:11:28Z
[ "python", "django" ]
How to create full compressed tar file using Python?
2,032,403
<p>how can I create a .tar.gz file which compresses the data as much as tar files are compressed...</p>
44
2010-01-09T04:59:37Z
2,032,407
<p>tarfile module is cool: <a href="http://docs.python.org/library/tarfile.html" rel="nofollow">http://docs.python.org/library/tarfile.html</a></p>
2
2010-01-09T05:01:33Z
[ "python", "compression", "zip", "tarfile" ]
How to create full compressed tar file using Python?
2,032,403
<p>how can I create a .tar.gz file which compresses the data as much as tar files are compressed...</p>
44
2010-01-09T04:59:37Z
2,032,433
<pre><code>import tarfile tar = tarfile.open("sample.tar.gz", "w:gz") for name in ["file1", "file2", "file3"]: tar.add(name) tar.close() </code></pre> <p>If you want to create a tar.bz2 compressed file, just replace file extension name with ".tar.bz2" and "w:gz" with "w:bz2".</p>
63
2010-01-09T05:17:44Z
[ "python", "compression", "zip", "tarfile" ]
How to create full compressed tar file using Python?
2,032,403
<p>how can I create a .tar.gz file which compresses the data as much as tar files are compressed...</p>
44
2010-01-09T04:59:37Z
2,032,439
<p>You call <a href="http://docs.python.org/library/tarfile.html#tarfile.open">tarfile.open</a> with <code>mode='w:gz'</code>, meaning "Open for gzip compressed writing."</p> <p>You'll probably want to end the filename (the <code>name</code> argument to <code>open</code>) with <code>.tar.gz</code>, but that doesn't af...
27
2010-01-09T05:19:07Z
[ "python", "compression", "zip", "tarfile" ]
How to create full compressed tar file using Python?
2,032,403
<p>how can I create a .tar.gz file which compresses the data as much as tar files are compressed...</p>
44
2010-01-09T04:59:37Z
17,081,026
<p>To build a <code>.tar.gz</code> for an entire directory tree:</p> <pre><code>def make_tarfile(output_filename, source_dir): with tarfile.open(output_filename, "w:gz") as tar: tar.add(source_dir, arcname=os.path.basename(source_dir)) </code></pre>
71
2013-06-13T06:58:45Z
[ "python", "compression", "zip", "tarfile" ]
Python ctypes callback function to SWIG
2,032,470
<p>I have a SWIG C++ function that expects a function pointer (WNDPROC), and want to give it a Python function that has been wrapped by ctypes.WINFUNCTYPE.</p> <p>It seems to me that this should be compatible, but SWIG's type checking throws an exception because it doesn't know that the ctypes.WINFUNCTYPE type is acct...
5
2010-01-09T05:35:31Z
2,455,069
<p>I don't have a windows machine to really check this, but I think you need to create a typemap to tell swig how to convert the PyObject wrapper to a WNDPROC:</p> <pre><code>// assuming the wrapped object has an attribute "pointer" which contains // the numerical address of the WNDPROC %typemap(in) WNDPROC { PyO...
3
2010-03-16T14:21:11Z
[ "c++", "python", "swig", "ctypes" ]
emacs windows run python program in current buffer and display the output on output window
2,032,476
<p>I use the Python-mode (not the default one comes with emacs 23). </p> <p>I could not execute the python program currently loaded in emacs.</p> <p>I am getting "Symbol's function definition is void: smart-operator-mode-on" error.</p> <p>Any clue or any tips makes a python program and it can be run on emacs and sho...
3
2010-01-09T05:37:44Z
2,032,661
<p>It works after turning it off (smart-operator-mode-on) I need to see how to solve smart-operator-mode-on</p> <p>(setq debug-on-error t) helps me to spot the error. Thanks Noufal.</p>
0
2010-01-09T07:08:13Z
[ "python", "emacs", "python-mode" ]
emacs windows run python program in current buffer and display the output on output window
2,032,476
<p>I use the Python-mode (not the default one comes with emacs 23). </p> <p>I could not execute the python program currently loaded in emacs.</p> <p>I am getting "Symbol's function definition is void: smart-operator-mode-on" error.</p> <p>Any clue or any tips makes a python program and it can be run on emacs and sho...
3
2010-01-09T05:37:44Z
7,505,297
<p>I got this error fixed by downloading the <code>smart-operator.el</code> file into a load-path and adding <code>require 'smart-operator'</code> before calling <code>smart-operator-mode-on</code>.</p>
0
2011-09-21T19:10:50Z
[ "python", "emacs", "python-mode" ]
Interactive Python GUI
2,032,617
<p>Python have been really bumpy for me, because the last time I created a GUI client, the client seems to hang when spawning a process, calling a shell script, and calling outside application.</p> <p>This have been my major problem with Python since then, and now I'm in a new project, can someone give me pointers, an...
2
2010-01-09T06:49:56Z
2,032,635
<p>Simplest (not necessarily "best" in an abstract sense): spawn the subprocess in a separate thread, communicating results back to the main thread via a Queue.Queue instance -- the main thread must periodically check that queue to see if the results have arrived yet, but periodic polling isn't hard to arrange in any e...
4
2010-01-09T06:54:58Z
[ "python", "user-interface", "pygtk", "interactive", "spawn" ]
Interactive Python GUI
2,032,617
<p>Python have been really bumpy for me, because the last time I created a GUI client, the client seems to hang when spawning a process, calling a shell script, and calling outside application.</p> <p>This have been my major problem with Python since then, and now I'm in a new project, can someone give me pointers, an...
2
2010-01-09T06:49:56Z
2,032,648
<p>Your main GUI thread will freeze if you spawn off a process and wait for it to completely. Often, you can simply use subprocess and poll it now and then for completion rather than <code>wait</code>ing for it to finish. This will keep your GUI from freezing.</p>
2
2010-01-09T07:00:39Z
[ "python", "user-interface", "pygtk", "interactive", "spawn" ]
In what circumstances should you serialize data? When should you not?
2,032,644
<blockquote> <p>I'm aware that serializing is used to convert data types into a storable format, for purposes such as caching.</p> </blockquote> <p>What I'm more specifically asking is, what are the circumstances in which you should actually decide to store data ( using <code>serialize()</code> in PHP, <code>pic...
2
2010-01-09T06:58:47Z
2,032,655
<h2>Example 1</h2> <p>Profile.</p> <ul> <li>Is it prohibitively costly to generate your content pages?</li> <li>Is it significantly less costly to deserialize your generated content?</li> </ul> <p>If both answers are yes, consider it.</p> <h2>Example 2</h2> <p>Profile.</p> <ul> <li>Is it prohibitively costly to g...
5
2010-01-09T07:06:45Z
[ "php", "python", "serialization" ]
In what circumstances should you serialize data? When should you not?
2,032,644
<blockquote> <p>I'm aware that serializing is used to convert data types into a storable format, for purposes such as caching.</p> </blockquote> <p>What I'm more specifically asking is, what are the circumstances in which you should actually decide to store data ( using <code>serialize()</code> in PHP, <code>pic...
2
2010-01-09T06:58:47Z
2,033,333
<p>What are the circumstances in which you should actually decide to store data ( using serialize() in PHP, pickle module in Python, et cetera )?</p> <p>That question is easy to answer. The various scenarios don't actually have much relevance.</p> <p>Here's the answer <strong>You serialize when you have to</strong>....
3
2010-01-09T12:27:09Z
[ "php", "python", "serialization" ]
_functools module
2,032,677
<p>How does this import work, what file does it use?</p> <pre><code>import _functools </code></pre> <p>In python 2.5:</p> <pre><code>import _functools print _functools.__file__ </code></pre> <p>Gives:</p> <pre><code>Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in &lt;module...
2
2010-01-09T07:13:23Z
2,032,684
<p>please be more clear when asking questions next time. I assume you want this</p> <pre><code>&gt;&gt;&gt; import _functools &gt;&gt;&gt; _functools.__file__ '/usr/lib/python2.6/lib-dynload/_functools.so' </code></pre>
0
2010-01-09T07:18:19Z
[ "python", "extension-modules" ]
_functools module
2,032,677
<p>How does this import work, what file does it use?</p> <pre><code>import _functools </code></pre> <p>In python 2.5:</p> <pre><code>import _functools print _functools.__file__ </code></pre> <p>Gives:</p> <pre><code>Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in &lt;module...
2
2010-01-09T07:13:23Z
2,032,686
<p>It is a shared object <code>_functools.so</code>, written in C. I guess, it is imported by the actual <code>functools</code> module. Why are you trying to import from it? Sure, it is possible, however, you can just as well <code>from functools import partial</code>.</p>
0
2010-01-09T07:19:02Z
[ "python", "extension-modules" ]
_functools module
2,032,677
<p>How does this import work, what file does it use?</p> <pre><code>import _functools </code></pre> <p>In python 2.5:</p> <pre><code>import _functools print _functools.__file__ </code></pre> <p>Gives:</p> <pre><code>Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in &lt;module...
2
2010-01-09T07:13:23Z
2,032,697
<p>For Python2.6, The <code>_functools</code> module is a builtin. You can see that if you simply type <code>import _functools ; repr(_functools)</code> and hit enter at your interpreter prompt.</p> <p>If you want to see the C source of the module, check out <a href="http://hg.python.org/cpython/file/d7e85ddb1336/Mod...
0
2010-01-09T07:24:02Z
[ "python", "extension-modules" ]
_functools module
2,032,677
<p>How does this import work, what file does it use?</p> <pre><code>import _functools </code></pre> <p>In python 2.5:</p> <pre><code>import _functools print _functools.__file__ </code></pre> <p>Gives:</p> <pre><code>Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in &lt;module...
2
2010-01-09T07:13:23Z
2,033,174
<p>The behaviour of the <code>functools.partial()</code> function is described in <a href="http://www.python.org/dev/peps/pep-0309/" rel="nofollow">PEP 309</a> in which it was defined. The although the actual implementations of built-ins are often in C PEP's including this one usually contain <a href="http://www.python...
0
2010-01-09T11:26:36Z
[ "python", "extension-modules" ]
_functools module
2,032,677
<p>How does this import work, what file does it use?</p> <pre><code>import _functools </code></pre> <p>In python 2.5:</p> <pre><code>import _functools print _functools.__file__ </code></pre> <p>Gives:</p> <pre><code>Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in &lt;module...
2
2010-01-09T07:13:23Z
2,034,034
<p>C-coded modules can be built-in (lacking <code>__file__</code>) or live in a <code>.so</code> or <code>.pyd</code> dynamic library (which their <code>__file__</code> will indicate) -- that's an implementation detail that you should not care about.</p> <p>If you want to understand how a Python-callable, C-coded func...
2
2010-01-09T16:38:58Z
[ "python", "extension-modules" ]
pyqt custom item delegate for qtablewidget
2,032,682
<p>I have a QTableWidget with 5 columns in it, how do I set all items on column 2 to be a QProgressBar?</p> <p>I tried something like:</p> <pre><code>self.downloads_table = QtGui.QTableWidget(0, 5) self.downloads_table.setItemDelegateForColumn(2, DownloadDelegate(self)) </code></pre> <p>Where DownloadDelegate is:</p...
1
2010-01-09T07:17:02Z
3,970,384
<p>The model must return <code>itemEditable</code> in <code>flags()</code></p>
0
2010-10-19T16:13:30Z
[ "python", "pyqt4" ]
pyqt custom item delegate for qtablewidget
2,032,682
<p>I have a QTableWidget with 5 columns in it, how do I set all items on column 2 to be a QProgressBar?</p> <p>I tried something like:</p> <pre><code>self.downloads_table = QtGui.QTableWidget(0, 5) self.downloads_table.setItemDelegateForColumn(2, DownloadDelegate(self)) </code></pre> <p>Where DownloadDelegate is:</p...
1
2010-01-09T07:17:02Z
9,352,914
<p>As Marconi said, </p> <pre><code>QTableWidget.setCellWidget(row, column, QWidget) </code></pre> <p>adds a QWidget into the cell at (row, column) and gives it the QTableWidget as parent.</p> <p>e.g. something along these lines:</p> <pre><code>table = QTableWidget(1, 3) item1 = QTableWidgetItem("foo") comboBox = ...
1
2012-02-19T20:27:13Z
[ "python", "pyqt4" ]
Porting python app to silverlight or flash
2,032,845
<p>I guess that title is self-explanatory. Is there any such effort been made?</p> <p>Some more info:</p> <p>it's client application (gui intensive)</p> <p>By porting I was thinking of cross-compiling.</p>
-1
2010-01-09T08:43:59Z
2,032,866
<p>i havent done this but it shouldnt be to difficult to port python o silverlight because you should be able to use <a href="http://ironpython.net/" rel="nofollow">IronPython</a> and add <code>clr</code> references to your python code to start using the silverlight assemblies.</p>
2
2010-01-09T08:56:01Z
[ "python", "flash", "silverlight" ]
Porting python app to silverlight or flash
2,032,845
<p>I guess that title is self-explanatory. Is there any such effort been made?</p> <p>Some more info:</p> <p>it's client application (gui intensive)</p> <p>By porting I was thinking of cross-compiling.</p>
-1
2010-01-09T08:43:59Z
2,032,886
<p>Between the two, porting to Silverlight is going to be much easier. You can target IronPython and focus primarily on changing/replacing the libraries that you've used in your Python app that aren't available in IronPython.</p> <p>"Porting" to Flash would be more reasonably written as "rewriting a Python applicatio...
2
2010-01-09T09:06:54Z
[ "python", "flash", "silverlight" ]
Searching for individual bipartite networks
2,032,950
<p>I have data in the below form, which makes up a bipartite network.</p> <pre><code>A1 - B1 A2 - B2 A2 - B1 A3 - B1 A4 - B2 A5 - B3 A6 - B3 A7 - B3 A7 - B3 A8 - B4 A9 - B3 </code></pre> <p>What I would like to do is write something (ideally in python or C) or use an existing library to identify individual communitie...
0
2010-01-09T09:46:32Z
2,033,062
<p>If you want to use Python, read about the <a href="http://networkx.lanl.gov/index.html" rel="nofollow">NetworkX</a> library. It has lots of modules and algorithm implementations for graphs. In particular, you may find the <a href="http://networkx.lanl.gov/reference/algorithms.bipartite.html?highlight=bipartite#modul...
1
2010-01-09T10:36:02Z
[ "python", "search", "graph", "social-networking", "igraph" ]
Searching for individual bipartite networks
2,032,950
<p>I have data in the below form, which makes up a bipartite network.</p> <pre><code>A1 - B1 A2 - B2 A2 - B1 A3 - B1 A4 - B2 A5 - B3 A6 - B3 A7 - B3 A7 - B3 A8 - B4 A9 - B3 </code></pre> <p>What I would like to do is write something (ideally in python or C) or use an existing library to identify individual communitie...
0
2010-01-09T09:46:32Z
2,033,065
<p>Maybe something like:</p> <pre><code>import collections data = ( ("A1", "B1"), ("A2", "B2"), ("A2", "B1") ) out = collections.defaultdict(list) for value, key in data: out[key].append(value) print out -&gt; defaultdict(&lt;type 'list'&gt;, {'B1': ['A1', 'A2'], 'B2': ['A2']}) </code></pre> <p>This only works o...
1
2010-01-09T10:36:42Z
[ "python", "search", "graph", "social-networking", "igraph" ]
Searching for individual bipartite networks
2,032,950
<p>I have data in the below form, which makes up a bipartite network.</p> <pre><code>A1 - B1 A2 - B2 A2 - B1 A3 - B1 A4 - B2 A5 - B3 A6 - B3 A7 - B3 A7 - B3 A8 - B4 A9 - B3 </code></pre> <p>What I would like to do is write something (ideally in python or C) or use an existing library to identify individual communitie...
0
2010-01-09T09:46:32Z
2,114,081
<p>Using Python and the <a href="http://igraph.sourceforge.net" rel="nofollow">igraph library</a>, you may do the following:</p> <pre><code>import igraph graph = igraph.Graph.Formula("A1-B1, A2-B2, A2-B1, A3-B1, A4-B2, A5-B3, A6-B3, A7-B3, A8-B4, A9-B3") comms = graph.clusters() for comm in comms: print ", ".join(...
3
2010-01-22T00:28:18Z
[ "python", "search", "graph", "social-networking", "igraph" ]
Searching for individual bipartite networks
2,032,950
<p>I have data in the below form, which makes up a bipartite network.</p> <pre><code>A1 - B1 A2 - B2 A2 - B1 A3 - B1 A4 - B2 A5 - B3 A6 - B3 A7 - B3 A7 - B3 A8 - B4 A9 - B3 </code></pre> <p>What I would like to do is write something (ideally in python or C) or use an existing library to identify individual communitie...
0
2010-01-09T09:46:32Z
5,863,012
<p>No! Take care to use the NetworkX library because that doesn't have more than 4 function for bipartite graphs. one for verify if it is bipartite, one for coloring the nodes, one for create a simple bipartite networks without weights and another for create a projection of the bipartite networks You can may be use the...
1
2011-05-02T22:08:09Z
[ "python", "search", "graph", "social-networking", "igraph" ]
Searching for individual bipartite networks
2,032,950
<p>I have data in the below form, which makes up a bipartite network.</p> <pre><code>A1 - B1 A2 - B2 A2 - B1 A3 - B1 A4 - B2 A5 - B3 A6 - B3 A7 - B3 A7 - B3 A8 - B4 A9 - B3 </code></pre> <p>What I would like to do is write something (ideally in python or C) or use an existing library to identify individual communitie...
0
2010-01-09T09:46:32Z
13,537,075
<p>@Eli has a good idea to find the connected components. Since you know the labels (in this case anyway) start with "A" you can do it like this:</p> <pre><code>import networkx as nx edges = """A1 - B1 A2 - B2 A2 - B1 A3 - B1 A4 - B2 A5 - B3 A6 - B3 A7 - B3 A7 - B3 A8 - B4 A9 - B3""".split('\n') G = nx.parse_edgelist...
1
2012-11-24T00:02:11Z
[ "python", "search", "graph", "social-networking", "igraph" ]
Subclassing dict: should dict.__init__() be called?
2,033,150
<p>Here is a twofold question, with a theoretical part, and a practical one:</p> <p>When subclassing dict:</p> <pre><code>class ImageDB(dict): def __init__(self, directory): dict.__init__(self) # Necessary?? ... </code></pre> <p>should <code>dict.__init__(self)</code> be called, just as a "safe...
25
2010-01-09T11:16:00Z
2,033,266
<p><a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">PEP 372</a> deals with adding an ordered dict to the collections module.</p> <p>It warns that "subclassing dict is a non-trivial task and many implementations don't override all the methods properly which can lead to unexpected results."</p> <p>The ...
1
2010-01-09T12:06:19Z
[ "python", "subclass", "dictionary", "init" ]
Subclassing dict: should dict.__init__() be called?
2,033,150
<p>Here is a twofold question, with a theoretical part, and a practical one:</p> <p>When subclassing dict:</p> <pre><code>class ImageDB(dict): def __init__(self, directory): dict.__init__(self) # Necessary?? ... </code></pre> <p>should <code>dict.__init__(self)</code> be called, just as a "safe...
25
2010-01-09T11:16:00Z
2,033,416
<p>You should probably call <code>dict.__init__(self)</code> when subclassing; in fact, you don't know what's happening precisely in dict (since it's a builtin), and that might vary across versions and implementations. Not calling it may result in improper behaviour, since you can't know where dict is holding its inter...
12
2010-01-09T12:55:56Z
[ "python", "subclass", "dictionary", "init" ]
Subclassing dict: should dict.__init__() be called?
2,033,150
<p>Here is a twofold question, with a theoretical part, and a practical one:</p> <p>When subclassing dict:</p> <pre><code>class ImageDB(dict): def __init__(self, directory): dict.__init__(self) # Necessary?? ... </code></pre> <p>should <code>dict.__init__(self)</code> be called, just as a "safe...
25
2010-01-09T11:16:00Z
2,033,554
<p>You should generally call base class' <code>__init__</code> so why make an exception here?</p> <p>Either do not override <code>__init__</code> or if you need to override <code>__init__</code> call base class <code>__init__</code>, If you worry about arguments just pass *args, **kwargs or nothing if you want empty ...
9
2010-01-09T13:56:43Z
[ "python", "subclass", "dictionary", "init" ]
Subclassing dict: should dict.__init__() be called?
2,033,150
<p>Here is a twofold question, with a theoretical part, and a practical one:</p> <p>When subclassing dict:</p> <pre><code>class ImageDB(dict): def __init__(self, directory): dict.__init__(self) # Necessary?? ... </code></pre> <p>should <code>dict.__init__(self)</code> be called, just as a "safe...
25
2010-01-09T11:16:00Z
2,148,300
<p>Beware of pickling when subclassing dict; this for example needs __getnewargs__ in 2.7, and maybe __getstate__ __setstate__ in older versions. (I have no idea why.)</p> <pre><code>class Dotdict( dict ): """ d.key == d["key"] """ def __init__(self, *args, **kwargs): dict.__init__( self, *args, **kwa...
3
2010-01-27T15:51:22Z
[ "python", "subclass", "dictionary", "init" ]
What do I use, CherryPy or Pylons?
2,033,195
<p>Hi I'm planning on building a site with social networking features. Which Python framework do you think is more appropriate or you would suggest over the other, CherryPy or Pylons?</p>
1
2010-01-09T11:35:30Z
2,033,246
<p>That's a subjective question. I suggest you read carefully each framework's description and choose the one that has the most features fitting your project.</p> <p>Here's an extensive <a href="http://old.nabble.com/Pylons-vs-CherryPy-td25693132.html" rel="nofollow">overview of the two frameworks</a>. This should hel...
3
2010-01-09T11:59:05Z
[ "python", "pylons", "cherrypy" ]
What do I use, CherryPy or Pylons?
2,033,195
<p>Hi I'm planning on building a site with social networking features. Which Python framework do you think is more appropriate or you would suggest over the other, CherryPy or Pylons?</p>
1
2010-01-09T11:35:30Z
2,033,585
<p>As S.Lott said it is vague, so best way would be to toss a coin, and I did<br> head=pylons tails=cherrypy</p> <p>but on toss it came standing up, so</p> <p><a href="http://www.djangoproject.com/" rel="nofollow">django</a> it is.</p> <p>and a django based platorm is <a href="http://pinaxproject.com/" rel="nofollow...
2
2010-01-09T14:07:52Z
[ "python", "pylons", "cherrypy" ]
Concatenation Operator + or ,
2,033,242
<pre><code>var1 = 'abc' var2 = 'xyz' print('literal' + var1 + var2) # literalabcxyz print('literal', var1, var2) # literal abc xyz </code></pre> <p>... except for automatic spaces with ',' whats the difference between the two? Which to use normally, also which is the fastest?</p> <p>Thanks</p>
7
2010-01-09T11:57:34Z
2,033,249
<p>Using a comma gives the print function multiple arguments (which in this case are printed all, seperated by a space. Using the plus will create one argument for print, which is printed in its entirety. I think using the + is best in this case.</p>
1
2010-01-09T11:59:33Z
[ "python", "python-3.x", "concatenation" ]
Concatenation Operator + or ,
2,033,242
<pre><code>var1 = 'abc' var2 = 'xyz' print('literal' + var1 + var2) # literalabcxyz print('literal', var1, var2) # literal abc xyz </code></pre> <p>... except for automatic spaces with ',' whats the difference between the two? Which to use normally, also which is the fastest?</p> <p>Thanks</p>
7
2010-01-09T11:57:34Z
2,033,251
<p>Passing strings as arguments to print joins them with the 'sep' keyword. Default is ' ' (space).</p> <p>Separator keyword is Python 3.x only. Before that the separator is always a space, except in 2.5(?) and up where you can <code>from __future__ import print_function</code> or something like that.</p> <pre><code>...
5
2010-01-09T12:00:16Z
[ "python", "python-3.x", "concatenation" ]
Concatenation Operator + or ,
2,033,242
<pre><code>var1 = 'abc' var2 = 'xyz' print('literal' + var1 + var2) # literalabcxyz print('literal', var1, var2) # literal abc xyz </code></pre> <p>... except for automatic spaces with ',' whats the difference between the two? Which to use normally, also which is the fastest?</p> <p>Thanks</p>
7
2010-01-09T11:57:34Z
2,033,272
<p>(You're using Python 3.x, where print is a function&mdash;in 2.x, print is a statement. It's a good idea to mention the major Python version&mdash;2.x or 3.x&mdash;especially when asking for help, because currently most people reasonably assume 2.x unless it's stated.)</p> <p>The first, <code>print('literal' + var...
15
2010-01-09T12:07:46Z
[ "python", "python-3.x", "concatenation" ]
how to use IPython
2,033,575
<p>I could not understand the ipython library. This url provide the common feature but I could not core-relate it. <a href="http://ipython.org/ipython-doc/stable/interactive/tutorial.html" rel="nofollow">http://ipython.org/ipython-doc/stable/interactive/tutorial.html</a></p> <p>How to I use IPython to improve my day...
4
2010-01-09T14:04:09Z
2,033,592
<p>ipython is an improved interactive prompt, not a library. It has features like tab completion and profiles which are not present in the vanilla interactive prompt (which is running python without an input file). All features are listed on the page you cited. </p> <p>So, it doesn't really improve your day to day pyt...
11
2010-01-09T14:10:11Z
[ "python", "ipython" ]
how to use IPython
2,033,575
<p>I could not understand the ipython library. This url provide the common feature but I could not core-relate it. <a href="http://ipython.org/ipython-doc/stable/interactive/tutorial.html" rel="nofollow">http://ipython.org/ipython-doc/stable/interactive/tutorial.html</a></p> <p>How to I use IPython to improve my day...
4
2010-01-09T14:04:09Z
10,855,324
<p>do you do any scientific computing? ipython 0.12 has new functionality called ipython notebook that's really useful for data analysis. you can easily print graphs and data inline in your browser and reload your code. You can then print it as a pdf and make a nice report.</p> <p>it's also useful for learning python...
1
2012-06-01T18:12:26Z
[ "python", "ipython" ]
Change the events for different parts of the same widget
2,033,810
<p>I have created a margin in a gtk.TextView widget. Now I want to make sure that the default event handler for mouse click, which is moving the text cursor to the clicked position, works only when clicked to the right of the margin. </p> <p>Is this possible?</p>
0
2010-01-09T15:18:09Z
2,049,683
<p>Try connecting to the <a href="http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-button-press-event" rel="nofollow">button-press-event</a> but doing it before the widget's own connection. If you connect after the view does it, this will be the default (GObject signal handlers are handled in reverse ...
1
2010-01-12T14:38:06Z
[ "python", "gtk", "pygtk" ]
cookielib and form authentication woes in Python
2,033,814
<p>InstaMapper is a GPS tracking service that updates the device's position more frequently when the device is being tracked live on the InstaMapper webpage. I'd like to have this happen all the time so I thought I'd write a python script to login to my account and access the page periodically.</p> <pre><code>import ...
0
2010-01-09T15:19:26Z
2,033,971
<p><code>action=login</code> is part of the parameters, and should be treated accordingly:</p> <pre><code>params = urllib.urlencode(dict(action='login', username_hb='user', password_hb='hunter2')) opener.open('http://www.instamapper.com/fe', params) </code></pre> <p>(Also, this particular username/password combinati...
0
2010-01-09T16:17:44Z
[ "python", "cookies", "gps", "cookielib" ]
cookielib and form authentication woes in Python
2,033,814
<p>InstaMapper is a GPS tracking service that updates the device's position more frequently when the device is being tracked live on the InstaMapper webpage. I'd like to have this happen all the time so I thought I'd write a python script to login to my account and access the page periodically.</p> <pre><code>import ...
0
2010-01-09T15:19:26Z
2,034,675
<p>Have you looked at whether there is a cookie specifically designed to foil your attempts? I suggest using Wireshark or other inspector to see if there is a cookie that changes (via javascript, etc) when you manually log in.</p> <p>(Ethical note: You may be violating the terms of service and incurring much more cos...
0
2010-01-09T19:41:55Z
[ "python", "cookies", "gps", "cookielib" ]
Image embossing in Python with PIL -- adding depth, azimuth, etc
2,034,037
<p>I am trying to emboss an image using <a href="http://en.wikipedia.org/wiki/Python_Imaging_Library" rel="nofollow">PIL</a>. </p> <p>PIL provides a basic way to emboss an image ( using <code>ImageFilter.EMBOSS</code>). </p> <p>In image editing packages like GIMP, you can vary parameters like Azimuth, depth and elev...
6
2010-01-09T16:39:51Z
2,034,258
<p>If you cannot achieve your goal by using or combination of operations (like rotating, then applying the EMBOSS filter, the re-rotating), (or enhancing the contrast then embossing) then you may resort to changing (or creating your own) filter matrix.</p> <p>Within ImageFilter.py you will find this class:</p> <pre><...
8
2010-01-09T17:40:49Z
[ "python", "image-processing", "python-imaging-library" ]
Image embossing in Python with PIL -- adding depth, azimuth, etc
2,034,037
<p>I am trying to emboss an image using <a href="http://en.wikipedia.org/wiki/Python_Imaging_Library" rel="nofollow">PIL</a>. </p> <p>PIL provides a basic way to emboss an image ( using <code>ImageFilter.EMBOSS</code>). </p> <p>In image editing packages like GIMP, you can vary parameters like Azimuth, depth and elev...
6
2010-01-09T16:39:51Z
2,130,236
<p>To increase the depth of an emboss filter, increase the radius of the filter's mask. Low depth:</p> <pre><code>h = [[1, 0, 0] [0, 0, 0] [0, 0, -1]] </code></pre> <p>versus high depth:</p> <pre><code>h = [[1, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, ...
2
2010-01-25T04:42:49Z
[ "python", "image-processing", "python-imaging-library" ]
How to access elements of matrices from mat file in python?
2,034,053
<p>When load matrices from mat file in python using <code>scipy.io</code>, it makes dictionary where key is name of matrix,and value is 2D array of that matrix. </p> <p>How can i access elements in this array?</p>
0
2010-01-09T16:44:58Z
2,034,083
<p>Doesn't</p> <pre><code>matrix[x][y] </code></pre> <p>work?</p>
0
2010-01-09T16:52:42Z
[ "python", "matlab" ]
How to access elements of matrices from mat file in python?
2,034,053
<p>When load matrices from mat file in python using <code>scipy.io</code>, it makes dictionary where key is name of matrix,and value is 2D array of that matrix. </p> <p>How can i access elements in this array?</p>
0
2010-01-09T16:44:58Z
2,034,087
<p>Suppose you have</p> <pre><code>mat = sio.loadmat('a.mat') </code></pre> <p>Then you can see which matrices were loaded by</p> <pre><code>print mat </code></pre> <p>For each key <code>key</code> in the dictionary, you can retrieve the corresponding matrix by</p> <pre><code>my_matrix = mat[key] </code></pre> <p...
2
2010-01-09T16:54:06Z
[ "python", "matlab" ]
How to access elements of matrices from mat file in python?
2,034,053
<p>When load matrices from mat file in python using <code>scipy.io</code>, it makes dictionary where key is name of matrix,and value is 2D array of that matrix. </p> <p>How can i access elements in this array?</p>
0
2010-01-09T16:44:58Z
2,034,101
<pre><code>&gt;&gt;&gt; A = array([ [1,2], [3,4], [5,6]]) &gt;&gt;&gt; A array([[1, 2], [3, 4], [5, 6]]) &gt;&gt;&gt; A[0] array([1, 2]) &gt;&gt;&gt; A[0][0] 1 </code></pre> <p>Here A can be a value in the dict object you have created. </p>
0
2010-01-09T16:57:31Z
[ "python", "matlab" ]
text in tables?
2,034,330
<p>I like to organize a lot of information from literature reviews in "tables" (information not unlike product comparisons, but for scientific research), but often the information I enter can contain lines or paragraphs of text and becomes unwieldy in a spreadsheet. I've heard SQL relational tables are often used for t...
1
2010-01-09T18:05:14Z
2,034,364
<p>The way you store and retrieve data would depend on what you plan to do with it.</p> <p>Text files have problems with manageability. You can't really take care of a directory tree with thousands and thousands of files. It would be a nightmare to search through them. If you're concurrently updating, you'll have to d...
4
2010-01-09T18:16:57Z
[ "python", "sql", "database", "table", "datatable" ]
Is there any way to load data dynamically into a python datastructure without recreating
2,034,338
<p>I have a process that builds a list from a database table and runs real time. Every now and then new data gets added to the database table. Querying data from the table every now and then is cumbersome, and time consuming, and this need to be as real time as possible.What is the right way to approach the problem?</p...
0
2010-01-09T18:07:21Z
2,034,394
<p>Wouldn't it make sense to just query the database again for all the new data that has come since you last queried? Something like <code>key &gt; highest_key_in_list</code> or <code>date &gt; highest_date_in_list</code> rather than loading up the whole thing again.</p>
0
2010-01-09T18:22:48Z
[ "python", "dynamic-data", "real-time" ]
Is there any way to load data dynamically into a python datastructure without recreating
2,034,338
<p>I have a process that builds a list from a database table and runs real time. Every now and then new data gets added to the database table. Querying data from the table every now and then is cumbersome, and time consuming, and this need to be as real time as possible.What is the right way to approach the problem?</p...
0
2010-01-09T18:07:21Z
2,034,395
<p>This feels a big hackish, but on your initial query create a temp table to hold the results. Add a column to that table that is an incrementing number I'll call id. Add a trigger to the table with data changing that updates your temp table. Check back with the database and query only for records with an id larger t...
0
2010-01-09T18:22:57Z
[ "python", "dynamic-data", "real-time" ]
Is there any way to load data dynamically into a python datastructure without recreating
2,034,338
<p>I have a process that builds a list from a database table and runs real time. Every now and then new data gets added to the database table. Querying data from the table every now and then is cumbersome, and time consuming, and this need to be as real time as possible.What is the right way to approach the problem?</p...
0
2010-01-09T18:07:21Z
2,034,409
<p>Sorry, it is rather difficult to deduce what <em>exactly</em> you want to be done.</p> <p>One point is not quite clear:<br> Is the process (python script?) to be run</p> <ul> <li>continously (daemon-like), - in that case, you don't need to store the dataset anywhere if it is relatively small. You can just keep it ...
0
2010-01-09T18:27:51Z
[ "python", "dynamic-data", "real-time" ]
Is there any way to load data dynamically into a python datastructure without recreating
2,034,338
<p>I have a process that builds a list from a database table and runs real time. Every now and then new data gets added to the database table. Querying data from the table every now and then is cumbersome, and time consuming, and this need to be as real time as possible.What is the right way to approach the problem?</p...
0
2010-01-09T18:07:21Z
2,034,431
<p>If the data is being added to the table in the program, just add it to the list at the same time.</p> <p>If multiple sources are adding to the table, query the table for all records whose primary key is > the last key you retrieved.</p>
0
2010-01-09T18:32:52Z
[ "python", "dynamic-data", "real-time" ]
Python CLI to edit Firefox bookmarks?
2,034,373
<p>Has anyone done a Python CLI to edit Firefox bookmarks ? My worldview is that of Unix file trees; I want</p> <ul> <li>find /re/ in given or all fields in given or all subtrees</li> <li>cd</li> <li>ls with context</li> <li>mv this ../there/</li> </ul> <p>Whether it uses bookamrks.html or places.sqlite is secondary ...
0
2010-01-09T18:18:51Z
2,034,573
<p>Assuming we're talking about Firefox 3 or better, the bookmarks are kept in a SQLite file, <a href="http://kb.mozillazine.org/Places.sqlite" rel="nofollow">places.sqlite</a> in the <a href="http://kb.mozillazine.org/Profile_folder_-_Firefox" rel="nofollow">profile folder</a>. So you need a routine to find the profi...
1
2010-01-09T19:10:18Z
[ "python", "firefox", "command-line-interface", "bookmarks" ]
Python CLI to edit Firefox bookmarks?
2,034,373
<p>Has anyone done a Python CLI to edit Firefox bookmarks ? My worldview is that of Unix file trees; I want</p> <ul> <li>find /re/ in given or all fields in given or all subtrees</li> <li>cd</li> <li>ls with context</li> <li>mv this ../there/</li> </ul> <p>Whether it uses bookamrks.html or places.sqlite is secondary ...
0
2010-01-09T18:18:51Z
2,034,590
<p>I don't know about all the features you've mentioned but "Organize bookmars" option in the Bookmarks menu is pretty decent with respect to features.</p>
0
2010-01-09T19:14:27Z
[ "python", "firefox", "command-line-interface", "bookmarks" ]
Python's interpretation of tabs and spaces to indent
2,034,517
<p>I decided, that I learn a bit of Python. The first introduction says that it uses indentation to group statements. While the best habit is clearly to use just one of these what happens if I interchange them? How many spaces will be considered equal to one tab? Or will it fail to work at all if tabs and spaces are mi...
15
2010-01-09T18:57:25Z
2,034,526
<p>4 spaces are one tab ( in my setup ) but as far as I know, they are not interchanged. you can use either spaces or tabs. not both.</p>
1
2010-01-09T18:59:05Z
[ "python", "tabs", "indentation", "spaces" ]
Python's interpretation of tabs and spaces to indent
2,034,517
<p>I decided, that I learn a bit of Python. The first introduction says that it uses indentation to group statements. While the best habit is clearly to use just one of these what happens if I interchange them? How many spaces will be considered equal to one tab? Or will it fail to work at all if tabs and spaces are mi...
15
2010-01-09T18:57:25Z
2,034,527
<p>Spaces are not treated as equivalent to tab. A line indented with a tab is at a different indentation from a line indented with 1, 2, 4 <s>or 8</s> spaces.</p> <p>Proof by counter-example (<em>erroneous, or, at best, limited - tab != 4 spaces</em>):</p> <pre><code>x = 1 if x == 1: ^Iprint "fff\n" print "yyy\n...
19
2010-01-09T18:59:33Z
[ "python", "tabs", "indentation", "spaces" ]
Python's interpretation of tabs and spaces to indent
2,034,517
<p>I decided, that I learn a bit of Python. The first introduction says that it uses indentation to group statements. While the best habit is clearly to use just one of these what happens if I interchange them? How many spaces will be considered equal to one tab? Or will it fail to work at all if tabs and spaces are mi...
15
2010-01-09T18:57:25Z
2,034,535
<p>Just don't interchange them :)<br> Set your IDE/editor to input 4 spaces upon pressing "tab" and you are good to go.</p>
2
2010-01-09T19:01:18Z
[ "python", "tabs", "indentation", "spaces" ]
Python's interpretation of tabs and spaces to indent
2,034,517
<p>I decided, that I learn a bit of Python. The first introduction says that it uses indentation to group statements. While the best habit is clearly to use just one of these what happens if I interchange them? How many spaces will be considered equal to one tab? Or will it fail to work at all if tabs and spaces are mi...
15
2010-01-09T18:57:25Z
2,034,536
<p>I would recommend that you go through <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">http://www.python.org/dev/peps/pep-0008/</a> which is the 'official' python style guide for Python code. It covers (among other things) the use of tabs/spaces.</p>
4
2010-01-09T19:01:45Z
[ "python", "tabs", "indentation", "spaces" ]
Python's interpretation of tabs and spaces to indent
2,034,517
<p>I decided, that I learn a bit of Python. The first introduction says that it uses indentation to group statements. While the best habit is clearly to use just one of these what happens if I interchange them? How many spaces will be considered equal to one tab? Or will it fail to work at all if tabs and spaces are mi...
15
2010-01-09T18:57:25Z
2,034,538
<p>Follow <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> for Python style. PEP 8 says: Indentation</p> <blockquote> <p>Use 4 spaces per indentation level.</p> <p>For really old code that you don't want to mess up, you can continue to use 8-space tabs.</p> </blockquote> <p>Tabs ...
15
2010-01-09T19:02:22Z
[ "python", "tabs", "indentation", "spaces" ]
Python's interpretation of tabs and spaces to indent
2,034,517
<p>I decided, that I learn a bit of Python. The first introduction says that it uses indentation to group statements. While the best habit is clearly to use just one of these what happens if I interchange them? How many spaces will be considered equal to one tab? Or will it fail to work at all if tabs and spaces are mi...
15
2010-01-09T18:57:25Z
2,035,311
<p>I believe that the tab character should simply never appear in source code under any circumstances. There's no advantage to it and it's an endless source of tiny errors. - use a character string with \t if you need a tab, it has the advantage that it's self-documenting. </p> <p><a href="http://www.jwz.org/doc/tab...
-2
2010-01-09T23:04:40Z
[ "python", "tabs", "indentation", "spaces" ]
Python's interpretation of tabs and spaces to indent
2,034,517
<p>I decided, that I learn a bit of Python. The first introduction says that it uses indentation to group statements. While the best habit is clearly to use just one of these what happens if I interchange them? How many spaces will be considered equal to one tab? Or will it fail to work at all if tabs and spaces are mi...
15
2010-01-09T18:57:25Z
25,471,702
<p>In Python 2, the interpretation of <kbd>TAB</kbd> is as if it is converted to spaces using 8-space tab stops (as provided by previous answers already); that is that each <kbd>TAB</kbd> furthers the indentation by 1 to 8 spaces so that the resulting indentation is divisible by 8.</p> <p>However this does not apply t...
6
2014-08-24T12:30:16Z
[ "python", "tabs", "indentation", "spaces" ]
ttk.Button returns None
2,034,576
<p>I am trying to use the invoke method of a ttk.Button, as shown at <a href="http://www.tkdocs.com/tutorial/widgets.html#button" rel="nofollow">TkDocs</a> (look at <em>"The Command Callback"</em>), but I keep getting this error:</p> <blockquote> <p>AttributeError: 'NoneType' object has no attribute 'invoke'</p> </b...
2
2010-01-09T19:11:08Z
2,034,596
<p>No, you're entirely wrong: your code does <strong>not</strong> show that <code>ttk.Button</code> returns <code>None</code> -- it shows that the <code>grid</code> method on the button object returns <code>None</code>! Don't you see that you're calling <code>.grid</code> on whatever it is that <code>ttk.Button</code>...
10
2010-01-09T19:15:24Z
[ "python", "tkinter", "ttk" ]
Datastore Design Inquiry
2,034,584
<p>I'm creating a Trivia app, and need some help designing my model relationships. This question may get fairly complicated, but I'll try to be concise.</p> <p>Trivia questions will all be part of a particular category. Categories may be a category within another category. If a trivia question is created/removed, I...
1
2010-01-09T19:13:14Z
2,034,622
<p>I'm not that familiar with Google App Engine, but here are some thoughts. First is to consider if "tags" are more appropriate than category &amp; sub categories. Will their be a rigid 2 level category scheme? Will all items have a main and subcategory assignment? </p> <p>Rather than having a class for each categ...
0
2010-01-09T19:23:42Z
[ "python", "database-design", "google-app-engine" ]
Datastore Design Inquiry
2,034,584
<p>I'm creating a Trivia app, and need some help designing my model relationships. This question may get fairly complicated, but I'll try to be concise.</p> <p>Trivia questions will all be part of a particular category. Categories may be a category within another category. If a trivia question is created/removed, I...
1
2010-01-09T19:13:14Z
2,034,989
<p>This isn't as complicated as you might think. Here's a Category class:</p> <pre><code>class Category(db.Model): title = db.StringProperty() subcategories = db.ListProperty(db.Key) quizzes = db.ListProperty(db.Key) def add_sub_category(self, title): new_category = Category(title) new...
0
2010-01-09T21:16:03Z
[ "python", "database-design", "google-app-engine" ]
Optimize function to sort a list of tuples
2,034,629
<p>I need to sort a list of tuples by first item in descending order, and then by second item in ascending order.</p> <p>To do this, I have implemented the following function, but I think it could be faster.</p> <pre><code>&gt;&gt;&gt; compare = lambda a, b: -cmp(b[1], a[1]) if b[0] == a[0] else cmp(b[0], a[0]) &gt;&...
1
2010-01-09T19:28:12Z
2,034,645
<p>For me, it is a little faster to use a key instead of a comparison function, and arguably also easier to read:</p> <pre><code>sorted([(0, 2), (0, 1), (1, 0), (1, 2)], key = lambda x:(-x[0], x[1])) </code></pre> <p>This requires Python 2.4 or newer.</p>
8
2010-01-09T19:34:41Z
[ "python", "optimization", "sorting" ]
Optimize function to sort a list of tuples
2,034,629
<p>I need to sort a list of tuples by first item in descending order, and then by second item in ascending order.</p> <p>To do this, I have implemented the following function, but I think it could be faster.</p> <pre><code>&gt;&gt;&gt; compare = lambda a, b: -cmp(b[1], a[1]) if b[0] == a[0] else cmp(b[0], a[0]) &gt;&...
1
2010-01-09T19:28:12Z
2,034,757
<p>How does this stack up for you?</p> <pre><code>compare = lambda a, b: cmp(b[0], a[0]) and cmp(a[1],b[1]) </code></pre>
0
2010-01-09T20:07:54Z
[ "python", "optimization", "sorting" ]
diff for single lines
2,034,727
<p>All diff tools I've found are just comparing line by line instead of char by char. Is there any library that gives details on single line strings? Maybe also a percentage difference, though I guess there are separate functions for that?</p>
5
2010-01-09T19:59:03Z
2,034,809
<p>What you could try is to split both strings up character by character into lines and then you can use diff on that. It's a dirty hack, but atleast it should work and is quite easy to implement.</p> <p>Alternately you can split the string up into a list of chars in Python and use difflib. Check <a href="http://docs....
3
2010-01-09T20:23:08Z
[ "python", "diff" ]
diff for single lines
2,034,727
<p>All diff tools I've found are just comparing line by line instead of char by char. Is there any library that gives details on single line strings? Maybe also a percentage difference, though I guess there are separate functions for that?</p>
5
2010-01-09T19:59:03Z
2,034,828
<p>I was looking for something similar recently, and came across <a href="http://www.gnu.org/software/wdiff/" rel="nofollow">wdiff</a>. It operates on words, not characters, but is this close to what you're looking for?</p>
4
2010-01-09T20:30:53Z
[ "python", "diff" ]
diff for single lines
2,034,727
<p>All diff tools I've found are just comparing line by line instead of char by char. Is there any library that gives details on single line strings? Maybe also a percentage difference, though I guess there are separate functions for that?</p>
5
2010-01-09T19:59:03Z
2,034,856
<p>This algorithm diffs word-by-word: </p> <p><a href="http://github.com/paulgb/simplediff">http://github.com/paulgb/simplediff</a></p> <p>available in Python and PHP. It can even spit out HTML formatted output using the <code>&lt;ins&gt;</code> and <code>&lt;del&gt;</code> tags.</p>
5
2010-01-09T20:35:50Z
[ "python", "diff" ]
diff for single lines
2,034,727
<p>All diff tools I've found are just comparing line by line instead of char by char. Is there any library that gives details on single line strings? Maybe also a percentage difference, though I guess there are separate functions for that?</p>
5
2010-01-09T19:59:03Z
2,034,866
<p>You can implement a simple <strong>Needleman–Wunsch</strong> algorithm. The pseudo code is available on Wikipedia: <a href="http://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm</a></p>
3
2010-01-09T20:37:45Z
[ "python", "diff" ]
Lines do not render on an offscreen frame buffer with a completely black texture
2,034,775
<p>If I have a frame buffer which has a textured binded to it which is simply black with full alpha and I try to draw a line to it, even if the line has full alpha it wont render. I'm not stupid, so the lines definitely aren't black. If the texture is white instead the line suddenly render correctly as if the colour of...
1
2010-01-09T20:12:30Z
2,048,235
<p>There is at least one thing that looks suspicious: you're turning on Texturing in your init code, and forgetting about it.</p> <p>So your lines are drawn with texturing on (and constant texture coordinates), presumably picking the texture that you're trying to write to.</p> <p>This is likely not what you want (I d...
1
2010-01-12T10:36:58Z
[ "python", "opengl", "framebuffer", "alphablending", "pyopengl" ]
Distributing a python application
2,034,787
<p>I have a simple python application where my directory structure is as follows:</p> <ul> <li>project/ <ul> <li>main.py</li> <li>config.py</li> <li>plugins/ <ul> <li>plugin1</li> <li>plugin2</li> <li>...</li> </ul></li> </ul></li> </ul> <p>Config.py only loads configuration files, it does not contain any configurati...
0
2010-01-09T20:16:05Z
2,034,934
<p><em>setuptools</em> install your package in a location which is reachable from python i.e. you can import it:</p> <pre><code>import project </code></pre> <p>the problem raise when you do relative imports instead of absolute imports. if your <code>main.py</code> imports <code>config.py</code> it works because they ...
11
2010-01-09T21:00:37Z
[ "python", "setuptools" ]
What's the newest way to develop gnome panel applets (using python)
2,034,834
<p>Today I've switched to GNOME (from XFCE) and found some of the cool stuff missing and I would like to (try to) do them on my own. I tried to find information on how to develop Gnome applets (items you place within the panel) and most likely in Python, but it's not a hard limitation.</p> <p>I found the <a href="http...
7
2010-01-09T20:31:35Z
2,034,947
<p>Theres an article called <a href="http://ubuntuforums.org/showthread.php?t=496185" rel="nofollow">Gnome Panel Applets in Python</a> from 2008 on the Ubuntu forums that may help with this.</p> <p>This includes defining a bonobo component. This <a href="http://projects.gnome.org/ORBit2/appletstutorial.html" rel="nofo...
4
2010-01-09T21:03:09Z
[ "python", "pygtk", "gnome" ]
What's the newest way to develop gnome panel applets (using python)
2,034,834
<p>Today I've switched to GNOME (from XFCE) and found some of the cool stuff missing and I would like to (try to) do them on my own. I tried to find information on how to develop Gnome applets (items you place within the panel) and most likely in Python, but it's not a hard limitation.</p> <p>I found the <a href="http...
7
2010-01-09T20:31:35Z
4,975,249
<p>In case anyone else comes across this question, in the forum post linked in Robert Christie's answer a user pointed out that simply using gtk.StatusIcon() is a more portable solution if you're just looking for tray icon functionality (as opposed to say a clock, or main menu applet). Additionally, if you think you ne...
2
2011-02-11T23:56:26Z
[ "python", "pygtk", "gnome" ]
How to deploy Django application at sub-url?
2,034,879
<p>I need to set up a django development environment that is publicly viewable on the internet (I am doing this for school, and my projects need to be viewable by my professor, this isn't a setup that needs much security). I have a virtual server running Ubuntu 8.04 LTS.</p> <p>I need to have multiple django applicat...
3
2010-01-09T20:40:32Z
2,035,305
<p>The Django documentation has a page describing <a href="http://docs.djangoproject.com/en/1.1/howto/deployment/modpython/" rel="nofollow">deployment on Apache</a>. There is also a section about running <a href="http://docs.djangoproject.com/en/1.1/howto/deployment/modpython/#multiple-django-installations-on-the-same-...
0
2010-01-09T23:01:57Z
[ "python", "django", "apache" ]
How to deploy Django application at sub-url?
2,034,879
<p>I need to set up a django development environment that is publicly viewable on the internet (I am doing this for school, and my projects need to be viewable by my professor, this isn't a setup that needs much security). I have a virtual server running Ubuntu 8.04 LTS.</p> <p>I need to have multiple django applicat...
3
2010-01-09T20:40:32Z
2,035,792
<p>You can use</p> <pre><code>WSGIScriptAlias /django1 /home/keratacon/www/django1/wsgi.py WSGIScriptAlias /django2 /home/keratacon/www/django2/wsgi.py </code></pre> <p>in your <a href="http://docs.djangoproject.com/en/dev/howto/deployment/wsgi/" rel="nofollow">apache+mod_wsgi config</a>, assuming <code>wsgi.py</code...
3
2010-01-10T02:11:28Z
[ "python", "django", "apache" ]
How to deploy Django application at sub-url?
2,034,879
<p>I need to set up a django development environment that is publicly viewable on the internet (I am doing this for school, and my projects need to be viewable by my professor, this isn't a setup that needs much security). I have a virtual server running Ubuntu 8.04 LTS.</p> <p>I need to have multiple django applicat...
3
2010-01-09T20:40:32Z
9,641,323
<p><a href="http://opensourcemissions.wordpress.com/2010/03/12/finally-a-working-django-non-root-url-with-mod_wsgi/" rel="nofollow">This blog</a> explains the solution (assuming that mod_wsgi is used, <strike>with nginx/uwsgi the solution is similar</strike> apparently in nginx/uwsgi this is not necessary).</p> <p>The...
0
2012-03-09T21:35:48Z
[ "python", "django", "apache" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,034,997
<p>If you are new to python, why not start with some simpler command line projects? I know you said you are not new to development, but maybe you should spend some time with the core python stuff before tacking on a GUI framework. Just a suggestion. </p> <p>Also, I would point out that Python 3+ code looks a bit di...
1
2010-01-09T21:18:24Z
[ "python" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,035,016
<p>I highly recommend</p> <blockquote> <p><a href="http://www.diveintopython3.net" rel="nofollow">http://www.diveintopython3.net</a></p> </blockquote> <p>It assumes you already understand programming, and walks you through examples that demonstrate the unique abilities of Python.</p>
8
2010-01-09T21:24:31Z
[ "python" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,035,019
<p><strong>Write a simple Text Editor.</strong></p> <p>That was one of the projects i started when i first learned python. It gets you used to the GUI framework, file IO, many types, OOP, lots... It's something that you can grow over time as your confidence builds and it's cross platform so it's handy.</p>
1
2010-01-09T21:25:04Z
[ "python" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,035,117
<p>If python is your first dynamic lanugage you might want to play with some of it's dynamic aspects.</p> <p>For example, using the <a href="http://docs.python.org/reference/datamodel.html#customizing-attribute-access" rel="nofollow"><strong>getattr</strong></a> and <a href="http://docs.python.org/reference/datamodel....
1
2010-01-09T21:57:16Z
[ "python" ]
What are some good projects to make for a newbie Python (but not new to programming) developer?
2,034,932
<p>I'm downloading Python 3.1.1 and that comes with the IDLE correct?</p> <p>I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python. </p> <p>What projects should I try to make in order to grasp some of the goodies Python brings to the table?</p> <p>Thanks a bunch SO.</p>
4
2010-01-09T21:00:02Z
2,035,148
<p>While it is a matter of personal preference, I certainly wouldn't want to play around with a GUI framework when starting out -- I would want to get a feel for the language first by playing around with smaller snippets, such as those suggested on <a href="http://codegolf.com/" rel="nofollow">Code Golf</a>. While gett...
0
2010-01-09T22:05:47Z
[ "python" ]