title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
HTTP POST Requests require multiple transmissions? | 2,339,742 | <p>I found the quoted text in Programming Python 3rd edition by Mark Lutz from Chapter 16: Server-Side Scripting (page 987):</p>
<blockquote>
<p>Forms also include a method option to specify the encoding style to be used to send data over a socket to the target server machine. Here, we use the <strong>post style, wh... | 2 | 2010-02-26T05:51:15Z | 22,616,141 | <p>The <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html" rel="nofollow">HTTP Expect 100-Continue header (see 8.2.3)</a> and <a href="https://tools.ietf.org/html/rfc2616#section-10.1.1" rel="nofollow">100 Continue response</a> allows the client split HTTP POSTs into 2 transmissions (over a single connectio... | 0 | 2014-03-24T17:13:55Z | [
"python",
"http",
"post",
"cgi",
"get"
] |
Why copy post data in Django instead of working with it directly? | 2,339,857 | <p>Django code samples involving post data often shows code similar to this:</p>
<pre><code>if request.method == "POST":
post = request.POST.copy()
#do stuff with post data
</code></pre>
<p>Is there a reason for copying the post data instead of working with it directly?</p>
| 5 | 2010-02-26T06:26:44Z | 2,339,963 | <p>I think it is because <code>request.POST</code> itself is defined immutable. If you want a version you can actually change (mutability), you need a copy of the data to work with.</p>
<p>See <a href="http://docs.djangoproject.com/en/1.6/ref/request-response/#querydict-objects" rel="nofollow">this link</a> (request.P... | 10 | 2010-02-26T06:57:26Z | [
"python",
"django"
] |
Logout functionality in django | 2,339,941 | <p>All</p>
<p>In django project if 2 template windows are opened and if logout is triggered in 1 window the other window cookies are not cleared.How to delete the cookies also so that the logout will be triggered.</p>
<pre><code>def logout(request):
//request = redirect('webbie.home.views.loginpage')
//reque... | 0 | 2010-02-26T06:49:53Z | 2,339,955 | <p>What do you mean exactly? You mean if you have to windows open with the same website, and you log out in one window, you are not logged out in the other window? I doubt that.</p>
<p>Of course you are not redirected in the other window to a certain page because you haven't done anything in this specific window. But ... | 0 | 2010-02-26T06:54:51Z | [
"python",
"django"
] |
Logout functionality in django | 2,339,941 | <p>All</p>
<p>In django project if 2 template windows are opened and if logout is triggered in 1 window the other window cookies are not cleared.How to delete the cookies also so that the logout will be triggered.</p>
<pre><code>def logout(request):
//request = redirect('webbie.home.views.loginpage')
//reque... | 0 | 2010-02-26T06:49:53Z | 2,341,104 | <p>In the cookie you should only store a session key. The server then needs to keep track of all session keys and associate expire date/time and user-account with them. For every user that logs in they should be given a new session key, though you may allow multiple logins/user-account. So when you check if the cookie ... | 1 | 2010-02-26T11:11:18Z | [
"python",
"django"
] |
How to force Excel VBA to use updated COM server | 2,339,993 | <p>I'm developing a COM server to be used from Excel VBA. When I update the server (edit code, unregister, re-register) Excel seems to carry on using the original version of the COM server, not the updated version. The only way I have found to get it to use the updated version is to close and re-open Excel, which get... | 0 | 2010-02-26T07:06:48Z | 2,340,361 | <p>Just a suggestion, have you tried to Unload the object? Maybe create a button in your excel spredsheat that force to unload the object.</p>
<p>I hope it helps</p>
| 0 | 2010-02-26T08:36:30Z | [
"python",
"com",
"excel-vba",
"win32com"
] |
How to force Excel VBA to use updated COM server | 2,339,993 | <p>I'm developing a COM server to be used from Excel VBA. When I update the server (edit code, unregister, re-register) Excel seems to carry on using the original version of the COM server, not the updated version. The only way I have found to get it to use the updated version is to close and re-open Excel, which get... | 0 | 2010-02-26T07:06:48Z | 2,354,316 | <p>I've found a solution to my problem - the general idea is to set things up so that the main COM server class dynamically loads the rest of the COM server code when it is called. So in Python I've created a COM server class that looks something like:</p>
<pre><code>import main_code
class COMInterface:
_public_... | 1 | 2010-03-01T07:07:42Z | [
"python",
"com",
"excel-vba",
"win32com"
] |
Decrypt VIM encrypted file in Python | 2,340,096 | <p>In my Python web app, I would need to decrypt a file that was encrypted using VIM. Assuming the web app knows the password used to encrypt the file in VIM, how do I write code to decrypt ?</p>
| 3 | 2010-02-26T07:32:56Z | 2,340,228 | <p>Turns out that vim uses the same encryption as PKZIP:</p>
<pre><code>from zipfile import _ZipDecrypter
fp = open(somefile, 'rb')
zd = _ZipDecrypter(somekey)
fp.read(12)
print ''.join(zd(c) for c in fp.read())
fp.close()
</code></pre>
| 7 | 2010-02-26T08:06:27Z | [
"python",
"vim",
"encryption"
] |
Decrypt VIM encrypted file in Python | 2,340,096 | <p>In my Python web app, I would need to decrypt a file that was encrypted using VIM. Assuming the web app knows the password used to encrypt the file in VIM, how do I write code to decrypt ?</p>
| 3 | 2010-02-26T07:32:56Z | 37,783,572 | <p>I wrote a tool to do exactly that, also supporting the more recent encryption methods:</p>
<p><a href="https://github.com/nlitsme/vimdecrypt" rel="nofollow">https://github.com/nlitsme/vimdecrypt</a></p>
| 1 | 2016-06-13T07:01:21Z | [
"python",
"vim",
"encryption"
] |
Python 3.1.1 string to hex | 2,340,319 | <p>I am trying to use <code>str.encode()</code> but I get</p>
<pre><code>>>> "hello".encode(hex)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not builtin_function_or_method
</code></pre>
<p>I have tried a bunch of variations and they seem to ... | 33 | 2010-02-26T08:27:09Z | 2,340,339 | <p>You've already got some good answers, but I thought you might be interested in a bit of the background too.</p>
<p>Firstly you're missing the quotes. It should be:</p>
<pre><code>"hello".encode("hex")
</code></pre>
<p>Secondly this codec hasn't been ported to Python 3.1. See <a href="http://bugs.python.org/issue7... | 15 | 2010-02-26T08:31:05Z | [
"python",
"string",
"python-3.x",
"hex"
] |
Python 3.1.1 string to hex | 2,340,319 | <p>I am trying to use <code>str.encode()</code> but I get</p>
<pre><code>>>> "hello".encode(hex)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not builtin_function_or_method
</code></pre>
<p>I have tried a bunch of variations and they seem to ... | 33 | 2010-02-26T08:27:09Z | 2,340,358 | <p>The <code>hex</code> codec has been chucked in 3.x. Use <a href="http://docs.python.org/3.1/library/binascii.html#binascii.b2a_hex"><code>binascii</code></a> instead:</p>
<pre><code>>>> binascii.hexlify(b'hello')
b'68656c6c6f'
</code></pre>
| 44 | 2010-02-26T08:36:12Z | [
"python",
"string",
"python-3.x",
"hex"
] |
Python 3.1.1 string to hex | 2,340,319 | <p>I am trying to use <code>str.encode()</code> but I get</p>
<pre><code>>>> "hello".encode(hex)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not builtin_function_or_method
</code></pre>
<p>I have tried a bunch of variations and they seem to ... | 33 | 2010-02-26T08:27:09Z | 2,340,360 | <p>Use hexlify - <a href="http://epydoc.sourceforge.net/stdlib/binascii-module.html" rel="nofollow">http://epydoc.sourceforge.net/stdlib/binascii-module.html</a></p>
| 3 | 2010-02-26T08:36:23Z | [
"python",
"string",
"python-3.x",
"hex"
] |
Python 3.1.1 string to hex | 2,340,319 | <p>I am trying to use <code>str.encode()</code> but I get</p>
<pre><code>>>> "hello".encode(hex)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not builtin_function_or_method
</code></pre>
<p>I have tried a bunch of variations and they seem to ... | 33 | 2010-02-26T08:27:09Z | 13,546,090 | <p>binascii methodes are easier by the way</p>
<pre><code>>>> import binascii
>>> x=b'test'
>>> x=binascii.hexlify(x)
>>> x
b'74657374'
>>> y=str(x,'ascii')
>>> y
'74657374'
>>> x=binascii.unhexlify(x)
>>> x
b'test'
>>> y=str(x,'ascii')
&... | 8 | 2012-11-24T22:05:49Z | [
"python",
"string",
"python-3.x",
"hex"
] |
Python 3.1.1 string to hex | 2,340,319 | <p>I am trying to use <code>str.encode()</code> but I get</p>
<pre><code>>>> "hello".encode(hex)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not builtin_function_or_method
</code></pre>
<p>I have tried a bunch of variations and they seem to ... | 33 | 2010-02-26T08:27:09Z | 20,692,530 | <p><a href="http://docs.python.org/dev/library/base64.html#base64.b16encode" rel="nofollow"><code>base64.b16encode</code></a> and <a href="http://docs.python.org/dev/library/base64.html#base64.b16decode" rel="nofollow"><code>base64.b16decode</code></a> convert bytes to and from hex and work across all Python versions. ... | 3 | 2013-12-19T22:00:32Z | [
"python",
"string",
"python-3.x",
"hex"
] |
Python 3.1.1 string to hex | 2,340,319 | <p>I am trying to use <code>str.encode()</code> but I get</p>
<pre><code>>>> "hello".encode(hex)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not builtin_function_or_method
</code></pre>
<p>I have tried a bunch of variations and they seem to ... | 33 | 2010-02-26T08:27:09Z | 32,342,464 | <p>In Python 3, all strings are unicode. Usually, if you encode an unicode object to a string, you use <code>.encode('TEXT_ENCODING')</code>, since <code>hex</code> is not a text encoding, you should use <code>codecs.encode()</code> to handle arbitrary codecs. For example:</p>
<pre><code>>>>> "hello".encod... | 2 | 2015-09-01T23:34:54Z | [
"python",
"string",
"python-3.x",
"hex"
] |
User location information mapping with lastfm music track history in python | 2,340,589 | <p>I have two separate python scripts. One is for getting user location
information (which I get from web based geofeed provider.User Gsm is registerd
with that services).Another is for retrieving lastfm user track history.I have already
able to get user location data and user music track information.</p>
<p>Goal is ... | 0 | 2010-02-26T09:33:57Z | 2,342,697 | <p>Write a third script that import both of the other as modules, and make sure each module's functionality is embodied in a <em>function</em> (as is Python's best practice), <strong>not</strong> just "floating" as module-level code -- a module's top-level statements should usually be limited to <code>import</code>, <c... | 1 | 2010-02-26T15:32:39Z | [
"python",
"location",
"last.fm"
] |
Create new class object | 2,340,915 | <p>I have 2 class in python cl1 in f1.py file and cl2 in f2.py file. I wrote import f2</p>
<pre><code>import f2
class cl1:
a = f2.cl2()
</code></pre>
<p>But i see error in <code>a = f2.cl2()</code>: module object has no attribute 'cl2'</p>
<p>Why?</p>
<p>Thank you.</p>
| 0 | 2010-02-26T10:33:16Z | 2,340,970 | <p>sorry, i was wrong:
your problem is probably that you have a circular import: f1 imports f2 and vice versa.
check your design, as it usually should be possible to design your software without a circular import.</p>
<p>see: <a href="http://amix.dk/blog/post/19343" rel="nofollow">this</a></p>
| 1 | 2010-02-26T10:44:13Z | [
"python"
] |
Create new class object | 2,340,915 | <p>I have 2 class in python cl1 in f1.py file and cl2 in f2.py file. I wrote import f2</p>
<pre><code>import f2
class cl1:
a = f2.cl2()
</code></pre>
<p>But i see error in <code>a = f2.cl2()</code>: module object has no attribute 'cl2'</p>
<p>Why?</p>
<p>Thank you.</p>
| 0 | 2010-02-26T10:33:16Z | 2,342,649 | <p>The following code works just fine (if you're using Python 3 you can omit the <code>(object)</code> parts, but in Python 2 you should leave them in -- they're not responsible for your bug, but if you get used to omitting them you'll have strange problems in the future as your code grows...):</p>
<p><code>f2.py</cod... | 0 | 2010-02-26T15:25:47Z | [
"python"
] |
SVN pre-commit hook to reject Python files with inconsistent tab usage | 2,341,011 | <p>The Python interpreter can be started with <code>-tt</code> to raise a <code>TabError</code> exception if the interpreted file has inconsistent tab usage.</p>
<p>I'm trying to write a pre-commit hook for SVN that rejects files that raise this exception. I can pass the file being committed to <code>python -tt</code>... | 3 | 2010-02-26T10:52:49Z | 2,341,031 | <p>You can do this using the <a href="http://docs.python.org/library/py_compile.html" rel="nofollow"><code>py_compile</code></a> module:</p>
<pre><code>$ python -tt -c "import py_compile; py_compile.compile('test.py', doraise=True)"
</code></pre>
<p>The <code>doraise=True</code> will raise an exception and return wit... | 5 | 2010-02-26T10:57:33Z | [
"python",
"svn",
"pre-commit-hook"
] |
SVN pre-commit hook to reject Python files with inconsistent tab usage | 2,341,011 | <p>The Python interpreter can be started with <code>-tt</code> to raise a <code>TabError</code> exception if the interpreted file has inconsistent tab usage.</p>
<p>I'm trying to write a pre-commit hook for SVN that rejects files that raise this exception. I can pass the file being committed to <code>python -tt</code>... | 3 | 2010-02-26T10:52:49Z | 2,341,097 | <p>The preferred tab usage in Python is no tab usage at all (use four spaces for indentation). If that is your coding style then the problem may be reduced to checking if there are any tabs in the code. And this can be easily done with simple regexp, even with 'grep', so there is no even need to run the interpreter.</p... | 2 | 2010-02-26T11:09:41Z | [
"python",
"svn",
"pre-commit-hook"
] |
Django 1.1.1 chokes on multipart/form-data | 2,341,314 | <h1>Initial story</h1>
<p>I'm trying to implement file upload using a simple form (I'm pasting stripped version, but all important parts are included):</p>
<pre><code> <form method="POST" action="" enctype="multipart/form-data">
<input type="file" name="up_file" size="50">
<input type="hid... | 1 | 2010-02-26T11:48:09Z | 2,342,102 | <p>You may need to provide your view and form code as we use form uploads with <code>enctype="multipart/form-data"</code> in Django 1.1.1 with great success.</p>
<p>The following dummy app, for example, works perfectly in the dev server.</p>
<p><strong>views.py</strong></p>
<pre><code>from django import forms
from d... | 4 | 2010-02-26T14:03:09Z | [
"python",
"django",
"file-upload"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 2,341,349 | <p>Make a list from the iterable, or use <a href="http://docs.python.org/library/itertools.html#itertools.tee" rel="nofollow"><code>itertools.tee()</code></a>.</p>
| 2 | 2010-02-26T11:54:12Z | [
"python",
"iterator"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 2,341,505 | <p>If you want to iterate once, you can write your sum function:</p>
<pre><code>def mysum(l):
s2 = 0
s = 0
for e in l:
s += e
s2 += e * e
return (s, s2)
</code></pre>
<p>and use the result in your <code>sigma</code> function.</p>
<p><strong>Edit</strong>: now you can calculate the var... | 11 | 2010-02-26T12:28:05Z | [
"python",
"iterator"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 2,341,536 | <p>I am not sure there is much choice.</p>
<p>You will have to iterate your numbers twice in any case as the standard deviation will require the mean information on each value.</p>
<p>If you have enough memory, you can gain on the I/O access by loading your file in memory during the first iteration but that is about ... | 1 | 2010-02-26T12:33:16Z | [
"python",
"iterator"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 2,341,552 | <p>You have two solutions</p>
<ol>
<li><p>Make a list out of your iterator and loop it as many time as you wish. Drawback is everything will be in memory, so not suitable if your file is big. Simple use of itertools.tee also will not save you</p></li>
<li><p>There is no other solution , <strong>unless</strong> , you d... | 0 | 2010-02-26T12:35:46Z | [
"python",
"iterator"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 2,341,635 | <p>I think Nick D has the correct answer.</p>
<p>Assming you want to compute both mean and variance in one sweep of the file (and you don't really want two functions that have to be called one after the other), you can collect the sum of the values and of their squares and them use such sums (toghether with the number... | 5 | 2010-02-26T12:50:46Z | [
"python",
"iterator"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 2,341,704 | <p>As I feel that there are good elements scattered in multiple answers, I would like to summarize:</p>
<ul>
<li><p>If your file is too big to conveniently fit in memory, and if you want a good precision in the variance, you do need to read the file twice (with one pass, the variance is the difference between two larg... | 1 | 2010-02-26T12:59:31Z | [
"python",
"iterator"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 9,217,341 | <p>You can compute both in one pass. See:</p>
<p><a href="http://www.johndcook.com/standard_deviation.html" rel="nofollow">http://www.johndcook.com/standard_deviation.html</a></p>
| 2 | 2012-02-09T19:23:01Z | [
"python",
"iterator"
] |
calculate mean and variance with one iteration | 2,341,340 | <p>I have an iterator of numbers, for example a file object:</p>
<pre><code>f = open("datafile.dat")
</code></pre>
<p>now I want to compute:</p>
<pre><code>mean = get_mean(f)
sigma = get_sigma(f, mean)
</code></pre>
<p>What is the best implementation? Suppose that the file is big and I would like to avoid to read i... | 15 | 2010-02-26T11:51:59Z | 12,079,270 | <p>You can use map reduce in an elegant fashion way</p>
<p>sample is the list you want to get its variance</p>
<p>sample = [a,b,c, ...]</p>
<pre><code>mean = float(reduce(lambda x,y : x+y, sample)) / len(sample)
variance = reduce(lambda x,y: x+y, map(lambda xi: (xi-mean)**2, sample))/ len(sample)
</code></pre>
<p>... | 0 | 2012-08-22T18:31:50Z | [
"python",
"iterator"
] |
Pylons application Internationalization | 2,341,387 | <p>What the best way to make pylons application internationalist?</p>
| 0 | 2010-02-26T12:02:58Z | 2,341,398 | <p>A <a href="http://www.google.com/search?q=pylons+i18n" rel="nofollow">Google search</a> finds <a href="http://wiki.pylonshq.com/display/pylonsdocs/Internationalization+and+Localization" rel="nofollow">these docs</a>.</p>
| 2 | 2010-02-26T12:05:10Z | [
"python",
"internationalization",
"pylons"
] |
Pylons application Internationalization | 2,341,387 | <p>What the best way to make pylons application internationalist?</p>
| 0 | 2010-02-26T12:02:58Z | 5,129,764 | <p>PyICU and I highly recommend Babel.
Also if you need SEO you should read this:
<a href="http://my.opera.com/WebApplications/blog/2008/03/17/search-engine-friendly" rel="nofollow">http://my.opera.com/WebApplications/blog/2008/03/17/search-engine-friendly</a></p>
<p>If want more info (you can start using babel in fiv... | 0 | 2011-02-26T21:09:12Z | [
"python",
"internationalization",
"pylons"
] |
how are pgp keys formatted? | 2,341,486 | <p>i want to write a program in python to simply read pgp keys. however, i cant seem to find any documentation describing how pgp keys are formatted. i dont want to be searching through the source code of open pgp to look for source code that i wont be able to understand. </p>
<p>say i open a public key, remove the to... | 1 | 2010-02-26T12:23:24Z | 2,341,514 | <p>You can read the PGP RFCs (looks like the latest is <a href="http://tools.ietf.org/html/rfc4880" rel="nofollow">RFC 4880</a>). But why not use <a href="http://pyme.sourceforge.net/" rel="nofollow">pyme</a> instead?</p>
| 3 | 2010-02-26T12:29:53Z | [
"python",
"encryption",
"pgp",
"gnupg"
] |
how to make python to return floating point? | 2,341,771 | <p>hi
I want python to return 0.5 if I write 1/2 (and not 1.0/2.0).
how do I make python to return the floating point?
(I tried using getcontext().prec form decimal module)</p>
<p>thanks </p>
<p>Ariel</p>
| 3 | 2010-02-26T13:11:58Z | 2,341,790 | <pre><code>from __future__ import division
</code></pre>
| 4 | 2010-02-26T13:13:49Z | [
"python"
] |
how to make python to return floating point? | 2,341,771 | <p>hi
I want python to return 0.5 if I write 1/2 (and not 1.0/2.0).
how do I make python to return the floating point?
(I tried using getcontext().prec form decimal module)</p>
<p>thanks </p>
<p>Ariel</p>
| 3 | 2010-02-26T13:11:58Z | 2,341,791 | <p>Use this, or switch to Python 3.0+</p>
<pre><code>from __future__ import division
</code></pre>
| 8 | 2010-02-26T13:13:53Z | [
"python"
] |
how to make python to return floating point? | 2,341,771 | <p>hi
I want python to return 0.5 if I write 1/2 (and not 1.0/2.0).
how do I make python to return the floating point?
(I tried using getcontext().prec form decimal module)</p>
<p>thanks </p>
<p>Ariel</p>
| 3 | 2010-02-26T13:11:58Z | 2,343,619 | <p>Python 3.x works the way you want by default.</p>
<p>Python 2.2 and greater support <code>from __future__ import division</code>, which makes / return floating point. There is also the // operator that still performs integer division when needed.</p>
<p>Also see <a href="http://www.python.org/dev/peps/pep-0238/" ... | 3 | 2010-02-26T17:46:27Z | [
"python"
] |
Python socket data returns <byte> object. How to regexp it? | 2,341,972 | <p>I'm writing a basic html-proxy in python (3), and up to now I'm not using prebuild classes like http.server.</p>
<p>I'm just starting a socket which accepts connection:</p>
<pre><code>self.listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.listen_socket.bind((socket.gethostname(), 4321))
self.l... | 2 | 2010-02-26T13:42:27Z | 2,342,095 | <p>You need to include an encoding when converting to a string, for example use:</p>
<pre><code>>>> str(b'GET http://...', 'UTF-8')
'GET http://...'
</code></pre>
<p>If you don't use an encoding then as you've discovered you get something a little less helpful:</p>
<pre><code>>>> str(b'GET http://.... | 3 | 2010-02-26T14:01:37Z | [
"python",
"proxy",
"sockets",
"http-headers",
"python-3.x"
] |
Python socket data returns <byte> object. How to regexp it? | 2,341,972 | <p>I'm writing a basic html-proxy in python (3), and up to now I'm not using prebuild classes like http.server.</p>
<p>I'm just starting a socket which accepts connection:</p>
<pre><code>self.listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.listen_socket.bind((socket.gethostname(), 4321))
self.l... | 2 | 2010-02-26T13:42:27Z | 2,342,217 | <p>Also, you might want to check the <code>*HTTPServer</code> classes. They provide a wrapper around being HTTP servers and will also parse headers for you.</p>
<p>If you can't, well, at the very least they will provide source code examples on how to do it!</p>
| 1 | 2010-02-26T14:24:00Z | [
"python",
"proxy",
"sockets",
"http-headers",
"python-3.x"
] |
Python socket data returns <byte> object. How to regexp it? | 2,341,972 | <p>I'm writing a basic html-proxy in python (3), and up to now I'm not using prebuild classes like http.server.</p>
<p>I'm just starting a socket which accepts connection:</p>
<pre><code>self.listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.listen_socket.bind((socket.gethostname(), 4321))
self.l... | 2 | 2010-02-26T13:42:27Z | 7,548,949 | <p>Methods are provided to convert between bytes and strings try str.encode() and bytes.decode()</p>
<p><a href="http://python.about.com/od/python30/ss/30_strings_3.htm" rel="nofollow">http://python.about.com/od/python30/ss/30_strings_3.htm</a></p>
| 0 | 2011-09-25T22:05:42Z | [
"python",
"proxy",
"sockets",
"http-headers",
"python-3.x"
] |
Remove default apps from Django-admin | 2,342,031 | <p>By default, in Django-admin there is Users, Groups, and Sites apps. How can I remove Groups and Sites?</p>
<p>I tried to remove <code>admin.autodiscover()</code> from root urls. Then, when I added something like <code>admin.site.register(User, UserAdmin)</code> somewhere in my app models I got an <code>AlreadyRegis... | 33 | 2010-02-26T13:50:26Z | 2,342,136 | <p>In an admin.py you know will definitely be loaded, try:</p>
<pre><code>admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.unregister(Site)
</code></pre>
| 63 | 2010-02-26T14:10:13Z | [
"python",
"django",
"django-admin"
] |
Remove default apps from Django-admin | 2,342,031 | <p>By default, in Django-admin there is Users, Groups, and Sites apps. How can I remove Groups and Sites?</p>
<p>I tried to remove <code>admin.autodiscover()</code> from root urls. Then, when I added something like <code>admin.site.register(User, UserAdmin)</code> somewhere in my app models I got an <code>AlreadyRegis... | 33 | 2010-02-26T13:50:26Z | 39,287,649 | <p>In addition to the above double check your ordering of "INSTALLED_APPS" in "settings.py"</p>
<pre><code>enter code hereINSTALLED_APPS = [
# djnago apps first
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfile... | 1 | 2016-09-02T08:23:40Z | [
"python",
"django",
"django-admin"
] |
In a MVC patterned framework where would a screen-scraping module be located? | 2,342,033 | <p>In a MVC patterned framework where would a screen-scraping module most logically be located? In the model or the controller? Or is it completely outside of this pattern?</p>
| 1 | 2010-02-26T13:50:47Z | 2,342,064 | <p>In a sense, the screen-scraper is the user of the application -- I'd think it would be a piece outside the MVC that interacts with the controller, just like a web page sends information to the controller. This would make it easy to put a web page over it if the interface changes. </p>
| 0 | 2010-02-26T13:56:45Z | [
"python",
"ruby-on-rails",
"model-view-controller"
] |
In a MVC patterned framework where would a screen-scraping module be located? | 2,342,033 | <p>In a MVC patterned framework where would a screen-scraping module most logically be located? In the model or the controller? Or is it completely outside of this pattern?</p>
| 1 | 2010-02-26T13:50:47Z | 2,342,101 | <p>I presume the scraper is only used to collect data.</p>
<p>if the data is scraped and stored, this process does not simply drop into either M V or C. You could run this scrapping process as a cron job on intervals you define, store the data and then define models to access the data.</p>
<p>i wouldn't recommend cal... | 0 | 2010-02-26T14:02:37Z | [
"python",
"ruby-on-rails",
"model-view-controller"
] |
In a MVC patterned framework where would a screen-scraping module be located? | 2,342,033 | <p>In a MVC patterned framework where would a screen-scraping module most logically be located? In the model or the controller? Or is it completely outside of this pattern?</p>
| 1 | 2010-02-26T13:50:47Z | 2,342,211 | <p>It depends on how you are planning on implementing the scraper. If you are going to have a UI where you click a button to scrape a screen then it is going to be in all three (M, V, and C). If it is going to be a background process (like mentioned before) it should be in M and C.</p>
| 0 | 2010-02-26T14:23:05Z | [
"python",
"ruby-on-rails",
"model-view-controller"
] |
In a MVC patterned framework where would a screen-scraping module be located? | 2,342,033 | <p>In a MVC patterned framework where would a screen-scraping module most logically be located? In the model or the controller? Or is it completely outside of this pattern?</p>
| 1 | 2010-02-26T13:50:47Z | 2,342,637 | <p>You can call it as you might a model if you design it to behave like one. Then it can be easily used within a controller:</p>
<pre><code>def update
@company = Company.find(params[:id])
@scraper = Scraper.find(:page => some_url, :method => :rip)
@scraper.product_details.each do |params|
@company.pr... | 2 | 2010-02-26T15:24:37Z | [
"python",
"ruby-on-rails",
"model-view-controller"
] |
Can I write parts of the Google App Engine code in Java, other parts in Python? | 2,342,059 | <p>Google App Engine supports both Python and Java application development.</p>
<p>Can I have both in the same application?</p>
| 7 | 2010-02-26T13:55:59Z | 2,342,111 | <blockquote>
<p><strong>Can I run Java and Python code in the same app?</strong></p>
<p>Each version of the app must specify a runtime language and it is possible to have version x of your app running Java, while version y is running Python. It would also be possible to use Jython.</p>
</blockquote>
<p>Source: ... | 9 | 2010-02-26T14:06:07Z | [
"java",
"python",
"google-app-engine"
] |
Can I write parts of the Google App Engine code in Java, other parts in Python? | 2,342,059 | <p>Google App Engine supports both Python and Java application development.</p>
<p>Can I have both in the same application?</p>
| 7 | 2010-02-26T13:55:59Z | 2,342,779 | <p>As far as I know, there are two ways:</p>
<ul>
<li>Write <strong>another app</strong> in java, publish it as a web services and call it from python (but that's not what you are looking for)</li>
<li>Make a <strong>java application</strong> but write it in <a href="http://www.jython.org/">jython</a>. Then your app w... | 5 | 2010-02-26T15:45:15Z | [
"java",
"python",
"google-app-engine"
] |
Can I write parts of the Google App Engine code in Java, other parts in Python? | 2,342,059 | <p>Google App Engine supports both Python and Java application development.</p>
<p>Can I have both in the same application?</p>
| 7 | 2010-02-26T13:55:59Z | 28,125,940 | <p>Just to have an updated answer for this question, </p>
<p>From this <a href="https://groups.google.com/forum/#!msg/google-appengine/1228g7-qXZY/_ubjgHlE2_wJ" rel="nofollow">answer</a> on GAE google groups, it looks like it is possible to have different modules in different languages.</p>
| 1 | 2015-01-24T13:26:53Z | [
"java",
"python",
"google-app-engine"
] |
wxPython Application.DoEvents() equivalent? | 2,342,183 | <p>Is there an Application.DoEvents() equivalent in wxPython?</p>
<p>I am creating a form, then doing a slow I/O event, and the form is only partially drawn until the event finishes. I'd like to have the form fully drawn before the I/O starts.</p>
<p>I've tried <code>self.Refresh()</code>, but it has no effect.</p>
| 2 | 2010-02-26T14:18:45Z | 2,342,214 | <p><a href="http://docs.wxwidgets.org/stable/wx_appinifunctions.html#wxyield" rel="nofollow"><code>wx.Yield</code></a> or <a href="http://docs.wxwidgets.org/stable/wx_appinifunctions.html#wxsafeyield" rel="nofollow"><code>wx.SafeYield</code></a></p>
<p>Although you should really use a separate thread to do the I/O and... | 1 | 2010-02-26T14:23:25Z | [
"python",
"wxpython",
"wxwidgets"
] |
Open a file in the proper encoding automatically | 2,342,284 | <p>I'm dealing with some problems in a few files about the encoding. We receive files from other company and have to read them (the files are in csv format)</p>
<p>Strangely, the files appear to be encoded in UTF-16. I am managing to do that, but I have to open them using the <code>codecs</code> module and specifying ... | 6 | 2010-02-26T14:34:27Z | 2,342,313 | <p><a href="http://pypi.python.org/pypi/chardet" rel="nofollow">chardet</a> can help you.</p>
<blockquote>
<p>Character encoding auto-detection in
Python 2 and 3. As smart as your
browser. Open source.</p>
</blockquote>
| 7 | 2010-02-26T14:39:06Z | [
"python"
] |
Open a file in the proper encoding automatically | 2,342,284 | <p>I'm dealing with some problems in a few files about the encoding. We receive files from other company and have to read them (the files are in csv format)</p>
<p>Strangely, the files appear to be encoded in UTF-16. I am managing to do that, but I have to open them using the <code>codecs</code> module and specifying ... | 6 | 2010-02-26T14:34:27Z | 2,342,499 | <p>If it will be fixed in Python 3, it should also be fixed by using</p>
<pre><code>from __future__ import unicode_literals
</code></pre>
| -2 | 2010-02-26T15:04:05Z | [
"python"
] |
Open a file in the proper encoding automatically | 2,342,284 | <p>I'm dealing with some problems in a few files about the encoding. We receive files from other company and have to read them (the files are in csv format)</p>
<p>Strangely, the files appear to be encoded in UTF-16. I am managing to do that, but I have to open them using the <code>codecs</code> module and specifying ... | 6 | 2010-02-26T14:34:27Z | 2,342,983 | <p>It won't be "fixed" in python 3, as it's not a fixable problem. Many documents are valid in several encodings, so the only way to determine the proper encoding is to know something about the document. Fortunately, in most cases we do know something about the document, like for instance, most characters will come c... | 5 | 2010-02-26T16:14:37Z | [
"python"
] |
Open a file in the proper encoding automatically | 2,342,284 | <p>I'm dealing with some problems in a few files about the encoding. We receive files from other company and have to read them (the files are in csv format)</p>
<p>Strangely, the files appear to be encoded in UTF-16. I am managing to do that, but I have to open them using the <code>codecs</code> module and specifying ... | 6 | 2010-02-26T14:34:27Z | 2,343,471 | <p>csv.reader cannot handle Unicode strings in 2.x. See the bottom of the <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv documentation</a> and <a href="http://stackoverflow.com/questions/2334436/how-to-parse-a-single-line-csv-string-without-the-csv-reader-iterator-in-python">this question</a> for... | 0 | 2010-02-26T17:22:10Z | [
"python"
] |
PyGreSQL NULLs for integer field | 2,342,390 | <p>I am trying to insert some rows into a table which has a field of integers, which can be NULL:</p>
<pre><code>cur.execute("INSERT INTO mytable (id, priority) VALUES (%(id)d, %(priority)d)", \
{'id': id, 'priority': priority})
</code></pre>
<p>The priority variable is either an integer or <code>None</co... | 0 | 2010-02-26T14:49:38Z | 11,287,039 | <p>Normally Postgresql performs automatic casting of string values to integer for integer columns. So it is generally safe to use a string formatter like %(priority)s for an integer column provided the string parameter contains an integer or is None. If the string is set to None then the column will be assigned NULL.<... | 1 | 2012-07-02T01:46:30Z | [
"python",
"database",
"pygresql"
] |
Python's time.sleep - never waking up | 2,342,397 | <p>I think this is going to be one of those simple-when-you-see-it problems, but it has got me baffled.</p>
<p>[<strong>STOP PRESS: I was right. Solution was found. See the answers.</strong>]</p>
<p>I am using Python's unittest framework to test a multi-threaded app. Nice and straight forward - I have 5 or so worker ... | 4 | 2010-02-26T14:50:49Z | 2,346,362 | <p>Sigh.</p>
<p>Worker Thread #1 is sleeping, and waking up afterwards. It is then going to log the wake message, and is blocked. Only one thread can be logging at a time.</p>
<p>UnitTest Thread is sleeping, and waking up afterwards. It is then going to log the wake message, and is blocked. Only one thread can be log... | 5 | 2010-02-27T05:40:42Z | [
"python",
"multithreading",
"deadlock",
"sleep"
] |
Python's time.sleep - never waking up | 2,342,397 | <p>I think this is going to be one of those simple-when-you-see-it problems, but it has got me baffled.</p>
<p>[<strong>STOP PRESS: I was right. Solution was found. See the answers.</strong>]</p>
<p>I am using Python's unittest framework to test a multi-threaded app. Nice and straight forward - I have 5 or so worker ... | 4 | 2010-02-26T14:50:49Z | 10,396,123 | <p>On linux, try change I/O scheduler to Completely Fair Queuing (CFQ). </p>
<pre><code>echo cfq > /sys/block/sda/queue/scheduler
</code></pre>
| -3 | 2012-05-01T09:56:40Z | [
"python",
"multithreading",
"deadlock",
"sleep"
] |
Python's c api and __add__ calls | 2,342,416 | <p>I am writing a binding system that exposes classes and functions to python in a slightly unusual way. </p>
<p>Normally one would create a python type and provide a list of functions that represent the methods of that type, and then allow python to use its generic tp_getattro function to select the right one. </p>
... | 3 | 2010-02-26T14:52:33Z | 2,342,500 | <p>Do you have an <code>nb_add</code> in your type's <a href="http://docs.python.org/c-api/typeobj.html#number-object-structures" rel="nofollow">number methods</a> structure (pointed by field <code>tp_as_number</code> of your <a href="http://docs.python.org/c-api/typeobj.html#type-objects" rel="nofollow">type object</a... | 3 | 2010-02-26T15:04:13Z | [
"python",
"api"
] |
Ordering of Django models | 2,342,913 | <p>I set up an <code>ordering='ordering_number'</code> Meta attribute to my Django model, thinking that Django will use it when comparing instances. (<code>ordering_number</code> is an IntegerField in my model.)</p>
<p>For example, if I have an instance <code>a</code> with <code>ordering_number = 4</code> and an insta... | 0 | 2010-02-26T16:05:03Z | 2,342,972 | <p>From <a href="http://docs.djangoproject.com/en/dev/ref/models/options/#ordering" rel="nofollow">the documentation</a>:</p>
<blockquote>
<p>The default ordering for the object, for use when obtaining lists of objects</p>
</blockquote>
<p>So the reason your comparisons aren't working is because they're not designe... | 2 | 2010-02-26T16:12:43Z | [
"python",
"django"
] |
How to add an Admin class to a model after syncdb? | 2,343,053 | <p>I added some models in my models.py and I want to add an admin class to use a wysiwyg-editor in text-fields.<br>
Well, I know that Django itself doesn't support migrations and I've used South, but it doesn't work either.<br>
South doesn't "see" the change.<br>
... | 0 | 2010-02-26T16:24:16Z | 2,343,087 | <p><code>syncdb</code> and South are only concerned with descendants of <code>Model</code> in apps listed in <code>INSTALLED_APPS</code>. Everything else is handled by Django directly.</p>
| 2 | 2010-02-26T16:29:25Z | [
"python",
"django",
"django-models",
"django-south"
] |
How to add an Admin class to a model after syncdb? | 2,343,053 | <p>I added some models in my models.py and I want to add an admin class to use a wysiwyg-editor in text-fields.<br>
Well, I know that Django itself doesn't support migrations and I've used South, but it doesn't work either.<br>
South doesn't "see" the change.<br>
... | 0 | 2010-02-26T16:24:16Z | 2,343,100 | <p>I'm fairly sure that if you follow the steps as outlined in the tutorial to create an admin app it'll just work. Migration isn't an issue as the admin app creates new tables rather than altering the existing one.</p>
| 1 | 2010-02-26T16:31:09Z | [
"python",
"django",
"django-models",
"django-south"
] |
How to add an Admin class to a model after syncdb? | 2,343,053 | <p>I added some models in my models.py and I want to add an admin class to use a wysiwyg-editor in text-fields.<br>
Well, I know that Django itself doesn't support migrations and I've used South, but it doesn't work either.<br>
South doesn't "see" the change.<br>
... | 0 | 2010-02-26T16:24:16Z | 2,344,046 | <p>You seem to be very confused, unfortunately. Of course Django reads the code in models.py - otherwise what would be the point of it? Django uses that code initially to define the model SQL when doing syncdb, but it doesn't modify existing database <em>tables</em> in subsequent calls to syncdb - hence the need for So... | 1 | 2010-02-26T18:50:57Z | [
"python",
"django",
"django-models",
"django-south"
] |
How to build an image object in PIL/Python | 2,343,115 | <p>I have a list of 3-item tuples that is the result of list(PIL.Image.getdata()).</p>
<p>How do I do the opposite: build a PIL.Image object from this list?</p>
| 4 | 2010-02-26T16:33:11Z | 2,344,074 | <p>The output of <code>getdata()</code> does not include the image format or the size, so you'll need to preserve those (or get the information some other way). Then do this, using the <a href="http://effbot.org/imagingbook/image.htm#tag-Image.Image.putdata" rel="nofollow"><code>putdata()</code></a> method:</p>
<pre>... | 7 | 2010-02-26T18:55:22Z | [
"python",
"image",
"python-imaging-library"
] |
django admin.site.name in template | 2,343,286 | <p>Hallo,</p>
<p>is there any chance to access the "name" value of the current admin.site object in a admin template?</p>
<p>I have 3 different admin.site-objects and want a template tag to generate generic content,depending on the current admin.site.name.</p>
<p>thanks in advance</p>
| 0 | 2010-02-26T16:56:04Z | 2,343,377 | <p>You could provide the name of the current site to all of your templates by <a href="http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors" rel="nofollow">writing a custom template context processor</a> that would set a variable (e.g., <code>SITE_NAME</code>) in the context for e... | 2 | 2010-02-26T17:07:52Z | [
"python",
"django",
"admin"
] |
Python sub-package references | 2,343,311 | <p>I am about at wits end with what should be an extremely simple issue. Here is the format of a simple example that I wrote to try to fix my problem. I have a folder top with <code>__all__ = ["p1","p2"]</code> in <code>__init__.py</code> . I then have sub-folders p1 and p2 with <code>__init__.py</code> in both of them... | 0 | 2010-02-26T16:58:26Z | 2,343,376 | <p>Your problem is that your top package is not in your sys.path.</p>
| 3 | 2010-02-26T17:07:48Z | [
"python",
"import",
"packages"
] |
Python sub-package references | 2,343,311 | <p>I am about at wits end with what should be an extremely simple issue. Here is the format of a simple example that I wrote to try to fix my problem. I have a folder top with <code>__all__ = ["p1","p2"]</code> in <code>__init__.py</code> . I then have sub-folders p1 and p2 with <code>__init__.py</code> in both of them... | 0 | 2010-02-26T16:58:26Z | 2,343,380 | <p>All you describe is just fine and does not reproduce the error -- here's the simplest version I can think of:</p>
<pre><code>$ mkdir /tmp/path
$ mkdir /tmp/path/top /tmp/path/top/p1 /tmp/path/top/p2
$ touch /tmp/path/top/__init__.py /tmp/path/top/p1/__init__.py /tmp/path/top/p2/__init__.py
$ touch /tmp/path/top/p1/... | 2 | 2010-02-26T17:08:22Z | [
"python",
"import",
"packages"
] |
Is there any Python wrapper around cron? | 2,343,403 | <p>I'm looking for a wrapper around cron.</p>
<p>I've stumbled upon PyCron but it's a Python implementation, not a wrapper.</p>
<p>Do you know any good cron Python wrapper ?</p>
<p>If not, did you test PyCron, and what can you tell about it ?</p>
<p>//EDIT (As an answer to comment asking for more details):</p>
<p>... | 5 | 2010-02-26T17:11:23Z | 2,348,796 | <p><a href="http://pypi.python.org/pypi/python-crontab/" rel="nofollow"><code>python-crontab</code></a> allows you to read and write user crontabs via python programs.</p>
<pre><code>from crontab import CronTab
tab = CronTab()
cron = tab.new(command='/foo/bar')
cron.every_reboot()
tab.write()
</code></pre>
| 9 | 2010-02-27T20:12:51Z | [
"python",
"cron",
"wrapper"
] |
Easiest way to serialize a simple class object with simplejson? | 2,343,535 | <p>I'm trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object "is not JSON serializable". </p>
<p>The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields from one parent superclass, e.g.:</p>
<pre><c... | 21 | 2010-02-26T17:31:25Z | 2,343,640 | <p>I've used this strategy in the past and been pretty happy with it: Encode your custom objects as JSON object literals (like Python <code>dict</code>s) with the following structure:</p>
<pre><code>{ '__ClassName__': { ... } }
</code></pre>
<p>That's essentially a one-item <code>dict</code> whose single key is a sp... | 22 | 2010-02-26T17:49:22Z | [
"python",
"json",
"simplejson"
] |
Easiest way to serialize a simple class object with simplejson? | 2,343,535 | <p>I'm trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object "is not JSON serializable". </p>
<p>The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields from one parent superclass, e.g.:</p>
<pre><c... | 21 | 2010-02-26T17:31:25Z | 4,682,553 | <p>An instance of a <strong>custom</strong> class could be represented as JSON formatted string with help of following function:</p>
<pre><code>def json_repr(obj):
"""Represent instance of a class as JSON.
Arguments:
obj -- any object
Return:
String that reprent JSON-encoded object.
"""
def serialize(obj... | 6 | 2011-01-13T16:38:01Z | [
"python",
"json",
"simplejson"
] |
Easiest way to serialize a simple class object with simplejson? | 2,343,535 | <p>I'm trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object "is not JSON serializable". </p>
<p>The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields from one parent superclass, e.g.:</p>
<pre><c... | 21 | 2010-02-26T17:31:25Z | 6,893,295 | <p>If you are using Django, it can be easily done via Django's serializers module. More info can be found here: <a href="https://docs.djangoproject.com/en/dev/topics/serialization/" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/serialization/</a></p>
| 2 | 2011-08-01T00:39:40Z | [
"python",
"json",
"simplejson"
] |
Easiest way to serialize a simple class object with simplejson? | 2,343,535 | <p>I'm trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object "is not JSON serializable". </p>
<p>The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields from one parent superclass, e.g.:</p>
<pre><c... | 21 | 2010-02-26T17:31:25Z | 11,976,261 | <p>I feel a bit silly about my possible 2 solutions rereading it now,
of course when you use django-rest-framework, this framework have some excellent features buildin for this problem mentioned above.</p>
<p>see <a href="http://django-rest-framework.org/examples/modelviews.html" rel="nofollow">this model view example... | 0 | 2012-08-15T19:54:05Z | [
"python",
"json",
"simplejson"
] |
Easiest way to serialize a simple class object with simplejson? | 2,343,535 | <p>I'm trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object "is not JSON serializable". </p>
<p>The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields from one parent superclass, e.g.:</p>
<pre><c... | 21 | 2010-02-26T17:31:25Z | 17,056,556 | <p>As specified in python's JSON docs // <code>help(json.dumps)</code> // > </p>
<p>You should simply override the <code>default()</code> method of <code>JSONEncoder</code> in order to provide a custom type conversion, and pass it as <code>cls</code> argument.</p>
<p>Here is one I use to cover Mongo's special data ty... | 2 | 2013-06-12T01:55:58Z | [
"python",
"json",
"simplejson"
] |
Easiest way to serialize a simple class object with simplejson? | 2,343,535 | <p>I'm trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object "is not JSON serializable". </p>
<p>The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields from one parent superclass, e.g.:</p>
<pre><c... | 21 | 2010-02-26T17:31:25Z | 24,171,143 | <p>This is kind of hackish and I'm sure there's probably a lot that can be wrong with it. However, I was producing a simple script and I ran the issue that I did not want to subclass my json serializer to serialize a list of model objects. I ended up using list comprehension</p>
<p>Let:
assets = list of modelobjects</... | 0 | 2014-06-11T19:33:53Z | [
"python",
"json",
"simplejson"
] |
Writing to file doesn't flush content automatically and cause out of memory in Python | 2,343,600 | <p>I made simple python program to generate big text file:</p>
<pre><code>import sys
import random
f = open('data.txt', 'w')
for i in range(100000000):
f.write(str(i) + "\t" + str(random.randint(0,1000)) + "\n")
f.close()
</code></pre>
<p>When I launch it using CPython it eat all available OS memory and writ... | 1 | 2010-02-26T17:42:42Z | 2,343,629 | <p>Have you tried <a href="http://docs.python.org/library/functions.html#open" rel="nofollow">passing in a buffer size</a> to the <code>open</code> function?</p>
<pre><code>f = open('data.txt', 'w', 5000)
</code></pre>
| -1 | 2010-02-26T17:48:14Z | [
"python",
"file",
"buffer",
"flush"
] |
Writing to file doesn't flush content automatically and cause out of memory in Python | 2,343,600 | <p>I made simple python program to generate big text file:</p>
<pre><code>import sys
import random
f = open('data.txt', 'w')
for i in range(100000000):
f.write(str(i) + "\t" + str(random.randint(0,1000)) + "\n")
f.close()
</code></pre>
<p>When I launch it using CPython it eat all available OS memory and writ... | 1 | 2010-02-26T17:42:42Z | 2,343,636 | <p>Buffering is not the problem. The problem is calling the <code>range()</code> function with a giant argument, which will attempt to allocate an array with lots of elements. You will get the same error if you just say</p>
<pre><code>r = range(100000000)
</code></pre>
| 9 | 2010-02-26T17:48:56Z | [
"python",
"file",
"buffer",
"flush"
] |
NLP project, python or C++ | 2,344,081 | <p>We are working on Arabic Natural Language Processing project, we have limited our choices to either write the code in Python or C++ (and Boost library). We are thinking of these points:</p>
<ul>
<li><p>Python</p>
<ul>
<li>Slower than C++ (There is ongoing work to make Python faster)</li>
<li>Better UTF8 support</l... | 2 | 2010-02-26T18:56:41Z | 2,344,099 | <blockquote>
<p>Familiar code, every programmer knows C or C-like code</p>
</blockquote>
<p>Many devs are familiar with C or C-like code, it doesn't make them C++ compliant.
Unexperienced C++ devs can do a lot of harm to such a complex project and you would have to take extra care.</p>
<p>I can't speak for python b... | 2 | 2010-02-26T19:01:18Z | [
"c++",
"python",
"boost",
"nlp"
] |
NLP project, python or C++ | 2,344,081 | <p>We are working on Arabic Natural Language Processing project, we have limited our choices to either write the code in Python or C++ (and Boost library). We are thinking of these points:</p>
<ul>
<li><p>Python</p>
<ul>
<li>Slower than C++ (There is ongoing work to make Python faster)</li>
<li>Better UTF8 support</l... | 2 | 2010-02-26T18:56:41Z | 2,344,106 | <p>Write it in Python, profile it, and if you need to speed parts of it up, write them in C++. Python and C++ are similar enough that the "familiar" advantage with C++ will be irrelevant pretty quick.</p>
<p>I say this as someone who has developed primarily in C++ and has recently gotten serious with Python. I like ... | 7 | 2010-02-26T19:02:29Z | [
"c++",
"python",
"boost",
"nlp"
] |
NLP project, python or C++ | 2,344,081 | <p>We are working on Arabic Natural Language Processing project, we have limited our choices to either write the code in Python or C++ (and Boost library). We are thinking of these points:</p>
<ul>
<li><p>Python</p>
<ul>
<li>Slower than C++ (There is ongoing work to make Python faster)</li>
<li>Better UTF8 support</l... | 2 | 2010-02-26T18:56:41Z | 2,344,124 | <p>Although this is subjective and argumentative, there is evidence that you can write a successful NLP project in python like <a href="http://code.google.com/p/nltk/" rel="nofollow">NLTK</a>. They also have a <a href="http://nltk.googlecode.com/svn/trunk/doc/howto/nlp-python.html" rel="nofollow">comparison of NLP func... | 9 | 2010-02-26T19:05:50Z | [
"c++",
"python",
"boost",
"nlp"
] |
NLP project, python or C++ | 2,344,081 | <p>We are working on Arabic Natural Language Processing project, we have limited our choices to either write the code in Python or C++ (and Boost library). We are thinking of these points:</p>
<ul>
<li><p>Python</p>
<ul>
<li>Slower than C++ (There is ongoing work to make Python faster)</li>
<li>Better UTF8 support</l... | 2 | 2010-02-26T18:56:41Z | 2,346,607 | <p>This is more or less a reply/supplement to Otto Almendinger's answer. If you honestly wanted to implement something (roughly) similar to his Python example in C++, I think something like this would be closer:</p>
<pre><code>#include <string>
#include <iostream>
int main() {
std::string temp;
w... | 3 | 2010-02-27T07:57:12Z | [
"c++",
"python",
"boost",
"nlp"
] |
NLP project, python or C++ | 2,344,081 | <p>We are working on Arabic Natural Language Processing project, we have limited our choices to either write the code in Python or C++ (and Boost library). We are thinking of these points:</p>
<ul>
<li><p>Python</p>
<ul>
<li>Slower than C++ (There is ongoing work to make Python faster)</li>
<li>Better UTF8 support</l... | 2 | 2010-02-26T18:56:41Z | 7,779,679 | <p>IMO go for C/C++ simply because of the 'familiar' factor. Though LOC's will be more in C/C++ you will save time in understanding and testing. </p>
| 0 | 2011-10-15T18:12:38Z | [
"c++",
"python",
"boost",
"nlp"
] |
Python Regex to match a file in a list of files (getting error) | 2,344,193 | <p>I'm trying to use a regex in Python to match a file (saved as a string, ie "/volumes/footage/foo/bar.mov") to a log file I create that contains a list of files. But when I run the script, it gives me this error: <code>sre_constants.error: unbalanced parenthesis</code>. The code I'm using is this:</p>
<p>To read the... | 2 | 2010-02-26T19:17:45Z | 2,344,215 | <p>Where is the regular expression pattern? Are you trying to use filenames contained in one file as patterns to search the other file? If so, you will want to step through <code>the_file</code> with someting like </p>
<pre><code>for the_pattern in the_file:
p = re.compile(the_pattern, re.IGNORECASE)
m = p.s... | 3 | 2010-02-26T19:21:38Z | [
"python",
"regex"
] |
Python Regex to match a file in a list of files (getting error) | 2,344,193 | <p>I'm trying to use a regex in Python to match a file (saved as a string, ie "/volumes/footage/foo/bar.mov") to a log file I create that contains a list of files. But when I run the script, it gives me this error: <code>sre_constants.error: unbalanced parenthesis</code>. The code I'm using is this:</p>
<p>To read the... | 2 | 2010-02-26T19:17:45Z | 2,344,224 | <p>What you're binding to name <code>the_file</code> in your first snippet is a <strong>file object</strong>, even though you say that's "saved as a string", the filename (i.e. the string) is actually named <code>theLogFile</code> but what you're trying t turn into a RE object is <strong>not</strong> <code>theLogFile</... | 1 | 2010-02-26T19:22:59Z | [
"python",
"regex"
] |
Python Regex to match a file in a list of files (getting error) | 2,344,193 | <p>I'm trying to use a regex in Python to match a file (saved as a string, ie "/volumes/footage/foo/bar.mov") to a log file I create that contains a list of files. But when I run the script, it gives me this error: <code>sre_constants.error: unbalanced parenthesis</code>. The code I'm using is this:</p>
<p>To read the... | 2 | 2010-02-26T19:17:45Z | 2,344,231 | <p><strong>the_file</strong> should be a string. In the above code the_file is the return value of open, which is a file object.</p>
| 1 | 2010-02-26T19:23:54Z | [
"python",
"regex"
] |
Python Regex to match a file in a list of files (getting error) | 2,344,193 | <p>I'm trying to use a regex in Python to match a file (saved as a string, ie "/volumes/footage/foo/bar.mov") to a log file I create that contains a list of files. But when I run the script, it gives me this error: <code>sre_constants.error: unbalanced parenthesis</code>. The code I'm using is this:</p>
<p>To read the... | 2 | 2010-02-26T19:17:45Z | 2,344,648 | <p>Gordon,</p>
<p>it would seem to me that the issue is in the data. You are compiling uninspected strings from the <code>filelist</code> into regexp, not heeding that they might contain meta characters relevant for the regexp engine.</p>
<p>In your for loop, add a <code>print the_file</code> before the call to re.co... | 2 | 2010-02-26T20:34:04Z | [
"python",
"regex"
] |
Python script is running. I have a method name as a string. How do I call this method? | 2,344,212 | <p>everyone. Please see example below. I'd like to supply a string to 'schedule_action' method which specifies, what Bot-class method should be called. In the example below I've represented it as 'bot.action()' but I have no idea how to do it correctly. Please help</p>
<pre><code>class Bot:
def work(self): pass
... | 5 | 2010-02-26T19:20:54Z | 2,344,226 | <p>In short,</p>
<pre><code>getattr(bot, action)()
</code></pre>
<p>getattr will look up an attribute on the object by name -- attributes can be data or member methods The extra <code>()</code> at the end calls the method.</p>
<p>You could get the method in a separate step, like this, as well:</p>
<pre><code>method... | 7 | 2010-02-26T19:23:18Z | [
"python"
] |
Python script is running. I have a method name as a string. How do I call this method? | 2,344,212 | <p>everyone. Please see example below. I'd like to supply a string to 'schedule_action' method which specifies, what Bot-class method should be called. In the example below I've represented it as 'bot.action()' but I have no idea how to do it correctly. Please help</p>
<pre><code>class Bot:
def work(self): pass
... | 5 | 2010-02-26T19:20:54Z | 2,344,228 | <p>Use <a href="http://docs.python.org/library/functions.html#getattr" rel="nofollow">getattr</a>:</p>
<pre><code>class Bot:
def fight(self):
print "fighting is fun!"
class Scheduler:
def schedule_action(self,action):
bot = Bot()
getattr(bot,action)()
scheduler = Scheduler()
sched... | 13 | 2010-02-26T19:23:27Z | [
"python"
] |
Python script is running. I have a method name as a string. How do I call this method? | 2,344,212 | <p>everyone. Please see example below. I'd like to supply a string to 'schedule_action' method which specifies, what Bot-class method should be called. In the example below I've represented it as 'bot.action()' but I have no idea how to do it correctly. Please help</p>
<pre><code>class Bot:
def work(self): pass
... | 5 | 2010-02-26T19:20:54Z | 2,344,234 | <pre><code>class Scheduler:
def schedule_action(self,action):
bot = Bot()
boundmethod = getattr(bot, action)
boundmethod()
</code></pre>
| 3 | 2010-02-26T19:24:16Z | [
"python"
] |
Python script is running. I have a method name as a string. How do I call this method? | 2,344,212 | <p>everyone. Please see example below. I'd like to supply a string to 'schedule_action' method which specifies, what Bot-class method should be called. In the example below I've represented it as 'bot.action()' but I have no idea how to do it correctly. Please help</p>
<pre><code>class Bot:
def work(self): pass
... | 5 | 2010-02-26T19:20:54Z | 2,344,241 | <pre><code>def schedule_action(self,action):
bot = Bot()
bot.__getattribute__(action)()
</code></pre>
| 1 | 2010-02-26T19:25:29Z | [
"python"
] |
Python script is running. I have a method name as a string. How do I call this method? | 2,344,212 | <p>everyone. Please see example below. I'd like to supply a string to 'schedule_action' method which specifies, what Bot-class method should be called. In the example below I've represented it as 'bot.action()' but I have no idea how to do it correctly. Please help</p>
<pre><code>class Bot:
def work(self): pass
... | 5 | 2010-02-26T19:20:54Z | 2,344,263 | <p>I'm not sure if it applies in your situation, but you may consider using a function pointer instead of manipulating the strings.</p>
<pre><code>class Bot:
def work(self):
print 'working'
def fight(self):
print 'fightin'
class Scheduler:
def schedule_action(self,action):
bot = B... | 6 | 2010-02-26T19:29:43Z | [
"python"
] |
Python script is running. I have a method name as a string. How do I call this method? | 2,344,212 | <p>everyone. Please see example below. I'd like to supply a string to 'schedule_action' method which specifies, what Bot-class method should be called. In the example below I've represented it as 'bot.action()' but I have no idea how to do it correctly. Please help</p>
<pre><code>class Bot:
def work(self): pass
... | 5 | 2010-02-26T19:20:54Z | 2,344,916 | <p>You can also use a dictionary to map methods to actions. For instance:</p>
<pre><code>ACTIONS = {"fight": Bot.fight,
"walk": Bot.walk,}
class Scheduler:
def schedule_action(self, action):
return ACTIONS[action](Bot())
</code></pre>
| 1 | 2010-02-26T21:23:34Z | [
"python"
] |
pylint: Using possibly undefined loop variable 'n' | 2,344,315 | <p>Pylint say</p>
<pre>
W: 6: Using possibly undefined loop variable 'n'
</pre>
<p>with this code:</p>
<pre><code>
iterator = (i*i for i in range(100) if i % 3 == 0)
for n, i in enumerate(iterator):
do_something(i)
print n
</code></pre>
<p>because if the iterator is empty (for example []) n is undefined, ok.... | 4 | 2010-02-26T19:38:49Z | 2,344,331 | <p>Have you considered merely initializing n to None before running the loop?</p>
| 5 | 2010-02-26T19:41:54Z | [
"python",
"enumerate"
] |
pylint: Using possibly undefined loop variable 'n' | 2,344,315 | <p>Pylint say</p>
<pre>
W: 6: Using possibly undefined loop variable 'n'
</pre>
<p>with this code:</p>
<pre><code>
iterator = (i*i for i in range(100) if i % 3 == 0)
for n, i in enumerate(iterator):
do_something(i)
print n
</code></pre>
<p>because if the iterator is empty (for example []) n is undefined, ok.... | 4 | 2010-02-26T19:38:49Z | 2,344,335 | <p>Define a default value for <code>n</code> before the <code>for</code> statement:</p>
<pre><code>iterator = (i*i for i in range(100) if i % 3 == 0)
n=None
for n, i in enumerate(iterator):
do_something(i)
print n
</code></pre>
| 3 | 2010-02-26T19:42:28Z | [
"python",
"enumerate"
] |
pysqlite, query for duplicate entries with swapped columns | 2,344,610 | <p>Currently I have a pysqlite db that I am using to store a list of road conditions. The source this list is generated from however is buggy and sometimes generates duplicates. Some of these duplicates will have the start and end points swapped but everything else the same. </p>
<p>The method i currently have looks l... | 1 | 2010-02-26T20:28:11Z | 2,348,946 | <p>Instead of the first query, you could use</p>
<pre><code>SELECT DISTINCT * FROM roadCond
</code></pre>
<p>which will retrieve all the records from the table, removing any duplicates.</p>
<p>As for the inner method, this query will return all the records which have "duplicates" with <code>start</code> and <code>en... | 0 | 2010-02-27T20:58:29Z | [
"python",
"sql",
"sqlite"
] |
Python: group results by time intervals | 2,344,639 | <p>I have a large data loaded from a pickled file. The data is a sorted list of tuples containing a datetime and an int like this</p>
<pre><code>[ (datetime.datetime(2010, 2, 26, 12, 8, 17), 5594813L),
(datetime.datetime(2010, 2, 26, 12, 7, 31), 5594810L),
(datetime.datetime(2010, 2, 26, 12, 6, 4) , 5594807L),
... | 5 | 2010-02-26T20:33:03Z | 2,344,653 | <p>Check out <a href="http://docs.python.org/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a>. You can pass a function that calculates the proper bucket as the key. Then, you can run your aggregations (counts, averages, what-have-you) on the groups in the resulting iterable.</... | 4 | 2010-02-26T20:35:15Z | [
"python"
] |
Python: group results by time intervals | 2,344,639 | <p>I have a large data loaded from a pickled file. The data is a sorted list of tuples containing a datetime and an int like this</p>
<pre><code>[ (datetime.datetime(2010, 2, 26, 12, 8, 17), 5594813L),
(datetime.datetime(2010, 2, 26, 12, 7, 31), 5594810L),
(datetime.datetime(2010, 2, 26, 12, 6, 4) , 5594807L),
... | 5 | 2010-02-26T20:33:03Z | 2,344,810 | <p><a href="http://docs.python.org/library/bisect.html#module-bisect" rel="nofollow"><code>bisect.bisect</code></a> is another way to solve this problem:</p>
<pre><code>import datetime
import bisect
import collections
data=[ (datetime.datetime(2010, 2, 26, 12, 8, 17), 5594813L),
(datetime.datetime(2010, 2, 26, 12,... | 3 | 2010-02-26T21:00:32Z | [
"python"
] |
Minimize python distribution size | 2,344,712 | <p>The hindrance we have to ship python is the large size of the standard library.
Is there a minimal python distribution or an easy way to pick and choose what we want from
the standard library?
The platform is linux.</p>
| 6 | 2010-02-26T20:46:29Z | 2,344,763 | <p>Have you looked at <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a>? It provides a way to ship Python programs without requiring a Python installation.</p>
| 2 | 2010-02-26T20:52:44Z | [
"python",
"size",
"minimize"
] |
Minimize python distribution size | 2,344,712 | <p>The hindrance we have to ship python is the large size of the standard library.
Is there a minimal python distribution or an easy way to pick and choose what we want from
the standard library?
The platform is linux.</p>
| 6 | 2010-02-26T20:46:29Z | 2,344,895 | <p>If all you want is to get the minimum subset you need (rather than build an <code>exe</code> which would constrain you to Windows systems), use the standard library module <a href="http://docs.python.org/library/modulefinder.html">modulefinder</a> to list all modules your program requires (you'll get all dependencie... | 5 | 2010-02-26T21:18:54Z | [
"python",
"size",
"minimize"
] |
Minimize python distribution size | 2,344,712 | <p>The hindrance we have to ship python is the large size of the standard library.
Is there a minimal python distribution or an easy way to pick and choose what we want from
the standard library?
The platform is linux.</p>
| 6 | 2010-02-26T20:46:29Z | 2,345,192 | <p>Like Hank Gay and Alex Martelli suggest, you can use py2exe. In addition I would suggest looking into using something like <a href="http://ironpython.net/" rel="nofollow">IronPython</a>. Depending on your application, you can use libraries that are built into the .NET framework (or MONO if for Linux). This reduces y... | 0 | 2010-02-26T22:10:26Z | [
"python",
"size",
"minimize"
] |
In Django - Model Inheritance - Does it allow you to override a parent model's attribute? | 2,344,751 | <p>I'm looking to do this:</p>
<pre><code>class Place(models.Model):
name = models.CharField(max_length=20)
rating = models.DecimalField()
class LongNamedRestaurant(Place): # Subclassing `Place`.
name = models.CharField(max_length=255) # Notice, I'm overriding `Place.name` to give it a longer length.
food_type ... | 45 | 2010-02-26T20:50:54Z | 2,345,037 | <p>Pasted your code into a fresh app, added app to INSTALLED_APPS and ran syncdb:</p>
<pre><code>django.core.exceptions.FieldError: Local field 'name' in class 'LongNamedRestaurant' clashes with field of similar name from base class 'Place'
</code></pre>
<p>Looks like Django does not support that. </p>
| 9 | 2010-02-26T21:43:43Z | [
"python",
"django",
"django-inheritance"
] |
In Django - Model Inheritance - Does it allow you to override a parent model's attribute? | 2,344,751 | <p>I'm looking to do this:</p>
<pre><code>class Place(models.Model):
name = models.CharField(max_length=20)
rating = models.DecimalField()
class LongNamedRestaurant(Place): # Subclassing `Place`.
name = models.CharField(max_length=255) # Notice, I'm overriding `Place.name` to give it a longer length.
food_type ... | 45 | 2010-02-26T20:50:54Z | 2,357,942 | <p>No, <a href="https://docs.djangoproject.com/en/dev/topics/db/models/#field-name-hiding-is-not-permitted">it is not</a>:</p>
<blockquote>
<h3>Field name âhidingâ is not permitted</h3>
<p>In normal Python class inheritance, it is permissible for a child
class to override any attribute from the parent cla... | 39 | 2010-03-01T18:08:20Z | [
"python",
"django",
"django-inheritance"
] |
In Django - Model Inheritance - Does it allow you to override a parent model's attribute? | 2,344,751 | <p>I'm looking to do this:</p>
<pre><code>class Place(models.Model):
name = models.CharField(max_length=20)
rating = models.DecimalField()
class LongNamedRestaurant(Place): # Subclassing `Place`.
name = models.CharField(max_length=255) # Notice, I'm overriding `Place.name` to give it a longer length.
food_type ... | 45 | 2010-02-26T20:50:54Z | 3,099,083 | <p>Maybe you could deal with contribute_to_class :</p>
<pre><code>class LongNamedRestaurant(Place):
food_type = models.CharField(max_length=25)
def __init__(self, *args, **kwargs):
super(LongNamedRestaurant, self).__init__(*args, **kwargs)
name = models.CharField(max_length=255)
name.... | 6 | 2010-06-23T05:18:36Z | [
"python",
"django",
"django-inheritance"
] |
In Django - Model Inheritance - Does it allow you to override a parent model's attribute? | 2,344,751 | <p>I'm looking to do this:</p>
<pre><code>class Place(models.Model):
name = models.CharField(max_length=20)
rating = models.DecimalField()
class LongNamedRestaurant(Place): # Subclassing `Place`.
name = models.CharField(max_length=255) # Notice, I'm overriding `Place.name` to give it a longer length.
food_type ... | 45 | 2010-02-26T20:50:54Z | 8,523,024 | <p>I know it's an old question, but i had a similar problem and found a workaround: </p>
<p>I had the following classes:</p>
<pre><code>class CommonInfo(models.Model):
image = models.ImageField(blank=True, null=True, default="")
class Meta:
abstract = True
class Year(CommonInfo):
year = models.I... | 3 | 2011-12-15T16:07:21Z | [
"python",
"django",
"django-inheritance"
] |
In Django - Model Inheritance - Does it allow you to override a parent model's attribute? | 2,344,751 | <p>I'm looking to do this:</p>
<pre><code>class Place(models.Model):
name = models.CharField(max_length=20)
rating = models.DecimalField()
class LongNamedRestaurant(Place): # Subclassing `Place`.
name = models.CharField(max_length=255) # Notice, I'm overriding `Place.name` to give it a longer length.
food_type ... | 45 | 2010-02-26T20:50:54Z | 18,159,571 | <p>That is not possible, and here is why: <code>LongNamedRestaurant</code> is also a <code>Place</code>, not only as a class but also in the database. The place-table contains an entry for every pure <code>Place</code> and for every <code>LongNamedRestaurant</code>. <code>LongNamedRestaurant</code> just creates an extr... | 12 | 2013-08-10T07:13:11Z | [
"python",
"django",
"django-inheritance"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.