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 |
|---|---|---|---|---|---|---|---|---|---|
Why can't a Python class definition assign a closure variable to itself? | 1,445,207 | <p>Why doesn't the following work in Python?</p>
<pre><code>def make_class(a):
class A(object):
a=a
return A
</code></pre>
| 2 | 2009-09-18T15:17:37Z | 1,445,231 | <p>works just fine:</p>
<pre><code>>>> def make_class(a):
class A(object):
_a=a
return A
>>> make_class('df')
<class '__main__.A'>
>>> make_class('df')._a
'df'
</code></pre>
<p>btw, <code>function</code> is not a reserved keyword in Python.</p>
| 9 | 2009-09-18T15:21:23Z | [
"python",
"closures"
] |
Why can't a Python class definition assign a closure variable to itself? | 1,445,207 | <p>Why doesn't the following work in Python?</p>
<pre><code>def make_class(a):
class A(object):
a=a
return A
</code></pre>
| 2 | 2009-09-18T15:17:37Z | 1,445,514 | <p>Try</p>
<pre><code>def make_class(a):
class A(object): pass
A.a=a
return A
</code></pre>
<p>The error you get (<code>NameError: name 'a' is not defined</code>) is because the name <code>a</code> in the class shadows the parameter <code>a</code> of the function; hence there is no <code>a</code> defined ... | 2 | 2009-09-18T16:07:59Z | [
"python",
"closures"
] |
Why can't a Python class definition assign a closure variable to itself? | 1,445,207 | <p>Why doesn't the following work in Python?</p>
<pre><code>def make_class(a):
class A(object):
a=a
return A
</code></pre>
| 2 | 2009-09-18T15:17:37Z | 1,453,254 | <p>Let's use a simpler example for the same problem:</p>
<pre><code>a = 'something'
def boo():
a = a
boo()
</code></pre>
<p>This fails because assignments in python, without an accompanying <code>global</code> or <code>nonlocal</code> statement, means that the assigned name is local to the current scope. This hap... | 6 | 2009-09-21T07:31:08Z | [
"python",
"closures"
] |
Writing a function to display current day using time_t? | 1,445,236 | <p>I've been writing a time converter to take the systems time_t and convert it into human readable date/time. Oh, and this is my second python script ever. We'll leave that fact aside and move on.</p>
<p>The full script is hosted <a href="http://paste.wowace.com/oc1wapgrfk2js834/" rel="nofollow" title="wowace pastebi... | 1 | 2009-09-18T15:21:53Z | 1,445,259 | <p>You could do it either with <a href="http://docs.python.org/library/time.html#time.strftime" rel="nofollow"><code>time.strftime</code></a>:</p>
<pre><code>>>> import time
>>> time.strftime('%Y %B %d')
'2009 September 18'
</code></pre>
<p>or with <a href="http://docs.python.org/library/datetime.ht... | 3 | 2009-09-18T15:25:42Z | [
"python",
"time",
"time-t"
] |
Writing a function to display current day using time_t? | 1,445,236 | <p>I've been writing a time converter to take the systems time_t and convert it into human readable date/time. Oh, and this is my second python script ever. We'll leave that fact aside and move on.</p>
<p>The full script is hosted <a href="http://paste.wowace.com/oc1wapgrfk2js834/" rel="nofollow" title="wowace pastebi... | 1 | 2009-09-18T15:21:53Z | 1,445,264 | <p>Why not use:</p>
<pre><code>from datetime import datetime
the_date = datetime.fromtimestamp(the_time)
print(the_date.strftime('%Y %B %d'))
</code></pre>
<p>The datetime module handles all the edge cases -- leap years, leap seconds, leap days -- as well as time zone conversion (with optional second argument)</p>
| 8 | 2009-09-18T15:26:30Z | [
"python",
"time",
"time-t"
] |
Writing a function to display current day using time_t? | 1,445,236 | <p>I've been writing a time converter to take the systems time_t and convert it into human readable date/time. Oh, and this is my second python script ever. We'll leave that fact aside and move on.</p>
<p>The full script is hosted <a href="http://paste.wowace.com/oc1wapgrfk2js834/" rel="nofollow" title="wowace pastebi... | 1 | 2009-09-18T15:21:53Z | 1,445,414 | <p>(I'm assuming you do this to learn Python, so I'll point out the errors in your code).</p>
<pre><code>>>> years = SecondsSinceEpoch / 31540000
</code></pre>
<p>Nonononono. You can't do that. Some years have 31536000 seconds, others have 31622400 seconds.</p>
<pre><code>>>> if calendar.isleap(yea... | 1 | 2009-09-18T15:51:27Z | [
"python",
"time",
"time-t"
] |
Writing a function to display current day using time_t? | 1,445,236 | <p>I've been writing a time converter to take the systems time_t and convert it into human readable date/time. Oh, and this is my second python script ever. We'll leave that fact aside and move on.</p>
<p>The full script is hosted <a href="http://paste.wowace.com/oc1wapgrfk2js834/" rel="nofollow" title="wowace pastebi... | 1 | 2009-09-18T15:21:53Z | 1,447,565 | <p>I'll also point out something odd in the code you posted:</p>
<pre><code> try:
SecondsSinceEpoch = time.time()
except IOError:
Print("Unable to get your system time!")
</code></pre>
<p>1.) Why would <code>time.time()</code> raise an IOError? As far as I know it's impossible for that ... | 0 | 2009-09-19T02:40:53Z | [
"python",
"time",
"time-t"
] |
How can I find out why subprocess.Popen wait() waits forever if stdout=PIPE? | 1,445,627 | <p>I have a program that writes to stdout and possibly stderr. I want to run it from python, capturing the stdout and stderr. My code looks like:</p>
<pre><code>from subprocess import *
p = Popen( exe, shell=TRUE, stdout=PIPE, stderr=PIPE )
rtrncode = p.wait()
</code></pre>
<p>For a couple of programs, this works fi... | 12 | 2009-09-18T16:30:59Z | 1,445,647 | <p>When a pipe's buffer fills up (typically 4KB or so), the writing process stops until a reading process has read some of the data in question; but here you're reading nothing until the subprocess is done, hence the deadlock. <a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.wait">The docs</a> ... | 28 | 2009-09-18T16:36:04Z | [
"python",
"subprocess"
] |
How can I find out why subprocess.Popen wait() waits forever if stdout=PIPE? | 1,445,627 | <p>I have a program that writes to stdout and possibly stderr. I want to run it from python, capturing the stdout and stderr. My code looks like:</p>
<pre><code>from subprocess import *
p = Popen( exe, shell=TRUE, stdout=PIPE, stderr=PIPE )
rtrncode = p.wait()
</code></pre>
<p>For a couple of programs, this works fi... | 12 | 2009-09-18T16:30:59Z | 1,445,653 | <p>Take a look at the <a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.wait" rel="nofollow">docs</a>. It states that you shouldn't use wait as it can cause a dead lock. Try using <a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate" rel="nofollow">communicate</a>.... | 1 | 2009-09-18T16:37:11Z | [
"python",
"subprocess"
] |
Whats the proper idiom for naming django model fields that are python reserved names? | 1,445,971 | <p>I have a model that needs to have a field named <code>complex</code> and another one named <code>type</code>. Those are both python reserved names. According to PEP 8, I should name them <code>complex_</code> and <code>type_</code> respectively, but django won't allow me to have fields named with a trailing undersco... | 5 | 2009-09-18T17:48:09Z | 1,446,128 | <p>Do you really want to use the <code>db_column="complex"</code> argument and call your field something else?</p>
| 1 | 2009-09-18T18:18:43Z | [
"python",
"django",
"idioms"
] |
Whats the proper idiom for naming django model fields that are python reserved names? | 1,445,971 | <p>I have a model that needs to have a field named <code>complex</code> and another one named <code>type</code>. Those are both python reserved names. According to PEP 8, I should name them <code>complex_</code> and <code>type_</code> respectively, but django won't allow me to have fields named with a trailing undersco... | 5 | 2009-09-18T17:48:09Z | 1,446,132 | <p>There's no problem with those examples. Just use <code>complex</code> and <code>type</code>. You are only shadowing in a very limited scope (the class definition itself). After that, you'll be accessing them using dot notation (<code>self.type</code>), so there's no ambiguity:</p>
<pre><code>Python 2.6.2 (releas... | 4 | 2009-09-18T18:19:44Z | [
"python",
"django",
"idioms"
] |
Passing Python Data to JavaScript via Django | 1,445,989 | <p>I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the ... | 39 | 2009-09-18T17:52:53Z | 1,446,060 | <p>It is suboptimal. Have you considered passing your data as JSON using django's built in serializer for that?</p>
| 2 | 2009-09-18T18:06:58Z | [
"javascript",
"python",
"django"
] |
Passing Python Data to JavaScript via Django | 1,445,989 | <p>I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the ... | 39 | 2009-09-18T17:52:53Z | 1,446,136 | <p>You can include <code><script></code> tags inside your .html templates, and then build your data structures however is convenient for you. The template language isn't only for HTML, it can also do Javascript object literals.</p>
<p>And Paul is right: it might be best to use a json module to create a JSON str... | 3 | 2009-09-18T18:19:57Z | [
"javascript",
"python",
"django"
] |
Passing Python Data to JavaScript via Django | 1,445,989 | <p>I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the ... | 39 | 2009-09-18T17:52:53Z | 1,446,170 | <p>I recommend against putting much JavaScript in your Django templates - it tends to be hard to write and debug, particularly as your project expands. Instead, try writing all of your JavaScript in a separate script file which your template loads and simply including just a JSON data object in the template. This allow... | 58 | 2009-09-18T18:26:20Z | [
"javascript",
"python",
"django"
] |
Passing Python Data to JavaScript via Django | 1,445,989 | <p>I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the ... | 39 | 2009-09-18T17:52:53Z | 1,446,959 | <p>See the related response to <a href="http://stackoverflow.com/questions/683462/best-way-to-integrate-python-and-javascript/683928#683928">this question</a>. One option is to use <a href="http://jsonpickle.googlecode.com/svn/docs/index.html" rel="nofollow">jsonpickle</a> to serialize between Python objects and JSON/J... | 0 | 2009-09-18T21:41:01Z | [
"javascript",
"python",
"django"
] |
Passing Python Data to JavaScript via Django | 1,445,989 | <p>I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the ... | 39 | 2009-09-18T17:52:53Z | 1,448,178 | <p>Putting Java Script embedded into Django template is <strong>rather</strong> always bad idea. </p>
<p><strong>Rather</strong>, because there are some exceptions from this rule.</p>
<p>Everything depends on the your Java Script code site and functionality.</p>
<p>It is better to have seperately static files, like ... | 1 | 2009-09-19T08:47:57Z | [
"javascript",
"python",
"django"
] |
Passing Python Data to JavaScript via Django | 1,445,989 | <p>I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the ... | 39 | 2009-09-18T17:52:53Z | 13,297,018 | <p>For anyone who might be having a problems with this, be sure you are rendering your json object under safe mode in the template. You can manually set this like this</p>
<pre><code><script type="text/javascript">
data_from_django = {{ my_data|safe }};
widget.init(data_from_django);
</script>
</co... | 24 | 2012-11-08T20:13:26Z | [
"javascript",
"python",
"django"
] |
Python 2.6 send connection object over Queue / Pipe / etc | 1,446,004 | <p>Given <a href="http://bugs.python.org/issue4892">this bug (Python Issue 4892)</a> that gives rise to the following error:</p>
<pre><code>>>> import multiprocessing
>>> multiprocessing.allow_connection_pickling()
>>> q = multiprocessing.Queue()
>>> p = multiprocessing.Pipe()
>&... | 11 | 2009-09-18T17:55:30Z | 1,446,407 | <p>Here's roughly what I did:</p>
<pre><code># Producer
from multiprocessing.reduction import reduce_connection
from multiprocessing import Pipe
# Producer and Consumer share the Queue we call queue
def handle(queue):
reader, writer = Pipe()
pickled_writer = pickle.dumps(reduce_connection(writer))
queue.p... | 7 | 2009-09-18T19:20:09Z | [
"python",
"queue",
"multiprocessing",
"pipe",
"pickle"
] |
Python 2.6 send connection object over Queue / Pipe / etc | 1,446,004 | <p>Given <a href="http://bugs.python.org/issue4892">this bug (Python Issue 4892)</a> that gives rise to the following error:</p>
<pre><code>>>> import multiprocessing
>>> multiprocessing.allow_connection_pickling()
>>> q = multiprocessing.Queue()
>>> p = multiprocessing.Pipe()
>&... | 11 | 2009-09-18T17:55:30Z | 4,719,933 | <p>(What I believe is) A better method, after some playing around (I was having the same problem. Wanted to pass a pipe through a pipe.) before discovering this post:</p>
<pre><code>>>> from multiprocessing import Pipe, reduction
>>> i, o = Pipe()
>>> reduced = reduction.reduce_connection(i)... | 8 | 2011-01-18T02:24:23Z | [
"python",
"queue",
"multiprocessing",
"pipe",
"pickle"
] |
Python cmd module command aliases | 1,446,137 | <p>I am making a command line interface in Python 3.1.1 using the cmd module.</p>
<p>Is there a way to create a command with more than one name e.g. "quit" and "exit"?
Or would it just be a case of making a number of commands that all reference the same function?</p>
| 2 | 2009-09-18T18:20:09Z | 1,446,164 | <p>Yes, it would just be a case of making a number of commands that all reference the same function.</p>
<p>This is common. It often helps to provide multiple common aliases for a command. It makes the user's life simpler because the odds of them guessing correctly are improved.</p>
| 4 | 2009-09-18T18:24:09Z | [
"python",
"cmd",
"command-line-interface"
] |
Can Unittest in Python run a list made of strings? | 1,446,317 | <p>I am using Selenium to run tests on a website. I have many individual test I need to run, and want to create a script that will run all of the python files in a certain folder. I can get the names, and import the modules, but once I do this I can't get the unittest to run the files. Here is some of the test code ... | 0 | 2009-09-18T18:58:58Z | 1,844,689 | <p>Although I wouldn't exactly recommend this approach (nor probably what you're trying to do), here's a simple approach that appears to accomplish roughly what you want.</p>
<p>In file "runner.py" (for example, similar to your above):
import glob
import unittest</p>
<pre><code>testfiles = glob.glob('subdir/*... | 0 | 2009-12-04T03:39:54Z | [
"python",
"selenium-rc"
] |
Can Unittest in Python run a list made of strings? | 1,446,317 | <p>I am using Selenium to run tests on a website. I have many individual test I need to run, and want to create a script that will run all of the python files in a certain folder. I can get the names, and import the modules, but once I do this I can't get the unittest to run the files. Here is some of the test code ... | 0 | 2009-09-18T18:58:58Z | 1,848,461 | <pre><code>## This will execute the tests we need to run
import sys, glob, os, time
def run_all_tests():
sys.path.append('/com/inthinc/python/tiwiPro/usedbyall/run files')
run_all_tests = glob.glob('/com/inthinc/python/tiwipro/usedbyall/run files/*.py')
for i in range( len(run_all_tests) ):
repla... | 0 | 2009-12-04T17:28:11Z | [
"python",
"selenium-rc"
] |
How to find out if Python is compiled with UCS-2 or UCS-4? | 1,446,347 | <p>Just what the title says.</p>
<pre><code>$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
</code></pre>
<p>Searching the official documentation, I found this:</p>
<blockquote>
<p><strong><a href="http://docs.python.org/3.1/library/sys.html#sys.maxunicode">sys.maxunicode</a></strong>: An integer g... | 45 | 2009-09-18T19:06:49Z | 1,446,378 | <p>65535 is UCS-2:</p>
<blockquote>
<p><a href="http://en.wikipedia.org/wiki/UTF-16/UCS-2" rel="nofollow">Thus code point U+0000 is encoded as the number 0, and U+FFFF is encoded as 65535 (which is FFFF16 in hexadecimal).</a></p>
</blockquote>
| 0 | 2009-09-18T19:14:20Z | [
"python",
"unicode",
"ucs2"
] |
How to find out if Python is compiled with UCS-2 or UCS-4? | 1,446,347 | <p>Just what the title says.</p>
<pre><code>$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
</code></pre>
<p>Searching the official documentation, I found this:</p>
<blockquote>
<p><strong><a href="http://docs.python.org/3.1/library/sys.html#sys.maxunicode">sys.maxunicode</a></strong>: An integer g... | 45 | 2009-09-18T19:06:49Z | 1,446,411 | <p>It's 0xFFFF (or 65535) for UCS-2, and 0x10FFFF (or 1114111) for UCS-4:</p>
<pre><code>Py_UNICODE
PyUnicode_GetMax(void)
{
#ifdef Py_UNICODE_WIDE
return 0x10FFFF;
#else
/* This is actually an illegal character, so it should
not be passed to unichr. */
return 0xFFFF;
#endif
}
</code></pre>
<p>The ... | 17 | 2009-09-18T19:20:44Z | [
"python",
"unicode",
"ucs2"
] |
How to find out if Python is compiled with UCS-2 or UCS-4? | 1,446,347 | <p>Just what the title says.</p>
<pre><code>$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
</code></pre>
<p>Searching the official documentation, I found this:</p>
<blockquote>
<p><strong><a href="http://docs.python.org/3.1/library/sys.html#sys.maxunicode">sys.maxunicode</a></strong>: An integer g... | 45 | 2009-09-18T19:06:49Z | 1,446,456 | <p>When built with --enable-unicode=ucs4:</p>
<pre><code>>>> import sys
>>> print sys.maxunicode
1114111
</code></pre>
<p>When built with --enable-unicode=ucs2:</p>
<pre><code>>>> import sys
>>> print sys.maxunicode
65535
</code></pre>
| 79 | 2009-09-18T19:33:45Z | [
"python",
"unicode",
"ucs2"
] |
How to find out if Python is compiled with UCS-2 or UCS-4? | 1,446,347 | <p>Just what the title says.</p>
<pre><code>$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
</code></pre>
<p>Searching the official documentation, I found this:</p>
<blockquote>
<p><strong><a href="http://docs.python.org/3.1/library/sys.html#sys.maxunicode">sys.maxunicode</a></strong>: An integer g... | 45 | 2009-09-18T19:06:49Z | 1,450,155 | <p>I had this same issue once. I documented it for myself on my wiki at</p>
<p><a href="http://arcoleo.org/dsawiki/Wiki.jsp?page=Python%20UTF%20-%20UCS2%20or%20UCS4">http://arcoleo.org/dsawiki/Wiki.jsp?page=Python%20UTF%20-%20UCS2%20or%20UCS4</a></p>
<p>I wrote -</p>
<pre><code>import sys
sys.maxunicode > 65536 ... | 9 | 2009-09-20T02:50:11Z | [
"python",
"unicode",
"ucs2"
] |
How to find out if Python is compiled with UCS-2 or UCS-4? | 1,446,347 | <p>Just what the title says.</p>
<pre><code>$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
</code></pre>
<p>Searching the official documentation, I found this:</p>
<blockquote>
<p><strong><a href="http://docs.python.org/3.1/library/sys.html#sys.maxunicode">sys.maxunicode</a></strong>: An integer g... | 45 | 2009-09-18T19:06:49Z | 35,801,395 | <p><a href="https://docs.python.org/2.7/library/sysconfig.html" rel="nofollow">sysconfig</a> will tell the unicode size from the configuration variables of python.</p>
<p>The buildflags can be queried like this.</p>
<p><strong>Python 2.7:</strong></p>
<pre><code>import sysconfig
sysconfig.get_config_var('Py_UNICODE_... | 3 | 2016-03-04T16:40:42Z | [
"python",
"unicode",
"ucs2"
] |
How to find out if Python is compiled with UCS-2 or UCS-4? | 1,446,347 | <p>Just what the title says.</p>
<pre><code>$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
</code></pre>
<p>Searching the official documentation, I found this:</p>
<blockquote>
<p><strong><a href="http://docs.python.org/3.1/library/sys.html#sys.maxunicode">sys.maxunicode</a></strong>: An integer g... | 45 | 2009-09-18T19:06:49Z | 38,990,558 | <p>I had the same issue and found a semi-official piece of code that does exactly that and may be interesting for people with the same issue: <a href="https://bitbucket.org/pypa/wheel/src/cf4e2d98ecb1f168c50a6de496959b4a10c6b122/wheel/pep425tags.py?at=default&fileviewer=file-view-default#pep425tags.py-83:89" rel="n... | 0 | 2016-08-17T07:28:02Z | [
"python",
"unicode",
"ucs2"
] |
How to find out if Python is compiled with UCS-2 or UCS-4? | 1,446,347 | <p>Just what the title says.</p>
<pre><code>$ ./configure --help | grep -i ucs
--enable-unicode[=ucs[24]]
</code></pre>
<p>Searching the official documentation, I found this:</p>
<blockquote>
<p><strong><a href="http://docs.python.org/3.1/library/sys.html#sys.maxunicode">sys.maxunicode</a></strong>: An integer g... | 45 | 2009-09-18T19:06:49Z | 39,368,698 | <p>Another way is to create an Unicode array and look at the itemsize:</p>
<pre><code>import array
bytes_per_char = array.array('u').itemsize
</code></pre>
<p>Quote from the <a href="https://docs.python.org/2/library/array.html" rel="nofollow"><code>array</code> docs</a>:</p>
<blockquote>
<p>The <code>'u'</code> t... | 1 | 2016-09-07T11:28:30Z | [
"python",
"unicode",
"ucs2"
] |
Clutter does not update screen outside of breakpoints | 1,446,554 | <p>I have some code:</p>
<pre><code>l1 = clutter.Label()
l1.set_position(100,100)
for i in range(0,10):
l1.set_text(str(i))
time.sleep(1)
</code></pre>
<p>That is designed to show a count from 1 to 10 seconds on the screen in clutter, but I'm getting a strange error. When I run the script normally the screen runs a... | 0 | 2009-09-18T20:01:49Z | 1,447,692 | <p>Have you tried <a href="http://www.clutter-project.org/contribute.html" rel="nofollow">posting</a> (or <a href="http://lists.o-hand.com/clutter/" rel="nofollow">searching</a>) on the Clutter mailing list? <a href="http://lists.o-hand.com/clutter/1167.html" rel="nofollow">Here</a>'s someone who got the same message ... | 0 | 2009-09-19T03:56:10Z | [
"python",
"linux",
"graphics",
"clutter-gui"
] |
Clutter does not update screen outside of breakpoints | 1,446,554 | <p>I have some code:</p>
<pre><code>l1 = clutter.Label()
l1.set_position(100,100)
for i in range(0,10):
l1.set_text(str(i))
time.sleep(1)
</code></pre>
<p>That is designed to show a count from 1 to 10 seconds on the screen in clutter, but I'm getting a strange error. When I run the script normally the screen runs a... | 0 | 2009-09-18T20:01:49Z | 1,982,896 | <p>Not sure if you've already figured out the answer to this but:</p>
<p>The reason you are having this problem is because you are blocking the main thread (where all the drawing occurs) with your time.sleep() calls, preventing the library from redrawing the screen.</p>
<p>E.g. your code is currently doing this:</p>
... | 4 | 2009-12-30T22:35:11Z | [
"python",
"linux",
"graphics",
"clutter-gui"
] |
Python decorator to ensure that kwargs are correct | 1,446,555 | <p>I have done a decorator that I used to ensure that the keyword arguments passed to a constructor are the <strong>correct/expected ones</strong>. The code is the following:
<code></p>
<pre><code>from functools import wraps
def keyargs_check(keywords):
"""
This decorator ensures that the keys passed in kwargs are th... | 2 | 2009-09-18T20:01:57Z | 1,446,657 | <p>Your decorator is not necessary. The only thing the decorator does that can't be done with the standard syntax is prevent keyword args from absorbing positional arguments. Thus</p>
<pre><code>class Base(object):
def __init__(name=None,surname=None,age=None):
#some code
class Child(Base):
def __in... | 4 | 2009-09-18T20:26:48Z | [
"python"
] |
How to make easy_install execute custom commands in setup.py? | 1,446,682 | <p>I want my setup.py to do some custom actions besides just installing the Python package (like installing an init.d script, creating directories and files, etc.) I know I can customize the distutils/setuptools classes to do my own actions. The problem I am having is that everything works when I cd to the package dire... | 7 | 2009-09-18T20:30:02Z | 1,446,925 | <p><a href="http://www.blueskyonmars.com/projects/paver/">Paver</a> takes setuptools to the next level and lets you write custom tasks. It allows you to extend the typical setup.py file and provides a simple way to bootstrap the Paver environment.</p>
| 5 | 2009-09-18T21:32:05Z | [
"python",
"setuptools",
"easy-install"
] |
How to make easy_install execute custom commands in setup.py? | 1,446,682 | <p>I want my setup.py to do some custom actions besides just installing the Python package (like installing an init.d script, creating directories and files, etc.) I know I can customize the distutils/setuptools classes to do my own actions. The problem I am having is that everything works when I cd to the package dire... | 7 | 2009-09-18T20:30:02Z | 1,621,540 | <p>It cannot be done. Enthought has a custom version of setuptools that does support this, but otherwise it is in the bug tracker as a wishlist item that has been under discussion since June.</p>
<p>However, there are ways to trick the system and you might consider them. One way is to have your most important module, ... | 4 | 2009-10-25T17:49:42Z | [
"python",
"setuptools",
"easy-install"
] |
What are good names for user defined exceptions? | 1,446,789 | <p>This question covers a broad range of programming languages; however, I am specifically working with Python in this case.</p>
<p>I would like to create some user defined exceptions, but I'm not sure how fine-grained they should be. For example, if I have the following class:</p>
<pre><code>class Race(object):
... | 4 | 2009-09-18T20:52:26Z | 1,446,824 | <p>I think the built-in ValueError may be appropriate in this case. From the Python docs:</p>
<blockquote>
<p>exception ValueError</p>
<p>Raised when a
built-in operation or function
receives an argument that has the
right type but an inappropriate value,
and the situation is not described by
a more p... | 6 | 2009-09-18T21:01:54Z | [
"python",
"exception",
"exception-handling"
] |
What are good names for user defined exceptions? | 1,446,789 | <p>This question covers a broad range of programming languages; however, I am specifically working with Python in this case.</p>
<p>I would like to create some user defined exceptions, but I'm not sure how fine-grained they should be. For example, if I have the following class:</p>
<pre><code>class Race(object):
... | 4 | 2009-09-18T20:52:26Z | 1,446,830 | <p>I try to use appropriate built-in exceptions as much as possible. In languages like Java and C# the exception list is so robust that you'll rarely find one you need to define yourself. I'm not super-familiar with Python's exception list, but IIRC there are at least a few pretty general good ones.</p>
| 1 | 2009-09-18T21:03:41Z | [
"python",
"exception",
"exception-handling"
] |
How to encapsulate python modules? | 1,446,852 | <p>Is it possible to encapsulate python modules 'mechanize' and 'BeautifulSoup' into a single .py file?</p>
<p>My problem is the following:
I have a python script that requires mechanize and BeautifulSoup. I am calling it from a php page. The webhost server supports python, but doesn't have the modules installed. That... | 2 | 2009-09-18T21:09:49Z | 1,446,876 | <p>You don't actually have to combine the files, or install them in a system-wide location. Just make sure the libraries are in a directory readable by your Python script (and therefore, by your PHP app) and added to the Python load path.</p>
<p>The Python runtime searches for libraries in the directories in the <code... | 4 | 2009-09-18T21:17:35Z | [
"python",
"encapsulation"
] |
How to encapsulate python modules? | 1,446,852 | <p>Is it possible to encapsulate python modules 'mechanize' and 'BeautifulSoup' into a single .py file?</p>
<p>My problem is the following:
I have a python script that requires mechanize and BeautifulSoup. I am calling it from a php page. The webhost server supports python, but doesn't have the modules installed. That... | 2 | 2009-09-18T21:09:49Z | 1,446,968 | <p>Check out virtualenv, to create a local python installation, where you can install BeautifulSoup and all other libraries you want.</p>
<p><a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">http://pypi.python.org/pypi/virtualenv</a></p>
| 2 | 2009-09-18T21:43:36Z | [
"python",
"encapsulation"
] |
How to encapsulate python modules? | 1,446,852 | <p>Is it possible to encapsulate python modules 'mechanize' and 'BeautifulSoup' into a single .py file?</p>
<p>My problem is the following:
I have a python script that requires mechanize and BeautifulSoup. I am calling it from a php page. The webhost server supports python, but doesn't have the modules installed. That... | 2 | 2009-09-18T21:09:49Z | 1,446,977 | <p>No, you can't (in general), because doing so would destroy the module searching method that python uses (files and directories). I guess that you could, with some hack, generate a module hierarchy without having the actual filesystem layout, but this is a huge hack, probably something like</p>
<pre><code>>>&g... | 0 | 2009-09-18T21:48:04Z | [
"python",
"encapsulation"
] |
Help with Python in the web | 1,447,010 | <p>I've been using <a href="http://werkzeug.pocoo.org/" rel="nofollow">Werkzeug</a> to make WSGI compliant applications. I'm trying to modify the code in the front page.</p>
<p>Its basic idea is that you go to the /hello URL and you get a "Hello World!" message. You go to /hello/ and you get "hello !". For example, /h... | 0 | 2009-09-18T21:59:03Z | 1,447,101 | <p>Directly on the page link to which you provide (<a href="http://werkzeug.pocoo.org/" rel="nofollow">http://werkzeug.pocoo.org/</a>) when clicking on 'Click here', you get a code for the hello X example. What you seem to be missing is:</p>
<pre><code>Hello ${url_values['name']|h}!
</code></pre>
<p>somewhere in your... | -1 | 2009-09-18T22:31:30Z | [
"python",
"wsgi",
"werkzeug"
] |
Help with Python in the web | 1,447,010 | <p>I've been using <a href="http://werkzeug.pocoo.org/" rel="nofollow">Werkzeug</a> to make WSGI compliant applications. I'm trying to modify the code in the front page.</p>
<p>Its basic idea is that you go to the /hello URL and you get a "Hello World!" message. You go to /hello/ and you get "hello !". For example, /h... | 0 | 2009-09-18T21:59:03Z | 1,447,174 | <p>HTML Forms have a static target address, <code>action="/something"</code>, but you want to <em>change the address depending user input</em>.
You have two options: </p>
<ol>
<li><p>Add javascript to the html form to
change the target address (by
appending the name) before the form
is submitted.</p></li>
<li><p>Write... | 0 | 2009-09-18T23:03:11Z | [
"python",
"wsgi",
"werkzeug"
] |
Help with Python in the web | 1,447,010 | <p>I've been using <a href="http://werkzeug.pocoo.org/" rel="nofollow">Werkzeug</a> to make WSGI compliant applications. I'm trying to modify the code in the front page.</p>
<p>Its basic idea is that you go to the /hello URL and you get a "Hello World!" message. You go to /hello/ and you get "hello !". For example, /h... | 0 | 2009-09-18T21:59:03Z | 1,447,221 | <p>HTML is based on the REST principle... each url should be an object, like a person; NOT an action, like saying hello to a person. Have the URL identify who you want to greet only if your web application knows who that is internally, by looking at its database.</p>
<p>If your webapplication has no object called Joe... | -1 | 2009-09-18T23:31:56Z | [
"python",
"wsgi",
"werkzeug"
] |
Help with Python in the web | 1,447,010 | <p>I've been using <a href="http://werkzeug.pocoo.org/" rel="nofollow">Werkzeug</a> to make WSGI compliant applications. I'm trying to modify the code in the front page.</p>
<p>Its basic idea is that you go to the /hello URL and you get a "Hello World!" message. You go to /hello/ and you get "hello !". For example, /h... | 0 | 2009-09-18T21:59:03Z | 1,447,616 | <p>Do it the right way: go to <code>/hello?name=joe</code> to say hello to joe, and so forth. That's how HTML/HTTP is <strong>designed</strong> to work! Your code behind the <code>/hello</code> URL just needs to get the <code>name</code> parameter from the request, if present, and respond accordingly.</p>
| 1 | 2009-09-19T03:14:15Z | [
"python",
"wsgi",
"werkzeug"
] |
Embed a spreadsheet/table in a PyGTK application? | 1,447,187 | <p>In my application, we want to present the user with a typical spreadsheet/table (OO.O/Excel-style), and then pull out the values and do something with them internally.</p>
<p>Is there a preexisting widget for PyGTK that does this? The <a href="http://faq.pygtk.org/index.py?req=all#19.14" rel="nofollow">PyGTK FAQ</a... | 2 | 2009-09-18T23:10:48Z | 1,447,200 | <p>It's perhaps a little more manual than, for instance, a GridView in .Net, but the Tree View widget will do what you need and much more. See <a href="http://www.pygtk.org/pygtk2tutorial/ch-TreeViewWidget.html" rel="nofollow">PyGtk TreeView</a></p>
| 3 | 2009-09-18T23:17:36Z | [
"python",
"pygtk",
"spreadsheet"
] |
Embed a spreadsheet/table in a PyGTK application? | 1,447,187 | <p>In my application, we want to present the user with a typical spreadsheet/table (OO.O/Excel-style), and then pull out the values and do something with them internally.</p>
<p>Is there a preexisting widget for PyGTK that does this? The <a href="http://faq.pygtk.org/index.py?req=all#19.14" rel="nofollow">PyGTK FAQ</a... | 2 | 2009-09-18T23:10:48Z | 1,447,210 | <p>You might consider embedding a web page viewer - you can do a lot with that: <a href="http://blog.mypapit.net/2009/09/pymoembed-web-browser-in-python-gtk-application.html" rel="nofollow">http://blog.mypapit.net/2009/09/pymoembed-web-browser-in-python-gtk-application.html</a></p>
| 0 | 2009-09-18T23:24:49Z | [
"python",
"pygtk",
"spreadsheet"
] |
Embed a spreadsheet/table in a PyGTK application? | 1,447,187 | <p>In my application, we want to present the user with a typical spreadsheet/table (OO.O/Excel-style), and then pull out the values and do something with them internally.</p>
<p>Is there a preexisting widget for PyGTK that does this? The <a href="http://faq.pygtk.org/index.py?req=all#19.14" rel="nofollow">PyGTK FAQ</a... | 2 | 2009-09-18T23:10:48Z | 1,450,766 | <p><code>GtkGrid</code> is deprecated in favor of the more powerful and more customizable <a href="http://library.gnome.org/devel/pygtk/stable/class-gtktreeview.html" rel="nofollow"><code>GtkTreeView</code></a>.</p>
<p>It can display trees and lists. To make it work like a table, you must define a <a href="http://libr... | 12 | 2009-09-20T10:49:20Z | [
"python",
"pygtk",
"spreadsheet"
] |
How do I partition datetime intervals which overlap (Org Mode clocked time)? | 1,447,257 | <p>I have related tasks from two Org files/subtrees where some of the clocked time overlaps. These are a manual worklog and a generated git commit log, see below.</p>
<p>One subtree's CLOCK: entries needs to be adjusted to remove overlapping time. The other subtree is considered complete, and it's CLOCK: entries shoul... | 2 | 2009-09-18T23:55:09Z | 1,447,648 | <p>Do you want help parsing the file format? Or just on figuring out the overlapping times?</p>
<p><code>datetime</code> objects are comparable in Python, so you can do something like this:</p>
<pre><code>>>> (a,b) = (datetime(2009, 9, 15, 8, 30), datetime(2009, 9, 15, 8, 45))
>>> (c,d) = (datetime(... | 2 | 2009-09-19T03:34:42Z | [
"python",
"datetime",
"emacs",
"overlap",
"org-mode"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 1,447,562 | <p>You can do what you need to do, but it isn't documented:</p>
<pre><code>>>> import json
>>> json.encoder.FLOAT_REPR = lambda f: ("%.2f" % f)
>>> json.dumps([23.67, 23.97, 23.87])
'[23.67, 23.97, 23.87]'
</code></pre>
| 7 | 2009-09-19T02:40:29Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 1,447,581 | <p>Unfortunately, I believe you have to do this by monkey-patching (which, to my opinion, indicates a design defect in the standard library <code>json</code> package). E.g., this code:</p>
<pre><code>import json
from json import encoder
encoder.FLOAT_REPR = lambda o: format(o, '.2f')
print json.dumps(23.67)
print jso... | 52 | 2009-09-19T02:48:41Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 1,645,929 | <p>If you're stuck with Python 2.5 or earlier versions: The monkey-patch trick does not seem to work with the original simplejson module if the C speedups are installed:</p>
<pre><code>$ python
Python 2.5.4 (r254:67916, Jan 20 2009, 11:06:13)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "... | 6 | 2009-10-29T19:15:58Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 1,733,105 | <pre><code>import simplejson
class PrettyFloat(float):
def __repr__(self):
return '%.15g' % self
def pretty_floats(obj):
if isinstance(obj, float):
return PrettyFloat(obj)
elif isinstance(obj, dict):
return dict((k, pretty_floats(v)) for k, v in obj.items())
elif isinstance(obj... | 37 | 2009-11-14T03:16:28Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 5,574,182 | <p>If you're using Python 2.7, a simple solution is to simply round your floats explicitly to the desired precision.</p>
<pre><code>>>> sys.version
'2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)]'
>>> json.dumps(1.0/3.0)
'0.3333333333333333'
>>> json.dumps(round(1.0/3.... | 19 | 2011-04-06T23:29:36Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 6,245,594 | <p>If you need to do this in python 2.7 without overriding the global json.encoder.FLOAT_REPR, here's one way.</p>
<pre><code>import json
import math
class MyEncoder(json.JSONEncoder):
"JSON encoder that renders floats to two decimal places"
FLOAT_FRMT = '{0:.2f}'
def floatstr(self, obj):
return... | 0 | 2011-06-05T20:19:17Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 6,769,777 | <p>Alex Martelli's solution will work for single threaded apps, but may not work for multi-threaded apps that need to control the number of decimal places per thread. Here is a solution that should work in multi threaded apps:</p>
<pre><code>import threading
from json import encoder
def FLOAT_REPR(f):
"""
Ser... | 2 | 2011-07-20T23:35:23Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 9,777,521 | <p>Pros:</p>
<ul>
<li>Works with any JSON encoder, or even python's repr. </li>
<li>Short(ish), seems to work.</li>
</ul>
<p>Cons:</p>
<ul>
<li>Ugly regexp hack, barely tested.</li>
<li><p>Quadratic complexity.</p>
<pre><code>def fix_floats(json, decimals=2, quote='"'):
pattern = r'^((?:(?:"(?:\\.|[^\\"])*?")... | 1 | 2012-03-19T20:34:01Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 23,390,008 | <p>When importing the standard json module, it is enough to change the default encoder FLOAT_REPR. There isn't really the need to import or create Encoder instances.</p>
<pre><code>import json
json.encoder.FLOAT_REPR = lambda o: format(o, '.2f')
json.dumps([23.67, 23.97, 23.87]) #returns '[23.67, 23.97, 23.87]'
</co... | 1 | 2014-04-30T13:51:32Z | [
"python",
"json",
"formatting",
"floating-point"
] |
Format floats with standard json module | 1,447,287 | <p>I am using the standard <a href="http://docs.python.org/library/json.html">json module</a> in python 2.6 to serialize a list of floats. However, I'm getting results like this:</p>
<pre><code>>>> import json
>>> json.dumps([23.67, 23.97, 23.87])
'[23.670000000000002, 23.969999999999999, 23.87000000... | 53 | 2009-09-19T00:08:37Z | 29,066,406 | <p>Really unfortunate that <code>dumps</code> doesn't allow you to do anything to floats. However <code>loads</code> does. So if you don't mind the extra CPU load, you could throw it through the encoder/decoder/encoder and get the right result:</p>
<pre><code>>>> json.dumps(json.loads(json.dumps([.33333333333... | 0 | 2015-03-15T21:30:41Z | [
"python",
"json",
"formatting",
"floating-point"
] |
How to send a file via HTTP, the good way, using Python? | 1,447,353 | <p>If a would-be-HTTP-server written in Python2.6 has local access to a file, what would be the most correct way for that server to return the file to a client, on request?</p>
<p>Let's say this is the current situation:</p>
<pre><code>header('Content-Type', file.mimetype)
header('Content-Length', file.size) # file s... | 5 | 2009-09-19T00:39:51Z | 1,447,388 | <p>If you don't have to return the response body (that is, if you are given a stream for the response body by your framework) you can avoid holding the file in memory with something like this:</p>
<pre><code>fp = file(path_to_the_file, 'rb')
while True:
bytes = fp.read(8192)
if bytes:
response.write(by... | 1 | 2009-09-19T01:01:05Z | [
"python",
"http",
"http-headers"
] |
How to send a file via HTTP, the good way, using Python? | 1,447,353 | <p>If a would-be-HTTP-server written in Python2.6 has local access to a file, what would be the most correct way for that server to return the file to a client, on request?</p>
<p>Let's say this is the current situation:</p>
<pre><code>header('Content-Type', file.mimetype)
header('Content-Length', file.size) # file s... | 5 | 2009-09-19T00:39:51Z | 1,447,400 | <p>This is how I send ZIP file,</p>
<pre><code> req.send_response(200)
req.send_header('Content-Type', 'application/zip')
req.send_header('Content-Disposition', 'attachment;'
'filename=%s' % filename)
</code></pre>
<p>Most browsers handle it correctly.</p>
| 6 | 2009-09-19T01:04:49Z | [
"python",
"http",
"http-headers"
] |
Installed Python to portable python | 1,447,422 | <p>I have installed python from .msi installer in windows and installed a lot of other modules. i would like to have all these available on a portable thumbdrive, but i don't want to redownload all the extramodules. Is there a way i can convert my C:\python26* to a portable python installation?</p>
| 1 | 2009-09-19T01:19:00Z | 1,447,430 | <p>Python is pretty smart about knowing where it is run from. What happens if you just copy the whole directory tree to the thumb drive?</p>
| 1 | 2009-09-19T01:21:30Z | [
"python"
] |
How do I see the results of my class on a file? | 1,447,487 | <p>I found this class to take a space delimited file and if there are multiple spaces, they will be treated as a single separator. How do I see the effects of this on a file?</p>
<pre><code>class FH:
def __init__(self, fh):
self.fh = fh
def close(self):
self.fh.close()
def seek(self, ar... | 0 | 2009-09-19T01:52:10Z | 1,447,512 | <p>Looks like this class takes a file (not a file name) in the initializer. Try:</p>
<pre><code>r = FH(file('classfhtry.csv', 'r'))
for line in r:
print line
</code></pre>
| 5 | 2009-09-19T02:07:08Z | [
"python",
"class"
] |
How do I see the results of my class on a file? | 1,447,487 | <p>I found this class to take a space delimited file and if there are multiple spaces, they will be treated as a single separator. How do I see the effects of this on a file?</p>
<pre><code>class FH:
def __init__(self, fh):
self.fh = fh
def close(self):
self.fh.close()
def seek(self, ar... | 0 | 2009-09-19T01:52:10Z | 1,447,533 | <p>dcrosta is correct. The class expects a space delimited contents in the file.
Have a file like:</p>
<p>somefile.txt</p>
<pre><code>one two
three four
five six
</code></pre>
<p>And follow the method as suggested above. The class is an iterator (it yields the lines from the file obj). So, the way to access to the f... | 0 | 2009-09-19T02:19:20Z | [
"python",
"class"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 1,447,591 | <p>Problem is, as explained e.g. <a href="http://en.wikipedia.org/wiki/Symbolic%5Flink#Microsoft%5FWindows">here</a>, that Windows' own support for the functionality of symbolic links varies across Windows releases, so that e.g. in Vista (with lots of work) you can get more functionality than in XP or 2000 (nothing AFA... | 8 | 2009-09-19T02:54:33Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 1,447,651 | <p>NTFS file system has junction points, i think you may use them instead</p>
<p>copied from my answer to <a href="http://stackoverflow.com/questions/1143260/create-ntfs-junction-point-in-python">Create NTFS junction point in Python</a></p>
<p>you can use python win32 API modules e.g.</p>
<pre><code>import win32file... | 27 | 2009-09-19T03:37:05Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 4,388,195 | <p>I put the following into Lib/site-packages/sitecustomize.py</p>
<pre><code>import os
__CSL = None
def symlink(source, link_name):
'''symlink(source, link_name)
Creates a symbolic link pointing to source named link_name'''
global __CSL
if __CSL is None:
import ctypes
csl = ctypes.... | 4 | 2010-12-08T13:49:47Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 7,924,557 | <p><a href="https://github.com/juntalis/ntfslink-python">python ntfslink extension</a></p>
<p>Or if you want to use pywin32, you can use the previously stated method, and to read, use:</p>
<pre><code>from win32file import *
from winioctlcon import FSCTL_GET_REPARSE_POINT
__all__ = ['islink', 'readlink']
# Win32file... | 9 | 2011-10-28T02:35:43Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 10,392,885 | <p>Juntalis's code does not handle Unicode so I modified it to use ctypes and also simplified it using struct. I've also consulted the code from <a href="http://stackoverflow.com/questions/8744246/using-a-struct-as-a-function-argument-with-the-python-ctypes-module">Using a struct as a function argument with the python... | 1 | 2012-05-01T02:34:13Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 20,511,634 | <p>os.symlink works on Python 3.3 using Windows 8.1 with an NTFS filesystem.</p>
| 2 | 2013-12-11T05:59:38Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 21,636,530 | <p>here is the link containing all methods of kernel32.dll</p>
<p><a href="http://www.geoffchappell.com/studies/windows/win32/kernel32/api/" rel="nofollow">http://www.geoffchappell.com/studies/windows/win32/kernel32/api/</a></p>
<p>I used CreateHardLinkA on Windows xp sp3, it worked!</p>
<p>import ctypes
if os.p... | -1 | 2014-02-07T19:47:56Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Symlinks on windows? | 1,447,575 | <p>Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.</p>
| 25 | 2009-09-19T02:44:58Z | 22,225,651 | <p>Using mklink command in subprocess create link.</p>
<pre><code>from subprocess import call
call(['mklink', 'LINK', 'TARGET'], shell=True)
</code></pre>
| 1 | 2014-03-06T13:13:59Z | [
"python",
"winapi",
"symlink",
"pywin32"
] |
Error trying to pass (large) image over socket in python | 1,447,684 | <p>I am trying to pass an image over python socket for smaller images it works fine but for larger images it gives error as</p>
<p>socket.error: [Errno 10040] A message sent on a datagram socket was larger than
the internal message buffer or some other network limit, or the buffer used to receive a datagram into was s... | 1 | 2009-09-19T03:52:22Z | 1,447,690 | <p><a href="http://support.ipswitch.com/kb/WSK-19980714-EM13.htm" rel="nofollow">The message you are sending is being truncated</a>.</p>
<p>Since you haven't shown the actual code that <code>send</code>s, I'm guessing you are trying to write the entire image to the socket. You'll have to break the image into several,... | 2 | 2009-09-19T03:55:41Z | [
"python",
"sockets"
] |
Error trying to pass (large) image over socket in python | 1,447,684 | <p>I am trying to pass an image over python socket for smaller images it works fine but for larger images it gives error as</p>
<p>socket.error: [Errno 10040] A message sent on a datagram socket was larger than
the internal message buffer or some other network limit, or the buffer used to receive a datagram into was s... | 1 | 2009-09-19T03:52:22Z | 1,447,700 | <p>Your image is too big to be sent in one UDP packet. You need to split the image data into several packets that are sent individually.</p>
<p>If you don't have a special reason to use UDP you could also use TCP by specifying <code>socket.SOCK_STREAM</code> instead of <code>socket.SOCK_DGRAM</code>. There you don't h... | 5 | 2009-09-19T04:02:13Z | [
"python",
"sockets"
] |
Django ORM, filtering objects by type with model inheritence | 1,447,742 | <p>So I have two models...</p>
<p>Parent and Child.</p>
<p>Child extends Parent.</p>
<p>When I do</p>
<p>Parent.objects.all(), I get both the Parents and the Children.</p>
<p>I only want Parents</p>
<p>Is there a Parent.objects.filter() argument I can use to only get the Parent objects instead of the objects that... | 1 | 2009-09-19T04:30:04Z | 1,447,755 | <p>The <code>filter</code> method is essentially about building the WHERE clause in the SQL query, and that's a realy awkward place to be quibbling about exact types. What about, instead...:</p>
<pre><code>(p for Parent.objects.all() if type(p) is Parent)
</code></pre>
<p>this is an iterable (use <code>[ ]</code> on ... | 2 | 2009-09-19T04:38:21Z | [
"python",
"django",
"django-models"
] |
Django ORM, filtering objects by type with model inheritence | 1,447,742 | <p>So I have two models...</p>
<p>Parent and Child.</p>
<p>Child extends Parent.</p>
<p>When I do</p>
<p>Parent.objects.all(), I get both the Parents and the Children.</p>
<p>I only want Parents</p>
<p>Is there a Parent.objects.filter() argument I can use to only get the Parent objects instead of the objects that... | 1 | 2009-09-19T04:30:04Z | 1,448,340 | <p>Are you sure that inheritance is the right solution here? What about this?</p>
<pre><code>class MyModel(models.Model):
foo = models.IntegerField()
parent = models.ForeignKey("self", null=True)
</code></pre>
<p>Then you can query for all objects that are parents like this:</p>
<pre><code>parents = MyModel.... | 2 | 2009-09-19T11:08:15Z | [
"python",
"django",
"django-models"
] |
Django ORM, filtering objects by type with model inheritence | 1,447,742 | <p>So I have two models...</p>
<p>Parent and Child.</p>
<p>Child extends Parent.</p>
<p>When I do</p>
<p>Parent.objects.all(), I get both the Parents and the Children.</p>
<p>I only want Parents</p>
<p>Is there a Parent.objects.filter() argument I can use to only get the Parent objects instead of the objects that... | 1 | 2009-09-19T04:30:04Z | 1,450,247 | <p>Maybe it's a good place to use an <strong>A</strong>bstract <strong>B</strong>ase <strong>C</strong>lass instead of using inheritance. The ABC hold all the fields that are common to your classes. So, in your case, you will have one ABC mostly defined has your current Parent Class and 2 classes that will inherit from... | 3 | 2009-09-20T03:43:13Z | [
"python",
"django",
"django-models"
] |
Django ORM, filtering objects by type with model inheritence | 1,447,742 | <p>So I have two models...</p>
<p>Parent and Child.</p>
<p>Child extends Parent.</p>
<p>When I do</p>
<p>Parent.objects.all(), I get both the Parents and the Children.</p>
<p>I only want Parents</p>
<p>Is there a Parent.objects.filter() argument I can use to only get the Parent objects instead of the objects that... | 1 | 2009-09-19T04:30:04Z | 3,670,924 | <p>I've found a better way to solve this, using the django ORM and without the need for any changes to your models (such as an ABC):</p>
<blockquote>
<pre><code>class Parent(models.Model):
field1 = models.IntegerField()
field2 = models.IntegerField()
class Child(Parent):
field3 = models.IntegerField()
#R... | 12 | 2010-09-08T18:43:48Z | [
"python",
"django",
"django-models"
] |
IDLE and Python have different path in Mac OS X | 1,447,961 | <p>I am running Mac OS X 10.5.8. I have installed Python 2.6 from the site. It's in my application directory. I have edited my .bash_profile to have:</p>
<pre><code># Setting PATH for MacPython 2.6
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${P... | 2 | 2009-09-19T06:34:45Z | 1,448,009 | <p>Seems to be a common problem:</p>
<p><a href="http://www.google.com/search?q=python+idle+pythonpath" rel="nofollow">http://www.google.com/search?q=python+idle+pythonpath</a></p>
<p>Unfortunately, no answers. The only suggestion seemed to be to edit the <code>idle</code> executable and adding a few <code>sys.path.i... | 0 | 2009-09-19T07:09:35Z | [
"python",
"django"
] |
IDLE and Python have different path in Mac OS X | 1,447,961 | <p>I am running Mac OS X 10.5.8. I have installed Python 2.6 from the site. It's in my application directory. I have edited my .bash_profile to have:</p>
<pre><code># Setting PATH for MacPython 2.6
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${P... | 2 | 2009-09-19T06:34:45Z | 1,448,173 | <p>Like all OS X application bundles, if you launch <code>IDLE.app</code> by double-clicking, a shell is not involved and thus .<code>bash_profile</code> or other shell initialization files are not invoked. There is a way to set user session environment variables through the use of a special <a href="http://developer.... | 2 | 2009-09-19T08:46:23Z | [
"python",
"django"
] |
Decorators should not have side effects? | 1,447,996 | <p>Editing because the initial code was confusing.</p>
<p>I would assume these two things to be same,</p>
<pre><code>#I would use either of these
#Option 1
def bar(*args):
pass
foo = deco(bar)
#Option2
@deco
def foo(*args):
pass
</code></pre>
<p>However if the decorators <code>deco</code> has side effects, ... | 0 | 2009-09-19T07:01:06Z | 1,448,006 | <p>Actually, these both are exactly the same:</p>
<pre><code>def foo(*args):
pass
foo = deco(foo)
@deco
def foo(*args):
pass
</code></pre>
<p>If you want to decorate <code>bar</code> and call it <code>foo</code>, <code>foo = deco(bar)</code> is the right way. It says: "decorate this previously defined thing ... | 2 | 2009-09-19T07:07:57Z | [
"python",
"django",
"decorator"
] |
Decorators should not have side effects? | 1,447,996 | <p>Editing because the initial code was confusing.</p>
<p>I would assume these two things to be same,</p>
<pre><code>#I would use either of these
#Option 1
def bar(*args):
pass
foo = deco(bar)
#Option2
@deco
def foo(*args):
pass
</code></pre>
<p>However if the decorators <code>deco</code> has side effects, ... | 0 | 2009-09-19T07:01:06Z | 1,448,797 | <p>Your examples do not express the same things in every case! Why do you insist on using bar? </p>
<p>Take your first example:</p>
<pre><code>#Option 1
def bar(*args):
pass
foo = deco(bar)
#Option2
@deco
def foo(*args):
pass
</code></pre>
<p>Option 1 does (literally)</p>
<pre><code>foo = deco(bar)
</code>... | 0 | 2009-09-19T15:43:04Z | [
"python",
"django",
"decorator"
] |
How to integrate JQGrid with Django/Python | 1,448,143 | <p>Anybody out there who have tried to use <a href="http://www.trirand.com/blog/" rel="nofollow">JQGrid</a> a Jquery plugin with django? </p>
<p>Please share your knowledge/code samples</p>
<p>Gath</p>
| 4 | 2009-09-19T08:23:11Z | 1,500,293 | <p>I'm trying to use it for the first day today. Right now I have imported an existing jquery app into a django project/app and now trying to get jqgrid to work with it. The thing I'm running into is having the javascript file actually call the python script for the json call for jgrid.</p>
<p>I have no idea if this... | -2 | 2009-09-30T19:48:53Z | [
"jquery",
"python",
"django",
"jqgrid"
] |
How to integrate JQGrid with Django/Python | 1,448,143 | <p>Anybody out there who have tried to use <a href="http://www.trirand.com/blog/" rel="nofollow">JQGrid</a> a Jquery plugin with django? </p>
<p>Please share your knowledge/code samples</p>
<p>Gath</p>
| 4 | 2009-09-19T08:23:11Z | 1,615,475 | <p>I've find a project that has already implemented integration
look at Google code <a href="http://code.google.com/p/django-jqgrid/" rel="nofollow">http://code.google.com/p/django-jqgrid/</a></p>
| 3 | 2009-10-23T19:34:14Z | [
"jquery",
"python",
"django",
"jqgrid"
] |
How to integrate JQGrid with Django/Python | 1,448,143 | <p>Anybody out there who have tried to use <a href="http://www.trirand.com/blog/" rel="nofollow">JQGrid</a> a Jquery plugin with django? </p>
<p>Please share your knowledge/code samples</p>
<p>Gath</p>
| 4 | 2009-09-19T08:23:11Z | 4,235,226 | <p>Is there any latest info on this? Looks like django-jqgrid not updated in a year</p>
| 1 | 2010-11-20T21:58:53Z | [
"jquery",
"python",
"django",
"jqgrid"
] |
How to integrate JQGrid with Django/Python | 1,448,143 | <p>Anybody out there who have tried to use <a href="http://www.trirand.com/blog/" rel="nofollow">JQGrid</a> a Jquery plugin with django? </p>
<p>Please share your knowledge/code samples</p>
<p>Gath</p>
| 4 | 2009-09-19T08:23:11Z | 9,029,522 | <p>take a look at <a href="http://readthedocs.org/docs/django-jquery-grid-admin/en/latest/" rel="nofollow">django-jquery-grid-admin</a></p>
| 0 | 2012-01-27T05:58:46Z | [
"jquery",
"python",
"django",
"jqgrid"
] |
Python SOCK_STREAM over internet | 1,448,193 | <p>I have a simple programs for socket client and server its not working over internet</p>
<pre><code># Echo server program
import socket
import ImageGrab
HOST = '' # Symbolic name meaning all available interfaces
PORT = 3000 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INE... | 2 | 2009-09-19T08:55:44Z | 1,448,227 | <p>You've got the right approach, but you are probably running into networking or firewall problems. Depending on how your friend's networking is configured, he may be behind NAT or a firewall that prevents you from making a direct connection into his computer.</p>
<p>To eliminate half the problem, you can use <code>t... | 4 | 2009-09-19T09:24:45Z | [
"python",
"sockets"
] |
What are the best benefits of using Pinax? | 1,448,292 | <p>I recently discovered <a href="http://pinaxproject.com/" rel="nofollow">Pinax</a> that appear to be an django stack with added most-used apps so easy and speed up development.</p>
<p>I never used or heard of Pinax before and like to know if you have feedback about it. I love Django and would like to understand what... | 24 | 2009-09-19T10:28:01Z | 1,448,640 | <p>Pinax is a collection of Django-Apps that have already been glued together for you with some code and sample templates.</p>
<p>It's not plug&play, because Django is not a CMS and Apps are not plugins, but you can get your site going really fast. You just have to remove the stuff you don't need, add other Django... | 13 | 2009-09-19T14:25:29Z | [
"python",
"django",
"pinax"
] |
What are the best benefits of using Pinax? | 1,448,292 | <p>I recently discovered <a href="http://pinaxproject.com/" rel="nofollow">Pinax</a> that appear to be an django stack with added most-used apps so easy and speed up development.</p>
<p>I never used or heard of Pinax before and like to know if you have feedback about it. I love Django and would like to understand what... | 24 | 2009-09-19T10:28:01Z | 1,448,968 | <p>I'm about to start using Pinax, and I'm glad I discovered it.</p>
<p>Our todo list for the site has a lot of things on it, such as new user sign-up with email verification, discussions, and a news feed for users that blends site-wide updates and updates for that user. We can code all of this up, but it'll take a wh... | 6 | 2009-09-19T17:02:43Z | [
"python",
"django",
"pinax"
] |
What are the best benefits of using Pinax? | 1,448,292 | <p>I recently discovered <a href="http://pinaxproject.com/" rel="nofollow">Pinax</a> that appear to be an django stack with added most-used apps so easy and speed up development.</p>
<p>I never used or heard of Pinax before and like to know if you have feedback about it. I love Django and would like to understand what... | 24 | 2009-09-19T10:28:01Z | 1,475,696 | <p>As the two other posts said, it comes with a lot of pre-packaged apps that take care of common tasks in modern websites. Here's a list of the external apps that come packaged: <a href="https://github.com/pinax/pinax/blob/master/requirements/pinax.txt" rel="nofollow">https://github.com/pinax/pinax/blob/master/require... | 4 | 2009-09-25T06:17:47Z | [
"python",
"django",
"pinax"
] |
Role-based security with Google App Engine and Python | 1,448,308 | <p>I would like to ask what is the common way for handling role-based security with Google App Engine, Python?</p>
<p>In the app.yaml, there is the "login" section, but available values are only "admin" and "required".</p>
<p>How do you normally handle role-based security?</p>
<ul>
<li>Create the model with two tabl... | 5 | 2009-09-19T10:42:25Z | 1,448,733 | <p>I would do this by adding a ListProperty for roles to the model representing users. The list contains any roles a given user belongs to. This way if you want to know whether a given user belongs to a given role (I expect, the most common operation), it is a fast membership test.</p>
<p>You could put the role names ... | 4 | 2009-09-19T15:10:37Z | [
"python",
"google-app-engine",
"role-based"
] |
Custom storage system for GridFS (MongoDB)? | 1,448,386 | <p>Can anyone point me to any projects/django apps that provide a plugable custom storage system so I can use GridFS with Django to store file uploads?</p>
<p>I've found django-mongodb but it doesnt seem to support GridFS, nor does django-storages.</p>
<p>I plan to run mysql for the normal database requrements and on... | 4 | 2009-09-19T11:38:03Z | 1,448,676 | <p>I work on PyMongo, the MongoDB Python driver, and haven't heard of any project to provide custom storage for Django using GridFS. This looks like it wouldn't be very hard to write on top of PyMongo: could probably be a direct translation of the <a href="http://api.mongodb.org/python/0.15.2/gridfs-module.html" rel="n... | 3 | 2009-09-19T14:40:16Z | [
"python",
"django",
"mongodb"
] |
Custom storage system for GridFS (MongoDB)? | 1,448,386 | <p>Can anyone point me to any projects/django apps that provide a plugable custom storage system so I can use GridFS with Django to store file uploads?</p>
<p>I've found django-mongodb but it doesnt seem to support GridFS, nor does django-storages.</p>
<p>I plan to run mysql for the normal database requrements and on... | 4 | 2009-09-19T11:38:03Z | 3,646,343 | <p><a href="https://github.com/django-mongodb-engine/mongodb-engine" rel="nofollow">django-mongodb-engine</a> might be worth a look as it enables you to do that without the need to make changes to your existing Django code.</p>
| 1 | 2010-09-05T14:13:25Z | [
"python",
"django",
"mongodb"
] |
Custom storage system for GridFS (MongoDB)? | 1,448,386 | <p>Can anyone point me to any projects/django apps that provide a plugable custom storage system so I can use GridFS with Django to store file uploads?</p>
<p>I've found django-mongodb but it doesnt seem to support GridFS, nor does django-storages.</p>
<p>I plan to run mysql for the normal database requrements and on... | 4 | 2009-09-19T11:38:03Z | 4,080,640 | <p>I recently implemented the <a href="http://schallis.com/2010/oct/18/so-gridfs-mongoengine--django-walk-into-a-bar-/" rel="nofollow">GridFS support in Mongoengine</a> which you might like to checkout. This includes a Django storage backend which you can plug right into you projects and use with ImageField etc. I'm us... | 1 | 2010-11-02T17:59:14Z | [
"python",
"django",
"mongodb"
] |
Custom storage system for GridFS (MongoDB)? | 1,448,386 | <p>Can anyone point me to any projects/django apps that provide a plugable custom storage system so I can use GridFS with Django to store file uploads?</p>
<p>I've found django-mongodb but it doesnt seem to support GridFS, nor does django-storages.</p>
<p>I plan to run mysql for the normal database requrements and on... | 4 | 2009-09-19T11:38:03Z | 5,202,247 | <p>I needed exactly that for <a href="https://github.com/rosarior/mayan" rel="nofollow">Mayan EDMS</a>, plugable storage and database separation. Using Michael Dirolf's latest PyMongo library, it was rather trivial to get a basic class going.</p>
<p>To use it:</p>
<pre><code>from gridfsstorage import GridFSStorage
f... | 1 | 2011-03-05T06:54:16Z | [
"python",
"django",
"mongodb"
] |
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, an... | 81 | 2009-09-19T12:04:41Z | 1,448,446 | <p>Install mysql and python via <a href="http://guide.macports.org/">Macports</a> The porters have done all the difficult work.</p>
<pre><code>sudo port install py26-mysql
sudo port install mysql5-server
</code></pre>
<p>should install what you need. (see <a href="http://stackoverflow.com/questions/1081231/macports-... | 36 | 2009-09-19T12:17:11Z | [
"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, an... | 81 | 2009-09-19T12:04:41Z | 1,448,476 | <p>Here is the tale of my rambling experience with this problem. Would love to see it edited or generalised if you have better experience of the issue... apply a bit of that SO magic.</p>
<p><strong>Note: Comments in next paragraph applied to Snow Leopard, but not to Lion, which appears to require 64-bit MySQL</stron... | 119 | 2009-09-19T12:37:04Z | [
"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, an... | 81 | 2009-09-19T12:04:41Z | 6,025,504 | <p>Here's another step I had to go through, after receiving an error on completing Step 9:</p>
<pre><code>ImportError: dlopen(/Users/rick/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18... | 13 | 2011-05-17T02:07:24Z | [
"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, an... | 81 | 2009-09-19T12:04:41Z | 13,867,261 | <p>Just had this problem (again!) after getting a new Lion box.</p>
<p>Best solution I've found (still not 100% optimal, but working):</p>
<ul>
<li><p>make sure you have 64-bit python. <a href="http://stackoverflow.com/questions/3207177/how-to-check-if-a-library-is-32bit-64bit-built-on-mac-os-x">How to check if a l... | 4 | 2012-12-13T19:46:17Z | [
"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, an... | 81 | 2009-09-19T12:04:41Z | 14,873,391 | <p>If you are using 64 bit MySQL, using ARCHFLAGS to specify your cpu architecture while building mysql-python libraries would do the trick:</p>
<pre><code>ARCHFLAGS='-arch x86_64' python setup.py build
ARCHFLAGS='-arch x86_64' python setup.py install
</code></pre>
| 0 | 2013-02-14T11:07:38Z | [
"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, an... | 81 | 2009-09-19T12:04:41Z | 18,178,419 | <p>A quick and easy way for Mac OS X <strong>10.8</strong> (Mountain Lion), <strong>10.9</strong> (Mavericks), <strong>10.10</strong> (Yosemite), and <strong>10.11</strong> (El Capitan):</p>
<p>I assume you have XCode, it's <a href="https://stackoverflow.com/questions/9329243/xcode-4-4-and-later-install-command-line-t... | 66 | 2013-08-12T01:32:58Z | [
"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, an... | 81 | 2009-09-19T12:04:41Z | 19,769,044 | <p>Install pip:</p>
<pre><code>sudo easy_install pip
</code></pre>
<p>Install brew:</p>
<pre><code>ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
</code></pre>
<p>Install mysql:</p>
<pre><code>brew install mysql
</code></pre>
<p>Install MySQLdb</p>
<pre><code>sudo pip install MySQL-p... | 8 | 2013-11-04T13:46:27Z | [
"python",
"mysql",
"osx"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.