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 |
|---|---|---|---|---|---|---|---|---|---|
launching vs2008 build from python | 263,820 | <p>The first batch file launches a command prompt, i need the second command to be in the ccontext of the first. how can I do this in python?</p>
<p>As is, it launches the batch, and blocks until the batch (with its command prompt context) terminates, and then executes <code>devenv</code> without the necessary contex... | 1 | 2008-11-04T23:08:03Z | 1,237,505 | <p>I think that the proper way for achieving this would be running this command:</p>
<pre><code>%comspec% /C "%VCINSTALLDIR%\vcvarsall.bat" x86 && vcbuild "project.sln"
</code></pre>
<p>Below you'll see the Python version of the same command:</p>
<pre><code>os.system('%comspec% /C "%VCINSTALLDIR%\\vcvarsall.... | 3 | 2009-08-06T08:00:33Z | [
"python",
"windows",
"visual-studio-2008",
"build-automation"
] |
Access Ruby objects with Python via XML-RPC? | 264,128 | <p>I am trying to export a Ruby framework via XML-RPC. However I am having some problems when trying to call a method from a class not directly added as a handler to the XML-RPC server. Please see my example below:</p>
<p>I have a test Ruby XML-RPC server as follows:</p>
<pre><code>require "xmlrpc/server"
class Exam... | 3 | 2008-11-05T01:33:50Z | 264,165 | <p>Your client (s in you Python code) is a ServerProxy object. It only accepts return values of type boolean, integers, floats, arrays, structures, dates or binary data.</p>
<p>However, without you doing the wiring, there is no way for it to return another ServerProxy, which you would need for accessing another class.... | 5 | 2008-11-05T02:03:03Z | [
"python",
"ruby",
"xml-rpc",
"interop"
] |
Access Ruby objects with Python via XML-RPC? | 264,128 | <p>I am trying to export a Ruby framework via XML-RPC. However I am having some problems when trying to call a method from a class not directly added as a handler to the XML-RPC server. Please see my example below:</p>
<p>I have a test Ruby XML-RPC server as follows:</p>
<pre><code>require "xmlrpc/server"
class Exam... | 3 | 2008-11-05T01:33:50Z | 264,586 | <p>XML-RPC can't pass objects. The set of parameter types is limited (as jakber says).</p>
| 1 | 2008-11-05T08:07:33Z | [
"python",
"ruby",
"xml-rpc",
"interop"
] |
Access Ruby objects with Python via XML-RPC? | 264,128 | <p>I am trying to export a Ruby framework via XML-RPC. However I am having some problems when trying to call a method from a class not directly added as a handler to the XML-RPC server. Please see my example below:</p>
<p>I have a test Ruby XML-RPC server as follows:</p>
<pre><code>require "xmlrpc/server"
class Exam... | 3 | 2008-11-05T01:33:50Z | 1,257,360 | <p>Returning a nil inside of a supported data structure will also cause an Internal Server Error message. The stdlib ruby xmlrpc server does not appear to support the xmlrpc extensions which allow nils, even though the python side does. xmlrpc4r supports nils but I haven't tried it yet.</p>
| 1 | 2009-08-10T21:38:59Z | [
"python",
"ruby",
"xml-rpc",
"interop"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 264,171 | <p><strong>You can't.</strong></p>
<p>Part of the FAQ states that there is no way you can access beyond row 1000 of a query, increasing the "OFFSET" will just result in a shorter result set, </p>
<p>ie: OFFSET 999 --> 1 result comes back. </p>
<p>From Wikipedia: </p>
<blockquote>
<p>App Engine limits the maximum ... | 14 | 2008-11-05T02:07:43Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 264,183 | <p>The 1000 record limit is a hard limit in Google AppEngine.</p>
<p>This presentation <a href="http://sites.google.com/site/io/building-scalable-web-applications-with-google-app-engine" rel="nofollow">http://sites.google.com/site/io/building-scalable-web-applications-with-google-app-engine</a> explains how to efficie... | 7 | 2008-11-05T02:17:22Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 264,204 | <p>To add the contents of the two queries together:</p>
<pre><code>list1 = first query
list2 = second query
list1 += list2
</code></pre>
<p>List 1 now contains all 2000 results.</p>
| 0 | 2008-11-05T02:33:05Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 264,334 | <p>Every time this comes up as a limitation, I always wonder "<em>why</em> do you need more than 1,000 results?" Did you know that Google themselves doesn't serve up more than 1,000 results? Try this search: <a href="http://www.google.ca/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=qhu... | 17 | 2008-11-05T04:21:46Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 721,858 | <p>App Engine gives you a nice way of "paging" through the results by 1000 by ordering on Keys and using the last key as the next offset. They even provide some sample code here:</p>
<p><a href="http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Queries_on_Keys">http://code.google.com/appeng... | 19 | 2009-04-06T14:59:46Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 1,000,121 | <p>The proposed solution only works if entries are sorted by key... If you are sorting by another column first, you still have to use a limit(offset, count) clause, then the 1000 entries limitation still apply. It is the same if you use two requests : one for retrieving indexes (with conditions and sort) and another us... | 0 | 2009-06-16T08:04:30Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 1,338,456 | <p>JJG: your solution above is awesome, except that it causes an infinite loop if you have 0 records. (I found this out while testing some of my reports locally).</p>
<p>I modified the start of the while loop to look like this:</p>
<pre><code>while count % 1000 == 0:
current_count = query.count()
if current_... | 1 | 2009-08-27T01:45:38Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 1,477,027 | <pre><code>class Count(object):
def getCount(self,cls):
class Count(object):
def getCount(self,cls):
"""
Count *all* of the rows (without maxing out at 1000)
"""
count = 0
query = cls.all().order('__key__')
while 1:
current_count = query.count()
count += current_count
if current_count == 0:
break
l... | 2 | 2009-09-25T12:29:42Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 2,204,144 | <p>This 1K limit issue is resolved.</p>
<p>query = MyModel.all()
for doc in query:
print doc.title</p>
<p>By treating the Query object as an iterable: The iterator retrieves results from the datastore in small batches, allowing for the app to stop iterating on results to avoid fetching more than is needed. Iterat... | 10 | 2010-02-04T23:58:37Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 2,305,538 | <p>Just for the record - fetch limit of 1000 entries is now gone:</p>
<p><a href="http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-including-major.html">http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-including-major.html</a></p>
<p>Quotation:</p>
<blockquote>
<p>No more 1000 result li... | 23 | 2010-02-21T10:08:56Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 3,543,527 | <p>Starting with Version 1.3.6 (released Aug-17-2010) you <strong>CAN</strong> </p>
<p><a href="http://code.google.com/p/googleappengine/wiki/SdkReleaseNotes#Version_1.3.6_-_August_17,_2010">From the changelog:</a></p>
<blockquote>
<p>Results of datastore count() queries <strong>and offsets for all datastore queri... | 36 | 2010-08-22T21:38:31Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 3,681,636 | <p>we are using something in our <code>ModelBase</code> class that is:</p>
<pre><code>@classmethod
def get_all(cls):
q = cls.all()
holder = q.fetch(1000)
result = holder
while len(holder) == 1000:
holder = q.with_cursor(q.cursor()).fetch(1000)
result += holder
return result
</code></pre>
<p>This get... | 3 | 2010-09-10T00:58:32Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 5,320,613 | <p>This is close to the solution provided by Gabriel, but doesn't fetch the results it just counts them:</p>
<pre><code>count = 0
q = YourEntityClass.all().filter('myval = ', 2)
countBatch = q.count()
while countBatch > 0:
count += countBatch
countBatch = q.with_cursor(q.cursor()).count()
logging.info('Cou... | 0 | 2011-03-16T03:07:51Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 7,017,248 | <pre><code>entities = []
for entity in Entity.all():
entities.append(entity)
</code></pre>
<p>Simple as that. Note that there is an RPC made for every entity which is much slower than fetching in chunks. So if you're concerned about performance, do the following:</p>
<p>If you have less than 1M items:</p>
<pre><... | 2 | 2011-08-10T20:21:05Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 24,514,424 | <p>Fetching though the remote api still has issues when more than 1000 records. We wrote this tiny function to iterate over a table in chunks:</p>
<pre><code>def _iterate_table(table, chunk_size = 200):
offset = 0
while True:
results = table.all().order('__key__').fetch(chunk_size+1, offset = offset)
... | 5 | 2014-07-01T15:44:55Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How to fetch more than 1000? | 264,154 | <p>How can I fetch more than 1000 record from data store and put all in one single list to pass to django?</p>
| 46 | 2008-11-05T01:56:20Z | 35,268,792 | <p>If you're using NDB:</p>
<pre><code>@staticmethod
def _iterate_table(table, chunk_size=200):
offset = 0
while True:
results = table.query().order(table.key).fetch(chunk_size + 1, offset=offset)
if not results:
break
for result in results[:chunk_size]:
yield re... | 0 | 2016-02-08T11:40:54Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
setting the gzip timestamp from Python | 264,224 | <p>I'm interested in compressing data using Python's <code>gzip</code> module. It happens that I want the compressed output to be deterministic, because that's often a really convenient property for things to have in general -- if some non-gzip-aware process is going to be looking for changes in the output, say, or if... | 3 | 2008-11-05T02:50:59Z | 264,297 | <p>In lib/gzip.py, we find the method that builds the header, including the part that does indeed contain a timestamp. In Python 2.5, this begins on line 143:</p>
<pre><code>def _write_gzip_header(self):
self.fileobj.write('\037\213') # magic header
self.fileobj.write('\010') # comp... | 0 | 2008-11-05T03:44:19Z | [
"python",
"gzip"
] |
setting the gzip timestamp from Python | 264,224 | <p>I'm interested in compressing data using Python's <code>gzip</code> module. It happens that I want the compressed output to be deterministic, because that's often a really convenient property for things to have in general -- if some non-gzip-aware process is going to be looking for changes in the output, say, or if... | 3 | 2008-11-05T02:50:59Z | 264,303 | <p>Yeah, you don't have any pretty options. The time is written with this line in _write_gzip_header:</p>
<pre><code>write32u(self.fileobj, long(time.time()))
</code></pre>
<p>Since they don't give you a way to override the time, you can do one of these things:</p>
<ol>
<li>Derive a class from GzipFile, and copy th... | 7 | 2008-11-05T03:49:51Z | [
"python",
"gzip"
] |
setting the gzip timestamp from Python | 264,224 | <p>I'm interested in compressing data using Python's <code>gzip</code> module. It happens that I want the compressed output to be deterministic, because that's often a really convenient property for things to have in general -- if some non-gzip-aware process is going to be looking for changes in the output, say, or if... | 3 | 2008-11-05T02:50:59Z | 264,348 | <p>It's not pretty, but you could monkeypatch time.time temporarily with something like this:</p>
<pre><code>import time
def fake_time():
return 100000000.0
def do_gzip(content):
orig_time = time.time
time.time = fake_time
# result = do gzip stuff here
time.time = orig_time
return result
</code... | 0 | 2008-11-05T04:32:23Z | [
"python",
"gzip"
] |
setting the gzip timestamp from Python | 264,224 | <p>I'm interested in compressing data using Python's <code>gzip</code> module. It happens that I want the compressed output to be deterministic, because that's often a really convenient property for things to have in general -- if some non-gzip-aware process is going to be looking for changes in the output, say, or if... | 3 | 2008-11-05T02:50:59Z | 265,445 | <p>Submit a <a href="http://www.python.org/dev/patches/" rel="nofollow">patch</a> in which the computation of the time stamp is factored out. It would almost certainly be accepted.</p>
| 2 | 2008-11-05T15:17:54Z | [
"python",
"gzip"
] |
setting the gzip timestamp from Python | 264,224 | <p>I'm interested in compressing data using Python's <code>gzip</code> module. It happens that I want the compressed output to be deterministic, because that's often a really convenient property for things to have in general -- if some non-gzip-aware process is going to be looking for changes in the output, say, or if... | 3 | 2008-11-05T02:50:59Z | 270,315 | <p>I've taken Mr. Coventry's advice and <a href="http://bugs.python.org/issue4272" rel="nofollow">submitted a patch</a>. However, given the current state of the Python release schedule, with 3.0 just around the corner, I don't expect it to show up in a release anytime soon. Still, we'll see what happens!</p>
<p>In t... | 1 | 2008-11-06T21:17:09Z | [
"python",
"gzip"
] |
setting the gzip timestamp from Python | 264,224 | <p>I'm interested in compressing data using Python's <code>gzip</code> module. It happens that I want the compressed output to be deterministic, because that's often a really convenient property for things to have in general -- if some non-gzip-aware process is going to be looking for changes in the output, say, or if... | 3 | 2008-11-05T02:50:59Z | 36,034,315 | <p>From Python 2.7 onwards you can specify the time to be used in the gzip header. N.B. filename is also included in the header and can also be specified manually.</p>
<pre><code>import gzip
content = b"Some content"
f = open("/tmp/f.gz", "wb")
gz = gzip.GzipFile(fileobj=f,mode="wb",filename="",mtime=0)
gz.write(cont... | 2 | 2016-03-16T11:25:36Z | [
"python",
"gzip"
] |
using jython and open office 2.4 to convert docs to pdf | 264,540 | <p>I completed a python script using pyuno which successfully converted a document/ xls / rtf etc to a pdf.
Then I needed to update a mssql database, due to open office currently supporting python 2.3, it's ancientness, lacks support for decent database libs. So I have resorted to using Jython, this way im not burdened... | 2 | 2008-11-05T07:17:32Z | 264,860 | <p>Using Jython is a great idea for this I think. But why could you not use two scripts, one with pyuno/2.3 and one with pymssql/2.5 (or whatever db adapter you are using)?.</p>
<p>The intermediate format could be anything like a pickle, or json, or XML.</p>
<p>Edit: I should add that I have used pyuno quite extensiv... | 0 | 2008-11-05T11:09:58Z | [
"python",
"jython",
"openoffice.org"
] |
using jython and open office 2.4 to convert docs to pdf | 264,540 | <p>I completed a python script using pyuno which successfully converted a document/ xls / rtf etc to a pdf.
Then I needed to update a mssql database, due to open office currently supporting python 2.3, it's ancientness, lacks support for decent database libs. So I have resorted to using Jython, this way im not burdened... | 2 | 2008-11-05T07:17:32Z | 267,651 | <p>And so it goes, according to this guy, you need some oil.... and it works like a charm</p>
<p><a href="http://www.oooforum.org/forum/viewtopic.phtml?p=304263#304263" rel="nofollow">http://www.oooforum.org/forum/viewtopic.phtml?p=304263#304263</a></p>
<p>include this lib C:\OpenOffice_24\program\classes\unoil.jar</... | 1 | 2008-11-06T04:38:37Z | [
"python",
"jython",
"openoffice.org"
] |
Python - one variable equals another variable when it shouldn't | 264,575 | <p>Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop.</p>
<pre><code>i=1
while (i>0):
x_past = x_present
j=0
while(j<3):
value=0
k=0
while(k<3):
... | 5 | 2008-11-05T07:54:08Z | 264,579 | <p>What are x_past and x_present? I don't know much Python, but from a .NET/Java perspective, if they're references to some data structure (a map or whatever) then making them references to the same object (as you do at the start) will mean that any changes made through one variable will be visible through the other. I... | 4 | 2008-11-05T08:00:34Z | [
"python",
"variables"
] |
Python - one variable equals another variable when it shouldn't | 264,575 | <p>Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop.</p>
<pre><code>i=1
while (i>0):
x_past = x_present
j=0
while(j<3):
value=0
k=0
while(k<3):
... | 5 | 2008-11-05T07:54:08Z | 264,580 | <p>It looks as if x_present is a list. I suspect that this means that the assignment x_last = x_present makes x_last into an alias, i.e. they reference the same variable. Might this be the case?</p>
| 0 | 2008-11-05T08:02:06Z | [
"python",
"variables"
] |
Python - one variable equals another variable when it shouldn't | 264,575 | <p>Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop.</p>
<pre><code>i=1
while (i>0):
x_past = x_present
j=0
while(j<3):
value=0
k=0
while(k<3):
... | 5 | 2008-11-05T07:54:08Z | 264,592 | <p>Yes, I think the answers here show your problem.
Just to try and clarify a little bit.</p>
<p>You're referencing a list, so when the list changes any reference to that list will reflect that change. To demonstrate:</p>
<pre><code>>>> x_present = [4,5,6]
>>>
>>> x_past = x_present
>&g... | 30 | 2008-11-05T08:13:16Z | [
"python",
"variables"
] |
Python - one variable equals another variable when it shouldn't | 264,575 | <p>Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop.</p>
<pre><code>i=1
while (i>0):
x_past = x_present
j=0
while(j<3):
value=0
k=0
while(k<3):
... | 5 | 2008-11-05T07:54:08Z | 264,593 | <p>try changing the <code>x_past = x_present</code> line to <code>x_past = [x for x in x_present]</code> and see if it helps.</p>
<p>the list copy shorthand is my favorite python feature since i can do one-liners that are not possible in other languages:</p>
<p><code>greaterthan100 = [x for x in number if x > 100]... | 0 | 2008-11-05T08:14:10Z | [
"python",
"variables"
] |
Python - one variable equals another variable when it shouldn't | 264,575 | <p>Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop.</p>
<pre><code>i=1
while (i>0):
x_past = x_present
j=0
while(j<3):
value=0
k=0
while(k<3):
... | 5 | 2008-11-05T07:54:08Z | 264,618 | <p>In Python, everything is an object.
So the statement x_past = x_present point to the same reference.</p>
| 0 | 2008-11-05T08:36:39Z | [
"python",
"variables"
] |
Python - one variable equals another variable when it shouldn't | 264,575 | <p>Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop.</p>
<pre><code>i=1
while (i>0):
x_past = x_present
j=0
while(j<3):
value=0
k=0
while(k<3):
... | 5 | 2008-11-05T07:54:08Z | 264,715 | <p>As others pointed out the answer is to replace: <code>x_past = x_present</code> by <code>x_past = x_present[:]</code>. In general you could use a <code>copy</code> module to copy an object in Python.</p>
<pre><code>>>> import copy
>>> a = range(10)
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>... | 3 | 2008-11-05T09:50:22Z | [
"python",
"variables"
] |
Why the Global Interpreter Lock? | 265,687 | <p>What is exactly the function of Python's Global Interpreter Lock?
Do other languages that are compiled to bytecode employ a similar mechanism?</p>
| 70 | 2008-11-05T16:23:48Z | 265,731 | <p>The following is from the <a href="http://www.python.org/doc/2.5.2/api/threads.html">official Python/C API Reference Manual</a>:</p>
<blockquote>
<p>The Python interpreter is not fully
thread safe. In order to support
multi-threaded Python programs,
there's a global lock that must be
held by the current t... | 27 | 2008-11-05T16:32:37Z | [
"python",
"multithreading",
"scripting",
"locking",
"bytecode"
] |
Why the Global Interpreter Lock? | 265,687 | <p>What is exactly the function of Python's Global Interpreter Lock?
Do other languages that are compiled to bytecode employ a similar mechanism?</p>
| 70 | 2008-11-05T16:23:48Z | 265,733 | <p>The global interpreter lock is a big mutex-type lock that protects reference counters from getting hosed. If you are writing pure python code, this all happens behind the scenes, but if you embedding Python into C, then you might have to explicitly take/release the lock.</p>
<p>This mechanism is not related to Pyt... | 16 | 2008-11-05T16:32:50Z | [
"python",
"multithreading",
"scripting",
"locking",
"bytecode"
] |
Why the Global Interpreter Lock? | 265,687 | <p>What is exactly the function of Python's Global Interpreter Lock?
Do other languages that are compiled to bytecode employ a similar mechanism?</p>
| 70 | 2008-11-05T16:23:48Z | 265,746 | <p>Regarding your second question, not all scripting languages use this, but it only makes them less powerful. For instance, the threads in Ruby are <a href="http://en.wikipedia.org/wiki/Green_threads" rel="nofollow">green</a> and not native.</p>
<p>In Python, the threads are native and the GIL only prevents them from... | 4 | 2008-11-05T16:35:11Z | [
"python",
"multithreading",
"scripting",
"locking",
"bytecode"
] |
Why the Global Interpreter Lock? | 265,687 | <p>What is exactly the function of Python's Global Interpreter Lock?
Do other languages that are compiled to bytecode employ a similar mechanism?</p>
| 70 | 2008-11-05T16:23:48Z | 265,795 | <p>In general, for any thread safety problem you will need to protect your internal data structures with locks.
This can be done with various levels of granularity.</p>
<ul>
<li><p>You can use fine-grained locking, where every separate structure has its own lock.</p></li>
<li><p>You can use coarse-grained locking wher... | 56 | 2008-11-05T16:44:11Z | [
"python",
"multithreading",
"scripting",
"locking",
"bytecode"
] |
Why the Global Interpreter Lock? | 265,687 | <p>What is exactly the function of Python's Global Interpreter Lock?
Do other languages that are compiled to bytecode employ a similar mechanism?</p>
| 70 | 2008-11-05T16:23:48Z | 266,111 | <p>Python, like perl 5, was not designed from the ground up to be thread safe. Threads were grafted on after the fact, so the global interpreter lock is used to maintain mutual exclusion to where only one thread is executing code at a given time in the bowels of the interpreter.</p>
<p>Individual Python threads are co... | 10 | 2008-11-05T18:18:32Z | [
"python",
"multithreading",
"scripting",
"locking",
"bytecode"
] |
Why the Global Interpreter Lock? | 265,687 | <p>What is exactly the function of Python's Global Interpreter Lock?
Do other languages that are compiled to bytecode employ a similar mechanism?</p>
| 70 | 2008-11-05T16:23:48Z | 266,426 | <p>Maybe <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=214235" rel="nofollow">this</a> article by the BDFL will help.</p>
| 2 | 2008-11-05T20:02:27Z | [
"python",
"multithreading",
"scripting",
"locking",
"bytecode"
] |
HTTP Request Timeout | 265,720 | <p>In Python 2.6, a new "timeout" parameter was added to the httplib.HTTPConnection class:
<a href="http://docs.python.org/library/httplib.html#httplib.HTTPConnection" rel="nofollow">http://docs.python.org/library/httplib.html#httplib.HTTPConnection</a></p>
<p>However, this is only a timeout for the connection to a se... | 2 | 2008-11-05T16:30:22Z | 265,741 | <p>You can set a global socket timeout <sup>(*)</sup>:</p>
<pre><code>import socket
timeout = 10
socket.setdefaulttimeout(timeout)
</code></pre>
<hr>
<p><sup>(*)</sup> <strong>EDIT</strong>: As people in the comments correctly point out: This is technically true, but it only has predictable results for tasks that i... | 9 | 2008-11-05T16:34:28Z | [
"python",
"http"
] |
HTTP Request Timeout | 265,720 | <p>In Python 2.6, a new "timeout" parameter was added to the httplib.HTTPConnection class:
<a href="http://docs.python.org/library/httplib.html#httplib.HTTPConnection" rel="nofollow">http://docs.python.org/library/httplib.html#httplib.HTTPConnection</a></p>
<p>However, this is only a timeout for the connection to a se... | 2 | 2008-11-05T16:30:22Z | 268,174 | <p>No, there isn't.</p>
<p>It's because the <a href="http://www.greenbytes.de/tech/webdav/rfc2616.html">HTTP spec</a> does not provide anything for the client to specify time-to-live information with a HTTP request. You can do this only on TCP level, as you mentioned.</p>
<p>On the other hand, the server may inform t... | 7 | 2008-11-06T10:09:21Z | [
"python",
"http"
] |
HTTP Request Timeout | 265,720 | <p>In Python 2.6, a new "timeout" parameter was added to the httplib.HTTPConnection class:
<a href="http://docs.python.org/library/httplib.html#httplib.HTTPConnection" rel="nofollow">http://docs.python.org/library/httplib.html#httplib.HTTPConnection</a></p>
<p>However, this is only a timeout for the connection to a se... | 2 | 2008-11-05T16:30:22Z | 4,453,301 | <p>You could also use <code>settimeout</code> on the socket of the connection (works with Python 2.5):</p>
<pre><code>connection = HTTPConnection('slow.service.com')
connection.request(...)
connection.sock.settimeout(5.0)
response = connection.getresponse()
response.read()
connection.close()
</code></pre>
<p>If the s... | 4 | 2010-12-15T18:03:27Z | [
"python",
"http"
] |
How do I process a string such as this using regular expressions? | 265,814 | <p>How can I create a regex for a string such as this:</p>
<pre><code><SERVER> <SERVERKEY> <COMMAND> <FOLDERPATH> <RETENTION> <TRANSFERMODE> <OUTPUTPATH> <LOGTO> <OPTIONAL-MAXSIZE> <OPTIONAL-OFFSET>
</code></pre>
<p>Most of these fields are just simple words... | 0 | 2008-11-05T16:47:56Z | 265,839 | <p>The problem is that because you're allowing spaces in filenames and using spaces to separate fields, the solution is ambiguous. You either need to use a different field separator character that can't appear in filenames, or use some other method of representing filenames with spaces in them, e.g. putting them in qu... | 4 | 2008-11-05T16:54:22Z | [
"python",
"regex"
] |
How do I process a string such as this using regular expressions? | 265,814 | <p>How can I create a regex for a string such as this:</p>
<pre><code><SERVER> <SERVERKEY> <COMMAND> <FOLDERPATH> <RETENTION> <TRANSFERMODE> <OUTPUTPATH> <LOGTO> <OPTIONAL-MAXSIZE> <OPTIONAL-OFFSET>
</code></pre>
<p>Most of these fields are just simple words... | 0 | 2008-11-05T16:47:56Z | 265,884 | <p>it is theoretically possible, but you are making things incredibly difficult for yourself. You have a number of problems here:</p>
<p>1) You are using space as a separator and you are also allowing spaces in the path names. You can avoid this by forcing the application to use paths without spaces in them.</p>
<p... | 3 | 2008-11-05T17:09:56Z | [
"python",
"regex"
] |
How do I process a string such as this using regular expressions? | 265,814 | <p>How can I create a regex for a string such as this:</p>
<pre><code><SERVER> <SERVERKEY> <COMMAND> <FOLDERPATH> <RETENTION> <TRANSFERMODE> <OUTPUTPATH> <LOGTO> <OPTIONAL-MAXSIZE> <OPTIONAL-OFFSET>
</code></pre>
<p>Most of these fields are just simple words... | 0 | 2008-11-05T16:47:56Z | 265,940 | <p>You need to restrict the fields between the paths in a way that the regexp can distinct them from the pathnames.</p>
<p>So unless you put in a special separator, the sequence</p>
<pre><code><OUTPUTPATH> <LOGTO>
</code></pre>
<p>with optional spaces will not work.</p>
<p>And if a path can look like th... | 0 | 2008-11-05T17:23:44Z | [
"python",
"regex"
] |
How do I process a string such as this using regular expressions? | 265,814 | <p>How can I create a regex for a string such as this:</p>
<pre><code><SERVER> <SERVERKEY> <COMMAND> <FOLDERPATH> <RETENTION> <TRANSFERMODE> <OUTPUTPATH> <LOGTO> <OPTIONAL-MAXSIZE> <OPTIONAL-OFFSET>
</code></pre>
<p>Most of these fields are just simple words... | 0 | 2008-11-05T16:47:56Z | 266,010 | <p>Just splitting on whitespace is never going to work. But if you can make some assumptions on the data it could be made to work.</p>
<p>Some assumptions I had in mind:</p>
<ul>
<li><code>SERVER</code>, <code>SERVERKEY</code> and <code>COMMAND</code> not containing any spaces: <code>\S+</code></li>
<li><code>FOLDERP... | 1 | 2008-11-05T17:44:39Z | [
"python",
"regex"
] |
How do I process a string such as this using regular expressions? | 265,814 | <p>How can I create a regex for a string such as this:</p>
<pre><code><SERVER> <SERVERKEY> <COMMAND> <FOLDERPATH> <RETENTION> <TRANSFERMODE> <OUTPUTPATH> <LOGTO> <OPTIONAL-MAXSIZE> <OPTIONAL-OFFSET>
</code></pre>
<p>Most of these fields are just simple words... | 0 | 2008-11-05T16:47:56Z | 266,018 | <p>Are less than/greater than allowed inside the values? Because if not you have a very simple solution:</p>
<p>Just replace ever occurance of "> " with just ">", split on "><", and strip out all less than/greater than from each item. It's probably longer than the regex code, but it will be clearer what'... | -1 | 2008-11-05T17:48:06Z | [
"python",
"regex"
] |
Django Forms, Display Error on ModelMultipleChoiceField | 265,888 | <p>I'm having an issue getting validation error messages to display for a particular field in a Django form, where the field in question is a <strong>ModelMultipleChoiceField</strong>.</p>
<p>In the <code>clean(self)</code> method for the Form, I try to add the error message to the field like so:</p>
<pre><code>msg =... | 1 | 2008-11-05T17:10:57Z | 314,830 | <p>Why are you instantiating an ErrorList and writing to self._errors directly? Calling "raise forms.ValidationError(msg)" takes care of all that already. </p>
<p>And what does your template look like?</p>
| 0 | 2008-11-24T17:19:27Z | [
"python",
"django",
"validation",
"forms"
] |
Django Forms, Display Error on ModelMultipleChoiceField | 265,888 | <p>I'm having an issue getting validation error messages to display for a particular field in a Django form, where the field in question is a <strong>ModelMultipleChoiceField</strong>.</p>
<p>In the <code>clean(self)</code> method for the Form, I try to add the error message to the field like so:</p>
<pre><code>msg =... | 1 | 2008-11-05T17:10:57Z | 1,265,411 | <p>Yeah, it sounds like you're doing it wrong.</p>
<p>You should be using the <a href="http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute" rel="nofollow">clean_</a> method instead. Read through that whole document, in fact - it's very informative.</p>
| 2 | 2009-08-12T10:37:18Z | [
"python",
"django",
"validation",
"forms"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 265,995 | <p>Not necessarily simpler, but a different way, if you are more familiar with the re family. </p>
<pre><code>import re, string
s = "string. With. Punctuation?" # Sample string
out = re.sub('[%s]' % re.escape(string.punctuation), '', s)
</code></pre>
| 16 | 2008-11-05T17:39:55Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 265,996 | <p>Do search and replace using the regex functions, as seen <a href="http://www.amk.ca/python/howto/regex/regex.html#SECTION000620000000000000000" rel="nofollow">here.</a>. If you have to repeatedly perform the operation, you can keep a compiled copy of the regex pattern (your punctuation) around, which will speed thin... | 0 | 2008-11-05T17:40:08Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 266,000 | <p>I usually use something like this:</p>
<pre><code>>>> s = "string. With. Punctuation?" # Sample string
>>> import string
>>> for c in string.punctuation:
... s= s.replace(c,"")
...
>>> s
'string With Punctuation'
</code></pre>
| 20 | 2008-11-05T17:41:27Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 266,162 | <p>From an efficiency perspective, you're not going to beat translate() - it's performing raw string operations in C with a lookup table - there's not much that will beat that but writing your own C code.
If speed isn't a worry, another option though is:</p>
<pre><code>exclude = set(string.punctuation)
s = ''.join(ch ... | 383 | 2008-11-05T18:36:11Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 2,402,306 | <pre><code>myString.translate(None, string.punctuation)
</code></pre>
| 39 | 2010-03-08T15:19:09Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 6,577,965 | <p>This might not be the best solution however this is how I did it.</p>
<pre><code>import string
f = lambda x: ''.join([i for i in x if i not in string.punctuation])
</code></pre>
| 4 | 2011-07-05T04:30:07Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 7,268,456 | <p>string.punctuation is ascii ONLY! A more correct (but also much slower) way is to use the unicodedata module:</p>
<pre><code># -*- coding: utf-8 -*-
from unicodedata import category
s = u'String â with - «punctation »...'
s = ''.join(ch for ch in s if category(ch)[0] != 'P')
print 'stripped', s
</code></pre>
| 12 | 2011-09-01T09:29:45Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 15,853,920 | <p>I like to use a function like this:</p>
<pre><code>def scrub(abc):
while abc[-1] is in list(string.punctuation):
abc=abc[:-1]
while abc[0] is in list(string.punctuation):
abc=abc[1:]
return abc
</code></pre>
| -2 | 2013-04-06T17:28:57Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 16,799,238 | <p>Regular expressions are simple enough, if you know them. </p>
<pre><code>import re
s = "string. With. Punctuation?"
s = re.sub(r'[^\w\s]','',s)
</code></pre>
| 27 | 2013-05-28T18:47:47Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 18,570,395 | <p>For Python 3 <code>str</code> or Python 2 <code>unicode</code> values, <a href="http://docs.python.org/3/library/stdtypes.html#str.translate" rel="nofollow"><code>str.translate()</code></a> only takes a dictionary; codepoints (integers) are looked up in that mapping and anything mapped to <code>None</code> is remove... | 5 | 2013-09-02T09:57:54Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 32,719,664 | <p>This question is over 6 years old, but I'd figured I chime in with a function I wrote. It's not very efficient, but it is simple and you can add or remove any punctuation that you desire:</p>
<pre><code>def stripPunc(wordList):
"""Strips punctuation from list of words"""
puncList = [".",";",":","!","?","/",... | 2 | 2015-09-22T14:30:47Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 33,192,523 | <p>One liner might be helpful in not very strict cases:</p>
<pre><code>''.join([c for c in s if c.isalnum() or c.isspace()])
</code></pre>
| 0 | 2015-10-17T23:03:59Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 36,122,360 | <p>Here's a one liner for python 3.5:</p>
<pre><code>import string
"l*ots! o(f. p@u)n[c}t]u[a'ti\"on#$^?/".translate(str.maketrans({a:None for a in string.punctuation}))
</code></pre>
| 3 | 2016-03-21T02:46:47Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 37,221,663 | <p>For the convenience of usage, I sum up the note of striping punctuation from a string in both Python2 and Python3. Please refer to other answers for the detailed description.</p>
<hr>
<p><strong>Python2</strong></p>
<pre><code>import string
s = "string. With. Punctuation?"
table = string.maketrans("","")
new_s... | 3 | 2016-05-14T01:57:29Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 37,894,054 | <p>I haven't seen this answer yet. Just use a regex removes all characters besides word characters (<code>\w</code>) and number characters (<code>\d</code>), followed by a whitespace character (<code>\s</code>):</p>
<pre><code>import re
s = "string. With. Punctuation?" # Sample string
out = re.sub(ur'[^\w\d\s]+', '',... | 0 | 2016-06-18T06:38:57Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 39,115,253 | <pre><code>>>> s = "string. With. Punctuation?"
>>> s = re.sub(r'[^\w\s]','',s)
>>> re.split(r'\s*', s)
['string', 'With', 'Punctuation']
</code></pre>
| 0 | 2016-08-24T05:43:58Z | [
"python",
"string",
"punctuation"
] |
Best way to strip punctuation from a string in Python | 265,960 | <p>It seems like there should be a simpler way than:</p>
<pre><code>import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
</code></pre>
<p>Is there?</p>
| 282 | 2008-11-05T17:30:32Z | 39,901,522 | <p><code>string.punctuation</code> misses loads of punctation marks that are commonly used in the real world. How about a solution that works for non-ascii punctuationï¼</p>
<pre><code>import regex
s = u"string. With. Someã»Really WeirdãNonï¼ASCIIã ãï¼Punctuationï¼ã?"
remove = regex.compile(ur'[\p{C}|\p{M... | 0 | 2016-10-06T16:46:01Z | [
"python",
"string",
"punctuation"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 266,132 | <p>What you're looking for is Mod_Python. It's an Apache-based interpreter for Python. Check it out here:</p>
<p><a href="http://www.modpython.org/" rel="nofollow">http://www.modpython.org/</a></p>
| 0 | 2008-11-05T18:24:26Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 266,209 | <p>Most Python applications are moving away from mod_python. It can vary by framework or provider, but most development effort is going into mod_wsgi.</p>
<p>Using the <a href="https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface" rel="nofollow">WSGI</a> standard will make your Python application server agnostic... | 2 | 2008-11-05T19:00:06Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 266,298 | <p><a href="http://code.google.com/appengine/" rel="nofollow">Google App Engine</a> has done it for you. Some limitations but it works great, and it gives you a path to hosting free.</p>
| 0 | 2008-11-05T19:35:59Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 266,509 | <p>I've worked with <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow">Django</a> using only the included server in the <code>manager.py</code> script and have not had any trouble moving to a production environment.</p>
<p>If you put your application in a host that does the environment co... | 1 | 2008-11-05T20:23:53Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 266,615 | <p>Of course Mac OS X, in recent versions, comes with Python and Apache. However you may want to have more flexibility in the versions you use, or you may not like the tweaks Apple has made to the way they are configured. A good way to get a more generic set of tools, including MySQL, is to install them anew. This w... | 0 | 2008-11-05T20:50:52Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 266,736 | <p>FWIW, we've found virtualenv [<a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">http://pypi.python.org/pypi/virtualenv</a>] to be an invaluable part of our dev setup. We typically work on multiple projects that use different versions of Python libraries etc. It's very difficult to do this on one machin... | 2 | 2008-11-05T21:18:42Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 267,522 | <p>You may want to look into <a href="http://www.web2py.com" rel="nofollow">web2py</a>. It includes an administration interface to develop via your browser. All you need in one package, including <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="nofollow">Python</a>.</p>
| 0 | 2008-11-06T02:51:18Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 275,578 | <p>I run a Linux virtual machine on my Mac laptop. This allows me to keep my development environment and production environments perfectly in sync (and make snapshots for easy experimentation / rollback). I've found <a href="http://www.vmware.com/download/fusion/" rel="nofollow">VMWare Fusion</a> works the best, but th... | 1 | 2008-11-09T03:54:34Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 624,603 | <p>Check out <a href="http://www.webfaction.com" rel="nofollow">WebFaction</a>âalthough I don't use them (nor am I related to / profit from their business in any way). I've read over and over how great their service is and particularly how <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollo... | 0 | 2009-03-09T00:13:13Z | [
"python",
"mysql",
"apache",
"osx"
] |
Setting up a Python web development environment on OS X | 266,114 | <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="nofollow">Mac OS X Leopard</a> and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the f... | 2 | 2008-11-05T18:19:44Z | 624,751 | <p><code>mod_wsgi</code> is really, really simple.</p>
<p><a href="http://github.com/dbr/pyerweb/blob/070e354c1837e7d22a8bd5160d7f0897391bf382/pyerweb.py#L64" rel="nofollow">Pyerweb</a> is a really simple (~90 lines including comments/whitespace) WSGI-compliant routing-framework I wrote. Basically the WSGI API is just... | 0 | 2009-03-09T01:48:17Z | [
"python",
"mysql",
"apache",
"osx"
] |
Python: Check if uploaded file is jpg | 266,648 | <p>How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)?</p>
<p>This is how far I got by now:</p>
<p>Script receives image via HTML Form Post and is processed by the following code</p>
<pre><code>...
incomming_image = self.request.get("img")
image = db.Blob(incomming_image)
.... | 15 | 2008-11-05T21:00:36Z | 266,724 | <p>You might have to check the bytes of the image <a href="http://www.obrador.com/essentialjpeg/headerinfo.htm" rel="nofollow">http://www.obrador.com/essentialjpeg/headerinfo.htm</a> describes how the jpeg header is set up</p>
| -2 | 2008-11-05T21:17:02Z | [
"python",
"google-app-engine",
"image",
"image-processing",
"mime"
] |
Python: Check if uploaded file is jpg | 266,648 | <p>How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)?</p>
<p>This is how far I got by now:</p>
<p>Script receives image via HTML Form Post and is processed by the following code</p>
<pre><code>...
incomming_image = self.request.get("img")
image = db.Blob(incomming_image)
.... | 15 | 2008-11-05T21:00:36Z | 266,731 | <p>If you need more than looking at extension, one way would be to read the JPEG header, and check that it matches valid data. The format for this is:</p>
<pre><code>Start Marker | JFIF Marker | Header Length | Identifier
0xff, 0xd8 | 0xff, 0xe0 | 2-bytes | "JFIF\0"
</code></pre>
<p>so a quick recogniser ... | 36 | 2008-11-05T21:17:54Z | [
"python",
"google-app-engine",
"image",
"image-processing",
"mime"
] |
Python: Check if uploaded file is jpg | 266,648 | <p>How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)?</p>
<p>This is how far I got by now:</p>
<p>Script receives image via HTML Form Post and is processed by the following code</p>
<pre><code>...
incomming_image = self.request.get("img")
image = db.Blob(incomming_image)
.... | 15 | 2008-11-05T21:00:36Z | 266,774 | <p>Use <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a>. If it can open the file, it's an image.</p>
<p>From the tutorial...</p>
<pre><code>>>> import Image
>>> im = Image.open("lena.ppm")
>>> print im.format, im.size, im.mode
</code></pre>
| 0 | 2008-11-05T21:29:10Z | [
"python",
"google-app-engine",
"image",
"image-processing",
"mime"
] |
Python: Check if uploaded file is jpg | 266,648 | <p>How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)?</p>
<p>This is how far I got by now:</p>
<p>Script receives image via HTML Form Post and is processed by the following code</p>
<pre><code>...
incomming_image = self.request.get("img")
image = db.Blob(incomming_image)
.... | 15 | 2008-11-05T21:00:36Z | 1,040,027 | <p>No need to use and install the PIL lybrary for this, there is the imghdr standard module exactly fited for this sort of usage.</p>
<p>See <a href="http://docs.python.org/library/imghdr.html">http://docs.python.org/library/imghdr.html</a></p>
<pre><code>import imghdr
image_type = imghdr.what(filename)
if not image... | 32 | 2009-06-24T18:18:02Z | [
"python",
"google-app-engine",
"image",
"image-processing",
"mime"
] |
Python: Check if uploaded file is jpg | 266,648 | <p>How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)?</p>
<p>This is how far I got by now:</p>
<p>Script receives image via HTML Form Post and is processed by the following code</p>
<pre><code>...
incomming_image = self.request.get("img")
image = db.Blob(incomming_image)
.... | 15 | 2008-11-05T21:00:36Z | 5,717,194 | <p>A more general solution is to use the Python binding to the Unix "file" command. For this, install the package python-magic. Example:</p>
<pre><code>import magic
ms = magic.open(magic.MAGIC_NONE)
ms.load()
type = ms.file("/path/to/some/file")
print type
f = file("/path/to/some/file", "r")
buffer = f.read(4096)
f... | 1 | 2011-04-19T13:34:07Z | [
"python",
"google-app-engine",
"image",
"image-processing",
"mime"
] |
Python: Check if uploaded file is jpg | 266,648 | <p>How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)?</p>
<p>This is how far I got by now:</p>
<p>Script receives image via HTML Form Post and is processed by the following code</p>
<pre><code>...
incomming_image = self.request.get("img")
image = db.Blob(incomming_image)
.... | 15 | 2008-11-05T21:00:36Z | 28,907,255 | <p>The last byte of the JPEG file specification seems to vary beyond just e0. Capturing the first three is 'good enough' of a heuristic signature to reliably identify whether the file is a jpeg. Please see below modified proposal: </p>
<pre><code>def is_jpg(filename):
data = open("uploads/" + filename,'rb').read(1... | 0 | 2015-03-06T20:39:54Z | [
"python",
"google-app-engine",
"image",
"image-processing",
"mime"
] |
Using Python's smtplib with Tor | 266,849 | <p>I'm conducting experiments regarding e-mail spam. One of these experiments require sending mail thru Tor. Since I'm using Python and smtplib for my experiments, I'm looking for a way to use the Tor proxy (or other method) to perform that mail sending.
Ideas how this can be done?</p>
| 3 | 2008-11-05T21:50:04Z | 275,164 | <p>Because of abuse by spammers, many Tor egress nodes decline to emit port 25 (SMTP) traffic, so you may have problems.</p>
| 1 | 2008-11-08T20:37:17Z | [
"python",
"smtp",
"tor"
] |
Using Python's smtplib with Tor | 266,849 | <p>I'm conducting experiments regarding e-mail spam. One of these experiments require sending mail thru Tor. Since I'm using Python and smtplib for my experiments, I'm looking for a way to use the Tor proxy (or other method) to perform that mail sending.
Ideas how this can be done?</p>
| 3 | 2008-11-05T21:50:04Z | 8,490,148 | <p><a href="http://bent.latency.net/smtpprox/" rel="nofollow">http://bent.latency.net/smtpprox/</a> I found this earlier, but haven't tried it</p>
| 1 | 2011-12-13T13:37:47Z | [
"python",
"smtp",
"tor"
] |
How do I treat an ASCII string as unicode and unescape the escaped characters in it in python? | 267,436 | <p>For example, if I have a <em>unicode</em> string, I can encode it as an <em>ASCII</em> string like so:</p>
<pre><code>>>> u'\u003cfoo/\u003e'.encode('ascii')
'<foo/>'
</code></pre>
<p>However, I have e.g. this <em>ASCII</em> string:</p>
<pre><code>'\u003foo\u003e'
</code></pre>
<p>... that I want ... | 20 | 2008-11-06T01:55:40Z | 267,444 | <p>It's a little dangerous depending on where the string is coming from, but how about:</p>
<pre><code>>>> s = '\u003cfoo\u003e'
>>> eval('u"'+s.replace('"', r'\"')+'"').encode('ascii')
'<foo>'
</code></pre>
| -1 | 2008-11-06T02:01:12Z | [
"python",
"unicode",
"ascii"
] |
How do I treat an ASCII string as unicode and unescape the escaped characters in it in python? | 267,436 | <p>For example, if I have a <em>unicode</em> string, I can encode it as an <em>ASCII</em> string like so:</p>
<pre><code>>>> u'\u003cfoo/\u003e'.encode('ascii')
'<foo/>'
</code></pre>
<p>However, I have e.g. this <em>ASCII</em> string:</p>
<pre><code>'\u003foo\u003e'
</code></pre>
<p>... that I want ... | 20 | 2008-11-06T01:55:40Z | 267,475 | <p>It took me a while to figure this one out, but <a href="http://www.egenix.com/www2002/python/unicode-proposal.txt">this page</a> had the best answer:</p>
<pre><code>>>> s = '\u003cfoo/\u003e'
>>> s.decode( 'unicode-escape' )
u'<foo/>'
>>> s.decode( 'unicode-escape' ).encode( 'ascii'... | 36 | 2008-11-06T02:26:05Z | [
"python",
"unicode",
"ascii"
] |
How do I treat an ASCII string as unicode and unescape the escaped characters in it in python? | 267,436 | <p>For example, if I have a <em>unicode</em> string, I can encode it as an <em>ASCII</em> string like so:</p>
<pre><code>>>> u'\u003cfoo/\u003e'.encode('ascii')
'<foo/>'
</code></pre>
<p>However, I have e.g. this <em>ASCII</em> string:</p>
<pre><code>'\u003foo\u003e'
</code></pre>
<p>... that I want ... | 20 | 2008-11-06T01:55:40Z | 1,750,741 | <p>On Python 2.5 the correct encoding is "unicode_escape", not "unicode-escape" (note the underscore).</p>
<p>I'm not sure if the newer version of Python changed the unicode name, but here only worked with the underscore. </p>
<p>Anyway, this is it.</p>
| 1 | 2009-11-17T18:14:37Z | [
"python",
"unicode",
"ascii"
] |
How do I treat an ASCII string as unicode and unescape the escaped characters in it in python? | 267,436 | <p>For example, if I have a <em>unicode</em> string, I can encode it as an <em>ASCII</em> string like so:</p>
<pre><code>>>> u'\u003cfoo/\u003e'.encode('ascii')
'<foo/>'
</code></pre>
<p>However, I have e.g. this <em>ASCII</em> string:</p>
<pre><code>'\u003foo\u003e'
</code></pre>
<p>... that I want ... | 20 | 2008-11-06T01:55:40Z | 11,281,948 | <p><em>Ned Batchelder</em> said:</p>
<blockquote>
<p>It's a little dangerous depending on where the string is coming from,
but how about:</p>
<pre><code>>>> s = '\u003cfoo\u003e'
>>> eval('u"'+s.replace('"', r'\"')+'"').encode('ascii')
'<foo>'
</code></pre>
</blockquote>
<p>Actually this ... | 1 | 2012-07-01T12:29:51Z | [
"python",
"unicode",
"ascii"
] |
How do I treat an ASCII string as unicode and unescape the escaped characters in it in python? | 267,436 | <p>For example, if I have a <em>unicode</em> string, I can encode it as an <em>ASCII</em> string like so:</p>
<pre><code>>>> u'\u003cfoo/\u003e'.encode('ascii')
'<foo/>'
</code></pre>
<p>However, I have e.g. this <em>ASCII</em> string:</p>
<pre><code>'\u003foo\u003e'
</code></pre>
<p>... that I want ... | 20 | 2008-11-06T01:55:40Z | 22,726,482 | <p>At some point you will run into issues when you encounter special characters like Chinese characters or emoticons in a string you want to decode i.e. errors that look like this:</p>
<pre><code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 109-123: ordinal not in range(128)
</code></pre>
<p>... | 0 | 2014-03-29T03:06:42Z | [
"python",
"unicode",
"ascii"
] |
scripting fruityloops or propellerheads reason from VB or Python? | 267,628 | <p>I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.</p>
<p>Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?</p>
<p>Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) d... | 9 | 2008-11-06T04:19:54Z | 267,654 | <p>I think both FL Studio and Reason can be configured as the default MIDI playback device. To send MIDI messages to either from VB.NET, you'll need to PInvoke the midiOutOpen, midiOutShortMsg and midiOutClose API calls. Here's a link to code samples:</p>
<p><a href="http://www.answers.com/topic/midioutopen" rel="no... | 2 | 2008-11-06T04:40:03Z | [
"python",
"vb.net",
"music"
] |
scripting fruityloops or propellerheads reason from VB or Python? | 267,628 | <p>I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.</p>
<p>Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?</p>
<p>Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) d... | 9 | 2008-11-06T04:19:54Z | 267,680 | <p>Note: This answer doesn't exactly answer the question you asked but it might achieve the result you want :)</p>
<p>You can author a VST plugin in Java using jVSTWrapper (<a href="http://jvstwrapper.sourceforge.net/" rel="nofollow">http://jvstwrapper.sourceforge.net/</a>). If you really wanted to use Python you coul... | 2 | 2008-11-06T04:57:01Z | [
"python",
"vb.net",
"music"
] |
scripting fruityloops or propellerheads reason from VB or Python? | 267,628 | <p>I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.</p>
<p>Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?</p>
<p>Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) d... | 9 | 2008-11-06T04:19:54Z | 268,066 | <p>When it comes to Reason, you can do with it to much because of it's closed architecture - you can use VST plugins (or any other type like DirectX ones) - your only option is to use MIDI.</p>
<p>Regarding Fruity Loops, you could write a VST plugin that can take an input from a scripting language (VB, Python or whate... | 0 | 2008-11-06T09:30:56Z | [
"python",
"vb.net",
"music"
] |
scripting fruityloops or propellerheads reason from VB or Python? | 267,628 | <p>I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.</p>
<p>Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?</p>
<p>Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) d... | 9 | 2008-11-06T04:19:54Z | 268,684 | <p>You could write a <a href="http://en.wikipedia.org/wiki/ReWire" rel="nofollow">Rewire</a> host. Though, you will have to get a license (the license is free, but your application must be proprietary, so no open source).</p>
<p>Alternatively, you could interface through MIDI messages.</p>
<p>Finally, you could imple... | 0 | 2008-11-06T13:30:11Z | [
"python",
"vb.net",
"music"
] |
scripting fruityloops or propellerheads reason from VB or Python? | 267,628 | <p>I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.</p>
<p>Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?</p>
<p>Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) d... | 9 | 2008-11-06T04:19:54Z | 2,840,001 | <p>Both applications support MIDI. It's just that they don't see each other. </p>
<p>In order to send messages via MIDI between applications, you need to install a <strong>virtual midi port</strong>.</p>
<p>There are several freely available, but this one works: <a href="http://www.midiox.com/zip/MidiYokeSetup.msi" r... | 3 | 2010-05-15T11:55:02Z | [
"python",
"vb.net",
"music"
] |
scripting fruityloops or propellerheads reason from VB or Python? | 267,628 | <p>I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.</p>
<p>Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?</p>
<p>Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) d... | 9 | 2008-11-06T04:19:54Z | 2,840,034 | <p>What you need is a VST MIDI scripter / scripting plugin to create a logic of MIDI events that can be sent to any MIDI channel. You would need to set a MIDI channel in FL for the VST instrument/effect you need to tweak its values. Google for it there are some plugins around and please share them back here if you find... | 1 | 2010-05-15T12:06:08Z | [
"python",
"vb.net",
"music"
] |
scripting fruityloops or propellerheads reason from VB or Python? | 267,628 | <p>I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.</p>
<p>Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?</p>
<p>Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) d... | 9 | 2008-11-06T04:19:54Z | 4,439,944 | <p>There's an opensource music workstation, called Frinika, and you can script that in Javascript. (Insert / delete notes , change midi effects like pitch wheel etc.) It can import / export regular midi files, so it will work with Fruity loops or whatever else you have.</p>
<pre><code>// Insert New
song.newLane("MyMi... | 0 | 2010-12-14T14:01:38Z | [
"python",
"vb.net",
"music"
] |
How to create a picture with animated aspects programmatically | 267,660 | <p>Background</p>
<p>I have been asked by a client to create a picture of the world which has animated arrows/rays that come from one part of the world to another. </p>
<p>The rays will be randomized, will represent a transaction, will fade out after they happen and will increase in frequency as time goes on. The ... | 1 | 2008-11-06T04:44:47Z | 267,676 | <p>It depends largely on the effort you want to expend on this, but the basic outline of an easy way. Would be to load an image of an arrow, and use a drawing library to color and rotate it in the direction you want to point(or draw it using shapes/curves).</p>
<p>Finally to actually animate it interpolate between the... | 1 | 2008-11-06T04:53:21Z | [
"python",
"image",
"graphics",
"animation",
"drawing"
] |
How to create a picture with animated aspects programmatically | 267,660 | <p>Background</p>
<p>I have been asked by a client to create a picture of the world which has animated arrows/rays that come from one part of the world to another. </p>
<p>The rays will be randomized, will represent a transaction, will fade out after they happen and will increase in frequency as time goes on. The ... | 1 | 2008-11-06T04:44:47Z | 267,698 | <blockquote>
<p>The client will present this as a slide in a presentation in a windows machine</p>
</blockquote>
<p>I think this is the key to your answer. Before going to a 3d implementation and writing all the code in the world to create this feature, you need to look at the presentation software. Chances are, yo... | 2 | 2008-11-06T05:07:21Z | [
"python",
"image",
"graphics",
"animation",
"drawing"
] |
How to create a picture with animated aspects programmatically | 267,660 | <p>Background</p>
<p>I have been asked by a client to create a picture of the world which has animated arrows/rays that come from one part of the world to another. </p>
<p>The rays will be randomized, will represent a transaction, will fade out after they happen and will increase in frequency as time goes on. The ... | 1 | 2008-11-06T04:44:47Z | 267,888 | <p>If you are adventurous use OpenGL :)</p>
<p>You can draw bezier curves in 3d space on top of a textured plane (earth map), you can specify a thickness for them and you can draw a point (small cone) at the end. It's easy and it looks nice, problem is learning the basics of OpenGL if you haven't used it before but th... | 1 | 2008-11-06T07:52:57Z | [
"python",
"image",
"graphics",
"animation",
"drawing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.