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 install MySQLdb (Python data access library to MySQL) on Mac OS X?
1,448,429
<p>I'm a Python newbie, but I've just spent a day working out how to get MySQLdb working properly, and the universe according to google includes numerous references to what a PITA it is, and an inordinate number of guides that seem to be outdated. Given that this site is intended to address these sorts of problems, and I know that I'm going to need a reference to the solution in future, I'm going to ask the question, provide my answer and see what else floats to the surface.</p> <p>So the question is how to get <a href="http://sourceforge.net/projects/mysql-python/files/">MySQLdb</a> working on Mac OS X?</p>
81
2009-09-19T12:04:41Z
22,513,919
<p>As statend on <a href="http://stackoverflow.com/questions/17599830/installing-mysql-python-on-mac">Installing MySQL-python on mac</a> :</p> <pre><code>pip uninstall MySQL-python brew install mysql pip install MySQL-python </code></pre> <p>Then test it :</p> <pre><code>python -c "import MySQLdb" </code></pre>
4
2014-03-19T17:41:07Z
[ "python", "mysql", "osx" ]
How to install MySQLdb (Python data access library to MySQL) on Mac OS X?
1,448,429
<p>I'm a Python newbie, but I've just spent a day working out how to get MySQLdb working properly, and the universe according to google includes numerous references to what a PITA it is, and an inordinate number of guides that seem to be outdated. Given that this site is intended to address these sorts of problems, and I know that I'm going to need a reference to the solution in future, I'm going to ask the question, provide my answer and see what else floats to the surface.</p> <p>So the question is how to get <a href="http://sourceforge.net/projects/mysql-python/files/">MySQLdb</a> working on Mac OS X?</p>
81
2009-09-19T12:04:41Z
22,886,248
<p>You could try using the pure-python <code>pymysql</code>:</p> <pre><code>sudo easy_install pymysql </code></pre> <p>(Or use <code>pip</code> if you have it installed.) Then, add this before you <code>import MySQLdb</code> in your code:</p> <pre><code>try: import pymysql pymysql.install_as_MySQLdb() except ImportError: pass </code></pre>
0
2014-04-05T20:15:32Z
[ "python", "mysql", "osx" ]
How to install MySQLdb (Python data access library to MySQL) on Mac OS X?
1,448,429
<p>I'm a Python newbie, but I've just spent a day working out how to get MySQLdb working properly, and the universe according to google includes numerous references to what a PITA it is, and an inordinate number of guides that seem to be outdated. Given that this site is intended to address these sorts of problems, and I know that I'm going to need a reference to the solution in future, I'm going to ask the question, provide my answer and see what else floats to the surface.</p> <p>So the question is how to get <a href="http://sourceforge.net/projects/mysql-python/files/">MySQLdb</a> working on Mac OS X?</p>
81
2009-09-19T12:04:41Z
23,849,606
<p>Or simple try:</p> <blockquote> <p>sudo easy_install MySQL-python</p> </blockquote> <p>If it gives a error</p> <p>EnvironmentError: mysql_config not found</p> <p>Just run this </p> <blockquote> <p>export PATH=$PATH:/usr/local/mysql/bin</p> </blockquote>
1
2014-05-24T20:59:40Z
[ "python", "mysql", "osx" ]
How to install MySQLdb (Python data access library to MySQL) on Mac OS X?
1,448,429
<p>I'm a Python newbie, but I've just spent a day working out how to get MySQLdb working properly, and the universe according to google includes numerous references to what a PITA it is, and an inordinate number of guides that seem to be outdated. Given that this site is intended to address these sorts of problems, and I know that I'm going to need a reference to the solution in future, I'm going to ask the question, provide my answer and see what else floats to the surface.</p> <p>So the question is how to get <a href="http://sourceforge.net/projects/mysql-python/files/">MySQLdb</a> working on Mac OS X?</p>
81
2009-09-19T12:04:41Z
23,869,683
<pre><code>export PATH=$PATH:/usr/local/mysql/bin/ </code></pre> <p>should fix the issue for you as the system is not able to find the mysql_config file.</p>
0
2014-05-26T12:00:14Z
[ "python", "mysql", "osx" ]
Python - I can't stop the program running
1,448,505
<p>I am completely new to python. I have installed it on windows. I am having a problem, I write:</p> <pre><code>from pylab import* subplot(111,projection="hammer") show() </code></pre> <p>After this it will not let me do anything else and ctrl-c does not work. I have looked at another post here and tried ctrl-break, ctrl-z and various other methods to no avail. Could anyone point me in the right direction.</p> <p>Many thanks</p>
1
2009-09-19T12:48:14Z
1,448,542
<p>If it's a simple matter of interrupting a running program, have you tried CTRL-D ?</p>
0
2009-09-19T13:14:01Z
[ "python" ]
Python - I can't stop the program running
1,448,505
<p>I am completely new to python. I have installed it on windows. I am having a problem, I write:</p> <pre><code>from pylab import* subplot(111,projection="hammer") show() </code></pre> <p>After this it will not let me do anything else and ctrl-c does not work. I have looked at another post here and tried ctrl-break, ctrl-z and various other methods to no avail. Could anyone point me in the right direction.</p> <p>Many thanks</p>
1
2009-09-19T12:48:14Z
1,448,543
<p>I'd recommend to use <a href="http://ipython.scipy.org/moin/" rel="nofollow">IPython</a>. It brings a matplotlib/pylab mode that handles all this for you. After you install IPython, you can start it with the <code>pylab</code> flag:</p> <pre><code>$ ipython -pylab </code></pre> <p>Then, in the interactive shell, you type your code:</p> <pre><code>In [1]: from pylab import* In [2]: subplot(111,projection="hammer") Out[2]: &lt;matplotlib.axes.HammerAxesSubplot object at 0x2241050&gt; In [3]: </code></pre> <p>IPython automatically shows the plot using a separate thread and returns control to the interactive shell.</p> <p>The documentation of <a href="http://matplotlib.sourceforge.net/users/shell.html" rel="nofollow">matplotlib</a> has a little more information on how all this works.</p>
1
2009-09-19T13:14:29Z
[ "python" ]
Python - I can't stop the program running
1,448,505
<p>I am completely new to python. I have installed it on windows. I am having a problem, I write:</p> <pre><code>from pylab import* subplot(111,projection="hammer") show() </code></pre> <p>After this it will not let me do anything else and ctrl-c does not work. I have looked at another post here and tried ctrl-break, ctrl-z and various other methods to no avail. Could anyone point me in the right direction.</p> <p>Many thanks</p>
1
2009-09-19T12:48:14Z
1,448,556
<p>Try this:</p> <p>After all of your imports for pylab and what not.. add:</p> <pre><code>import signal signal.signal(signal.SIGINT, signal.SIG_DFL) </code></pre> <p>This will cause CTRL-C to not be caught by anything in your program, which should then cause it to kill the program.</p>
0
2009-09-19T13:25:47Z
[ "python" ]
Python - I can't stop the program running
1,448,505
<p>I am completely new to python. I have installed it on windows. I am having a problem, I write:</p> <pre><code>from pylab import* subplot(111,projection="hammer") show() </code></pre> <p>After this it will not let me do anything else and ctrl-c does not work. I have looked at another post here and tried ctrl-break, ctrl-z and various other methods to no avail. Could anyone point me in the right direction.</p> <p>Many thanks</p>
1
2009-09-19T12:48:14Z
1,448,648
<p>Try catching <code>KeyboardInterrupt</code> like so:</p> <pre><code>try: show() except KeyboardInterrupt: print "Shutting down." import sys sys.exit() </code></pre>
0
2009-09-19T14:27:22Z
[ "python" ]
Python subprocess.Popen - adding GCC flags results in "no input files" error
1,448,558
<p>I'm building a Python script to automate my build process, which invokes GCC using subprocess.Popen. My initial attempt works fine.</p> <pre><code>&gt;&gt;&gt; import subprocess &gt;&gt;&gt; p = Popen(['gcc', 'hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT) &gt;&gt;&gt; p.wait() 0 &gt;&gt;&gt; p.communicate() ('', None) </code></pre> <p>However, once I pass additional options to GCC I get the error "no input files", as demonstrated below:</p> <pre><code>&gt;&gt;&gt; import subprocess &gt;&gt;&gt; p = Popen(['gcc', '-o hello hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT) &gt;&gt;&gt; p.wait() 1 &gt;&gt;&gt; p.communicate() ('gcc: no input files\r\n', None) </code></pre> <p>Any ideas what may be causing this issue?</p>
2
2009-09-19T13:27:20Z
1,448,567
<p>Shouldn't that be</p> <pre><code>p = Popen(['gcc', '-o', 'hello', 'hello.c'], stdout=subprocess.PIPE, stderr=stderr=subprocess.STDOUT) </code></pre>
6
2009-09-19T13:33:19Z
[ "python", "gcc", "subprocess", "popen" ]
Multiple visualizations in one page
1,448,638
<p>I am using python-visualization library for computing the datasource. I tried to put more than one visualization in a single page. Both are line charts and data comes from a seperate URLs for each visualizations.</p> <pre><code>&lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/site_media/js/jquery-1.2.6.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; google.load('visualization', '1', { packages: ['linechart'] }); &lt;/script&gt; &lt;script type="text/javascript"&gt; var visualization1, visualization2; function drawVisualization1() { var query1 = new google.visualization.Query('/datasource1/'); query1.send(handleQueryResponse1); var query2 = new google.visualization.Query('/datasource2/'); query2.send(handleQueryResponse2); } function handleQueryResponse1(response) { if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } var data1 = response.getDataTable(); visualization1 = new google.visualization.LineChart(document.getElementById('visualization1')); var options = {}; options['width'] = 600; options['height'] = 200; visualization1.draw(data1, options); } function handleQueryResponse2(response) { if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } var data2 = response.getDataTable(); visualization2 = new google.visualization.LineChart(document.getElementById('visualization2')); var options = {}; options['width'] = 600; options['height'] = 200; visualization2.draw(data2, options); } google.setOnLoadCallback(drawVisualization1); &lt;/script&gt; &lt;body&gt; &lt;div id="visualization1" class="span-15"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt; &lt;div id="visualization2" class="span-15"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt; &lt;/body&gt; </code></pre> <p>Datasources:</p> <pre><code>def datasource1(request): data = [] description = {"col1": ("number", "col1"),"col2": ("number", "col2"),} for i in range(datetime.today().hour + 1): data.append({"col1":datetime.today().hour,"col2":datetime.today().hour }) data_table = gviz_api.DataTable(description) data_table.LoadData(data) return HttpResponse(data_table.ToJSonResponse(columns_order=( "col1","col2",))) def datasource2(request): data = [] description = {"col1": ("number", "col1"),"col2": ("number", "col2"),} for i in range(datetime.today().hour + 1): data.append({"col1":datetime.today().hour,"col2":datetime.today().hour }) data_table = gviz_api.DataTable(description) data_table.LoadData(data) return HttpResponse(data_table.ToJSonResponse(columns_order=( "col1","col2",))) </code></pre> <p>When I render the page only the first visualization comes up , the second visualization never appears. Can some one help me out?</p>
2
2009-09-19T14:24:52Z
1,449,197
<p>You can try something like </p> <pre><code>function Charts(){ var self = this; self.chart = []; self.settings = { width: 650, height: 250 }; self.add = function(type, element, dataTable, options){ self.chart.push({ o: new google.visualization[type]($(element)[0]), data: dataTable, draw: function(){ var settings = $.extend({}, self.settings, options); this.o.draw(this.data, settings); } }); return self; }; self.draw = function(){ $.each(self.chart, function(i, chart){ chart.draw(); }); return self; }; } </code></pre> <p>and then </p> <pre><code>//var data1 = 'someDataTable', // data2 = 'anotherDataTable'; charts = new Charts(); var settings = {width:600, height:200 }; charts.add('LineChart', '#visualization1', settings, data1); charts.add('LineChart', '#visualization2', settings, data2); charts.draw(); </code></pre> <p>Sorry, havn't tested myself, just thought it can help you. </p> <p>And I'll advice is to load from Google jQuery as well.</p> <pre><code>google.load("jquery", "1.2.6"); </code></pre> <p>Hope it'll help you :)</p>
0
2009-09-19T18:38:58Z
[ "javascript", "jquery", "python", "django", "google-visualization" ]
Multiple visualizations in one page
1,448,638
<p>I am using python-visualization library for computing the datasource. I tried to put more than one visualization in a single page. Both are line charts and data comes from a seperate URLs for each visualizations.</p> <pre><code>&lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/site_media/js/jquery-1.2.6.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; google.load('visualization', '1', { packages: ['linechart'] }); &lt;/script&gt; &lt;script type="text/javascript"&gt; var visualization1, visualization2; function drawVisualization1() { var query1 = new google.visualization.Query('/datasource1/'); query1.send(handleQueryResponse1); var query2 = new google.visualization.Query('/datasource2/'); query2.send(handleQueryResponse2); } function handleQueryResponse1(response) { if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } var data1 = response.getDataTable(); visualization1 = new google.visualization.LineChart(document.getElementById('visualization1')); var options = {}; options['width'] = 600; options['height'] = 200; visualization1.draw(data1, options); } function handleQueryResponse2(response) { if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } var data2 = response.getDataTable(); visualization2 = new google.visualization.LineChart(document.getElementById('visualization2')); var options = {}; options['width'] = 600; options['height'] = 200; visualization2.draw(data2, options); } google.setOnLoadCallback(drawVisualization1); &lt;/script&gt; &lt;body&gt; &lt;div id="visualization1" class="span-15"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt; &lt;div id="visualization2" class="span-15"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt; &lt;/body&gt; </code></pre> <p>Datasources:</p> <pre><code>def datasource1(request): data = [] description = {"col1": ("number", "col1"),"col2": ("number", "col2"),} for i in range(datetime.today().hour + 1): data.append({"col1":datetime.today().hour,"col2":datetime.today().hour }) data_table = gviz_api.DataTable(description) data_table.LoadData(data) return HttpResponse(data_table.ToJSonResponse(columns_order=( "col1","col2",))) def datasource2(request): data = [] description = {"col1": ("number", "col1"),"col2": ("number", "col2"),} for i in range(datetime.today().hour + 1): data.append({"col1":datetime.today().hour,"col2":datetime.today().hour }) data_table = gviz_api.DataTable(description) data_table.LoadData(data) return HttpResponse(data_table.ToJSonResponse(columns_order=( "col1","col2",))) </code></pre> <p>When I render the page only the first visualization comes up , the second visualization never appears. Can some one help me out?</p>
2
2009-09-19T14:24:52Z
3,850,573
<p>Happened to me too. The solution was for the server to return the reqId parameter. If you have two visualizations on the same page, one will have reqId 0 and the other reqId 1. make sure the server returns those reqIds back appropriately in the response.</p> <p>If both responses return '0' then only one visualization will render (the first one).</p>
0
2010-10-03T16:27:12Z
[ "javascript", "jquery", "python", "django", "google-visualization" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
1,448,832
<p>What version of Python do you have? SQLite is integrated in Python since 2.5:</p> <p><a href="http://docs.python.org/library/sqlite3.html" rel="nofollow">http://docs.python.org/library/sqlite3.html</a></p> <p>If you insist on compiling it yourself, the package is called sqlite3-devel, you can find it e.g. <a href="http://rpm.pbone.net/index.php3/stat/4/idpl/7965440/com/sqlite3-devel-3.5.7-17.1.i586.rpm.html" rel="nofollow">here</a></p>
2
2009-09-19T16:02:39Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
1,448,856
<p>I'm the one who answered the other question :) On systems that use RPM packages, i.e. you normally use 'yum' to install things, the package is named sqlite3-devel.</p> <p>On most Debian based systems (i.e. you use apt-get to install packages), the package is named sqlite3-dev.</p> <p>This is a very typical difference between the two, most other packages follow the same naming convention.</p>
0
2009-09-19T16:12:35Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
1,448,865
<blockquote> <p>how to check if I have "sqlite3-dev"</p> </blockquote> <p>That's entirely dependent on what Linux distro you're using -- is it Fedora, Suse, Ubuntu, Gentoo, Mandrake, or which other one out of the dozens out there; there are several packaging strategies and tools used to check which packages are there, get more, and so forth.</p> <p>So, never ask questions about checking, getting or tweaking packages on Linux without specifying the distribution[s] of interest -- it makes it essentially impossible to offer precise, specific help.</p> <p><strong>Edit</strong>: the simplest way I know of getting details about your Linux distribution (works on all the ones I have at hand to try, but I don't have a particularly wide array...;-):</p> <pre><code>$ cat /etc/*-release DISTRIB_CODENAME=hardy DISTRIB_DESCRIPTION="Ubuntu 8.04.2" DISTRIB_ID=Ubuntu DISTRIB_RELEASE=8.04 ...etc, etc... </code></pre> <p>This is probably going to be the contents of file <code>/etc/lsb-release</code>, but I'm suggesting the <code>*-release</code> because I think there may be some other such files involved.</p> <p>Of course, if the need to check your distro applies inside a file or program, reading this file (or files) and locating specific contents will also be quite feasible; but for the purpose of informing would-be helpers about what distro you're using, the <code>cat</code> at the shell prompt is going to be quite sufficient;-).</p>
3
2009-09-19T16:17:24Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
2,805,246
<p>I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.</p>
0
2010-05-10T18:17:09Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
3,999,614
<p>I had the same problem, I'm using python 2.4, neither <code>sqlite3-dev</code> nor <code>libsqlite3-dev</code> are available for CentOS.</p> <pre><code>yum install python-devel </code></pre> <p>seems to solve the issue.</p>
3
2010-10-22T18:01:50Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
5,896,406
<p>I had following compile errors on <strong>CentOS release 5.6</strong>:</p> <pre><code>src/cache.h:34: error: expected specifier-qualifier-list before 'PyObject_HEAD' src/cache.h:44: error: expected specifier-qualifier-list before 'PyObject_HEAD' src/cache.h:61: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'pysqlite_NodeType' src/cache.h:62: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'pysqlite_CacheType' src/cache.h:64: error: expected declaration specifiers or '...' before 'PyObject' src/cache.h:64: error: expected declaration specifiers or '...' before 'PyObject' src/cache.h:67: error: expected declaration specifiers or '...' before 'PyObject' src/cache.h:67: error: expected declaration specifiers or '...' before 'PyObject' </code></pre> <p>Installing <strong>python-devel</strong> helped me too:</p> <p><strong>yum install python-devel</strong></p>
1
2011-05-05T10:42:37Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
10,068,852
<p>You could use yum or apt-get instead first type :</p> <pre><code> sudo yum(or apt-get) search python-sqlite3 </code></pre> <p>you will get something like python-sqlite3dbm.noarch</p> <p>then type :</p> <pre><code> sudo yum(or apt-get) install python-sqlite3dbm.noarch </code></pre> <p>this way your os will install all you need for you and you wont get errors</p>
2
2012-04-09T04:21:43Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
12,262,783
<p>Did you install the python sqlite lib?</p> <pre><code>sudo apt-get install python-sqlite </code></pre>
0
2012-09-04T11:42:26Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
18,519,411
<p>I was able to resolve the same build error by installing the sqlite-devel package:</p> <pre><code>sudo yum install sqlite-devel </code></pre>
4
2013-08-29T19:23:04Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
How to install pysqlite?
1,448,819
<p>I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:</p> <pre><code>gunzip pysqlite-2.5.5.tar.gz tar xvf pysqlite-2.5.5.tar \cd pysqlite-2.5.5 python setup.py install </code></pre> <p>At the last step I have a problem. I get the following error message:</p> <pre><code>error: command 'gcc' failed with exit status 1 </code></pre> <p><a href="http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html" rel="nofollow">I found that other peoples also had this problem</a>.</p> <p>As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).</p> <p>May be I should change some paths in <code>"setup.cfg"</code>? At the moment I have there:</p> <pre><code>#define= #include_dirs=/usr/local/include #library_dirs=/usr/local/lib libraries=sqlite3 define=SQLITE_OMIT_LOAD_EXTENSION </code></pre> <p>And if I type "which sqlite3" I get:</p> <pre><code>/usr/bin/sqlite3 </code></pre> <p>I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have <code>sqlite3-dev</code>. And if I do not have it how to get it?</p> <p>Can anybody pleas help me with that problem.</p> <p>Thank you in advance. </p>
3
2009-09-19T15:55:09Z
19,143,252
<p>For Debian distros I fixed this problem with</p> <pre><code>sudo apt-get install libsqlite3-dev </code></pre>
6
2013-10-02T17:38:20Z
[ "python", "linux", "sqlite", "gcc", "pysqlite" ]
variable length of %s with the % operator in python
1,448,820
<p>I'm trying to do this:</p> <pre><code>max_title_width = max([len(text) for text in columns]) for column in columns: print "%10s, blah" % column </code></pre> <p>But I want to replace the <code>10</code> with the value of <code>max_title_width</code>. How do I do this in the most pythonic way possible?</p>
18
2009-09-19T15:56:38Z
1,448,834
<p>This is a carryover from the C formatting markup:</p> <pre><code>print "%*s, blah" % (max_title_width,column) </code></pre> <p>If you want left-justified text (for entries shorter than <code>max_title_width</code>), put a '-' before the '*'.</p> <pre><code>&gt;&gt;&gt; text = "abcdef" &gt;&gt;&gt; print "&lt;%*s&gt;" % (len(text)+2,text) &lt; abcdef&gt; &gt;&gt;&gt; print "&lt;%-*s&gt;" % (len(text)+2,text) &lt;abcdef &gt; &gt;&gt;&gt; </code></pre> <p>If the len field is shorter than the text string, the string just overflows:</p> <pre><code>&gt;&gt;&gt; print "&lt;%*s&gt;" % (len(text)-2,text) &lt;abcdef&gt; </code></pre> <p>If you want to clip at a maximum length, use the '.' precision field of the format placeholder:</p> <pre><code>&gt;&gt;&gt; print "&lt;%.*s&gt;" % (len(text)-2,text) &lt;abcd&gt; </code></pre> <p>Put them all together this way:</p> <pre><code>% - if left justified * or integer - min width (if '*', insert variable length in data tuple) .* or .integer - max width (if '*', insert variable length in data tuple) </code></pre>
44
2009-09-19T16:03:17Z
[ "python" ]
variable length of %s with the % operator in python
1,448,820
<p>I'm trying to do this:</p> <pre><code>max_title_width = max([len(text) for text in columns]) for column in columns: print "%10s, blah" % column </code></pre> <p>But I want to replace the <code>10</code> with the value of <code>max_title_width</code>. How do I do this in the most pythonic way possible?</p>
18
2009-09-19T15:56:38Z
1,448,842
<p>You have the new strings formatting methods from Python 3 and Python 2.6.</p> <blockquote> <p>Starting in Python 2.6, the built-in str and unicode classes provide the ability to do complex variable substitutions and value formatting via the str.format() method described in PEP 3101. The Formatter class in the string module allows you to create and customize your own string formatting behaviors using the same implementation as the built-in format() method.</p> <p>(...)</p> <p><a href="http://docs.python.org/library/string.html#format-string-syntax">For example</a>, <strong>suppose you wanted to have a replacement field whose field width is determined by another variable</strong>:</p> <pre><code>&gt;&gt;&gt; "A man with two {0:{1}}.".format("noses", 10) "A man with two noses ." &gt;&gt;&gt; print("A man with two {0:{1}}.".format("noses", 10)) A man with two noses . </code></pre> </blockquote> <hr> <p>So for your example it would be</p> <pre><code>max_title_width = max(len(text) for text in columns) for column in columns: print "A man with two {0:{1}}".format(column, max_title_width) </code></pre> <p>I personally love the new formatting methods, as they are far more powerful and readable in my humble opinion.</p>
22
2009-09-19T16:04:59Z
[ "python" ]
variable length of %s with the % operator in python
1,448,820
<p>I'm trying to do this:</p> <pre><code>max_title_width = max([len(text) for text in columns]) for column in columns: print "%10s, blah" % column </code></pre> <p>But I want to replace the <code>10</code> with the value of <code>max_title_width</code>. How do I do this in the most pythonic way possible?</p>
18
2009-09-19T15:56:38Z
1,448,844
<p>you could create your template outside of the loop:</p> <pre><code>tmpl = '%%%ds, blah' % max_title_width for column in columns: print tmpl % column </code></pre> <p>You could also learn about the <a href="http://docs.python.org/tutorial/inputoutput.html#input-and-output" rel="nofollow">new formatting</a> in python.</p> <p>and btw, <a href="http://docs.python.org/library/functions.html#max" rel="nofollow"><code>max</code></a> doesn't require a list, you can pass it an iterable:</p> <pre><code>max_title_width = max(len(i) for i in columns) </code></pre>
2
2009-09-19T16:06:34Z
[ "python" ]
variable length of %s with the % operator in python
1,448,820
<p>I'm trying to do this:</p> <pre><code>max_title_width = max([len(text) for text in columns]) for column in columns: print "%10s, blah" % column </code></pre> <p>But I want to replace the <code>10</code> with the value of <code>max_title_width</code>. How do I do this in the most pythonic way possible?</p>
18
2009-09-19T15:56:38Z
18,036,492
<p>Python 2.6+ alternate version examples:</p> <pre><code>&gt;&gt;&gt; '{:{n}s}, blah'.format('column', n=10) 'column , blah' &gt;&gt;&gt; '{:*&gt;{l}s}'.format(password[-3:], l=len(password)) # password = 'stackoverflow' '**********low' &gt;&gt;&gt; '{:,.{n}f} {}'.format(1234.567, 'USD', n=2) '1,234.57 USD' </code></pre> <p>Hint: first non-keyword args, then keyword args.</p>
3
2013-08-03T19:31:57Z
[ "python" ]
subversion python bindings documentation?
1,448,894
<p>Where can I find a good introduction to using the subversion python bindings?</p> <p>I found <a href="http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html">one section in the svnbook</a> that talks about it; and some <a href="http://jtauber.com/python%5Fsubversion%5Fbinding/">basic examples from 1.3</a>.</p> <p>Is there something a bit more thorough and up-to-date?</p>
7
2009-09-19T16:32:18Z
1,448,910
<p>This looks like a pretty complete documentation:</p> <p><a href="http://pysvn.tigris.org/docs/pysvn_prog_ref.html" rel="nofollow">http://pysvn.tigris.org/docs/pysvn_prog_ref.html</a></p> <p>And here are a couple examples:</p> <p><a href="http://svn.apache.org/repos/asf/subversion/trunk/tools/examples/" rel="nofollow">http://svn.apache.org/repos/asf/subversion/trunk/tools/examples/</a></p>
1
2009-09-19T16:37:59Z
[ "python", "svn", "documentation" ]
subversion python bindings documentation?
1,448,894
<p>Where can I find a good introduction to using the subversion python bindings?</p> <p>I found <a href="http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html">one section in the svnbook</a> that talks about it; and some <a href="http://jtauber.com/python%5Fsubversion%5Fbinding/">basic examples from 1.3</a>.</p> <p>Is there something a bit more thorough and up-to-date?</p>
7
2009-09-19T16:32:18Z
7,356,388
<p>If you build Subversion from source the Subversion Python bindings aren't automatically included. You have to specifically build and include them. Luckily, you can do this after you've installed Subversion. The source for the bindings is included within the Subversion source code. </p> <p>These instructions are for Subversion 1.5.9 and Python 2.4.3 on Red Hat Enterprise Linux, but they should be easily hackable for recent versions of Subversion and Python and generic unix installs. </p> <p>First, download swig from <a href="http://downloads.sourceforge.net/swig" rel="nofollow">http://downloads.sourceforge.net/swig</a></p> <pre><code>tar -xvf swig-&lt;version&gt;.tar.gz cd swig-&lt;version&gt; </code></pre> <p>At this point you have to make a decision. You can install swig for all supported languages or you can install for just what you need. 'make check' can take up to an hour to run and may fail due to errors from languages you aren't concerned with. </p> <p>If you want to use all supported languages run: </p> <pre><code>./configure </code></pre> <p>If you want to scope down to just python, run:</p> <pre><code>./configure --with-python=/usr/local/bin/python2.4 --without-perl --without-ruby --without-php4 </code></pre> <p>Next, run:</p> <pre><code>make </code></pre> <p>If you opted for the full install, run:</p> <pre><code>make -k check </code></pre> <p>If you scoped down to just python you only need to run the python tests:</p> <pre><code>make check-python-examples make check-python-test-suite </code></pre> <p>If everything's OK, you're ready to install swig:</p> <p>make install </p> <p>From here, installing the subversion python bindings should be fairly straightforward:</p> <pre><code>tar -xvf subversion-1.5.9.tar.gz --gzip cd subversion-1.5.9 make swig-py make install-swig-py touch /usr/lib64/python2.4/site-packages/svn-python.pth echo /usr/local/lib/svn-python &gt; /usr/lib64/python2.4/site-packages/svn-python.pth </code></pre> <p>As always, your mileage may vary depending on your specific versions and architecture. Good luck.</p>
1
2011-09-09T01:55:12Z
[ "python", "svn", "documentation" ]
subversion python bindings documentation?
1,448,894
<p>Where can I find a good introduction to using the subversion python bindings?</p> <p>I found <a href="http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html">one section in the svnbook</a> that talks about it; and some <a href="http://jtauber.com/python%5Fsubversion%5Fbinding/">basic examples from 1.3</a>.</p> <p>Is there something a bit more thorough and up-to-date?</p>
7
2009-09-19T16:32:18Z
15,856,850
<p>Just wanted to add a little clarification here. </p> <p>Thanks to the above two answers (<a href="http://stackoverflow.com/a/1448910/277826">@BenjaminWohlwend</a> and <a href="http://stackoverflow.com/a/7356388/277826">@Logan</a>), I became aware there are more than one set of Python bindings/interfaces for Subversion; I did this on my Ubuntu 11.04 box:</p> <pre><code>$ apt-cache search '[Ss]vn|[Ss]ubversion' | grep -i python python-svn - A(nother) Python interface to Subversion python-svn-dbg - A(nother) Python interface to Subversion (debug extension) python-subversion - Python bindings for Subversion python-subversion-dbg - Python bindings for Subversion (debug extension) python-opster - a python command line parsing speedster python-py - Advanced Python testing tool and networking lib python-rope - Python refactoring library python-subvertpy - Alternative Python bindings for Subversion </code></pre> <p>One can look at the Debian package filelist, to determine which libraries these refer to; so we have: </p> <ul> <li><code>python-subversion</code> - or SWIG bindings (or <code>libsvn</code>, <code>libsvn_swig_py</code>) <a href="http://packages.ubuntu.com/lucid/i386/python-subversion/filelist" rel="nofollow">filelist</a> <ul> <li>Examples: <a href="http://svn.apache.org/repos/asf/subversion/trunk/tools/examples/" rel="nofollow"><a href="http://svn.apache.org/repos/asf/subversion/trunk/tools/examples/" rel="nofollow">http://svn.apache.org/repos/asf/subversion/trunk/tools/examples/</a></a> , <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/python/tests/" rel="nofollow"><a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/python/tests/" rel="nofollow">http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/python/tests/</a></a></li> <li><code>import svn.core, svn.client</code> ; <code>from svn import fs, core, repos</code></li> </ul></li> <li><code>python-svn</code> - or <code>pysvn</code> <a href="http://packages.ubuntu.com/lucid/i386/python-svn/filelist" rel="nofollow">filelist</a> <ul> <li>Examples: <a href="http://sourcecodebrowser.com/pysvn/1.4.1/dir_cd55444703d7fb2488815f1970d01a75.html" rel="nofollow"><a href="http://sourcecodebrowser.com/pysvn/1.4.1/dir_cd55444703d7fb2488815f1970d01a75.html" rel="nofollow">http://sourcecodebrowser.com/pysvn/1.4.1/dir_cd55444703d7fb2488815f1970d01a75.html</a></a> , <a href="http://pysvn.tigris.org/docs/pysvn_prog_guide.html" rel="nofollow"><a href="http://pysvn.tigris.org/docs/pysvn_prog_guide.html" rel="nofollow">http://pysvn.tigris.org/docs/pysvn_prog_guide.html</a></a></li> <li><code>import pysvn</code> </li> </ul></li> <li><code>python-subvertpy</code> - or <code>subvertpy</code> <a href="http://packages.ubuntu.com/lucid/i386/python-subvertpy/filelist" rel="nofollow">filelist</a> <ul> <li>Examples: <a href="http://sourcecodebrowser.com/subvertpy/0.7.2/dir_22b88615bda8eebb370e96884c00fb89.html" rel="nofollow"><a href="http://sourcecodebrowser.com/subvertpy/0.7.2/dir_22b88615bda8eebb370e96884c00fb89.html" rel="nofollow">http://sourcecodebrowser.com/subvertpy/0.7.2/dir_22b88615bda8eebb370e96884c00fb89.html</a></a></li> <li><code>from subvertpy import delta, repos</code> , <code>from subvertpy.ra import RemoteAccess, Auth</code></li> </ul></li> </ul> <p>... and I also found another in the repository: </p> <ul> <li><code>ctypes-python</code> - or <code>csvn</code> <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/ctypes-python/" rel="nofollow">source</a> <ul> <li>Examples: <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/ctypes-python/examples/" rel="nofollow"><a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/ctypes-python/examples/" rel="nofollow">http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/ctypes-python/examples/</a></a></li> <li><code>import csvn.core</code> , <code>from csvn.repos import *</code></li> </ul></li> </ul> <p>The link <a href="http://svn.apache.org/repos/asf/subversion" rel="nofollow">http://svn.apache.org/repos/asf/subversion</a> (which I got from <a href="http://stackoverflow.com/a/1448910/277826">@BenjaminWohlwend</a>) is apparently the Apache Software Foundation (asf?) Subversion repository for Subversion source code itself. </p> <p>The OP's quest for documentation seems related to <code>python-subversion</code> (or SWIG bindings (or <code>libsvn</code>); whose build-from-source instructions are in <a href="http://stackoverflow.com/a/7356388/277826">@Logan</a>'s post. I couldn't find much better documentation source from the <a href="http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html" rel="nofollow">svn.developer: Using the APIs</a> already referred in the OP, except for the <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/python/README" rel="nofollow">bindings/swig/python/README</a>; it explains how SWIG generates Python interfaces from C:</p> <blockquote> <p>TRANSLATING PARAMETER LISTS </p> <p>The argument-reductions laws of the SWIG bindings something go like<br> this: </p> <pre><code>- The module prefix can be omitted. o: void *some_C_function = svn_client_foo; becomes: import svn.client func = svn.client.foo </code></pre> <p>[...]</p> </blockquote> <p>Then, one could look in, say, <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/python/svn/core.py" rel="nofollow">svn/core.py</a>, and find functions (and "Symbols defined explicitly") like <code>svn_mergeinfo_merge</code>; noting that <code>core.py</code> imports <code>libsvn.core</code> - where <code>libsvn</code> probably refers to the shared object (<code>.so</code>) files built from the C file <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c" rel="nofollow">libsvn_swig_py/swigutil_py.c</a>. </p> <p>Then, we can look up <code>svn_mergeinfo_merge</code>, and find a commit message like <a href="http://svnsearch.org/svnsearch/repos/SVN/search?revision=23570" rel="nofollow">SVNSearch: Subversion (commit 23570 05.03.2007)</a>, which refers to that function, and a <code>svn_mergeinfo.h</code>; looking up that file further, we find it in the ASF repository: <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/include/svn_mergeinfo.h" rel="nofollow">svn_mergeinfo.h</a>, which indeed contains:</p> <pre><code>/** Like svn_mergeinfo_merge2, but uses only one pool. * * @deprecated Provided for backward compatibility with the 1.5 API. */ SVN_DEPRECATED svn_error_t * svn_mergeinfo_merge(svn_mergeinfo_t mergeinfo, svn_mergeinfo_t changes, apr_pool_t *pool); </code></pre> <p>Seeing <code>DEPRECATED</code> there, it's probably good here to refer to <a href="http://mail-archives.apache.org/mod_mbox/subversion-commits/201109.mbox/%3C20110926151521.BBBCD23888E4@eris.apache.org%3E" rel="nofollow">svn commit: r1175903 (Mon Sep 26 2011)</a>:</p> <blockquote> <ul> <li><p>subversion/libsvn_subr/mergeinfo.c </p> <p>(svn_mergeinfo_merge2): New. </p> <p>(svn_mergeinfo_merge): Move to deprecated.c. </p> <p>(svn_mergeinfo_catalog_merge): Use the new API.</p></li> </ul> </blockquote> <p>That is - that particular function has been deprecated in 2011 - so hopefully, one's Python SVN bindings and SVN installation should be matching... </p>
3
2013-04-06T22:42:00Z
[ "python", "svn", "documentation" ]
subversion python bindings documentation?
1,448,894
<p>Where can I find a good introduction to using the subversion python bindings?</p> <p>I found <a href="http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html">one section in the svnbook</a> that talks about it; and some <a href="http://jtauber.com/python%5Fsubversion%5Fbinding/">basic examples from 1.3</a>.</p> <p>Is there something a bit more thorough and up-to-date?</p>
7
2009-09-19T16:32:18Z
16,027,927
<p>Hope it's OK with another post re: <code>python-subversion</code>: I wanted to try <a href="http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html#svn.developer.usingapi.otherlangs.ex-2" rel="nofollow">Example 8.3. A Python status crawler - Using the APIs (svnbook)</a>. on Ubuntu 11.04, Python 2.7, <code>svn_client_status2</code> crashed on a filename with UTF-8 characters with "<em>Error (22): Error converting entry in directory 'path' to UTF-8</em>" - the solution to this is to call <code>setlocale</code> before any calls to this function. </p> <p>I also realized there are <code>svn_client_status3</code> and <code>svn_client_status4</code> in the Python API; <code>svn_client_status3</code> has a slightly different call, and also needs <code>setlocale</code>. However, <code>svn_client_status4</code> should NOT be used - it segfaults, since it needs a struct argument which Python cannot deliver; for more, see <a href="http://stackoverflow.com/a/16027750/277826">#16027750 Debugging: stepping through Python script using gdb?</a>. </p> <p>To wrap it up, here is the Example 8.3 with locale setting which uses <code>svn_client_status3</code> - and doesn't crash on my system (even on filenames with UTF-8 characters):</p> <pre><code>#!/usr/bin/env python # modified from: # http://svnbook.red-bean.com/en/1.5/svn.developer.usingapi.html # does the same as `svn status`, and is marked: """Crawl a working copy directory, printing status information.""" # tested on Python 2.7, Ubuntu Natty 11.04; needs: # sudo apt-get install python-subversion import locale print locale.getlocale() # (None, None) - in C: ANSI_X3.4-1968 locale.setlocale(locale.LC_ALL, '') # would print en_US.UTF-8 print locale.getlocale() # NOW it is ('en_US', 'UTF-8') import sys import os.path import getopt import svn.core, svn.client, svn.wc def generate_status_code(status): """Translate a status value into a single-character status code, using the same logic as the Subversion command-line client.""" code_map = { svn.wc.svn_wc_status_none : ' ', svn.wc.svn_wc_status_normal : ' ', svn.wc.svn_wc_status_added : 'A', svn.wc.svn_wc_status_missing : '!', svn.wc.svn_wc_status_incomplete : '!', svn.wc.svn_wc_status_deleted : 'D', svn.wc.svn_wc_status_replaced : 'R', svn.wc.svn_wc_status_modified : 'M', svn.wc.svn_wc_status_merged : 'G', svn.wc.svn_wc_status_conflicted : 'C', svn.wc.svn_wc_status_obstructed : '~', svn.wc.svn_wc_status_ignored : 'I', svn.wc.svn_wc_status_external : 'X', svn.wc.svn_wc_status_unversioned : '?', } return code_map.get(status, '?') def do_status(wc_path, verbose): # Build a client context baton. ctx = svn.client.svn_client_ctx_t() def _status_callback(path, status): """A callback function for svn_client_status.""" # Print the path, minus the bit that overlaps with the root of # the status crawl text_status = generate_status_code(status.text_status) prop_status = generate_status_code(status.prop_status) print '%s%s %s' % (text_status, prop_status, path) # Do the status crawl, using _status_callback() as our callback function. revision = svn.core.svn_opt_revision_t() revision.type = svn.core.svn_opt_revision_head #~ svn.client.svn_client_status2(wc_path, revision, _status_callback, #~ svn.core.svn_depth_infinity, verbose, #~ 0, 0, 1, ctx) svn.client.svn_client_status3(wc_path, revision, _status_callback, svn.core.svn_depth_infinity, verbose, 0, 0, 1, (), ctx) # DO NOT USE svn_client_status4! (needs a C struct argument) def usage_and_exit(errorcode): """Print usage message, and exit with ERRORCODE.""" stream = errorcode and sys.stderr or sys.stdout stream.write("""Usage: %s OPTIONS WC-PATH Options: --help, -h : Show this usage message --verbose, -v : Show all statuses, even uninteresting ones """ % (os.path.basename(sys.argv[0]))) sys.exit(errorcode) if __name__ == '__main__': # Parse command-line options. try: opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose"]) except getopt.GetoptError: usage_and_exit(1) verbose = 0 for opt, arg in opts: if opt in ("-h", "--help"): usage_and_exit(0) if opt in ("-v", "--verbose"): verbose = 1 if len(args) != 1: usage_and_exit(2) # Canonicalize the repository path. wc_path = svn.core.svn_path_canonicalize(args[0]) # Do the real work. try: do_status(wc_path, verbose) except svn.core.SubversionException, e: sys.stderr.write("Error (%d): %s\n" % (e.apr_err, e.message)) sys.exit(1) </code></pre>
0
2013-04-16T02:44:09Z
[ "python", "svn", "documentation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
1,449,170
<p>If MySQLdb's now distributed in a way that requires <code>setuptools</code>, your choices are either to download the latter (e.g. from <a href="http://pypi.python.org/pypi/setuptools">here</a>) or refactor MySQLdb's setup.py to bypass <code>setuptools</code> (maybe just importing <code>setup</code> and <code>Extension</code> from plain <code>distutils</code> instead might work, but you may also need to edit some of the <code>setup_*.py</code> files in the same directory).</p> <p>Depending on how your site's Python installation is configured, installing extensions for your own individual use without requiring sysadm rights may be hard, but it's never truly impossible if you have shell access. You'll need to tweak your Python's sys.path to start with a directory of your own that's your personal equivalent of the system-wide site pacages directory, e.g. by setting <code>PYTHONPATH</code> persistently in your own environment, and then manually place in said personal directory what normal installs would normally place in site-packages (and/or subdirectories thereof).</p>
15
2009-09-19T18:28:15Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
1,449,172
<p>This was sort of tricky for me too, I did the following which worked pretty well.</p> <ul> <li>Download the appropriate Python .egg for setuptools (ie, for Python 2.6, you can get it <a href="http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c9-py2.6.egg#md5=ca37b1ff16fa2ede6e19383e7b59245a">here</a>. Grab the correct one from the PyPI site <a href="http://pypi.python.org/pypi/setuptools">here</a>.)</li> <li><code>chmod</code> the egg to be executable: <code>chmod a+x [egg]</code> (ie, for Python 2.6, <code>chmod a+x setuptools-0.6c9-py2.6.egg</code>)</li> <li>Run <code>./[egg]</code> (ie, for Python 2.6, <code>./setuptools-0.6c9-py2.6.egg</code>)</li> </ul> <p>Not sure if you'll need to use sudo if you're just installing it for you current user. You'd definitely need it to install it for all users.</p>
5
2009-09-19T18:28:40Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
2,997,359
<pre><code>#!/usr/bin/env python import os import sys from **distutils.core** import setup, Extension if sys.version_info &lt; (2, 3): raise Error("Python-2.3 or newer is required") if os.name == "posix": from setup_posix import get_config else: # assume windows from setup_windows import get_config metadata, options = get_config() metadata['ext_modules'] = [Extension(sources=['_mysql.c'], **options)] metadata['long_description'] = metadata['long_description'].replace(r'\n', '') setup(**metadata) </code></pre>
2
2010-06-08T12:48:35Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
3,469,290
<p>Also, you can see the build dependencies in the file setup.cfg</p>
1
2010-08-12T15:23:48Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
4,319,894
<p>I resolved this issue on centos5.4 by running the following command to install setuptools</p> <p>yum install python-setuptools</p> <p>I hope that helps.</p>
11
2010-11-30T23:47:30Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
9,675,988
<p>After trying many suggestions, simply using <code>sudo apt-get install python-mysqldb</code> worked for me.</p> <p>More info: <a href="http://stackoverflow.com/questions/2952187/getting-error-loading-mysqldb-module-no-module-named-mysqldb-have-tried-pre">Getting &quot;Error loading MySQLdb module: No module named MySQLdb&quot; - have tried previously posted solutions</a></p>
27
2012-03-12T22:57:07Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
11,645,913
<p>I am experiencing the same problem right now. According to <a href="http://blog.flairpy.com/?p=19" rel="nofollow">this post</a> you need to have a C Compiler or GCC. I'll try to fix the problem by installing C compiler. I'll inform you if it works (we'll I guess you don't need it anymore, but I'll post the result anyway) :)</p>
1
2012-07-25T08:46:13Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
11,653,179
<p>When you need to install modules in Linux/Unix and you lack sudo / admin rights, one simple way around it is to use the user scheme installation, basically run </p> <p>"python setup.py install --user" from the command line in the folder of the module / library to be installed</p> <p>(see <a href="http://docs.python.org/install/index.html" rel="nofollow">http://docs.python.org/install/index.html</a> for further details)</p>
0
2012-07-25T15:25:17Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
11,662,181
<p>well installing C compiler or GCC didn't work but I found a way to successfully install mysqldb package </p> <p>kindly follow Mike schrieb's (Thanks to him) instructions <a href="http://www.velocityreviews.com/forums/t696557-how-to-install-setuptools-egg.html" rel="nofollow">here</a> . In my case, I used setuptools-0.6c11-py2.7.egg and setuptools-0.6c11 . Then download the executable file <a href="http://www.codegood.com/archives/129" rel="nofollow">here</a> then install that file. hope it helps :)</p>
1
2012-07-26T04:06:00Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
12,640,450
<p>@main:</p> <pre><code>$ su $ yum install MySQL-python </code></pre> <p>and it will be installed (MySQLdb).</p>
5
2012-09-28T12:55:09Z
[ "python", "mysql", "installation" ]
How to install MySQLdb package? (ImportError: No module named setuptools)
1,449,130
<p>I am trying to install MySQLdb package. I found the source code <a href="https://sourceforge.net/projects/mysql-python/files/">here</a>.</p> <p>I did the following:</p> <pre><code>gunzip MySQL-python-1.2.3c1.tar.gz tar xvf MySQL-python-1.2.3c1.tar cd MySQL-python-1.2.3c1 python setup.py build </code></pre> <p>As the result I got the following:</p> <pre><code>Traceback (most recent call last): File "setup.py", line 5, in ? from setuptools import setup, Extension ImportError: No module named setuptools </code></pre> <p>Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:</p> <pre><code>sudo python setup.py install </code></pre> <p>And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?</p> <p>Thank you.</p>
39
2009-09-19T18:07:44Z
22,069,709
<p>For Python 2.7, one can easily install using this </p> <blockquote> <p>apt-get install python2.7-mysqldb</p> </blockquote>
2
2014-02-27T13:17:09Z
[ "python", "mysql", "installation" ]
Simple object recognition
1,449,139
<p><strong>===SOLVED===</strong></p> <p>Thanks for your suggestions and comments. By working on the flood_fill algorithm given in <a href="http://www.apress.com/book/view/9781430218432" rel="nofollow">Beginning Python Visualization</a> book (Chapter 9 - Image Processing) I have implemented what I have wanted. I can count the objects, get enclosing rectangles for each object (therefore height and widths), and lastly can construct NumPy arrays or matrices for each of them. </p> <p>Although it is not an optimized approach it does what I want. The source code (lab2.py) and the png file (lab2-particles.png) that I use have been put under <a href="http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450" rel="nofollow">http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450</a>.</p> <p>You need NumPy and PIL installed, and matplotlib to see the histogram. Core of the code lies within the objfind function where the main recursive object search action occurs.</p> <p>One further update:</p> <p>SciPy's <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.label.html#scipy.ndimage.measurements.label" rel="nofollow">ndimage.label()</a> does exactly what I want, too.</p> <p>Cheers for <strong>David-Warde Farley</strong> and <strong>Zachary Pincus</strong> from the NumPy and SciPy mailing-lists for pointing this right into my eyes :)</p> <p><strong>=============</strong></p> <p>Hello,</p> <p>I have an image that contains the shadows of ice particles measured by a particle spectrometer. I want to be able to identify each object, so that I can later classify and use them further in my calculations.</p> <p>In essence, what I am willing to do is to simply implement a fuzzy selection tool where I can simply select each entity.</p> <p>How could I easily solve this problem? (Preferably using Python)</p> <p>Thanks. </p> <p>NOTE: In my question I am referring to each specific connected pixels as objects or entities. My intention to extract them and create NumPy array representations as shown below. (Here I am using the top-left object; if a pixel exist use 1's if not use 0's. This object's shape is 3 by 3 which correspondingly 3 pixel height by 3 pixel width. These are projections of real ice-particles onto 2D domain, under the assumption of their being spherical and equivalent radius is (height+width)/2, and later some scalings --from pixels to actual sizes and volume calculations will follow)</p> <pre><code>import numpy as np np.array([[1,1,1], [1,1,1], [0,0,1]]) array([[1, 1, 1], [1, 1, 1], [0, 0, 1]]) </code></pre> <p>Here is a section from the image which I am going to use.</p> <p><img src="http://img43.imageshack.us/img43/2327/particles.png" alt="screenshot" /></p>
6
2009-09-19T18:11:29Z
1,449,163
<p><a href="http://opencv.willowgarage.com/wiki/PythonInterface" rel="nofollow">OpenCV</a> has a Python interface that you might find useful. </p>
2
2009-09-19T18:23:26Z
[ "python", "image-processing", "computer-vision", "pattern-recognition" ]
Simple object recognition
1,449,139
<p><strong>===SOLVED===</strong></p> <p>Thanks for your suggestions and comments. By working on the flood_fill algorithm given in <a href="http://www.apress.com/book/view/9781430218432" rel="nofollow">Beginning Python Visualization</a> book (Chapter 9 - Image Processing) I have implemented what I have wanted. I can count the objects, get enclosing rectangles for each object (therefore height and widths), and lastly can construct NumPy arrays or matrices for each of them. </p> <p>Although it is not an optimized approach it does what I want. The source code (lab2.py) and the png file (lab2-particles.png) that I use have been put under <a href="http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450" rel="nofollow">http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450</a>.</p> <p>You need NumPy and PIL installed, and matplotlib to see the histogram. Core of the code lies within the objfind function where the main recursive object search action occurs.</p> <p>One further update:</p> <p>SciPy's <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.label.html#scipy.ndimage.measurements.label" rel="nofollow">ndimage.label()</a> does exactly what I want, too.</p> <p>Cheers for <strong>David-Warde Farley</strong> and <strong>Zachary Pincus</strong> from the NumPy and SciPy mailing-lists for pointing this right into my eyes :)</p> <p><strong>=============</strong></p> <p>Hello,</p> <p>I have an image that contains the shadows of ice particles measured by a particle spectrometer. I want to be able to identify each object, so that I can later classify and use them further in my calculations.</p> <p>In essence, what I am willing to do is to simply implement a fuzzy selection tool where I can simply select each entity.</p> <p>How could I easily solve this problem? (Preferably using Python)</p> <p>Thanks. </p> <p>NOTE: In my question I am referring to each specific connected pixels as objects or entities. My intention to extract them and create NumPy array representations as shown below. (Here I am using the top-left object; if a pixel exist use 1's if not use 0's. This object's shape is 3 by 3 which correspondingly 3 pixel height by 3 pixel width. These are projections of real ice-particles onto 2D domain, under the assumption of their being spherical and equivalent radius is (height+width)/2, and later some scalings --from pixels to actual sizes and volume calculations will follow)</p> <pre><code>import numpy as np np.array([[1,1,1], [1,1,1], [0,0,1]]) array([[1, 1, 1], [1, 1, 1], [0, 0, 1]]) </code></pre> <p>Here is a section from the image which I am going to use.</p> <p><img src="http://img43.imageshack.us/img43/2327/particles.png" alt="screenshot" /></p>
6
2009-09-19T18:11:29Z
1,449,173
<ol> <li><p>Scan every square (e.g. from the top-left, left-to-right, top-to-bottom)</p></li> <li><p>When you hit a blue square then:</p> <p>a. Record this square as a location of a new object</p> <p>b. Find all the other contiguous blue squares (e.g. by looking at the neighbours of this square, and the neighbours of those neighbours, etc.) and mark them as being part of the same object</p></li> <li><p>Continue to scan</p></li> <li><p>When you find another blue square, test to see whether it's part of a known object before going to step 2; alternatively in step 2b, erase any square after you've associated it with an object</p></li> </ol>
5
2009-09-19T18:29:19Z
[ "python", "image-processing", "computer-vision", "pattern-recognition" ]
Simple object recognition
1,449,139
<p><strong>===SOLVED===</strong></p> <p>Thanks for your suggestions and comments. By working on the flood_fill algorithm given in <a href="http://www.apress.com/book/view/9781430218432" rel="nofollow">Beginning Python Visualization</a> book (Chapter 9 - Image Processing) I have implemented what I have wanted. I can count the objects, get enclosing rectangles for each object (therefore height and widths), and lastly can construct NumPy arrays or matrices for each of them. </p> <p>Although it is not an optimized approach it does what I want. The source code (lab2.py) and the png file (lab2-particles.png) that I use have been put under <a href="http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450" rel="nofollow">http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450</a>.</p> <p>You need NumPy and PIL installed, and matplotlib to see the histogram. Core of the code lies within the objfind function where the main recursive object search action occurs.</p> <p>One further update:</p> <p>SciPy's <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.label.html#scipy.ndimage.measurements.label" rel="nofollow">ndimage.label()</a> does exactly what I want, too.</p> <p>Cheers for <strong>David-Warde Farley</strong> and <strong>Zachary Pincus</strong> from the NumPy and SciPy mailing-lists for pointing this right into my eyes :)</p> <p><strong>=============</strong></p> <p>Hello,</p> <p>I have an image that contains the shadows of ice particles measured by a particle spectrometer. I want to be able to identify each object, so that I can later classify and use them further in my calculations.</p> <p>In essence, what I am willing to do is to simply implement a fuzzy selection tool where I can simply select each entity.</p> <p>How could I easily solve this problem? (Preferably using Python)</p> <p>Thanks. </p> <p>NOTE: In my question I am referring to each specific connected pixels as objects or entities. My intention to extract them and create NumPy array representations as shown below. (Here I am using the top-left object; if a pixel exist use 1's if not use 0's. This object's shape is 3 by 3 which correspondingly 3 pixel height by 3 pixel width. These are projections of real ice-particles onto 2D domain, under the assumption of their being spherical and equivalent radius is (height+width)/2, and later some scalings --from pixels to actual sizes and volume calculations will follow)</p> <pre><code>import numpy as np np.array([[1,1,1], [1,1,1], [0,0,1]]) array([[1, 1, 1], [1, 1, 1], [0, 0, 1]]) </code></pre> <p>Here is a section from the image which I am going to use.</p> <p><img src="http://img43.imageshack.us/img43/2327/particles.png" alt="screenshot" /></p>
6
2009-09-19T18:11:29Z
1,449,176
<p>Looking at the image you provided, all you need to do next is to apply a simple <a href="http://en.wikipedia.org/wiki/Region%5Fgrowing" rel="nofollow">region growing algorithm</a>. If I were using MATLAB, I would use <strong><a href="http://www.mathworks.com/access/helpdesk/help/toolbox/images/bwlabel.html" rel="nofollow">bwlabel</a></strong>/<strong><a href="http://www.mathworks.com/access/helpdesk/help/toolbox/images/bwboundaries.html" rel="nofollow">bwboundaries</a></strong> functions. I believe there's an equivalent function somewhere in <em>numpy</em>, or use <em>OpenCV</em> with python wrappers as suggested by @kwatford</p>
3
2009-09-19T18:31:15Z
[ "python", "image-processing", "computer-vision", "pattern-recognition" ]
Simple object recognition
1,449,139
<p><strong>===SOLVED===</strong></p> <p>Thanks for your suggestions and comments. By working on the flood_fill algorithm given in <a href="http://www.apress.com/book/view/9781430218432" rel="nofollow">Beginning Python Visualization</a> book (Chapter 9 - Image Processing) I have implemented what I have wanted. I can count the objects, get enclosing rectangles for each object (therefore height and widths), and lastly can construct NumPy arrays or matrices for each of them. </p> <p>Although it is not an optimized approach it does what I want. The source code (lab2.py) and the png file (lab2-particles.png) that I use have been put under <a href="http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450" rel="nofollow">http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450</a>.</p> <p>You need NumPy and PIL installed, and matplotlib to see the histogram. Core of the code lies within the objfind function where the main recursive object search action occurs.</p> <p>One further update:</p> <p>SciPy's <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.label.html#scipy.ndimage.measurements.label" rel="nofollow">ndimage.label()</a> does exactly what I want, too.</p> <p>Cheers for <strong>David-Warde Farley</strong> and <strong>Zachary Pincus</strong> from the NumPy and SciPy mailing-lists for pointing this right into my eyes :)</p> <p><strong>=============</strong></p> <p>Hello,</p> <p>I have an image that contains the shadows of ice particles measured by a particle spectrometer. I want to be able to identify each object, so that I can later classify and use them further in my calculations.</p> <p>In essence, what I am willing to do is to simply implement a fuzzy selection tool where I can simply select each entity.</p> <p>How could I easily solve this problem? (Preferably using Python)</p> <p>Thanks. </p> <p>NOTE: In my question I am referring to each specific connected pixels as objects or entities. My intention to extract them and create NumPy array representations as shown below. (Here I am using the top-left object; if a pixel exist use 1's if not use 0's. This object's shape is 3 by 3 which correspondingly 3 pixel height by 3 pixel width. These are projections of real ice-particles onto 2D domain, under the assumption of their being spherical and equivalent radius is (height+width)/2, and later some scalings --from pixels to actual sizes and volume calculations will follow)</p> <pre><code>import numpy as np np.array([[1,1,1], [1,1,1], [0,0,1]]) array([[1, 1, 1], [1, 1, 1], [0, 0, 1]]) </code></pre> <p>Here is a section from the image which I am going to use.</p> <p><img src="http://img43.imageshack.us/img43/2327/particles.png" alt="screenshot" /></p>
6
2009-09-19T18:11:29Z
1,451,137
<p>I used to do this kind of analysis on micrographs and eventually put everything I needed into an image processing and analysis package written in C, driven via Tcl. (It worked with 512 x 512 images only, which explains why 512 crops up so often. There were images with pixels of various sizes allocated, but most of the work was done with 8-bit pixels, which explains why there is that business of 0xff and maximum meaningful count of 254 on an image.) </p> <p>Briefly, the 'zz' at the begining of the Tcl commands sends the remainder of the line to the package's parser which calls the appropriate C routine with the given arguments. Right after the 'zz' is an argument that indicates the input and output of the command. (There can be multiple inputs but only a single output.) 'r' indicates a 512 x 512 x 8-bit image. The third word is the name of the command to be invoked; 'graphs' marks up an image as described in the text below. So, 'zz rr graphs' means 'Call the ZZ parser; input an r image to the graphs command and get back an r image.' The rest of the Tcl command line specifies which of the pre-allocated images to use. (The 'g' image is an ROI, i.e., region-of-interest, image; almost all ZZ ops are done under ROI control.) So, 'r1 r1 g8' means 'Use r1 as input, use r1 as output (that is, mark up the input image itself), and do the operation wherever the corresponding pixel on image g8 --- that is, r8, used as an ROI --- is >0.</p> <p>I don't think it is available online anywhere, but if you want to pick through the source code or even compile the whole shebang, I'll be happy to send it to you. Here's an excerpt from the manual (but I think I see some errors in the manual at this late date --- that's embarrassing ...):</p> <p><strong>Example 6. Counting features.</strong></p> <p>Problem</p> <p>Counting is a common task. The items counted are called “features”, and it is usually necessary to prepare images carefully so that features correspond in a one-to-one way with things that are the real objects to be counted. Here, however, we ignore image preparation and consider, instead, the mechanics of counting. The first counting exercise is to find out how many features are on the images in the directory ./cells?</p> <p>Approach</p> <p>First, let us define “feature”. A feature is the largest group of “set” (non-zero) pixels all of which can be reached by travelling from one set pixel to another along north-south-east-west (up-down-right-left) routes, starting from a given set pixel. The zz command that detects and marks such features on an image is “zz rr graphs R:src R:dest G:ROI”, so called because the mathematical term for such a feature is a “graph”. If all the pixels on an image are set, then there is only a single graph on the image, but it contains 262144 pixels (512 * 512). If pixels are set and clear (equal to zero) in a checkerboard pattern, then there will be 131072 (512 * 512 / 2) graphs, but each will containing only one pixel. Briefly explained, “zz rr graphs” starts in the upper-left corner of an image and scans each succeeding row left to right until it finds a set pixel, then finds all the set pixels attached to that through north, south, east, or west borders (“4-connected”). It then sets all pixels in that graph to 1 (0x01). After finding and marking graph 1, it starts scanning again at the pixel after the one where it first discovered graph 1, this time ignoring any pixels that already belong to a graph. The first 254 graphs that it finds will be marked uniquely; all graphs found after that, however, will be marked with the value 255 (0xff) and so cannot be distinguished from each other. The key to being able to count any number of graphs accurately is to process each image in stages, that is, find the number of graphs on an image and, if the number is greater than 254, erase the 254 graphs just found, repeating the process until 254 or fewer graphs are found. The Tcl language provides the means to set up control of this operation.</p> <p>Let us begin to build the commands needed by reading a ZZ image file into an R image and detecting and marking the graphs. Before the processing loop, we declare and zero a variable to hold the total number of features in the image series. Within the processing loop, we begin by reading the image file into an R image and detecting and marking the graphs.</p> <pre><code>zz ur to $inDir/$img r1 zz rr graphs r1 r1 g8 </code></pre> <p>Next, we zero some variables to keep track of the counts, then use the “ra max” command to find out whether more than 254 graphs were detected.</p> <pre><code>set nGraphs [ zz ra max r1 a1 g1 ] </code></pre> <p>If nGraphs does equal 255, then the 254 accurately counted graphs should be added to the total, the graphs from 1 through 254 should be erased, and the count repeated for as many times as it takes to reduce the number of graphs below 255.</p> <pre><code>while {$nGraphs == 255} { incr sumGraphs 254 zz rbr lt r1 155 r1 g1 0 255 set sumGraphs 0 zz rr graphs r1 r1 g8 set nGraphs [ zz ra max r1 a1 g8 ] } </code></pre> <p>When the “while” loop exits, the variable nGraphs must hold a number less than 255, that is, a number of accurately counted graphs; this is added to the rising total of the number of features in the image series.</p> <pre><code>incr sumGraphs $nGraphs </code></pre> <p>After the processing loop, print out the total number of features found in the series.</p> <pre><code>puts “Total number of features in $inDir \ images $beginImg through $endImg is $sumGraphs.” </code></pre> <p>After the processing loop, print out the total number of features found in the series.</p>
3
2009-09-20T14:27:17Z
[ "python", "image-processing", "computer-vision", "pattern-recognition" ]
Simple object recognition
1,449,139
<p><strong>===SOLVED===</strong></p> <p>Thanks for your suggestions and comments. By working on the flood_fill algorithm given in <a href="http://www.apress.com/book/view/9781430218432" rel="nofollow">Beginning Python Visualization</a> book (Chapter 9 - Image Processing) I have implemented what I have wanted. I can count the objects, get enclosing rectangles for each object (therefore height and widths), and lastly can construct NumPy arrays or matrices for each of them. </p> <p>Although it is not an optimized approach it does what I want. The source code (lab2.py) and the png file (lab2-particles.png) that I use have been put under <a href="http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450" rel="nofollow">http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450</a>.</p> <p>You need NumPy and PIL installed, and matplotlib to see the histogram. Core of the code lies within the objfind function where the main recursive object search action occurs.</p> <p>One further update:</p> <p>SciPy's <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.label.html#scipy.ndimage.measurements.label" rel="nofollow">ndimage.label()</a> does exactly what I want, too.</p> <p>Cheers for <strong>David-Warde Farley</strong> and <strong>Zachary Pincus</strong> from the NumPy and SciPy mailing-lists for pointing this right into my eyes :)</p> <p><strong>=============</strong></p> <p>Hello,</p> <p>I have an image that contains the shadows of ice particles measured by a particle spectrometer. I want to be able to identify each object, so that I can later classify and use them further in my calculations.</p> <p>In essence, what I am willing to do is to simply implement a fuzzy selection tool where I can simply select each entity.</p> <p>How could I easily solve this problem? (Preferably using Python)</p> <p>Thanks. </p> <p>NOTE: In my question I am referring to each specific connected pixels as objects or entities. My intention to extract them and create NumPy array representations as shown below. (Here I am using the top-left object; if a pixel exist use 1's if not use 0's. This object's shape is 3 by 3 which correspondingly 3 pixel height by 3 pixel width. These are projections of real ice-particles onto 2D domain, under the assumption of their being spherical and equivalent radius is (height+width)/2, and later some scalings --from pixels to actual sizes and volume calculations will follow)</p> <pre><code>import numpy as np np.array([[1,1,1], [1,1,1], [0,0,1]]) array([[1, 1, 1], [1, 1, 1], [0, 0, 1]]) </code></pre> <p>Here is a section from the image which I am going to use.</p> <p><img src="http://img43.imageshack.us/img43/2327/particles.png" alt="screenshot" /></p>
6
2009-09-19T18:11:29Z
1,451,151
<p><a href="http://en.wikipedia.org/wiki/Connected%5FComponent%5FLabeling" rel="nofollow">Connected component analysis</a> may be what you are looking for.</p>
2
2009-09-20T14:32:23Z
[ "python", "image-processing", "computer-vision", "pattern-recognition" ]
Google app engine and python and objects that pass by value
1,449,257
<p>This is really a python language question, but its wrapped around a Google appengine specific problem.</p> <p>We have</p> <pre> class User( db.Model ) : email = db.StringProperty() name = db.StringProperty() password = db.StringProperty() # more fields.. </pre> <p>Because the user account is accessed so often, we keep a copy in session using <a href="http://gaeutilities.appspot.com/" rel="nofollow">gaeutilities</a> (as a bonus question, <em>is this bad on GAE?</em> I thought I'd relieve the db a bit.)</p> <pre> class UpdateProfile( webapp.RequestHandler ): def post( self ): # User posting update to his name self.session = sessions.Session() ####### # way#1: update the copy of the User object in SESSION, then .put() it self.session[ 'current_user' ].name = self.request.get( 'name' ) self.session[ 'current_user' ].put() # does not work. ####### ####### # way#2: make a copy of the User object in SESSION, then .put() it user = self.session[ 'current_user' ] user.name = self.request.get( 'name' ) user.put() # works to update the datastore, but the copy of user in self.session # is NOT UPDATED! <b>I thought Python was # pass-by-reference.</b> It is when you work with lists anyway. # Why isn't it "acting right" with this type of object?? ####### ####### # way#3: way that works. user = self.session[ 'current_user' ] user.name = self.request.get( 'name' ) user.put() self.session[ 'current_user' ] = user # works completely ####### </pre> <p>What is happening in each of these 3 cases? Why don't cases 1 and 2 work?</p>
2
2009-09-19T19:06:48Z
1,449,305
<p>I'm guessing: </p> <p>Putting objects in the Session means that the objects is serialized ( pickled usually ) and stored somewhere (disk, memory, db). When it is retrieved from the Session, a <em>new</em> object is created from serialized the old state.</p> <ul> <li>In the first example each <code>self.session[ 'current_user' ]</code> gives you a new object, one of which you update and the other is saved to the db.</li> <li>In the 2nd you get one object, save it to the DB but not in the session.</li> </ul> <p>Btw, Python does "call by sharing", but that has nothing to do with your problem ;-)</p>
3
2009-09-19T19:30:13Z
[ "python", "google-app-engine" ]
Google app engine and python and objects that pass by value
1,449,257
<p>This is really a python language question, but its wrapped around a Google appengine specific problem.</p> <p>We have</p> <pre> class User( db.Model ) : email = db.StringProperty() name = db.StringProperty() password = db.StringProperty() # more fields.. </pre> <p>Because the user account is accessed so often, we keep a copy in session using <a href="http://gaeutilities.appspot.com/" rel="nofollow">gaeutilities</a> (as a bonus question, <em>is this bad on GAE?</em> I thought I'd relieve the db a bit.)</p> <pre> class UpdateProfile( webapp.RequestHandler ): def post( self ): # User posting update to his name self.session = sessions.Session() ####### # way#1: update the copy of the User object in SESSION, then .put() it self.session[ 'current_user' ].name = self.request.get( 'name' ) self.session[ 'current_user' ].put() # does not work. ####### ####### # way#2: make a copy of the User object in SESSION, then .put() it user = self.session[ 'current_user' ] user.name = self.request.get( 'name' ) user.put() # works to update the datastore, but the copy of user in self.session # is NOT UPDATED! <b>I thought Python was # pass-by-reference.</b> It is when you work with lists anyway. # Why isn't it "acting right" with this type of object?? ####### ####### # way#3: way that works. user = self.session[ 'current_user' ] user.name = self.request.get( 'name' ) user.put() self.session[ 'current_user' ] = user # works completely ####### </pre> <p>What is happening in each of these 3 cases? Why don't cases 1 and 2 work?</p>
2
2009-09-19T19:06:48Z
1,461,932
<p>I'm the author of gaeutilities. I contacted Nick to talk about this, and he gave me some good ideas. I'll have a solution for this in the final 1.3 release.</p>
2
2009-09-22T18:51:53Z
[ "python", "google-app-engine" ]
Google app engine and python and objects that pass by value
1,449,257
<p>This is really a python language question, but its wrapped around a Google appengine specific problem.</p> <p>We have</p> <pre> class User( db.Model ) : email = db.StringProperty() name = db.StringProperty() password = db.StringProperty() # more fields.. </pre> <p>Because the user account is accessed so often, we keep a copy in session using <a href="http://gaeutilities.appspot.com/" rel="nofollow">gaeutilities</a> (as a bonus question, <em>is this bad on GAE?</em> I thought I'd relieve the db a bit.)</p> <pre> class UpdateProfile( webapp.RequestHandler ): def post( self ): # User posting update to his name self.session = sessions.Session() ####### # way#1: update the copy of the User object in SESSION, then .put() it self.session[ 'current_user' ].name = self.request.get( 'name' ) self.session[ 'current_user' ].put() # does not work. ####### ####### # way#2: make a copy of the User object in SESSION, then .put() it user = self.session[ 'current_user' ] user.name = self.request.get( 'name' ) user.put() # works to update the datastore, but the copy of user in self.session # is NOT UPDATED! <b>I thought Python was # pass-by-reference.</b> It is when you work with lists anyway. # Why isn't it "acting right" with this type of object?? ####### ####### # way#3: way that works. user = self.session[ 'current_user' ] user.name = self.request.get( 'name' ) user.put() self.session[ 'current_user' ] = user # works completely ####### </pre> <p>What is happening in each of these 3 cases? Why don't cases 1 and 2 work?</p>
2
2009-09-19T19:06:48Z
1,463,780
<p>Sorry, I'm new to this site, and I don't see where to comment on an answer?</p> <p>Anyway, I've fixed the specific issue that instigated the original post. While serialization of data is still suboptimal, happening on write, I have managed to make sure assigning model entities as items in a session will work as expected. Rather than get into rewriting the serialization (would be a major rewrite), I instead chose to detect when a model was being inserted as a session data item, and set a ReferenceProperty for it. This means that the model objects never have to get the overhead of being serialized at all.</p> <p>If the entity the ReferenceProperty is associated is deleted, the ReferenceProperty in the session will be deleted when you try to load it as well. This does mean you'll have to catch exceptions such as KeyError that are raised by Session, as a dictionary should. I hope this is intuitive enough, but am open to any comments. I'll check this page again a few times over the next several weeks.</p>
1
2009-09-23T03:11:48Z
[ "python", "google-app-engine" ]
How to install setuptools?
1,449,396
<p>I'm trying to install setuptools. When I run "sh setuptools-0.6c9-py2.4.egg" I get the following message:</p> <blockquote> <p>Permission denied: '/usr/lib/python2.4/site-packages/test-easy-install-26338.write-test'</p> </blockquote> <p>It is expectable, since I do not have root permissions on the system. Some how I came to the idea of creating a "Virtual" Python.</p> <p>I download "virtual-python.py" and run it using the site-wide Python. It creates "lib", "bin" and "include" sub-directories in my home-directory. In the end of the output of "virtual-python.py" I see the following message:</p> <blockquote> <p>You're now ready to download ez_setup.py, and run /home/myname/bin/python ez_setup.py</p> </blockquote> <p>I download this file and run it. But than I get the same error message:</p> <blockquote> <p>Permission denied: '/usr/lib/python2.4/site-packages/test-easy-install-925.write-test'</p> </blockquote> <p>OK. I use "prefix" to force ez_setup.py to write to the local directory:</p> <pre><code>/home/myname/bin/python ez_setup.py --prefix=~ </code></pre> <p>And then I get:</p> <blockquote> <ul> <li>You can set up the installation directory to support ".pth" files by<br /> using one of the approaches described here:</li> </ul> <p><a href="http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations">http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations</a></p> </blockquote> <p>So, I am redirected to the same page which I read before. So, I do not know what to do now. </p> <p>I also have another hint:</p> <blockquote> <ul> <li>You can add the installation directory to the PYTHONPATH environment variable. (It must then also be on PYTHONPATH whenever you run Python and want to use the package(s) you are installing.)</li> </ul> </blockquote> <p>But if I type:</p> <pre><code>PYTHONPATH=/home/myname/lib/python2.4/site-packages </code></pre> <p>I still get the same result as if Python does not see my environment variables.</p> <p>Can anybody, pleas, help me with that?</p>
5
2009-09-19T20:03:14Z
1,449,437
<p>Virtualenv comes with setuptools pre-installed, I believe. I know that it at least comes with <code>easy_install</code>. You should then be able to run:</p> <pre><code>/home/myname/bin/easy_install setuptools </code></pre> <p>This should install the newest version of setuptools on your virtualenv.</p>
1
2009-09-19T20:26:12Z
[ "python", "setuptools" ]
How to install setuptools?
1,449,396
<p>I'm trying to install setuptools. When I run "sh setuptools-0.6c9-py2.4.egg" I get the following message:</p> <blockquote> <p>Permission denied: '/usr/lib/python2.4/site-packages/test-easy-install-26338.write-test'</p> </blockquote> <p>It is expectable, since I do not have root permissions on the system. Some how I came to the idea of creating a "Virtual" Python.</p> <p>I download "virtual-python.py" and run it using the site-wide Python. It creates "lib", "bin" and "include" sub-directories in my home-directory. In the end of the output of "virtual-python.py" I see the following message:</p> <blockquote> <p>You're now ready to download ez_setup.py, and run /home/myname/bin/python ez_setup.py</p> </blockquote> <p>I download this file and run it. But than I get the same error message:</p> <blockquote> <p>Permission denied: '/usr/lib/python2.4/site-packages/test-easy-install-925.write-test'</p> </blockquote> <p>OK. I use "prefix" to force ez_setup.py to write to the local directory:</p> <pre><code>/home/myname/bin/python ez_setup.py --prefix=~ </code></pre> <p>And then I get:</p> <blockquote> <ul> <li>You can set up the installation directory to support ".pth" files by<br /> using one of the approaches described here:</li> </ul> <p><a href="http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations">http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations</a></p> </blockquote> <p>So, I am redirected to the same page which I read before. So, I do not know what to do now. </p> <p>I also have another hint:</p> <blockquote> <ul> <li>You can add the installation directory to the PYTHONPATH environment variable. (It must then also be on PYTHONPATH whenever you run Python and want to use the package(s) you are installing.)</li> </ul> </blockquote> <p>But if I type:</p> <pre><code>PYTHONPATH=/home/myname/lib/python2.4/site-packages </code></pre> <p>I still get the same result as if Python does not see my environment variables.</p> <p>Can anybody, pleas, help me with that?</p>
5
2009-09-19T20:03:14Z
1,449,541
<p>You have to activate your virtualenv first, else you just have a bunch of folders. Use the full path to the scripts in your virtual env's <code>bin</code> or do <code>source bin/activate</code></p>
1
2009-09-19T21:14:11Z
[ "python", "setuptools" ]
How to install setuptools?
1,449,396
<p>I'm trying to install setuptools. When I run "sh setuptools-0.6c9-py2.4.egg" I get the following message:</p> <blockquote> <p>Permission denied: '/usr/lib/python2.4/site-packages/test-easy-install-26338.write-test'</p> </blockquote> <p>It is expectable, since I do not have root permissions on the system. Some how I came to the idea of creating a "Virtual" Python.</p> <p>I download "virtual-python.py" and run it using the site-wide Python. It creates "lib", "bin" and "include" sub-directories in my home-directory. In the end of the output of "virtual-python.py" I see the following message:</p> <blockquote> <p>You're now ready to download ez_setup.py, and run /home/myname/bin/python ez_setup.py</p> </blockquote> <p>I download this file and run it. But than I get the same error message:</p> <blockquote> <p>Permission denied: '/usr/lib/python2.4/site-packages/test-easy-install-925.write-test'</p> </blockquote> <p>OK. I use "prefix" to force ez_setup.py to write to the local directory:</p> <pre><code>/home/myname/bin/python ez_setup.py --prefix=~ </code></pre> <p>And then I get:</p> <blockquote> <ul> <li>You can set up the installation directory to support ".pth" files by<br /> using one of the approaches described here:</li> </ul> <p><a href="http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations">http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations</a></p> </blockquote> <p>So, I am redirected to the same page which I read before. So, I do not know what to do now. </p> <p>I also have another hint:</p> <blockquote> <ul> <li>You can add the installation directory to the PYTHONPATH environment variable. (It must then also be on PYTHONPATH whenever you run Python and want to use the package(s) you are installing.)</li> </ul> </blockquote> <p>But if I type:</p> <pre><code>PYTHONPATH=/home/myname/lib/python2.4/site-packages </code></pre> <p>I still get the same result as if Python does not see my environment variables.</p> <p>Can anybody, pleas, help me with that?</p>
5
2009-09-19T20:03:14Z
1,452,826
<p>Just adding extra detail to what already have been said.</p> <ol> <li>Download <code>tar.gz</code> of the latest version of <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>.</li> <li>Unpack it.</li> <li>You don't even need to install it, just run <code>virtualenv.py</code>, for example:<br> <code>virtualenv-1.3.3/virtualenv.py mypyenv</code><br> <code>mypyenv</code> virtual Python environment will be created in your current directory and it will contain <code>easy_install</code> ready to use.</li> <li>Activate it:<br><code>source mypyenv/bin/activate</code><br>or on Windows do:<br> <code>mypyenv\Scripts\activate.bat</code><br> Now, your PATH is set to point at Python executables under <code>mypyenv</code>. From this shell session, you will be able to <code>easy_install</code> whatever you want, and resulting stuff will be installed in the guts of <code>mypyenv</code> instead of your default Python location, thus obviating any need for admin privileges.</li> </ol> <p><em>OS X Snow Leopard caveat:</em><br> For some reason, <code>virtualenv-1.3.3</code> does not play well with built-in Python under <code>/System/Frameworks</code>. I had to build a separate version of Python from source, and installed it under <code>/usr/local/python_2_6_2</code>.<br>With that done, I used <code>--python /usr/local/python_2_6_2/bin/python</code> option with virtualenv.</p>
8
2009-09-21T03:54:43Z
[ "python", "setuptools" ]
How do I install Python packages on Windows?
1,449,494
<p>I'm having a hard time setting up python packages. EasyInstall from <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> is supposed to help that, but they don't have an executable for Python 2.6.</p> <p>For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!</p>
89
2009-09-19T20:52:58Z
1,449,498
<p>You don't need the executable for setuptools. You can download the source code, unpack it, traverse to the downloaded directory and run <code>python setup.py install</code> in the command prompt</p>
20
2009-09-19T20:54:53Z
[ "python", "pip" ]
How do I install Python packages on Windows?
1,449,494
<p>I'm having a hard time setting up python packages. EasyInstall from <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> is supposed to help that, but they don't have an executable for Python 2.6.</p> <p>For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!</p>
89
2009-09-19T20:52:58Z
1,449,704
<p><a href="http://web.archive.org/web/20120625104458/http://blog.sadphaeton.com/2009/01/20/python-development-windows-part-2-installing-easyinstallcould-be-easier.html">This</a> is a good tutorial on how to get <code>easy_install</code> on windows. The short answer: add <code>C:\Python26\Scripts</code> (or whatever python you have installed) to your PATH. </p>
51
2009-09-19T22:40:01Z
[ "python", "pip" ]
How do I install Python packages on Windows?
1,449,494
<p>I'm having a hard time setting up python packages. EasyInstall from <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> is supposed to help that, but they don't have an executable for Python 2.6.</p> <p>For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!</p>
89
2009-09-19T20:52:58Z
1,455,501
<p>You can also just download and run ez_setup.py, though the SetupTools documentation no longer suggests this. Worked fine for me as recently as 2 weeks ago.</p>
0
2009-09-21T16:40:12Z
[ "python", "pip" ]
How do I install Python packages on Windows?
1,449,494
<p>I'm having a hard time setting up python packages. EasyInstall from <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> is supposed to help that, but they don't have an executable for Python 2.6.</p> <p>For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!</p>
89
2009-09-19T20:52:58Z
13,445,682
<p>As I <a href="http://stackoverflow.com/questions/11453866/python-modules-names-vs-the-name-of-the-actual-package">wrote elsewhere</a></p> <blockquote> <p>Packaging in Python is dire. The root cause is that the language ships without a package manager. </p> <p>Fortunately, there is one package manager for Python, called <a href="http://www.pip-installer.org/en/latest/index.html">Pip</a>. Pip is inspired by Ruby's Gem, but lacks some features. Ironically, Pip itself is <a href="http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows">complicated to install</a>. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming. </p> </blockquote> <hr> <p>So the right thing to do is to install pip. However if you can't be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p> <p>In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.</p>
11
2012-11-18T23:22:03Z
[ "python", "pip" ]
How do I install Python packages on Windows?
1,449,494
<p>I'm having a hard time setting up python packages. EasyInstall from <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> is supposed to help that, but they don't have an executable for Python 2.6.</p> <p>For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!</p>
89
2009-09-19T20:52:58Z
15,626,784
<p>The <a href="http://stackoverflow.com/a/1449704/1438393">accepted answer</a> is outdated. So first, <a href="https://pypi.python.org/pypi/pip"><code>pip</code></a> is preferred over <code>easy_install</code>, (<a href="http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install">Why use pip over easy_install?</a>). Then follow these steps to install <code>pip</code> on Windows, it's quite easy.</p> <ol> <li><p>Install <a href="https://pypi.python.org/pypi/setuptools#installation-instructions"><code>setuptools</code></a>:</p> <pre><code>curl https://bootstrap.pypa.io/ez_setup.py | python </code></pre></li> <li><p>Install <a href="http://www.pip-installer.org/en/latest/installing.html"><code>pip</code></a>:</p> <pre><code>curl https://bootstrap.pypa.io/get-pip.py | python </code></pre></li> <li><p>Optionally, you can add the path to your environment so that you can use <code>pip</code> anywhere. It's somewhere like <code>C:\Python33\Scripts</code>.</p></li> </ol>
121
2013-03-25T23:34:12Z
[ "python", "pip" ]
How do I install Python packages on Windows?
1,449,494
<p>I'm having a hard time setting up python packages. EasyInstall from <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> is supposed to help that, but they don't have an executable for Python 2.6.</p> <p>For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!</p>
89
2009-09-19T20:52:58Z
17,430,135
<p>I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. <a href="http://cli.learncodethehardway.org/book/" rel="nofollow">This</a> can help you get started with it.</p> <ul> <li>Firstly, you'll need to add python installation to your PATH variable. <a href="http://superuser.com/questions/608892/changing-windows-7-path-avriable">This</a> should help.</li> <li>You need to download the package in zip format that you are trying to install and unzip it. If it is some odd zip format use 7Zip and it should be extracted.</li> <li>Navigate to the directory extracted with setup.py using Windows Powershell (Use link for it if you have problems)</li> <li>Run the command <code>python setup.py install</code></li> </ul> <p>That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.</p>
2
2013-07-02T15:53:04Z
[ "python", "pip" ]
How do I install Python packages on Windows?
1,449,494
<p>I'm having a hard time setting up python packages. EasyInstall from <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> is supposed to help that, but they don't have an executable for Python 2.6.</p> <p>For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!</p>
89
2009-09-19T20:52:58Z
23,833,666
<p>Newer versions of Python for Windows come with the <em>pip</em> package manager. <a href="https://pip.pypa.io/en/latest/installing/">(source)</a></p> <blockquote> <p>pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4</p> </blockquote> <p>Use that to install packages:</p> <pre><code>cd C:/Python/Scripts/ pip.exe install &lt;package-name&gt; </code></pre>
36
2014-05-23T15:56:04Z
[ "python", "pip" ]
How to convert an NSDictionary to a Python dict?
1,449,620
<p>I have a plugin written entirely in Python using PyObjC whose core classes I need to convert to Objective-C. One of them basically just loads up a Python module and executes a specific function, passing it keyword arguments. In PyObjC, this was extremely.</p> <p>However, I'm having difficulty figuring out how to do the same thing using the Python C API. In particular, I'm unsure how best to convert an NSDictionary (which might hold integers, strings, booleans, or all of the above) into a format that I can then pass on to Python as keyword arguments.</p> <p>Anyone have pointers on how to accomplish something like this? Thanks in advance!</p> <p><strong>Edit</strong>: just to clarify, I'm converting my existing class which was formerly Python into Objective-C, and am having trouble figuring out how to move from an NSDictionary in Objective-C to a Python dictionary I can pass on when I invoke the remaining Python scripts. The Objective-C class is basically just a Python loader, but I'm unfamiliar with the Python C API and am having trouble figuring out where to look for examples or functions that will help me.</p>
2
2009-09-19T21:47:03Z
1,449,948
<p>Oh, looks like I misunderstood your question. Well, going the other direction isn't terribly different. This should be (as least a start of) the function you're looking for (I haven't tested it thoroughly though, so beware of the bugs):</p> <pre><code>// Returns a new reference PyObject *ObjcToPyObject(id object) { if (object == nil) { // This technically doesn't need to be an extra case, // but you may want to differentiate it for error checking return NULL; } else if ([object isKindOfClass:[NSString class]]) { return PyString_FromString([object UTF8String]); } else if ([object isKindOfClass:[NSNumber class]]) { // You could probably do some extra checking here if you need to // with the -objCType method. return PyLong_FromLong([object longValue]); } else if ([object isKindOfClass:[NSArray class]]) { // You may want to differentiate between NSArray (analagous to tuples) // and NSMutableArray (analagous to lists) here. Py_ssize_t i, len = [object count]; PyObject *list = PyList_New(len); for (i = 0; i &lt; len; ++i) { PyObject *item = ObjcToPyObject([object objectAtIndex:i]); NSCAssert(item != NULL, @"Can't add NULL item to Python List"); // Note that PyList_SetItem() "steals" the reference to the passed item. // (i.e., you do not need to release it) PyList_SetItem(list, i, item); } return list; } else if ([object isKindOfClass:[NSDictionary class]]) { PyObject *dict = PyDict_New(); for (id key in object) { PyObject *pyKey = ObjcToPyObject(key); NSCAssert(pyKey != NULL, @"Can't add NULL key to Python Dictionary"); PyObject *pyItem = ObjcToPyObject([object objectForKey:key]); NSCAssert(pyItem != NULL, @"Can't add NULL item to Python Dictionary"); PyDict_SetItem(dict, pyKey, pyItem); Py_DECREF(pyKey); Py_DECREF(pyItem); } return dict; } else { NSLog(@"ObjcToPyObject() could not convert Obj-C object to PyObject."); return NULL; } } </code></pre> <p>You may also want to take a look at the <a href="http://docs.python.org/c-api/index.html" rel="nofollow">Python/C API Reference manual</a> if you haven't already.</p>
2
2009-09-20T00:38:54Z
[ "python", "objective-c", "pyobjc" ]
PIL not rendering fonts uniformly across machines
1,449,663
<p>I wrote some code that spits out an image. The code ran on my local machine yields this image:</p> <p><img src="http://img32.yfrog.com/img32/9476/local.png" alt="local" title="" /></p> <p>and on my webhost, it looks like this:</p> <p><img src="http://img32.imageshack.us/img32/858/hoste.png" alt="host" title="" /></p> <p>As you can see they are different. The top is much nicer. Both are using the same code, and the same font file (VeraMoBd.ttf), the same version of PIL (1.1.6), and the same Python version (2.6).</p> <p>I googled around and there doesn't seem to be any kind of global settings relating to how PIL renders fonts... What could be causing different results?</p>
2
2009-09-19T22:14:29Z
1,449,843
<p>I would <em>guess</em> that the top image was rendered with the TrueType hinting bytecode VM enabled, where the bottom was using only FreeType's auto-hinting. (Personally I prefer the bottom!)</p> <p>There are, unfortunately, <a href="http://freetype.org/patents.html" rel="nofollow">software patent</a> issues which mean the hinting bytecode feature is not available on all binary builds. This is why it's not a simple run-time feature you can enable and disable, but something that is decided at compile-time. If you compile your own copy of FreeType you can enable the feature by <code>#define</code>-ing the flag TT_CONFIG_OPTION_BYTECODE_INTERPRETER in <code>config/ftoption.h</code> — if your lawyer reckons it's a good idea.</p>
4
2009-09-19T23:54:51Z
[ "python", "python-imaging-library" ]
Converting 2.5 byte comparisons to 3
1,449,791
<p>I'm trying to convert a 2.5 program to 3.</p> <p>Is there a way in python 3 to change a byte string, such as b'\x01\x02' to a python 2.5 style string, such as '\x01\x02', so that string and byte-by-byte comparisons work similarly to 2.5? I'm reading the string from a binary file.</p> <p>I have a 2.5 program that reads bytes from a file, then compares or processes each byte or combination of bytes with specified constants. To run the program under 3, I'd like to avoid changing all my constants to bytes and byte strings ('\x01' to b'\x01'), then dealing with issues in 3 such as:</p> <pre><code>a = b'\x01' b = b'\x02' </code></pre> <p>results in</p> <pre><code>(a+b)[0] != a </code></pre> <p>even though similar operation work in 2.5. I have to do (a+b)[0] == ord(a), while a+b == b'\x01\x02' works fine. (By the way, what do I do to (a+b)[0] so it equals a?)</p> <p>Unpacking structures is also an issue.</p> <p>Am I missing something simple?</p>
2
2009-09-19T23:32:17Z
1,449,886
<p>Bytes is an immutable sequence of integers (in the range 0&lt;= to &lt;256), therefore when you're accessing <code>(a+b)[0]</code> you're getting back an integer, exactly the same one you'd get by accessing <code>a[0]</code>. so when you're comparing sequence <code>a</code> to an integer <code>(a+b)[0]</code>, they're naturally different.</p> <p>using the slice notation you could however get a sequence back:</p> <pre><code>&gt;&gt;&gt; (a+b)[:1] == a # 1 == len(a) ;) True </code></pre> <p>because slicing returns bytes object.</p> <p>I would also advised to run 2to3 utility (it needs to be run with py2k) to convert some code automatically. It won't solve all your problems, but it'll help a lot.</p>
3
2009-09-20T00:12:10Z
[ "python", "python-3.x" ]
Python TurtleGraphics - Making a randomly moving turtle?
1,449,826
<p>I'm trying to create a randomly moving turtle here by following these steps in a function I've called drunk_turtle():</p> <p>Repeat the following as many times as you like:</p> <ul> <li>Randomly choose an integer, called rand_num, from -1 to 1 (i.e. randomly set rand_num to be -1, 0, or 1)</li> <li>Make the turtle turn right rand_num * 90 degrees;</li> <li>Go forward 5, 10, or 15 --- choose this value at random. 5 = 1*5, 10 = 2*5, 15 = 3*5, ...</li> </ul> <p>How do I make code that does this? I don't really get how to get my random integer or get it to pick randomly 5, 10, or 15. Any help is appreciated. Thanks!</p>
0
2009-09-19T23:48:08Z
1,449,866
<p>You can find all of that information in <a href="http://docs.python.org/library/random.html" rel="nofollow">the Python random manual</a>.</p> <blockquote> <p><code>random.randint(a, b)</code></p> <pre><code>Return a random integer N such that a &lt;= N &lt;= b. </code></pre> </blockquote> <p>So you would do <code>random.randint(-1,1)</code> to get a number from -1, 0, or 1.</p> <p>To get 5, 10, or 15, just do <code>5 * random.randint(1,3)</code>.</p> <p>If you had a more complicated set of numbers to choose from -- say (6, 25, or 33) -- you can do <code>random.choice([6, 25, 33])</code>.</p>
1
2009-09-20T00:02:47Z
[ "python" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
1,449,945
<p>The file <code>hooks/pre-commit</code> in your repository is a script or program which will be executed before a successful commit. Simply make this a script which updates your file with the proper version number as it is being committed (the revision number is passed to your script as it's run). Here's a tutorial with an example of writing a pre-commit hook: <a href="http://wordaligned.org/articles/a-subversion-pre-commit-hook" rel="nofollow">http://wordaligned.org/articles/a-subversion-pre-commit-hook</a></p>
4
2009-09-20T00:38:10Z
[ "python", "svn", "revision" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
1,449,949
<p>Check out <a href="http://pysvn.tigris.org/" rel="nofollow">pysvn</a>. it exposes extensions in Python for Subversion runtime functionality.</p>
3
2009-09-20T00:39:00Z
[ "python", "svn", "revision" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
1,449,950
<p>There's a snippet of code in Django that allows you to do this, I'd recommend looking at it. <a href="http://code.djangoproject.com/browser/django/trunk/django/utils/version.py" rel="nofollow">http://code.djangoproject.com/browser/django/trunk/django/utils/version.py</a></p>
4
2009-09-20T00:39:21Z
[ "python", "svn", "revision" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
1,450,760
<p>I do this by simply running a small script when building my project. The script just calls svn info in combination with sed to get out the bare revision data and injects that number into the revision.txt file. </p> <p>The Hudson build server makes it even easier as it sets the SVN revision number as an environment variable right before invoking your Build scripts.</p>
3
2009-09-20T10:46:38Z
[ "python", "svn", "revision" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
1,454,120
<p>I'm not sure about the Python specifics, but if put the string $Revision$ into your file somewhere and you have enable-auto-props=true in your SVN config, it'll get rewritten to something like $Revision: 144$. You could then parse this in your script.</p> <p>There are <a href="http://svnbook.red-bean.com/en/1.1/ch07s02.html#svn-ch-7-sect-2.3.4">a number of property keywords you can use in this way</a>.</p> <p>This won't have any overhead, e.g. querying the SVN repo, because the string is hard-coded into your file on commit or update.</p> <p>I'm not sure how you'd parse this in Python but in PHP I'd do:</p> <pre><code>$revString = '$Revision: 144$'; if(preg_match('/: ([0-9]+)\$/', $revString, $matches) { echo 'Revision is ' . $matches[1]; } </code></pre>
24
2009-09-21T11:43:56Z
[ "python", "svn", "revision" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
1,458,623
<p>I find the when it is run section slightly ambiguous - when it is run from where ? From an SVN checkout or from released code ? All the solutions work on injecting the SVN version somehow into the Python source or somewhere in the repository in a separate version file.</p> <p>The version file is changed on fresh checkouts, so clean checkouts need to be done before distribution. So my question of where the program is being run remains.</p>
1
2009-09-22T07:32:22Z
[ "python", "svn", "revision" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
1,812,153
<p>Similar to, but a little more pythonic than the PHP answer; put this in your module's <code>__init__.py</code>:</p> <pre><code>__version__ = filter(str.isdigit, "$Revision: 13 $") </code></pre> <p>and make sure you add the Revision property:</p> <pre><code>svn propset svn:keywords Revision __init__.py </code></pre>
13
2009-11-28T10:06:25Z
[ "python", "svn", "revision" ]
Getting SVN revision number into a program automatically
1,449,935
<p>I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)</p>
16
2009-09-20T00:33:45Z
25,541,266
<p>Or you can do like this:</p> <pre><code>import re,subprocess svn_info = subprocess.check_output("svn info") print (re.search(ur"Revision:\s\d+", svn_info)).group() </code></pre> <p>it prints <code>"Revision: 2874"</code> in my project</p> <p>Or like this:</p> <pre><code>print (subprocess.check_output("svnversion")).split(":")[0] </code></pre> <p>it prints <code>"2874"</code> in my project</p>
2
2014-08-28T05:22:27Z
[ "python", "svn", "revision" ]
Python TurtleGraphics - Smoothing out random walks?
1,449,990
<p>I need some help with this question relating to TurtleGraphics in Python:</p> <p>A small detail of tipsy_turtle() is that when the turtle turns 90 degrees it immediately "jumps" to the new direction. This makes its movement seem jagged. It might look better if the turtle moved smoothly when turning. So, for this question, write a function called smooth_tipsy_turtle() that is the same as tipsy_turtle(), except instead of using the turtle.right(d) function, write a brand new function called smooth_right(d) that works as follows:</p> <pre><code> - If d is negative then - repeat the following -d times: - turn left 1 using the ordinary turtle.left command - Otherwise, repeat the following d times: - turn right 1 using the ordinary turtle.right command </code></pre> <p>Here is my original function to get the random turtle movement:</p> <pre><code>def tipsy_turtle(num_steps): turtle.reset() for step in range(num_steps): rand_num = random.randint(-1, 1) turtle.right(rand_num * 90) turtle.forward(5 * random.randint(1, 3)) </code></pre> <p>So, how would I go about making this work? I tried adding:</p> <pre><code> if rand_num*90 &lt; 0: for step in range(rand_num*90): turtle.left(rand_num*90) else: turtle.right(rand_num*90) </code></pre> <p>But it didn't really work out and I don't know what I did wrong. Thanks!</p>
2
2009-09-20T01:03:37Z
1,449,996
<p>Hopefully this sample clears up what went wrong in your example -- you performed either <code>rand_num*90*rand_num*90</code> left turns, or <code>rand_num*90</code> right turns!</p> <pre><code>if rand_num &lt; 0: # don't need to multiply by 90 here - it's either +ve or -ve. for step in xrange(90): # xrange is preferred over range in situations like this turtle.left(rand_num) # net result is 90 left turns in rand_num direction else: for step in xrange(90): turtle.right(rand_num) </code></pre> <p>Or you could write this as:</p> <pre><code>for step in xrange(90): if rand_num &lt; 0: turtle.left(rand_num) else: turtle.right(rand_num) </code></pre> <p>For code like this, it's really a matter of preference.</p>
2
2009-09-20T01:12:53Z
[ "python" ]
Python TurtleGraphics - Smoothing out random walks?
1,449,990
<p>I need some help with this question relating to TurtleGraphics in Python:</p> <p>A small detail of tipsy_turtle() is that when the turtle turns 90 degrees it immediately "jumps" to the new direction. This makes its movement seem jagged. It might look better if the turtle moved smoothly when turning. So, for this question, write a function called smooth_tipsy_turtle() that is the same as tipsy_turtle(), except instead of using the turtle.right(d) function, write a brand new function called smooth_right(d) that works as follows:</p> <pre><code> - If d is negative then - repeat the following -d times: - turn left 1 using the ordinary turtle.left command - Otherwise, repeat the following d times: - turn right 1 using the ordinary turtle.right command </code></pre> <p>Here is my original function to get the random turtle movement:</p> <pre><code>def tipsy_turtle(num_steps): turtle.reset() for step in range(num_steps): rand_num = random.randint(-1, 1) turtle.right(rand_num * 90) turtle.forward(5 * random.randint(1, 3)) </code></pre> <p>So, how would I go about making this work? I tried adding:</p> <pre><code> if rand_num*90 &lt; 0: for step in range(rand_num*90): turtle.left(rand_num*90) else: turtle.right(rand_num*90) </code></pre> <p>But it didn't really work out and I don't know what I did wrong. Thanks!</p>
2
2009-09-20T01:03:37Z
1,450,067
<p>You might be able to do without the conditional for left-vs-right. I don't have python syntax down, so here's pseudocode</p> <pre><code>turtle left randomly generated value 0 to 90 turtle right randomly generated value 0 to 90 turtle forward some amount </code></pre> <p>I.e., generate a random angle and turn left that much, then generate another random angle and turn right by that much. This way you don't have to worry about generating or dealing with negative randoms. You can keep all the random angles positive, and the combination of a left followed by a right effectively does a subtraction for you which gives a nice gaussian distribution to the changes in direction. </p>
0
2009-09-20T01:50:55Z
[ "python" ]
Python TurtleGraphics - Smoothing out random walks?
1,449,990
<p>I need some help with this question relating to TurtleGraphics in Python:</p> <p>A small detail of tipsy_turtle() is that when the turtle turns 90 degrees it immediately "jumps" to the new direction. This makes its movement seem jagged. It might look better if the turtle moved smoothly when turning. So, for this question, write a function called smooth_tipsy_turtle() that is the same as tipsy_turtle(), except instead of using the turtle.right(d) function, write a brand new function called smooth_right(d) that works as follows:</p> <pre><code> - If d is negative then - repeat the following -d times: - turn left 1 using the ordinary turtle.left command - Otherwise, repeat the following d times: - turn right 1 using the ordinary turtle.right command </code></pre> <p>Here is my original function to get the random turtle movement:</p> <pre><code>def tipsy_turtle(num_steps): turtle.reset() for step in range(num_steps): rand_num = random.randint(-1, 1) turtle.right(rand_num * 90) turtle.forward(5 * random.randint(1, 3)) </code></pre> <p>So, how would I go about making this work? I tried adding:</p> <pre><code> if rand_num*90 &lt; 0: for step in range(rand_num*90): turtle.left(rand_num*90) else: turtle.right(rand_num*90) </code></pre> <p>But it didn't really work out and I don't know what I did wrong. Thanks!</p>
2
2009-09-20T01:03:37Z
1,450,351
<p>I guess I'll venture an answer even though I am not completely sure what you want (see my comment to the question, and don't be surprised if I edit this answer as appropriate!).</p> <p>Assuming you want the turtle to turn some number of degrees at each step, not necessarily 90, but not more than 90, then simply use <code>rand_num = random.randint(-90, 90)</code> and then <code>turtle.right(rand_num)</code>.</p>
0
2009-09-20T05:17:56Z
[ "python" ]
Is there any module that allows Django/Python to work with gnupg?
1,450,036
<p>I was wondering if there's any django module, or in such case any python module, that will allow me to create my own application to manage the creation, administration, etc of GnuPG keys, as well as the ability to sign and encrypt documents through this application?</p> <p>If there's no such module, how can I do that?</p> <p>Thank you.</p>
2
2009-09-20T01:33:22Z
1,450,052
<p><a href="http://py-gnupg.sourceforge.net/" rel="nofollow">GnuPGInterface</a> can <a href="http://sourceforge.net/docman/display%5Fdoc.php?docid=5499&amp;group%5Fid=29555" rel="nofollow">do all of that</a> -- it's essentially a Python wrapper around the GnuPG program.</p> <p><a href="http://pyme.sourceforge.net/" rel="nofollow">PyMe</a> might be easier to use as it is designed to wrap around GPGME (ME = Made Easy).</p> <p>From <a href="http://pyme.sourceforge.net/doc/pyme/index.html" rel="nofollow">the PyME features page</a>:</p> <blockquote> <ul> <li><p>Ability to sign, encrypt, decrypt, and verify data.</p></li> <li><p>Ability to list keys, export and import keys, and manage the keyring.</p></li> </ul> </blockquote>
2
2009-09-20T01:40:03Z
[ "python", "django", "gnupg" ]
Is there any module that allows Django/Python to work with gnupg?
1,450,036
<p>I was wondering if there's any django module, or in such case any python module, that will allow me to create my own application to manage the creation, administration, etc of GnuPG keys, as well as the ability to sign and encrypt documents through this application?</p> <p>If there's no such module, how can I do that?</p> <p>Thank you.</p>
2
2009-09-20T01:33:22Z
1,987,745
<p>I wrote a Django app <a href="http://code.google.com/p/django-email-extras/" rel="nofollow">django-email-extras</a> that does exactly what you're looking for. It lets users manage GPG keys via the Django admin and encrypts all mail to recipients with valid keys and includes support for multi-part templated emails with attachments.</p>
4
2010-01-01T02:38:57Z
[ "python", "django", "gnupg" ]
Which queue is most appropriate?
1,450,038
<p>I'm building a mobile photo sharing site in Python similar to TwitPic and have been exploring various queues to handle the image processing. I've looked into RabbitMQ and ActiveMQ but I'm thinking that there is a better solution for my use case. I'm looking for something a little more lightweight. I'm open to any suggestions.</p>
2
2009-09-20T01:33:24Z
1,450,046
<p>You could write a daemon that uses python's built-in <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow">multiprocessing</a> library and its <a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.Queue" rel="nofollow">Queue</a>.</p> <p>All you should have to do is set up a pool of workers, and have them wait on jobs from the Queue. Your main process can dump new jobs into the Queue, and you're good to go.</p>
2
2009-09-20T01:38:18Z
[ "python", "queue" ]
Which queue is most appropriate?
1,450,038
<p>I'm building a mobile photo sharing site in Python similar to TwitPic and have been exploring various queues to handle the image processing. I've looked into RabbitMQ and ActiveMQ but I'm thinking that there is a better solution for my use case. I'm looking for something a little more lightweight. I'm open to any suggestions.</p>
2
2009-09-20T01:33:24Z
1,450,105
<p>Are you considering single machine architecture, or a cluster of machines? Forwarding the image to an available worker process on the same machine or a different machine isn't profoundly different, particularly if you use TCP sockets. Knowing what workers are available, spawning more if necessary and the resources are available, having a fail-safe mechanism if a worker crashes, etc, gradually make the problem more complicated.</p> <p>It could be something as simple as using httplib to push the image to a private server running Apache or twisted and a collection of cgi applications. When you add another server, round robin the request amongst them.</p>
0
2009-09-20T02:14:49Z
[ "python", "queue" ]
Which queue is most appropriate?
1,450,038
<p>I'm building a mobile photo sharing site in Python similar to TwitPic and have been exploring various queues to handle the image processing. I've looked into RabbitMQ and ActiveMQ but I'm thinking that there is a better solution for my use case. I'm looking for something a little more lightweight. I'm open to any suggestions.</p>
2
2009-09-20T01:33:24Z
1,450,118
<p><a href="http://gearman.org/" rel="nofollow">Gearman</a> is good in that it optionally allows you to synchronize multiple jobs executed on multiple workers.</p> <p>I've used <a href="http://xph.us/software/beanstalkd/" rel="nofollow">beanstalkd</a> successfully in a few high-volume applications.</p> <p>The latter is better-suited to async jobs, and the former gives you more flexibility when you'd like to block on job execution.</p>
1
2009-09-20T02:24:21Z
[ "python", "queue" ]
Delete many elements of list (python)
1,450,111
<p>I have a list L.</p> <p>I can delete element i by doing:</p> <pre><code>del L[i] </code></pre> <p>But what if I have a set of non contiguous indexes to delete?</p> <pre><code>I=set([i1, i2, i3,...]) </code></pre> <p>Doing:</p> <pre><code>for i in I: del L[i] </code></pre> <p>Won't work.</p> <p>Any ideas?</p>
10
2009-09-20T02:18:34Z
1,450,120
<pre><code>for i in I: del L[i] </code></pre> <p>won't work, because (depending on the order) you may invalidate the iterator -- this will usually show up as some items which you intended to delete remaining in the list.</p> <p>It's always safe to delete items from the list in the reverse order of their indices. The easiest way to do this is with sorted():</p> <pre><code>for i in sorted(I, reverse=True): del L[i] </code></pre>
7
2009-09-20T02:25:05Z
[ "python", "list" ]
Delete many elements of list (python)
1,450,111
<p>I have a list L.</p> <p>I can delete element i by doing:</p> <pre><code>del L[i] </code></pre> <p>But what if I have a set of non contiguous indexes to delete?</p> <pre><code>I=set([i1, i2, i3,...]) </code></pre> <p>Doing:</p> <pre><code>for i in I: del L[i] </code></pre> <p>Won't work.</p> <p>Any ideas?</p>
10
2009-09-20T02:18:34Z
1,450,175
<blockquote> <p>Eine Minuten bitte, Ich hap eine kleine Problemo avec diese Religione. -- Eddie Izzard (doing his impression of Martin Luther)</p> </blockquote> <p>Deleting by reverse-iterating over a list to preserve the iterator <em>is</em> a common solution to this problem. But another solution is to change this into a different problem. Instead of deleting items from the list using some criteria (in your case, the index exists in a list of indexes to be deleted), create a new list that leaves out the offending items.</p> <pre><code>L[:] = [ item for i,item in enumerate(L) if i not in I ] </code></pre> <p>For that matter, where did you come up with the indexes in <code>I</code> in the first place? You could combine the logic of getting the indexes to be removed and building the new list. Assuming this is a list of objects and you only want to keep those that pass an <code>isValid</code> test:</p> <pre><code>L[:] = [ item for item in L if item.isValid() ] </code></pre> <p>This is much more straightforward than:</p> <pre><code>I = set() for i in range(len(L)): if not L[i].isValid(): I.add(i) for i in sorted(I, reverse=True): del L[i] </code></pre> <p>For the most part, I turn any question about "how to delete from a list the items that I don't want" into "how to create a new list containing just the items I want".</p> <p>EDITED: changed "L = ..." to "L[:] = ..." per Alex Martelli's answer to <a href="http://stackoverflow.com/questions/1352885/remove-elements-as-you-traverse-a-list-in-python">this question</a>.</p>
28
2009-09-20T03:04:55Z
[ "python", "list" ]
Delete many elements of list (python)
1,450,111
<p>I have a list L.</p> <p>I can delete element i by doing:</p> <pre><code>del L[i] </code></pre> <p>But what if I have a set of non contiguous indexes to delete?</p> <pre><code>I=set([i1, i2, i3,...]) </code></pre> <p>Doing:</p> <pre><code>for i in I: del L[i] </code></pre> <p>Won't work.</p> <p>Any ideas?</p>
10
2009-09-20T02:18:34Z
1,455,447
<p>If your original list data can safely be turned into a set (i.e. all unique values and doesn't need to maintain order), you could also use set operations:</p> <pre><code>Lset = set(L) newset = Lset.difference(I) </code></pre> <p>You could also maybe do something with a Bag/Multiset, though it probably isn't worth the effort. Paul McGuire's second listcomp solution is certainly best for most cases.</p>
0
2009-09-21T16:28:16Z
[ "python", "list" ]
Delete many elements of list (python)
1,450,111
<p>I have a list L.</p> <p>I can delete element i by doing:</p> <pre><code>del L[i] </code></pre> <p>But what if I have a set of non contiguous indexes to delete?</p> <pre><code>I=set([i1, i2, i3,...]) </code></pre> <p>Doing:</p> <pre><code>for i in I: del L[i] </code></pre> <p>Won't work.</p> <p>Any ideas?</p>
10
2009-09-20T02:18:34Z
23,283,296
<pre><code>L = [ item for item in L if L.index(item) not in I ] </code></pre>
-1
2014-04-25T02:43:15Z
[ "python", "list" ]
Delete many elements of list (python)
1,450,111
<p>I have a list L.</p> <p>I can delete element i by doing:</p> <pre><code>del L[i] </code></pre> <p>But what if I have a set of non contiguous indexes to delete?</p> <pre><code>I=set([i1, i2, i3,...]) </code></pre> <p>Doing:</p> <pre><code>for i in I: del L[i] </code></pre> <p>Won't work.</p> <p>Any ideas?</p>
10
2009-09-20T02:18:34Z
32,743,979
<p>You can use <code>numpy.delete</code> as follows:</p> <pre><code>import numpy as np a = ['a', 'l', 3.14, 42, 'u'] I = [1, 3, 4] np.delete(a, I).tolist() # Returns: ['a', '3.14'] </code></pre> <p>If you don't mind ending up with a <code>numpy</code> array at the end, you can leave out the <code>.tolist()</code>. You should see some pretty major speed improvements, too, making this a more scalable solution. I haven't benchmarked it, but <code>numpy</code> operations are compiled code written in either C or Fortran.</p>
3
2015-09-23T15:43:47Z
[ "python", "list" ]
Proxy with urllib2
1,450,132
<p>I open urls with:</p> <p><code>site = urllib2.urlopen('http://google.com')</code></p> <p>And what I want to do is connect the same way with a proxy I got somewhere telling me:</p> <p><code>site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})</code></p> <p>but that didn't work either.</p> <p>I know urllib2 has something like a proxy handler, but I can't recall that function.</p>
56
2009-09-20T02:30:24Z
1,450,142
<p>You have to install a ProxyHandler</p> <pre><code>urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler({'http': '127.0.0.1'}) ) ) urllib2.urlopen('http://www.google.com') </code></pre>
12
2009-09-20T02:34:39Z
[ "python", "proxy", "urllib2" ]
Proxy with urllib2
1,450,132
<p>I open urls with:</p> <p><code>site = urllib2.urlopen('http://google.com')</code></p> <p>And what I want to do is connect the same way with a proxy I got somewhere telling me:</p> <p><code>site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})</code></p> <p>but that didn't work either.</p> <p>I know urllib2 has something like a proxy handler, but I can't recall that function.</p>
56
2009-09-20T02:30:24Z
1,450,154
<pre><code>proxy = urllib2.ProxyHandler({'http': '127.0.0.1'}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) urllib2.urlopen('http://www.google.com') </code></pre>
107
2009-09-20T02:49:35Z
[ "python", "proxy", "urllib2" ]
Proxy with urllib2
1,450,132
<p>I open urls with:</p> <p><code>site = urllib2.urlopen('http://google.com')</code></p> <p>And what I want to do is connect the same way with a proxy I got somewhere telling me:</p> <p><code>site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})</code></p> <p>but that didn't work either.</p> <p>I know urllib2 has something like a proxy handler, but I can't recall that function.</p>
56
2009-09-20T02:30:24Z
9,739,556
<p>To use the default system proxies (e.g. from the http_support environment variable), the following works for the current request (without installing it into urllib2 globally):</p> <pre><code>url = 'http://www.example.com/' proxy = urllib2.ProxyHandler() opener = urllib2.build_opener(proxy) in_ = opener.open(url) in_.read() </code></pre>
5
2012-03-16T14:55:23Z
[ "python", "proxy", "urllib2" ]
Proxy with urllib2
1,450,132
<p>I open urls with:</p> <p><code>site = urllib2.urlopen('http://google.com')</code></p> <p>And what I want to do is connect the same way with a proxy I got somewhere telling me:</p> <p><code>site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})</code></p> <p>but that didn't work either.</p> <p>I know urllib2 has something like a proxy handler, but I can't recall that function.</p>
56
2009-09-20T02:30:24Z
19,843,346
<p>You can set proxies using environment variables.</p> <pre><code>import os os.environ['http_proxy'] = '127.0.0.1' os.environ['https_proxy'] = '127.0.0.1' </code></pre> <p><code>urllib2</code> will add proxy handlers automatically this way. You need to set proxies for different protocols separately otherwise they will fail (in terms of not going through proxy), see below.</p> <p>For example:</p> <pre><code>proxy = urllib2.ProxyHandler({'http': '127.0.0.1'}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) urllib2.urlopen('http://www.google.com') # next line will fail (will not go through the proxy) (https) urllib2.urlopen('https://www.google.com') </code></pre> <p>Instead </p> <pre><code>proxy = urllib2.ProxyHandler({ 'http': '127.0.0.1', 'https': '127.0.0.1' }) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) # this way both http and https requests go through the proxy urllib2.urlopen('http://www.google.com') urllib2.urlopen('https://www.google.com') </code></pre>
6
2013-11-07T18:03:36Z
[ "python", "proxy", "urllib2" ]
Proxy with urllib2
1,450,132
<p>I open urls with:</p> <p><code>site = urllib2.urlopen('http://google.com')</code></p> <p>And what I want to do is connect the same way with a proxy I got somewhere telling me:</p> <p><code>site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})</code></p> <p>but that didn't work either.</p> <p>I know urllib2 has something like a proxy handler, but I can't recall that function.</p>
56
2009-09-20T02:30:24Z
26,253,907
<p>In Addition to the accepted answer: My scipt gave me an error </p> <pre><code>File "c:\Python23\lib\urllib2.py", line 580, in proxy_open if '@' in host: TypeError: iterable argument required </code></pre> <p>Solution was to add http:// in front of the proxy string:</p> <pre><code>proxy = urllib2.ProxyHandler({'http': 'http://proxy.xy.z:8080'}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) urllib2.urlopen('http://www.google.com') </code></pre>
2
2014-10-08T09:48:21Z
[ "python", "proxy", "urllib2" ]
Proxy with urllib2
1,450,132
<p>I open urls with:</p> <p><code>site = urllib2.urlopen('http://google.com')</code></p> <p>And what I want to do is connect the same way with a proxy I got somewhere telling me:</p> <p><code>site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})</code></p> <p>but that didn't work either.</p> <p>I know urllib2 has something like a proxy handler, but I can't recall that function.</p>
56
2009-09-20T02:30:24Z
36,835,088
<p>In addition set the proxy for the command line session Open a command line where you might want to run your script</p> <pre><code>netsh winhttp set proxy YourProxySERVER:yourProxyPORT </code></pre> <p>run your script in that terminal.</p>
0
2016-04-25T08:09:21Z
[ "python", "proxy", "urllib2" ]
Proxy with urllib2
1,450,132
<p>I open urls with:</p> <p><code>site = urllib2.urlopen('http://google.com')</code></p> <p>And what I want to do is connect the same way with a proxy I got somewhere telling me:</p> <p><code>site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})</code></p> <p>but that didn't work either.</p> <p>I know urllib2 has something like a proxy handler, but I can't recall that function.</p>
56
2009-09-20T02:30:24Z
38,168,940
<p>One can also use requests if we would like to access a web page using proxies. Python 3 code: </p> <pre><code>&gt;&gt;&gt; import requests &gt;&gt;&gt; url = 'http://www.google.com' &gt;&gt;&gt; proxy = '169.50.87.252:80' &gt;&gt;&gt; requests.get(url, proxies={"http":proxy}) &lt;Response [200]&gt; </code></pre> <p>More than one proxies can also be added.</p> <pre><code>&gt;&gt;&gt; proxy1 = '169.50.87.252:80' &gt;&gt;&gt; proxy2 = '89.34.97.132:8080' &gt;&gt;&gt; requests.get(url, proxies={"http":proxy1,"http":proxy2}) &lt;Response [200]&gt; </code></pre>
1
2016-07-03T10:19:37Z
[ "python", "proxy", "urllib2" ]
Change the focus from one Text widget to another
1,450,180
<p>I'm new to Python and I'm trying to create a simple GUI using Tkinter. </p> <p>So often in many user interfaces, hitting the tab button will change the focus from one Text widget to another. Whenever I'm in a Text widget, tab only indents the text cursor.</p> <p>Does anyone know if this is configurable? If not, can <code>PyQt</code> or any other Python UI framework offer this functionality?</p>
8
2009-09-20T03:06:06Z
1,450,234
<p>Due to the cross platform nature, the focus traversal is somewhat customizable, usually letting the X windows manager handle it (with focus follows mouse, or click). According to <a href="http://tcl.tk/man/tcl8.5/" rel="nofollow">the manual</a> it should be possible to <code>bind</code> an event to the key press event, scanning for tab presses, and triggering a <code>focusNext</code> event in those cases.</p>
-3
2009-09-20T03:31:41Z
[ "python", "text", "tabs", "tkinter" ]
Change the focus from one Text widget to another
1,450,180
<p>I'm new to Python and I'm trying to create a simple GUI using Tkinter. </p> <p>So often in many user interfaces, hitting the tab button will change the focus from one Text widget to another. Whenever I'm in a Text widget, tab only indents the text cursor.</p> <p>Does anyone know if this is configurable? If not, can <code>PyQt</code> or any other Python UI framework offer this functionality?</p>
8
2009-09-20T03:06:06Z
1,450,779
<p>Not sure about TKinter, but with PyQt, one can connect a function to the tab changed signal emitted by the tab box(the signal also carries an int value). But as far as I am aware Qt is pretty good at doing the right thing without it being specified.</p>
0
2009-09-20T10:57:52Z
[ "python", "text", "tabs", "tkinter" ]
Change the focus from one Text widget to another
1,450,180
<p>I'm new to Python and I'm trying to create a simple GUI using Tkinter. </p> <p>So often in many user interfaces, hitting the tab button will change the focus from one Text widget to another. Whenever I'm in a Text widget, tab only indents the text cursor.</p> <p>Does anyone know if this is configurable? If not, can <code>PyQt</code> or any other Python UI framework offer this functionality?</p>
8
2009-09-20T03:06:06Z
1,451,343
<p>This is very easy to do with Tkinter.</p> <p>There are a couple of things that have to happen to make this work. First, you need to make sure that the standard behavior <i>doesn't</i> happen. That is, you don't want tab to both insert a tab and move focus to the next widget. By default events are processed by a specific widget prior to where the standard behavior occurs (typically in class bindings). Tk has a simple built-in mechanism to stop events from further processing. </p> <p>Second, you need to make sure you send focus to the appropriate widget. There is built-in support for determining what the next widget is.</p> <p>For example:</p> <pre><code>def focus_next_window(event): event.widget.tk_focusNext().focus() return("break") text_widget=Text(...) text_widget.bind("&lt;Tab&gt;", focus_next_window) </code></pre> <p>Important points about this code:</p> <ul> <li>The method <code>tk_focusNext()</code> returns the next widget in the keyboard traversal hierarchy.</li> <li>the method <code>focus()</code> sets the focus to that widget</li> <li>returning <code>"break"</code> is critical in that it prevents the class binding from firing. It is this class binding that inserts the tab character, which you don't want.</li> </ul> <p>If you want this behavior for all text widgets in an application you can use the <code>bind_class()</code> method instead of <code>bind()</code> to make this binding affect all text widgets. </p> <p>You can also have the binding send focus to a very specific widget but I recommend sticking with the default traversal order, then make sure the traversal order is correct.</p>
10
2009-09-20T15:57:10Z
[ "python", "text", "tabs", "tkinter" ]
Modifying locals in Python
1,450,275
<p>locals is a built in function that returns a dictionary of local values. The documentation says:</p> <blockquote> <p>Warning</p> <p>The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter.</p> </blockquote> <p>Unfortunately, exec has the same problem in Python 3.0. Is there any way round this?</p> <p><strong>Use Case</strong></p> <p>Consider:</p> <pre><code>@depends("a", "b", "c", "d", "e", "f") def test(): put_into_locals(test.dependencies) </code></pre> <p>depends stores the strings provided in its arguments in a list <code>test.dependences</code>. These strings are keys in a dictionary <code>d</code>. I would like to be able to able to write <code>put_into_locals</code> so that we could pull the values out of <code>d</code> and put them into the locals. Is this possible?</p>
10
2009-09-20T04:03:29Z
1,450,280
<p>I'm not sure if it is subject to the same restrictions, but you can get a direct reference to the current frame (and from there, the local variables dictionary) through the inspect module:</p> <pre><code>&gt;&gt;&gt; import inspect &gt;&gt;&gt; inspect.currentframe().f_locals['foo'] = 'bar' &gt;&gt;&gt; dir() ['__builtins__', '__doc__', '__name__', '__package__', 'foo', 'inspect'] &gt;&gt;&gt; foo 'bar' </code></pre>
-1
2009-09-20T04:13:58Z
[ "python", "locals" ]
Modifying locals in Python
1,450,275
<p>locals is a built in function that returns a dictionary of local values. The documentation says:</p> <blockquote> <p>Warning</p> <p>The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter.</p> </blockquote> <p>Unfortunately, exec has the same problem in Python 3.0. Is there any way round this?</p> <p><strong>Use Case</strong></p> <p>Consider:</p> <pre><code>@depends("a", "b", "c", "d", "e", "f") def test(): put_into_locals(test.dependencies) </code></pre> <p>depends stores the strings provided in its arguments in a list <code>test.dependences</code>. These strings are keys in a dictionary <code>d</code>. I would like to be able to able to write <code>put_into_locals</code> so that we could pull the values out of <code>d</code> and put them into the locals. Is this possible?</p>
10
2009-09-20T04:03:29Z
1,450,304
<p>This isn't possible. I think this is to allow for performance optimizations later on. Python bytecode references locals by index, not by name; if locals() was required to be writable, it could prevent interpreters from implementing some optimizations, or make them more difficult.</p> <p>I'm fairly certain you're not going to find any core API that guarantees you can edit locals like this, because if that API could do it, locals() wouldn't have this restriction either.</p> <p>Don't forget that all locals must exist at compile-time; if you reference a name that isn't bound to a local at compile-time, the compiler assumes it's a global. You can't "create" locals after compilation.</p> <p>See <a href="http://stackoverflow.com/questions/1360721/how-to-get-set-local-variables-of-a-function-from-outside-in-python/1361058#1361058">this question</a> for one possible solution, but it's a serious hack and you really don't want to do that.</p> <p>Note that there's a basic problem with your example code:</p> <pre><code>@depends("a", "b", "c", "d", "e", "f") def test(): put_into_locals(test.dependencies) </code></pre> <p><code>"test.dependencies"</code> isn't referring to "f.dependencies" where f is the current function; it's referencing the actual global value "test". That means if you use more than one decorator:</p> <pre><code>@memoize @depends("a", "b", "c", "d", "e", "f") def test(): put_into_locals(test.dependencies) </code></pre> <p>it'll no longer work, since "test" is memoize's wrapped function, not depends's. Python <em>really</em> needs a way to refer to "the currently-executing function" (and class).</p>
3
2009-09-20T04:37:28Z
[ "python", "locals" ]
Modifying locals in Python
1,450,275
<p>locals is a built in function that returns a dictionary of local values. The documentation says:</p> <blockquote> <p>Warning</p> <p>The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter.</p> </blockquote> <p>Unfortunately, exec has the same problem in Python 3.0. Is there any way round this?</p> <p><strong>Use Case</strong></p> <p>Consider:</p> <pre><code>@depends("a", "b", "c", "d", "e", "f") def test(): put_into_locals(test.dependencies) </code></pre> <p>depends stores the strings provided in its arguments in a list <code>test.dependences</code>. These strings are keys in a dictionary <code>d</code>. I would like to be able to able to write <code>put_into_locals</code> so that we could pull the values out of <code>d</code> and put them into the locals. Is this possible?</p>
10
2009-09-20T04:03:29Z
1,450,341
<p>I just tested exec and it works in Python 2.6.2</p> <pre><code>&gt;&gt;&gt; def test(): ... exec "a = 5" ... print a ... &gt;&gt;&gt; test() 5 </code></pre> <p>If you are using Python 3.x, it does not work anymore because locals are optimized as an array at runtime, instead of using a dictionary.</p> <p>When Python detects the "exec statement", it will force Python to switch local storage from array to dictionary. However since "exec" is a function in Python 3.x, the compiler cannot make this distinction since the user could have done something like "exec = 123".</p> <p><a href="http://bugs.python.org/issue4831">http://bugs.python.org/issue4831</a></p> <blockquote> <p>To modify the locals of a function on the fly is not possible without several consequences: normally, function locals are not stored in a dictionary, but an array, whose indices are determined at compile time from the known locales. This collides at least with new locals added by exec. The old exec statement circumvented this, because the compiler knew that if an exec without globals/locals args occurred in a function, that namespace would be "unoptimized", i.e. not using the locals array. Since exec() is now a normal function, the compiler does not know what "exec" may be bound to, and therefore can not treat is specially.</p> </blockquote>
11
2009-09-20T05:09:33Z
[ "python", "locals" ]
Modifying locals in Python
1,450,275
<p>locals is a built in function that returns a dictionary of local values. The documentation says:</p> <blockquote> <p>Warning</p> <p>The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter.</p> </blockquote> <p>Unfortunately, exec has the same problem in Python 3.0. Is there any way round this?</p> <p><strong>Use Case</strong></p> <p>Consider:</p> <pre><code>@depends("a", "b", "c", "d", "e", "f") def test(): put_into_locals(test.dependencies) </code></pre> <p>depends stores the strings provided in its arguments in a list <code>test.dependences</code>. These strings are keys in a dictionary <code>d</code>. I would like to be able to able to write <code>put_into_locals</code> so that we could pull the values out of <code>d</code> and put them into the locals. Is this possible?</p>
10
2009-09-20T04:03:29Z
1,450,858
<p>The local variables are modified by assignment statements.</p> <p>If you have dictionary keys which are strings, please don't also make them local variables -- just use them as dictionary keys.</p> <p>If you absolutely <strong>must</strong> have local variables do this.</p> <pre><code>def aFunction( a, b, c, d, e, f ): # use a, b, c, d, e and f as local variables aFunction( **someDictWithKeys_a_b_c_d_e_f ) </code></pre> <p>That will populate some local variables from your dictionary without doing anything magical.</p>
5
2009-09-20T11:50:01Z
[ "python", "locals" ]
Django FormPreview - What is it for?
1,450,295
<p>While looking across the Django documentation, I came across the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-preview/" rel="nofollow">FormPreview</a>. </p> <p>The description says this:</p> <blockquote> <p>Django comes with an optional “form preview” application that helps automate the following workflow:</p> <p>“Display an HTML form, force a preview, then do something with the submission.”</p> </blockquote> <p>What is meant by "force a preview"? What would you use this feature for an in application?</p>
2
2009-09-20T04:32:00Z
1,450,313
<p>I think they mean (I use django but I didn't know of this until now..) that you can let people write, for example in a textarea box like I'm doing right now. After the user submits it the system would preview it to the user and give him the chance to read and edit what he submitted, before it being submitted again all the way to the database.</p>
2
2009-09-20T04:43:04Z
[ "python", "django", "forms" ]
Django FormPreview - What is it for?
1,450,295
<p>While looking across the Django documentation, I came across the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-preview/" rel="nofollow">FormPreview</a>. </p> <p>The description says this:</p> <blockquote> <p>Django comes with an optional “form preview” application that helps automate the following workflow:</p> <p>“Display an HTML form, force a preview, then do something with the submission.”</p> </blockquote> <p>What is meant by "force a preview"? What would you use this feature for an in application?</p>
2
2009-09-20T04:32:00Z
1,450,413
<p>To force a preview means the users are forced to see the value they have inserted on the form input fields, before django actually saves it to the database.</p> <p>One example is <a href="http://docs.djangoproject.com/en/dev/ref/contrib/comments/" rel="nofollow">django comment system</a>, which enforce the users to take a look at the comment they have written before django actually saves it to the database. You would see that the users are redirected to another page to take a look at their comment, and after that there is a submit button to actually save the comment.</p>
2
2009-09-20T06:10:01Z
[ "python", "django", "forms" ]
How do you read from stdin in Python?
1,450,393
<p>I'm trying to do some of the <a href="http://en.wikipedia.org/wiki/Code_golf">code golf</a> challenges, but they all require the input to be taken from <code>stdin</code>. How do I get that in Python?</p>
854
2009-09-20T05:48:07Z
1,450,396
<p>Here's from <a href="http://oreilly.com/catalog/lpython/chapter/ch09.html#16308">Learning Python</a>:</p> <pre><code>import sys data = sys.stdin.readlines() print "Counted", len(data), "lines." </code></pre> <p>On Unix, you could test it by doing something like:</p> <pre><code>% cat countlines.py | python countlines.py Counted 3 lines. </code></pre> <p>On Windows or DOS, you'd do:</p> <pre><code>C:\&gt; type countlines.py | python countlines.py Counted 3 lines. </code></pre>
117
2009-09-20T05:51:00Z
[ "python", "stdin" ]