title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
App Engine: 13 StringPropertys vs. 1 StringListProperty (w.r.t. indexing/storage and query performance) | 1,220,794 | <p>A bit of background first: <a href="http://code.google.com/p/geomodel" rel="nofollow">GeoModel</a> is a library I wrote that adds very basic geospatial indexing and querying functionality to App Engine apps. It is similar in approach to geohashing. The equivalent location hash in GeoModel is called a 'geocell.'</p>
... | 3 | 2009-08-03T05:36:06Z | 1,222,133 | <p>You're correct that there's no significant overhead per-index - 13n entries in one index is more or less equivalent to n entries in 13 indexes. There's a total index count limit of 100, though, so this eats up a fair chunk of your available indexes.</p>
<p>That said, using a ListProperty is definitely a far superio... | 5 | 2009-08-03T12:40:46Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
App Engine: 13 StringPropertys vs. 1 StringListProperty (w.r.t. indexing/storage and query performance) | 1,220,794 | <p>A bit of background first: <a href="http://code.google.com/p/geomodel" rel="nofollow">GeoModel</a> is a library I wrote that adds very basic geospatial indexing and querying functionality to App Engine apps. It is similar in approach to geohashing. The equivalent location hash in GeoModel is called a 'geocell.'</p>
... | 3 | 2009-08-03T05:36:06Z | 1,223,095 | <blockquote>
<blockquote>
<p>Lastly, if anyone has any other suggestions or tips that can help improve storage utilization, query performance and/or ease of use </p>
</blockquote>
</blockquote>
<p>The StringListproperty is the way to go for the reasons mentioned above, but in actual usage one might want to add... | 1 | 2009-08-03T15:47:37Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
App Engine: 13 StringPropertys vs. 1 StringListProperty (w.r.t. indexing/storage and query performance) | 1,220,794 | <p>A bit of background first: <a href="http://code.google.com/p/geomodel" rel="nofollow">GeoModel</a> is a library I wrote that adds very basic geospatial indexing and querying functionality to App Engine apps. It is similar in approach to geohashing. The equivalent location hash in GeoModel is called a 'geocell.'</p>
... | 3 | 2009-08-03T05:36:06Z | 7,483,965 | <p>Looks like you ended up with 13 indices because you encoded in hex (for human readability / map levels?).
If you had utilized full potential of a byte (ByteString), you'd have had 256 cells instead of 16 cells per character (byte). There by reducing to far fewer number of indices for the same precision. </p>
<bloc... | 0 | 2011-09-20T10:50:15Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Creating Date Intervals in Python | 1,220,872 | <p>I want to use a for loop to print every date between 2 dates. Actually going to merge this with a MySQL query to pass the date into the query itself and into the filename of the output.</p>
<p>So, how can I change this:</p>
<pre><code>sum = 0
for i in range(1,11):
print sum
sum += i
</code></pre>
<p>To this?</... | 2 | 2009-08-03T06:19:56Z | 1,220,895 | <p>This will work:</p>
<pre><code>import datetime
a = datetime.date(2009, 1, 1)
b = datetime.date(2009, 7, 1)
one_day = datetime.timedelta(1)
day = a
while day <= b:
# do important stuff
day += one_day
</code></pre>
| 7 | 2009-08-03T06:33:27Z | [
"python",
"mysql"
] |
Creating Date Intervals in Python | 1,220,872 | <p>I want to use a for loop to print every date between 2 dates. Actually going to merge this with a MySQL query to pass the date into the query itself and into the filename of the output.</p>
<p>So, how can I change this:</p>
<pre><code>sum = 0
for i in range(1,11):
print sum
sum += i
</code></pre>
<p>To this?</... | 2 | 2009-08-03T06:19:56Z | 1,220,903 | <p>Try this:</p>
<pre><code>import datetime
dt1 = datetime.date(2009, 1, 1)
dt2 = datetime.date(2009, 7, 1)
dt = dt1
while dt <= dt2:
print dt.strftime("%Y-%m-%d")
dt += datetime.timedelta(days=1)
</code></pre>
<p>You say you are restricted to an older version of Python. If you don't have the datetime mod... | 2 | 2009-08-03T06:35:42Z | [
"python",
"mysql"
] |
Creating Date Intervals in Python | 1,220,872 | <p>I want to use a for loop to print every date between 2 dates. Actually going to merge this with a MySQL query to pass the date into the query itself and into the filename of the output.</p>
<p>So, how can I change this:</p>
<pre><code>sum = 0
for i in range(1,11):
print sum
sum += i
</code></pre>
<p>To this?</... | 2 | 2009-08-03T06:19:56Z | 1,220,990 | <pre><code>In [1]: from dateutil.relativedelta import *
In [2]: from datetime import *
In [3]: aday = datetime.today()
In [4]: nextweek = aday+relativedelta(weeks=1)
In [5]: while aday<nextweek:
...: print datetime.strftime(aday,format='%Y-%b-%d')
...: aday+=relativedelta(days=1)
...:
..... | 2 | 2009-08-03T07:06:02Z | [
"python",
"mysql"
] |
Barchart with vertical labels in python/matplotlib | 1,221,108 | <p>I'm using matplotlib to generate a (vertical) barchart. The problem is my labels are rather long. Is there any way to display them vertically, either in the bar or above it or below it?</p>
| 29 | 2009-08-03T07:46:13Z | 1,221,218 | <p>Do you mean something like this:</p>
<pre><code>>>> from matplotlib import *
>>> plot(xrange(10))
>>> yticks(xrange(10), rotation='vertical')
</code></pre>
<p>?</p>
<p>In general, to show any text in matplotlib with a vertical orientation, you can add the keyword <code>rotation='vertica... | 40 | 2009-08-03T08:32:27Z | [
"python",
"charts",
"matplotlib",
"bar-chart"
] |
Barchart with vertical labels in python/matplotlib | 1,221,108 | <p>I'm using matplotlib to generate a (vertical) barchart. The problem is my labels are rather long. Is there any way to display them vertically, either in the bar or above it or below it?</p>
| 29 | 2009-08-03T07:46:13Z | 1,241,078 | <p>I would suggest looking at <a href="http://matplotlib.sourceforge.net/gallery.html" rel="nofollow">the matplotlib gallery</a>. At least two of the examples seem to be relevant:</p>
<ul>
<li><a href="http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/text%5Frotation.html" rel="nofollow">text_rotation.py</a>... | 3 | 2009-08-06T20:03:58Z | [
"python",
"charts",
"matplotlib",
"bar-chart"
] |
returning a value to a c# program through python script | 1,221,135 | <p>I have a C# program which executes a python scrip</p>
<p>How can I retrieve the python returning value in my C# program ?</p>
<p>thanks!</p>
| 1 | 2009-08-03T07:59:41Z | 1,221,152 | <p>As far as I know, you should use ScriptScope object which you create from the ScriptEngine object using CreateScope method</p>
<pre><code>ScriptEngine engine = ScriptRuntime.Create().GetEngine("py");
ScriptScope scope = engine.CreateScope();
</code></pre>
<p>Then you can share variables between the C# program and ... | 2 | 2009-08-03T08:04:15Z | [
"c#",
"python"
] |
returning a value to a c# program through python script | 1,221,135 | <p>I have a C# program which executes a python scrip</p>
<p>How can I retrieve the python returning value in my C# program ?</p>
<p>thanks!</p>
| 1 | 2009-08-03T07:59:41Z | 1,221,155 | <p>if your using System.Diagnostics.Process to launch your python script, then you can get the return code after process exit</p>
<p>using </p>
<pre><code>process.ExitCode
</code></pre>
| 1 | 2009-08-03T08:06:46Z | [
"c#",
"python"
] |
need to put a nested Dict into a text file | 1,221,202 | <p>I have a nested dict like this</p>
<pre><code>d={ time1 : column1 : {data1,data2,data3}
column2 : {data1,data2,data3}
column3 : {data1,data2,data3} #So on.
time2 : {column1: } #Same as Above
}
</code></pre>
<p>data1,data2,data3 represent the type of data and not the ... | 0 | 2009-08-03T08:25:44Z | 1,221,359 | <p>I would do it like this:</p>
<pre><code>#get the row with maximum number of columns
maxrowlen = 0
maxrowkey = ""
for timesid in d.keys():
if len(timesid.keys()) > maxrowlen:
maxrowlen = len(timesid.keys())
maxrowkey = timesid
maxrowcols = sorted(d[maxrowkey].keys())
# prepare the writing
c... | 1 | 2009-08-03T09:14:20Z | [
"python",
"file",
"dictionary"
] |
need to put a nested Dict into a text file | 1,221,202 | <p>I have a nested dict like this</p>
<pre><code>d={ time1 : column1 : {data1,data2,data3}
column2 : {data1,data2,data3}
column3 : {data1,data2,data3} #So on.
time2 : {column1: } #Same as Above
}
</code></pre>
<p>data1,data2,data3 represent the type of data and not the ... | 0 | 2009-08-03T08:25:44Z | 1,221,545 | <p>I would use JSON.</p>
<p>In Python 2.6 it's directly available, in earlier Python's you have to download and install it.</p>
<pre><code>try:
import json
exception ImportError:
import simplejson as json
out= open( "myFile.json", "w" )
json.dump( { 'timestamp': time.time(), 'data': d }, indent=2 )
out.close... | 2 | 2009-08-03T10:08:33Z | [
"python",
"file",
"dictionary"
] |
Executing a MySQL query on command line via os.system in Python | 1,221,232 | <p>I am trying to pass the 'day' from the while loop into a sql statement that then gets passed into a MySQL command line to be executed with -e</p>
<p>I can not use the DB module or other python libraries to access MySQL, it needs to be done via command line. It also looks like I might need to convert the day to a s... | 1 | 2009-08-03T08:36:15Z | 1,221,261 | <p>Try explicit formatting and quoting resulting string:</p>
<pre><code>sql = "....WHERE d.Date = '" + date.isoformat() + "' GROUP BY ..."
</code></pre>
<p>Quotes at os.system call are messy and redirection look weird (if it's not a typo)</p>
<pre><code>os.system("mysql db -h -sN -u -p -e '" + sql + "' > /home/ou... | 1 | 2009-08-03T08:45:11Z | [
"python",
"mysql",
"shell"
] |
Executing a MySQL query on command line via os.system in Python | 1,221,232 | <p>I am trying to pass the 'day' from the while loop into a sql statement that then gets passed into a MySQL command line to be executed with -e</p>
<p>I can not use the DB module or other python libraries to access MySQL, it needs to be done via command line. It also looks like I might need to convert the day to a s... | 1 | 2009-08-03T08:36:15Z | 1,221,273 | <p>Well, you can save the mysql template query in a config file and parse it with <a href="http://docs.python.org/library/configparser.html" rel="nofollow">ConfigParser</a>:</p>
<p>The config file will look like that:</p>
<pre><code>[mysql query configuration]
dbhost =
db =
username = guest
password =
[query temp... | 0 | 2009-08-03T08:47:20Z | [
"python",
"mysql",
"shell"
] |
Executing a MySQL query on command line via os.system in Python | 1,221,232 | <p>I am trying to pass the 'day' from the while loop into a sql statement that then gets passed into a MySQL command line to be executed with -e</p>
<p>I can not use the DB module or other python libraries to access MySQL, it needs to be done via command line. It also looks like I might need to convert the day to a s... | 1 | 2009-08-03T08:36:15Z | 1,557,007 | <p>Code below might help you out. It isn't particularly exciting and is deliberately simple. This is not the way many programmers would tackle this problem, but without more info it seems to fulfil your requirements.</p>
<p>I have also made an assumption that you are new to python; If I'm wrong, feel free to ignore th... | 3 | 2009-10-12T21:16:58Z | [
"python",
"mysql",
"shell"
] |
Find unique elements in tuples in a python list | 1,221,775 | <p>Is there a better way to do this in python, or rather: Is this a good way to do it?</p>
<pre><code>x = ('a', 'b', 'c')
y = ('d', 'e', 'f')
z = ('g', 'e', 'i')
l = [x, y, z]
s = set([e for (_, e, _) in l])
</code></pre>
<p>I looks somewhat ugly but does what i need without writing a complex "get_unique_elements_f... | 3 | 2009-08-03T11:15:37Z | 1,221,802 | <p>That's fine, that's what sets are for. One thing I would change is this:</p>
<pre><code>s = set(e[1] for e in l)
</code></pre>
<p>as it enhances readability. Note that I also turned the list comprehension into a generator expression; no need to create a temporary list.</p>
| 22 | 2009-08-03T11:24:26Z | [
"python",
"list",
"set",
"tuples"
] |
Why does Django post_save signal give me pre_save data? | 1,221,878 | <p>Im trying to connect a "Information" object to many "Customers" (see code below)</p>
<p>When one Information object is updated, I want to send email to each Customer that is connected to the Information.</p>
<p>However, when I log the sold_to field that the signal recieves I always get what the data is like BEFORE... | 9 | 2009-08-03T11:42:41Z | 1,222,282 | <p>There's an open ticket for the issue you are facing <a href="http://code.djangoproject.com/ticket/5390">here</a>. You could either keep an eye on that for when it makes it into a release, or you could try applying the patch that it provides and see if that helps.</p>
| 5 | 2009-08-03T13:12:06Z | [
"python",
"django",
"django-signals"
] |
Why does Django post_save signal give me pre_save data? | 1,221,878 | <p>Im trying to connect a "Information" object to many "Customers" (see code below)</p>
<p>When one Information object is updated, I want to send email to each Customer that is connected to the Information.</p>
<p>However, when I log the sold_to field that the signal recieves I always get what the data is like BEFORE... | 9 | 2009-08-03T11:42:41Z | 1,251,607 | <p>This is my solution, after applying the patch from code.djangoproject.com mentioned above.</p>
<p>Added this in models.py:</p>
<pre><code>from django.db.models.signals import m2m_changed
m2m_changed.connect(send_admin_email, sender=Information)
</code></pre>
<p>And the send_admin_email function:</p>
<pre><code>d... | 1 | 2009-08-09T15:43:04Z | [
"python",
"django",
"django-signals"
] |
Why does Django post_save signal give me pre_save data? | 1,221,878 | <p>Im trying to connect a "Information" object to many "Customers" (see code below)</p>
<p>When one Information object is updated, I want to send email to each Customer that is connected to the Information.</p>
<p>However, when I log the sold_to field that the signal recieves I always get what the data is like BEFORE... | 9 | 2009-08-03T11:42:41Z | 9,172,783 | <p>I run across the same issue since I have M2M fields in my model I also got the pre_save like data. </p>
<p>In the situation, the problem is that in M2M fields both related models should be saved in order to get the auto generated IDs. </p>
<p>In my solution, neither I used the post_save signal nor m2m_changed sign... | 1 | 2012-02-07T08:01:11Z | [
"python",
"django",
"django-signals"
] |
Convolution of two functions in Python | 1,222,147 | <p>I will have to implement a convolution of two functions in Python, but SciPy/Numpy appear to have functions only for the convolution of two arrays.</p>
<p>Before I try to implement this by using the the regular integration expression of convolution, I would like to ask if someone knows of an already available modul... | 2 | 2009-08-03T12:42:53Z | 1,224,347 | <p>You could try to implement the <a href="http://en.wikipedia.org/wiki/Convolution#Discrete%5Fconvolution" rel="nofollow">Discrete Convolution</a> if you need it point by point.</p>
| 1 | 2009-08-03T20:07:25Z | [
"python",
"convolution"
] |
Convolution of two functions in Python | 1,222,147 | <p>I will have to implement a convolution of two functions in Python, but SciPy/Numpy appear to have functions only for the convolution of two arrays.</p>
<p>Before I try to implement this by using the the regular integration expression of convolution, I would like to ask if someone knows of an already available modul... | 2 | 2009-08-03T12:42:53Z | 1,226,509 | <p>Yes, SciPy/Numpy is mostly concerned about arrays.</p>
<p>If you can tolerate an approximate solution, and your functions only operate over a range of value (not infinite) you can fill an array with the values and convolve the arrays.</p>
<p>If you want something more "correct" calculus-wise you would probably nee... | 1 | 2009-08-04T09:29:38Z | [
"python",
"convolution"
] |
signals or triggers in SQLAlchemy | 1,222,208 | <p>does SQLAlchemy have something similar to Django's signal concept? Basically, I'd like to trigger a few functions when I pre-save or post-save some entity objects. Thanks.</p>
<p>Edit: I JUST want equivalent of django-signals in SQLAlchemy.</p>
| 11 | 2009-08-03T12:54:48Z | 1,222,267 | <p>You didn't make clear, whether you are integrating SQLAlchemy and Django, or you JUST want equivalent of django-signals in SQLAlchemy.</p>
<p>If you want equivalent of Django signals like post_save, pre_save, pre_delete etc, i would refer you the page,</p>
<p><a href="http://www.sqlalchemy.org/docs/05/reference/or... | 5 | 2009-08-03T13:09:43Z | [
"python",
"django",
"sqlalchemy"
] |
signals or triggers in SQLAlchemy | 1,222,208 | <p>does SQLAlchemy have something similar to Django's signal concept? Basically, I'd like to trigger a few functions when I pre-save or post-save some entity objects. Thanks.</p>
<p>Edit: I JUST want equivalent of django-signals in SQLAlchemy.</p>
| 11 | 2009-08-03T12:54:48Z | 1,222,946 | <p>You may want to consider the <a href="http://www.sqlalchemy.org/docs/05/reference/orm/interfaces.html#sqlalchemy.orm.interfaces.SessionExtension" rel="nofollow">sqlalchemy.orm.SessionExtension</a> as well</p>
<p>Here's some code I threw together to set an owner id on an instance and set an update_date that get's th... | 2 | 2009-08-03T15:22:57Z | [
"python",
"django",
"sqlalchemy"
] |
signals or triggers in SQLAlchemy | 1,222,208 | <p>does SQLAlchemy have something similar to Django's signal concept? Basically, I'd like to trigger a few functions when I pre-save or post-save some entity objects. Thanks.</p>
<p>Edit: I JUST want equivalent of django-signals in SQLAlchemy.</p>
| 11 | 2009-08-03T12:54:48Z | 4,539,784 | <p>Here's my take at this problem, it uses <a href="http://pypi.python.org/pypi/Louie" rel="nofollow">Louie</a> to dispatch signals:</p>
<p><strong><code>dispatch.py</code></strong></p>
<pre><code>"""
Signals dispatching for SQLAlchemy mappers.
"""
import louie
from sqlalchemy.orm.interfaces import MapperExtension
i... | 2 | 2010-12-27T15:38:22Z | [
"python",
"django",
"sqlalchemy"
] |
signals or triggers in SQLAlchemy | 1,222,208 | <p>does SQLAlchemy have something similar to Django's signal concept? Basically, I'd like to trigger a few functions when I pre-save or post-save some entity objects. Thanks.</p>
<p>Edit: I JUST want equivalent of django-signals in SQLAlchemy.</p>
| 11 | 2009-08-03T12:54:48Z | 12,663,837 | <p>I think you are looking for `ORM Events'.
You can find documentation here: </p>
<p><a href="http://docs.sqlalchemy.org/en/latest/orm/events.html" rel="nofollow">http://docs.sqlalchemy.org/en/latest/orm/events.html</a></p>
| 6 | 2012-09-30T18:28:50Z | [
"python",
"django",
"sqlalchemy"
] |
signals or triggers in SQLAlchemy | 1,222,208 | <p>does SQLAlchemy have something similar to Django's signal concept? Basically, I'd like to trigger a few functions when I pre-save or post-save some entity objects. Thanks.</p>
<p>Edit: I JUST want equivalent of django-signals in SQLAlchemy.</p>
| 11 | 2009-08-03T12:54:48Z | 20,677,966 | <p>You can use inner <code>MapperExtension</code> class:</p>
<pre><code>class YourModel(db.Model):
class BaseExtension(MapperExtension):
def before_insert(self, mapper, connection, instance):
# do something here
def before_update(self, mapper, connection, instance):
# do ... | 0 | 2013-12-19T09:37:36Z | [
"python",
"django",
"sqlalchemy"
] |
Is there a good html parser like HtmlAgilityPack (.NET) for Python? | 1,222,222 | <p>I'm looking for a good html parser like HtmlAgilityPack (open-source .NET project: <a href="http://www.codeplex.com/htmlagilitypack" rel="nofollow">http://www.codeplex.com/htmlagilitypack</a>), but for using with Python.</p>
<p>Anyone knows?</p>
| 2 | 2009-08-03T12:58:05Z | 1,222,233 | <p>Use <a href="http://www.crummy.com/software/BeautifulSoup/">Beautiful Soup</a> like everyone does.</p>
| 8 | 2009-08-03T13:00:12Z | [
"python",
"html",
"parsing"
] |
Is there a good html parser like HtmlAgilityPack (.NET) for Python? | 1,222,222 | <p>I'm looking for a good html parser like HtmlAgilityPack (open-source .NET project: <a href="http://www.codeplex.com/htmlagilitypack" rel="nofollow">http://www.codeplex.com/htmlagilitypack</a>), but for using with Python.</p>
<p>Anyone knows?</p>
| 2 | 2009-08-03T12:58:05Z | 1,222,240 | <p><a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> should be something you search for. It is a html/xml parser that can deal with invalid pages and allows e.g. to iterate over specific tags.</p>
| 0 | 2009-08-03T13:02:05Z | [
"python",
"html",
"parsing"
] |
Is there a good html parser like HtmlAgilityPack (.NET) for Python? | 1,222,222 | <p>I'm looking for a good html parser like HtmlAgilityPack (open-source .NET project: <a href="http://www.codeplex.com/htmlagilitypack" rel="nofollow">http://www.codeplex.com/htmlagilitypack</a>), but for using with Python.</p>
<p>Anyone knows?</p>
| 2 | 2009-08-03T12:58:05Z | 1,222,991 | <p>Others have recommended BeautifulSoup, but it's much better to use <a href="http://codespeak.net/lxml/">lxml</a>. Despite its name, it is also for parsing and scraping HTML. It's much, much faster than BeautifulSoup, and it even handles "broken" HTML better than BeautifulSoup (their claim to fame). It has a compatib... | 8 | 2009-08-03T15:31:44Z | [
"python",
"html",
"parsing"
] |
Is there a way to modify a class in a class method in Python? | 1,222,311 | <p>I wanted to do something like setattr to a class in class method in Python, but the class doesn't exist so I basically get:</p>
<pre><code>NameError: global name 'ClassName' is not defined
</code></pre>
<p>Is there a way for a class method to modify the class? Something like this but that actually works:</p>
<pre... | 0 | 2009-08-03T13:18:05Z | 1,222,327 | <p>Class methods get the class passed as the first argument:</p>
<pre><code>class Bla(object):
@classmethod
def cm(cls,value):
cls.storedValue = value
Bla.cm("Hello")
print Bla.storedValue # prints "Hello"
</code></pre>
<p><hr></p>
<p><strong>Edit</strong>: I think I understand your problem now. If... | 5 | 2009-08-03T13:22:30Z | [
"python"
] |
Is there a way to modify a class in a class method in Python? | 1,222,311 | <p>I wanted to do something like setattr to a class in class method in Python, but the class doesn't exist so I basically get:</p>
<pre><code>NameError: global name 'ClassName' is not defined
</code></pre>
<p>Is there a way for a class method to modify the class? Something like this but that actually works:</p>
<pre... | 0 | 2009-08-03T13:18:05Z | 1,222,634 | <p>Another way you could do this would be to use a <a href="http://www.python.org/dev/peps/pep-3129/" rel="nofollow">class decorator</a>, though these are only available from Python 2.6 onwards IIRC.</p>
<p>Something like this:</p>
<pre><code>def addattributes(cls):
cls.foobar = 10
return cls
@addattributes
... | 0 | 2009-08-03T14:22:54Z | [
"python"
] |
Is there a way to modify a class in a class method in Python? | 1,222,311 | <p>I wanted to do something like setattr to a class in class method in Python, but the class doesn't exist so I basically get:</p>
<pre><code>NameError: global name 'ClassName' is not defined
</code></pre>
<p>Is there a way for a class method to modify the class? Something like this but that actually works:</p>
<pre... | 0 | 2009-08-03T13:18:05Z | 1,223,035 | <p>While many good suggestions have been advanced, the closest one can get to the originally requested code, that is:</p>
<pre><code>class ClassName(object):
def HocusPocus(name):
setattr(ClassName, name, property(fget=..., fset=...))
HocusPocus("blah")
HocusPocus("bleh")
</code></pre>
<p>is this... | 0 | 2009-08-03T15:39:14Z | [
"python"
] |
Screen Scrape Form Results | 1,222,373 | <p>I was recently requested by a client to build a website for their insurance business. As part of this, they want to do some screen scraping of the quote site for one of their providers. They asked if their was an API to do this, and were told there wasn't one, but that if they could get the data from their engine ... | 3 | 2009-08-03T13:30:22Z | 1,222,427 | <p>You can pass a <code>data</code> parameter to <a href="http://docs.python.org/library/urllib.html#urllib.urlopen" rel="nofollow"><code>urllib.urlopen</code></a> to send POST data with the request just like you had filled out the form. You'll obviously have to take a look at what data exactly the form contains.</p>
... | 2 | 2009-08-03T13:41:36Z | [
"python",
"forms",
"screen-scraping"
] |
Screen Scrape Form Results | 1,222,373 | <p>I was recently requested by a client to build a website for their insurance business. As part of this, they want to do some screen scraping of the quote site for one of their providers. They asked if their was an API to do this, and were told there wasn't one, but that if they could get the data from their engine ... | 3 | 2009-08-03T13:30:22Z | 1,222,613 | <p>A really nice library for screen-scraping is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, which I believe is a clone of an original library written in Perl. Anyway, that in combination with the <a href="http://wwwsearch.sourceforge.net/ClientForm/">ClientForm</a> module, and some additional ... | 5 | 2009-08-03T14:17:43Z | [
"python",
"forms",
"screen-scraping"
] |
Screen Scrape Form Results | 1,222,373 | <p>I was recently requested by a client to build a website for their insurance business. As part of this, they want to do some screen scraping of the quote site for one of their providers. They asked if their was an API to do this, and were told there wasn't one, but that if they could get the data from their engine ... | 3 | 2009-08-03T13:30:22Z | 1,222,906 | <p>I see the other two answers already mention all the major libraries of choice for the purpose... as long as the site being scraped does not make extensive use of Javascript, that is. If it IS a Javascript-heavy site and dependent on JS for the data it fetches and display (e.g. via AJAX) your problem is an order of m... | 0 | 2009-08-03T15:13:32Z | [
"python",
"forms",
"screen-scraping"
] |
Screen Scrape Form Results | 1,222,373 | <p>I was recently requested by a client to build a website for their insurance business. As part of this, they want to do some screen scraping of the quote site for one of their providers. They asked if their was an API to do this, and were told there wasn't one, but that if they could get the data from their engine ... | 3 | 2009-08-03T13:30:22Z | 1,222,959 | <p>Others have recommended BeautifulSoup, but it's much better to use <a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a>. Despite its name, it is also for parsing and scraping HTML. It's much, much faster than BeautifulSoup, and it even handles "broken" HTML better than BeautifulSoup (their claim to fame). It... | 0 | 2009-08-03T15:25:27Z | [
"python",
"forms",
"screen-scraping"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,222,524 | <p>In Python:</p>
<pre><code>'[%s]' % ', '.join(pythonlistwithemails)
</code></pre>
<p>In bare HTML it is impossible... you'd have to use javascript.</p>
| 4 | 2009-08-03T14:00:33Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,222,595 | <p>It all depends how the HTML generation is treating your <em>values</em> array. Here is what you usually do to serialize a unicode string:</p>
<pre><code>In [550]: ss=u'one@example.com'
In [551]: print ss # uses str() implicitly
Out[552]: one@example.com
In [552]: str(ss)
Out[552]: 'one@example.com'
In [553]: r... | 1 | 2009-08-03T14:14:53Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,222,604 | <p>I don't know any Python, but if those <code>u</code>-markers and the single quotes show, doesn't that actually indicate that you're accessing the list members in the wrong way? </p>
<p>You're printing the whole list rather than each item, and the output looks like debug information to me. Such debug information cou... | 2 | 2009-08-03T14:15:52Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,223,618 | <p>Option 1:</p>
<pre><code>myStr = str('[ ' + ', '.join(ss) + ' ]')
</code></pre>
<p>Option 2:</p>
<pre><code>myStr = '[ ' + ', '.join(ss) + ' ]'
myStr = myStr.encode(<whatever encoding you want>, <whatever way of handling errors you wish to use>)
</code></pre>
<p>I'm not used to Python pre-version 3, ... | 0 | 2009-08-03T17:37:54Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,223,862 | <pre><code>"[{0}]".format(", ".join(python_email_list))
</code></pre>
<p>From Python 2.6 format() method is the preferred way of string formatting.
Docs <a href="http://docs.python.org/library/stdtypes.html" rel="nofollow">here</a>.</p>
| 2 | 2009-08-03T18:24:24Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,226,523 | <p>The easiest way for you to do it would be to iterate over your email list. e.g. </p>
<pre><code>{% for email in Emails %}
email,
{% endfor %}
</code></pre>
<p>This way you (or a designer) will have a lot more control of the layout.</p>
<p>Have a look at the <a href="http://docs.djangoproject.com/en/dev/topics/tem... | -1 | 2009-08-04T09:33:02Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,228,904 | <p>In the template</p>
<pre><code>[ {{ email_list|join:", " }} ]
</code></pre>
<p>note: the [, and ] are literal square brackets, not code :)</p>
| 1 | 2009-08-04T17:37:12Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
Dropping the Unicode markers in Html output | 1,222,508 | <p>I have a python list which holds a few email ids accepted as unicode strings:</p>
<pre><code>[u'one@example.com',u'two@example.com',u'three@example.com']
</code></pre>
<p>This is assigned to <code>values['Emails']</code> and <code>values</code> is passed to render as html.
The Html renders as this:</p>
<blockquot... | 1 | 2009-08-03T13:58:29Z | 1,248,797 | <p>This is actually a long and formatted comment on <a href="http://stackoverflow.com/questions/1222508/dropping-the-unicode-markers-in-html-output/1237495#1237495">the last answer</a>. Still not knowing any Python, I am a bit disappointed by not using <code>join</code> to get commas between each address (like <a href=... | 0 | 2009-08-08T12:45:39Z | [
"python",
"html",
"django",
"unicode",
"html-lists"
] |
List Comprehensions in Python : efficient selection in a list | 1,222,677 | <p>Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a <em>distance</em> to an other element).</p>
<p>I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code</p>
<pre><code>result = [... | 7 | 2009-08-03T14:30:18Z | 1,222,717 | <p>Sure, the difference between the following two:</p>
<pre><code>[f(x) for x in list]
</code></pre>
<p>and this:</p>
<pre><code>(f(x) for x in list)
</code></pre>
<p>is that the first will generate the list in memory, whereas the second is a new generator, with lazy evaluation.</p>
<p>So, simply write the "unfilt... | 8 | 2009-08-03T14:38:39Z | [
"python",
"list-comprehension"
] |
List Comprehensions in Python : efficient selection in a list | 1,222,677 | <p>Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a <em>distance</em> to an other element).</p>
<p>I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code</p>
<pre><code>result = [... | 7 | 2009-08-03T14:30:18Z | 1,222,720 | <p>Don't use a list comprehension; a normal for loop is fine here.</p>
| 3 | 2009-08-03T14:39:03Z | [
"python",
"list-comprehension"
] |
List Comprehensions in Python : efficient selection in a list | 1,222,677 | <p>Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a <em>distance</em> to an other element).</p>
<p>I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code</p>
<pre><code>result = [... | 7 | 2009-08-03T14:30:18Z | 1,222,729 | <p>Just compute the distances beforehand and then filter the results:</p>
<pre><code>with_distances = ((myFunction(C), C) for C in originalList)
result = [C for C in with_distances if C[0] < limit]
</code></pre>
<p>Note: instead of building a new list, I use a generator expression to build the distance/element pai... | 3 | 2009-08-03T14:42:03Z | [
"python",
"list-comprehension"
] |
List Comprehensions in Python : efficient selection in a list | 1,222,677 | <p>Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a <em>distance</em> to an other element).</p>
<p>I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code</p>
<pre><code>result = [... | 7 | 2009-08-03T14:30:18Z | 1,222,730 | <p>Rather than using a global variable as in your option 2, you could rely on the fact that in Python parameters are passed by object - that is, the object that is passed into your <code>myFunction</code> function is the <em>same</em> object as the one in the list (this isn't exactly the same thing as call by reference... | 0 | 2009-08-03T14:42:05Z | [
"python",
"list-comprehension"
] |
List Comprehensions in Python : efficient selection in a list | 1,222,677 | <p>Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a <em>distance</em> to an other element).</p>
<p>I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code</p>
<pre><code>result = [... | 7 | 2009-08-03T14:30:18Z | 1,222,732 | <p>What's wrong with option 1?</p>
<p>"duplicate my originalList and waste some memory (the list could be quite big - more than 10,000 elements)"</p>
<p>10,000 elements is only 10,000 pointers to tuples that point to existing objects. Think 160K or so of memory. Hardly worth talking about.</p>
| 0 | 2009-08-03T14:42:59Z | [
"python",
"list-comprehension"
] |
List Comprehensions in Python : efficient selection in a list | 1,222,677 | <p>Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a <em>distance</em> to an other element).</p>
<p>I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code</p>
<pre><code>result = [... | 7 | 2009-08-03T14:30:18Z | 1,222,784 | <p>Some options:</p>
<ul>
<li>Use <a href="http://en.wikipedia.org/wiki/Memoization" rel="nofollow">memoization</a></li>
<li>Use a normal for loop</li>
<li>Create an unfiltered list, then filter it (your option 1). The 'wasted' memory will be reclaimed by the GC very quickly - it's not something you need to worry abou... | 0 | 2009-08-03T14:52:33Z | [
"python",
"list-comprehension"
] |
List Comprehensions in Python : efficient selection in a list | 1,222,677 | <p>Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a <em>distance</em> to an other element).</p>
<p>I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code</p>
<pre><code>result = [... | 7 | 2009-08-03T14:30:18Z | 1,226,540 | <p>Lasse V. Karlsen has an excellent reply to your question.</p>
<p>If your distance computation is slow, I guess your elements are polylines, or something like that, right ?</p>
<p>There are lots of ways to make it faster :</p>
<ul>
<li><p>If the distance between bounding boxes of objects is > X, then it follows th... | 1 | 2009-08-04T09:37:38Z | [
"python",
"list-comprehension"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,222,804 | <p>I think that you will be better served going straight into 3.0. Unless you have a legacy codebase to contend with, there are very few advantages to learning the 2.xx ways of doing things.</p>
<p>In the Python world (as in most others, really), releases do tend to take a while to migrate down to all of the subproje... | 3 | 2009-08-03T14:55:43Z | [
"python",
"python-3.x"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,222,832 | <p>Use python 3.1, Luke.</p>
| 1 | 2009-08-03T14:58:45Z | [
"python",
"python-3.x"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,222,843 | <p>Absolutely not 3.0 - 3.1 is out and is stabler, better, faster in every respect; it makes absolutely no sense to start with 3.0 at this time, if you want to take up the 3 series it should on all accounts be 3.1.</p>
<p>As for 2.6 vs 3.1, 3.1 is a better language (especially because some cruft was removed that had a... | 18 | 2009-08-03T15:00:58Z | [
"python",
"python-3.x"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,222,856 | <p>You should go with the latest release of any programming language you learn unless you have a specific reason <strong>not</strong> to. Since you don't have an existing project that won't work with Python 3.0, you should feel free to use the newest version.</p>
| 2 | 2009-08-03T15:03:20Z | [
"python",
"python-3.x"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,222,924 | <p>Python 3.1 should not be used until other libraries have caught up with support for it.</p>
<p>You should use 2.6 now. It has several 3.x features back-ported to it, so that migrating to 3.x won't be difficult later on, and you won't learn obsolete practices.</p>
| 3 | 2009-08-03T15:18:03Z | [
"python",
"python-3.x"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,223,029 | <p>The good news is that it's not really that tough to learn both Python 2.x and 3.x. You can install the latest 2.x version as the version registered with the system to run Python scripts by default, but also install the latest 3.x version to explicitly kick off when you want to. That's what I have on my Windows Vis... | 2 | 2009-08-03T15:38:08Z | [
"python",
"python-3.x"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,225,173 | <p>Short answer: Start with Python 2.6.</p>
<p>Why: Programming is more fun and useful when you can leverage the work of others. This means using 3rd party libraries often. Many of the popular libraries for Python don't have 3.x support yet. PIL and NumPy/SciPy come to mind. My favorite interpreter, ipython, also does... | 8 | 2009-08-03T23:53:05Z | [
"python",
"python-3.x"
] |
Should I Start With Python 3.0? | 1,222,782 | <p>Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? ... | 11 | 2009-08-03T14:52:17Z | 1,540,468 | <p>Use 3.1</p>
<p>Why?</p>
<p>1) Because as long as everyone is still using 2.6, the libraries will have less reasons to migrate to 3.1. As long as those libraries are not ported to 3.1, you are stuck with the choice of either not using the strengths of 3.1, or only doing the jobs half way by using the hackish solut... | 7 | 2009-10-08T21:02:30Z | [
"python",
"python-3.x"
] |
GIL in Python 3.1 | 1,222,929 | <p>Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration</p>
| 14 | 2009-08-03T15:18:55Z | 1,222,957 | <p>GIL is still there in CPython 3.1; the <a href="http://code.google.com/p/unladen-swallow/">Unladen Swallow</a> projects aims (among many other performance boosts) to eventually remove it, but it's still a way from its goals, and is working on 2.6 first with the intent of eventually porting to 3.x for whatever x will... | 22 | 2009-08-03T15:25:03Z | [
"python",
"multithreading",
"gil"
] |
GIL in Python 3.1 | 1,222,929 | <p>Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration</p>
| 14 | 2009-08-03T15:18:55Z | 1,224,503 | <p>The GIL is a good thing.</p>
<p>Just make your C++ application release the GIL while it is doing its multithreaded work. Python code will continue to run in the other threads, unspoiled. Only acquire the GIL when you have to touch python objects.</p>
| 4 | 2009-08-03T20:39:39Z | [
"python",
"multithreading",
"gil"
] |
GIL in Python 3.1 | 1,222,929 | <p>Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration</p>
| 14 | 2009-08-03T15:18:55Z | 1,225,350 | <p>The GIL will not affect your code which does not use python objects. In Numpy, we release the GIL for computational code (linear algebra calls, etc...), and the underlying code can use multithreading freely (in fact, those are generally 3rd party libraries which do not know anything about python)</p>
| 9 | 2009-08-04T01:17:51Z | [
"python",
"multithreading",
"gil"
] |
GIL in Python 3.1 | 1,222,929 | <p>Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration</p>
| 14 | 2009-08-03T15:18:55Z | 1,457,021 | <p>I guess there will always be a GIL.
The reason is performance. Making all the low level access thread safe - means putting a mutex around each hash operation etc. is heavy. Remember that a simple statement like</p>
<pre><code>self.foo(self.bar, 3, val)
</code></pre>
<p>Might already have at least 3 (if val is a gl... | 0 | 2009-09-21T21:36:43Z | [
"python",
"multithreading",
"gil"
] |
GIL in Python 3.1 | 1,222,929 | <p>Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration</p>
| 14 | 2009-08-03T15:18:55Z | 2,137,581 | <p>Significant changes will occur in the GIL for Python 3.2. Take a look at the <a href="http://docs.python.org/dev/py3k/whatsnew/3.2.html#multi-threading">What's New for Python 3.2</a>, and <a href="http://mail.python.org/pipermail/python-dev/2009-October/093359.html">the thread that initiated it in the mailing list</... | 12 | 2010-01-26T04:51:43Z | [
"python",
"multithreading",
"gil"
] |
GIL in Python 3.1 | 1,222,929 | <p>Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration</p>
| 14 | 2009-08-03T15:18:55Z | 4,965,477 | <p>As I understand it the "brainfuck" scheduler will replace the GIL from python 3.2</p>
<p><a href="http://bugs.python.org/issue7946" rel="nofollow">BFS bainfuck scheduler</a></p>
| 1 | 2011-02-11T03:54:50Z | [
"python",
"multithreading",
"gil"
] |
GIL in Python 3.1 | 1,222,929 | <p>Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration</p>
| 14 | 2009-08-03T15:18:55Z | 4,965,523 | <p>If the GIL is getting in the way, just use the <a href="http://docs.python.org/dev/library/multiprocessing.html" rel="nofollow">multiprocessing</a> module. It spawns new processes but uses the threading model and (most of the) api. In other words, you can do process-based parallelism in a thread-like way.</p>
| 1 | 2011-02-11T04:05:27Z | [
"python",
"multithreading",
"gil"
] |
Are there any cleverly efficient algorithms to perform a calculation over the space of partitionings of a string? | 1,223,007 | <p>I'm working on a statistical project that involves iterating over every possible way to partition a collection of strings and running a simple calculation on each. Specifically, each possible substring has a probability associated with it, and I'm trying to get the sum across all partitions of the product of the sub... | 3 | 2009-08-03T15:33:54Z | 1,223,046 | <p>First, profile to find the bottleneck.</p>
<p>If the bottleneck is simply the massive number of possible partitions, I recommend parallelization, possibly via <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow"><code>multiprocessing</code></a>. If that's still not enough, you might look int... | 3 | 2009-08-03T15:40:49Z | [
"python",
"string",
"partitioning"
] |
Are there any cleverly efficient algorithms to perform a calculation over the space of partitionings of a string? | 1,223,007 | <p>I'm working on a statistical project that involves iterating over every possible way to partition a collection of strings and running a simple calculation on each. Specifically, each possible substring has a probability associated with it, and I'm trying to get the sum across all partitions of the product of the sub... | 3 | 2009-08-03T15:33:54Z | 1,223,140 | <p>A <a href="http://en.wikipedia.org/wiki/Dynamic%5Fprogramming" rel="nofollow">Dynamic Programming</a> solution (if I understood the question right):</p>
<pre><code>def dynProgSolution(text, probs):
probUpTo = [1]
for i in range(1, len(text)+1):
cur = sum(v*probs[text[k:i]] for k, v in enumerate(probUpTo))
... | 5 | 2009-08-03T15:57:35Z | [
"python",
"string",
"partitioning"
] |
Are there any cleverly efficient algorithms to perform a calculation over the space of partitionings of a string? | 1,223,007 | <p>I'm working on a statistical project that involves iterating over every possible way to partition a collection of strings and running a simple calculation on each. Specifically, each possible substring has a probability associated with it, and I'm trying to get the sum across all partitions of the product of the sub... | 3 | 2009-08-03T15:33:54Z | 1,223,144 | <p>Your substrings are going to be reused over and over again by the longer strings, so caching the values using a <a href="http://en.wikipedia.org/wiki/Memoization" rel="nofollow">memoizing</a> technique seems like an obvious thing to try. This is just a time-space trade off. The simplest implementation is to use a di... | 1 | 2009-08-03T15:58:10Z | [
"python",
"string",
"partitioning"
] |
Are there any cleverly efficient algorithms to perform a calculation over the space of partitionings of a string? | 1,223,007 | <p>I'm working on a statistical project that involves iterating over every possible way to partition a collection of strings and running a simple calculation on each. Specifically, each possible substring has a probability associated with it, and I'm trying to get the sum across all partitions of the product of the sub... | 3 | 2009-08-03T15:33:54Z | 1,223,148 | <p>You may get a minor reduction of the amount of computation by a small refactoring based on associative properties of arithmetic (and string concatenation) though I'm not sure it will be a life-changer. The core idea would be as follows:</p>
<p>consider a longish string e.g. 'abcdefghik', 10-long, for definiteness ... | 1 | 2009-08-03T15:58:36Z | [
"python",
"string",
"partitioning"
] |
Are there any cleverly efficient algorithms to perform a calculation over the space of partitionings of a string? | 1,223,007 | <p>I'm working on a statistical project that involves iterating over every possible way to partition a collection of strings and running a simple calculation on each. Specifically, each possible substring has a probability associated with it, and I'm trying to get the sum across all partitions of the product of the sub... | 3 | 2009-08-03T15:33:54Z | 1,223,236 | <p>You should look into the <code>itertools</code> module. It can create a generator for you that is very fast. Given your input string, it will provide you with all possible permutations. Depending on what you need, there is also a <code>combinations()</code> generator. I'm not quite sure if you're looking at "b|ca" w... | 0 | 2009-08-03T16:16:28Z | [
"python",
"string",
"partitioning"
] |
How to write native newline character to a file descriptor in Python? | 1,223,289 | <p>The <code>os.write</code> function can be used to writes bytes into a <em>file descriptor</em> (not file object). If I execute <em><code>os.write(fd, '\n')</code></em>, only the LF character will be written into the file, even on Windows. I would like to have CRLF in the file on Windows and only LF in Linux.<br>
Wha... | 18 | 2009-08-03T16:30:43Z | 1,223,303 | <p>Use this</p>
<pre><code>import os
os.write(fd, os.linesep)
</code></pre>
| 37 | 2009-08-03T16:33:16Z | [
"python"
] |
How to write native newline character to a file descriptor in Python? | 1,223,289 | <p>The <code>os.write</code> function can be used to writes bytes into a <em>file descriptor</em> (not file object). If I execute <em><code>os.write(fd, '\n')</code></em>, only the LF character will be written into the file, even on Windows. I would like to have CRLF in the file on Windows and only LF in Linux.<br>
Wha... | 18 | 2009-08-03T16:30:43Z | 1,223,313 | <p>How about <code>os.write(<file descriptor>, os.linesep)</code>? (<code>import os</code> is unnecessary because you seem to have already imported it, otherwise you'd be getting errors using <code>os.write</code> to begin with.)</p>
| 8 | 2009-08-03T16:36:00Z | [
"python"
] |
Error starting Django with Pinax | 1,223,513 | <p>Upon trying to start a Pinax app, I receive the following error:</p>
<pre><code>Error: No module named notification
</code></pre>
<p>Below are the steps I took</p>
<pre><code>svn co http://svn.pinaxproject.com/pinax/trunk/ pinax
cd pinax/pinax/projects/basic_project
./manage.py syncdb
</code></pre>
<p>Any sugge... | 1 | 2009-08-03T17:18:38Z | 1,223,664 | <p>Two thoughts:
1. Check all of your imports to make sure that notification is getting into the namespace.
2. You may be missing quotes around an import path (eg. in your urls.py: (r'^test', 'mysite.notification') -- sometimes I forget the quotes around the view)</p>
| 0 | 2009-08-03T17:48:05Z | [
"python",
"django",
"pinax"
] |
Error starting Django with Pinax | 1,223,513 | <p>Upon trying to start a Pinax app, I receive the following error:</p>
<pre><code>Error: No module named notification
</code></pre>
<p>Below are the steps I took</p>
<pre><code>svn co http://svn.pinaxproject.com/pinax/trunk/ pinax
cd pinax/pinax/projects/basic_project
./manage.py syncdb
</code></pre>
<p>Any sugge... | 1 | 2009-08-03T17:18:38Z | 1,225,094 | <p>Try following the latest install instructions here:</p>
<p><a href="http://github.com/pinax/pinax/blob/600d6c5ca0b45814bdc73b1264d28bb66c661ac8/INSTALL" rel="nofollow">http://github.com/pinax/pinax/blob/600d6c5ca0b45814bdc73b1264d28bb66c661ac8/INSTALL</a></p>
<p>Don't think this will work on Windows (maybe if you ... | 0 | 2009-08-03T23:22:29Z | [
"python",
"django",
"pinax"
] |
Error starting Django with Pinax | 1,223,513 | <p>Upon trying to start a Pinax app, I receive the following error:</p>
<pre><code>Error: No module named notification
</code></pre>
<p>Below are the steps I took</p>
<pre><code>svn co http://svn.pinaxproject.com/pinax/trunk/ pinax
cd pinax/pinax/projects/basic_project
./manage.py syncdb
</code></pre>
<p>Any sugge... | 1 | 2009-08-03T17:18:38Z | 1,225,786 | <p>I'd avoid the svn version all together. It's unmaintained and out of date. Instead, use the git version at <a href="http://github.com/pinax/pinax" rel="nofollow">http://github.com/pinax/pinax</a> or (even better) the recently release 0.7b3 downloadable from <a href="http://pinaxproject.com" rel="nofollow">http://pin... | 5 | 2009-08-04T05:22:18Z | [
"python",
"django",
"pinax"
] |
Python TypeError unsupported operand type(s) for %: 'file' and 'unicode' | 1,223,563 | <p>I'm working on a django field validation and I can't figure out why I'm getting a type error for this section:</p>
<pre><code>def clean_tid(self):
data = self.cleaned_data['tid']
stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN") % data
resul... | 0 | 2009-08-03T17:29:17Z | 1,223,568 | <p>Check your parenthesis.</p>
<p>Wrong</p>
<pre><code>stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN") % data
</code></pre>
<p>Might be right.</p>
<pre><code>stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -... | 1 | 2009-08-03T17:30:52Z | [
"python",
"django",
"unicode",
"typeerror"
] |
Python TypeError unsupported operand type(s) for %: 'file' and 'unicode' | 1,223,563 | <p>I'm working on a django field validation and I can't figure out why I'm getting a type error for this section:</p>
<pre><code>def clean_tid(self):
data = self.cleaned_data['tid']
stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN") % data
resul... | 0 | 2009-08-03T17:29:17Z | 1,223,939 | <p>Just a small tip - it's better to use <code>subprocess</code> module and <code>Popen</code> class instead of <code>os.popen</code> function. More details <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">here (docs)</a>.</p>
| 1 | 2009-08-03T18:40:41Z | [
"python",
"django",
"unicode",
"typeerror"
] |
Lightweight markup language for Python | 1,223,741 | <p>Programming a Python web application, I want to create a text area where the users can enter text in a lightweight markup language. The text will be imported to a html template and viewed on the page. Today I use this command to create the textarea, which allows users to enter any (html) text:</p>
<pre><code>my_tex... | 4 | 2009-08-03T18:02:54Z | 1,223,778 | <p>You could use <a href="http://docutils.sourceforge.net/rst.html" rel="nofollow">restructured text</a> . I'm not sure if it has a sanitizing option, but it's well supported by Python, and it generates all sorts of formats.</p>
| 2 | 2009-08-03T18:08:18Z | [
"python",
"html",
"markup"
] |
Lightweight markup language for Python | 1,223,741 | <p>Programming a Python web application, I want to create a text area where the users can enter text in a lightweight markup language. The text will be imported to a html template and viewed on the page. Today I use this command to create the textarea, which allows users to enter any (html) text:</p>
<pre><code>my_tex... | 4 | 2009-08-03T18:02:54Z | 1,223,981 | <p>Use the python <a href="http://www.freewisdom.org/projects/python-markdown/Using%5Fas%5Fa%5FModule" rel="nofollow">markdown</a> implementation</p>
<pre><code>import markdown
mode = "remove" # or "replace" or "escape"
md = markdown.Markdown(safe_mode=mode)
html = md.convert(text)
</code></pre>
<p>It is very flexibl... | 8 | 2009-08-03T18:49:43Z | [
"python",
"html",
"markup"
] |
Lightweight markup language for Python | 1,223,741 | <p>Programming a Python web application, I want to create a text area where the users can enter text in a lightweight markup language. The text will be imported to a html template and viewed on the page. Today I use this command to create the textarea, which allows users to enter any (html) text:</p>
<pre><code>my_tex... | 4 | 2009-08-03T18:02:54Z | 1,224,521 | <p>This simple sanitizing function uses a whitelist and is roughly the same as the solution of <a href="http://stackoverflow.com/questions/699468/python-html-sanitizer-scrubber-filter">python-html-sanitizer-scrubber-filter</a>, but also allows to limit the use of attributes (since you probably don't want someone to use... | 1 | 2009-08-03T20:42:23Z | [
"python",
"html",
"markup"
] |
How do I associate input to a Form with a Model in Django? | 1,223,763 | <p>In Django, how do I associate a Form with a Model so that data entered into the form are inserted into the database table associated with the Model? How do I save that user input to that database table?</p>
<p>For example:</p>
<pre><code>class PhoneNumber(models.Model):
FirstName = models.CharField(max_length... | 2 | 2009-08-03T18:06:07Z | 1,223,907 | <p>I'm not sure which class do you mean. I know that there were a helper, something like <code>form_for_model</code> (don't really remember the exact name; that was way before 1.0 version was released). Right now I'd it that way:</p>
<pre><code>import myproject.myapp.models as models
class PhoneNumberForm(forms.Model... | 2 | 2009-08-03T18:32:10Z | [
"python",
"django"
] |
How do I associate input to a Form with a Model in Django? | 1,223,763 | <p>In Django, how do I associate a Form with a Model so that data entered into the form are inserted into the database table associated with the Model? How do I save that user input to that database table?</p>
<p>For example:</p>
<pre><code>class PhoneNumber(models.Model):
FirstName = models.CharField(max_length... | 2 | 2009-08-03T18:06:07Z | 1,223,909 | <p>I think <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method" rel="nofollow">ModelForm.save</a> documentation should explain it. With its base class (Form) you would need to use the Form.cleaned_data() to get the field values and set them to appropriate Model fields "by hand". Mod... | 1 | 2009-08-03T18:32:44Z | [
"python",
"django"
] |
How do I associate input to a Form with a Model in Django? | 1,223,763 | <p>In Django, how do I associate a Form with a Model so that data entered into the form are inserted into the database table associated with the Model? How do I save that user input to that database table?</p>
<p>For example:</p>
<pre><code>class PhoneNumber(models.Model):
FirstName = models.CharField(max_length... | 2 | 2009-08-03T18:06:07Z | 1,224,656 | <p>The Django documentation is pretty clear on this subject. However, here is a rough guide for you to get started: You can either override the form's save method or implement that functionality in the view.</p>
<pre><code>if form.is_valid() # validation - first the fields, then the form itself is validated
form.s... | 0 | 2009-08-03T21:09:12Z | [
"python",
"django"
] |
How do I associate input to a Form with a Model in Django? | 1,223,763 | <p>In Django, how do I associate a Form with a Model so that data entered into the form are inserted into the database table associated with the Model? How do I save that user input to that database table?</p>
<p>For example:</p>
<pre><code>class PhoneNumber(models.Model):
FirstName = models.CharField(max_length... | 2 | 2009-08-03T18:06:07Z | 1,224,807 | <p>Back when I first used Forms and Models (without using ModelForm), what I remember doing was checking if the form was valid, which would set your cleaned data, manually moving the data from the form to the model (or whatever other processing you want to do), and then saving the model. As you can tell, this was extr... | 3 | 2009-08-03T21:51:22Z | [
"python",
"django"
] |
How to stop WSGI from hanging apache | 1,223,927 | <p>I have django running through WSGI like this :</p>
<pre><code><VirtualHost *:80>
WSGIScriptAlias / /home/ptarjan/django/django.wsgi
WSGIDaemonProcess ptarjan processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup ptarjan
Alias /media /home/ptarjan/django/mysite/media/
</VirtualHost&g... | 8 | 2009-08-03T18:38:40Z | 1,224,066 | <p>If I understand well the question, you want to protect apache from locking up when running some random scripts from people. Well, if you're running untrusted code, I think you have other things to worry about that are worst than apache.</p>
<p>That said, you can use some configuration directives to adjust a <em>saf... | 3 | 2009-08-03T19:03:55Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
How to stop WSGI from hanging apache | 1,223,927 | <p>I have django running through WSGI like this :</p>
<pre><code><VirtualHost *:80>
WSGIScriptAlias / /home/ptarjan/django/django.wsgi
WSGIDaemonProcess ptarjan processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup ptarjan
Alias /media /home/ptarjan/django/mysite/media/
</VirtualHost&g... | 8 | 2009-08-03T18:38:40Z | 1,224,993 | <p>It is not 'deadlock-timeout' you want as specified by another, that is for a very special purpose which will not help in this case.</p>
<p>As far as trying to use mod_wsgi features, you instead want the 'inactivity-timeout' option for WSGIDaemonProcess directive.</p>
<p>Even then, this is not a complete solution. ... | 12 | 2009-08-03T22:49:06Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
How can I merge fields in a CSV string using Python? | 1,223,967 | <p>I am trying to merge three fields in each line of a CSV file using Python. This would be simple, except some of the fields are surrounded by double quotes and include commas. Here is an example:</p>
<pre><code>,,Joe,Smith,New Haven,CT,"Moved from Portland, CT",,goo,
</code></pre>
<p>Is there a simple algorithm tha... | 2 | 2009-08-03T18:47:30Z | 1,223,982 | <p>Something like this?</p>
<pre><code>import csv
source= csv.reader( open("some file","rb") )
dest= csv.writer( open("another file","wb") )
for row in source:
result= row[:6] + [ row[6]+row[7]+row[8] ] + row[9:]
dest.writerow( result )
</code></pre>
<p><hr /></p>
<p><strong>Example</strong></p>
<pre><code>... | 10 | 2009-08-03T18:49:56Z | [
"python",
"database",
"string",
"csv"
] |
How can I merge fields in a CSV string using Python? | 1,223,967 | <p>I am trying to merge three fields in each line of a CSV file using Python. This would be simple, except some of the fields are surrounded by double quotes and include commas. Here is an example:</p>
<pre><code>,,Joe,Smith,New Haven,CT,"Moved from Portland, CT",,goo,
</code></pre>
<p>Is there a simple algorithm tha... | 2 | 2009-08-03T18:47:30Z | 1,224,027 | <p>There's a builtin module in Python for parsing CSV files:</p>
<p><a href="http://docs.python.org/library/csv.html" rel="nofollow">http://docs.python.org/library/csv.html</a></p>
| 1 | 2009-08-03T18:57:23Z | [
"python",
"database",
"string",
"csv"
] |
How can I merge fields in a CSV string using Python? | 1,223,967 | <p>I am trying to merge three fields in each line of a CSV file using Python. This would be simple, except some of the fields are surrounded by double quotes and include commas. Here is an example:</p>
<pre><code>,,Joe,Smith,New Haven,CT,"Moved from Portland, CT",,goo,
</code></pre>
<p>Is there a simple algorithm tha... | 2 | 2009-08-03T18:47:30Z | 1,224,104 | <p>You have tagged this question as 'database'. In fact, maybe it would be easier to upload the two files to separate tables of the db (you can use sqllite or any python sql library, like sqlalchemy) and then join them.</p>
<p>That would give you some advantage after, you would be able to use a sql syntax to query the... | 1 | 2009-08-03T19:12:35Z | [
"python",
"database",
"string",
"csv"
] |
How can I merge fields in a CSV string using Python? | 1,223,967 | <p>I am trying to merge three fields in each line of a CSV file using Python. This would be simple, except some of the fields are surrounded by double quotes and include commas. Here is an example:</p>
<pre><code>,,Joe,Smith,New Haven,CT,"Moved from Portland, CT",,goo,
</code></pre>
<p>Is there a simple algorithm tha... | 2 | 2009-08-03T18:47:30Z | 1,225,253 | <p>You can use the csv module to do the heavy lifting: <a href="http://docs.python.org/library/csv.html" rel="nofollow">http://docs.python.org/library/csv.html</a></p>
<p>You didn't say exactly how you wanted to merge the columns; presumably you don't want your merged field to be "Moved from Portland, CTgoo". The code... | 2 | 2009-08-04T00:24:52Z | [
"python",
"database",
"string",
"csv"
] |
Reading files in python | 1,224,391 | <p>Trying to understand how you're supposed to read files in python. This is what I've done and it isn't working quite properly:</p>
<pre><code>import os.path
filename = "A 180 mb large file.data"
size = os.path.getsize(filename)
f = open(filename, "r")
contents = f.read()
f.close()
print "The real filesize is", si... | 1 | 2009-08-03T20:18:08Z | 1,224,421 | <p>If your file confuses the C libraries, then your results are expected.</p>
<p>The OS thinks it's 180Mb.</p>
<p>However, there are null bytes scattered around, which can confuse the C stdio libraries.</p>
<p>Try opening the file with "rb" and see if you get different results.</p>
| 5 | 2009-08-03T20:24:53Z | [
"python",
"file"
] |
Reading files in python | 1,224,391 | <p>Trying to understand how you're supposed to read files in python. This is what I've done and it isn't working quite properly:</p>
<pre><code>import os.path
filename = "A 180 mb large file.data"
size = os.path.getsize(filename)
f = open(filename, "r")
contents = f.read()
f.close()
print "The real filesize is", si... | 1 | 2009-08-03T20:18:08Z | 1,224,437 | <p>The first is the filesize in bytes, the other times you read the file <em>as text</em> and count <em>characters</em>. Change all <code>open(filename, "r")</code> to <code>open(filename, "rb")</code> and it works.</p>
| 3 | 2009-08-03T20:27:24Z | [
"python",
"file"
] |
Reading files in python | 1,224,391 | <p>Trying to understand how you're supposed to read files in python. This is what I've done and it isn't working quite properly:</p>
<pre><code>import os.path
filename = "A 180 mb large file.data"
size = os.path.getsize(filename)
f = open(filename, "r")
contents = f.read()
f.close()
print "The real filesize is", si... | 1 | 2009-08-03T20:18:08Z | 1,226,467 | <p>This is not about strings : Python is perfectly happy with null bytes in strings.</p>
<p>This is because you are on Windows and you open the file in text mode, so it converts all "\n" into "\r\n", thus destroying all your binary data.</p>
<p>Open your file in binary mode with mode "rb"</p>
| 0 | 2009-08-04T09:19:43Z | [
"python",
"file"
] |
Check for a module in Python without using exceptions | 1,224,585 | <p>I can check for a module in Python doing something like:</p>
<pre><code>try:
import some_module
except ImportError:
print "No some_module!"
</code></pre>
<p>But I don't want to use try/except. Is there a way to accomplish this? (it should work on Python 2.5.x.)</p>
<p><strong>Note:</strong> The reason for no ... | 3 | 2009-08-03T20:55:47Z | 1,224,607 | <p>All methods of importing modules raise exceptions when called. You could try searching the filesystem yourself first for the file, but there are many things to consider.</p>
<p>Not sure why you don't want to use <code>try</code>/<code>except</code> though. It is the best solution, far better than the one I provided... | 0 | 2009-08-03T20:59:56Z | [
"python",
"module",
"python-module"
] |
Check for a module in Python without using exceptions | 1,224,585 | <p>I can check for a module in Python doing something like:</p>
<pre><code>try:
import some_module
except ImportError:
print "No some_module!"
</code></pre>
<p>But I don't want to use try/except. Is there a way to accomplish this? (it should work on Python 2.5.x.)</p>
<p><strong>Note:</strong> The reason for no ... | 3 | 2009-08-03T20:55:47Z | 1,224,621 | <p>sys.modules dictionary seems to contain the info you need.</p>
| -1 | 2009-08-03T21:02:49Z | [
"python",
"module",
"python-module"
] |
Check for a module in Python without using exceptions | 1,224,585 | <p>I can check for a module in Python doing something like:</p>
<pre><code>try:
import some_module
except ImportError:
print "No some_module!"
</code></pre>
<p>But I don't want to use try/except. Is there a way to accomplish this? (it should work on Python 2.5.x.)</p>
<p><strong>Note:</strong> The reason for no ... | 3 | 2009-08-03T20:55:47Z | 1,224,626 | <p>You can read <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-import-statement" rel="nofollow">here</a> about how Python locates and imports modules. If you wanted to, you could replicate this logic in python, searching through sys.modules, sys.meta_path & sys.path to look for the required modul... | 1 | 2009-08-03T21:03:27Z | [
"python",
"module",
"python-module"
] |
Check for a module in Python without using exceptions | 1,224,585 | <p>I can check for a module in Python doing something like:</p>
<pre><code>try:
import some_module
except ImportError:
print "No some_module!"
</code></pre>
<p>But I don't want to use try/except. Is there a way to accomplish this? (it should work on Python 2.5.x.)</p>
<p><strong>Note:</strong> The reason for no ... | 3 | 2009-08-03T20:55:47Z | 1,224,911 | <p>It takes trickery to perform the request (and one <code>raise</code> statement is in fact inevitable because it's the one and only way specified in the PEP 302 for an import hook to say "I don't deal with this path item"!), but the following would avoid any <code>try</code>/<code>except</code>:</p>
<pre><code>impor... | 7 | 2009-08-03T22:20:54Z | [
"python",
"module",
"python-module"
] |
is it possible to get python purple running either in cygwin or on a linux that isn't debian? | 1,224,726 | <p>python purple says it needs dbms and debhelper in order to run, but I don't run debian. Is there a way to get this running on a different linux? or in cygwin?</p>
| 0 | 2009-08-03T21:30:15Z | 1,250,118 | <p>Both cdbs and debhelper are only needed if you are trying to build a debian package. Just do a regular <code>python setup.py build</code>, and it should work fine (assuming you have the other prerequisites available).</p>
| 5 | 2009-08-08T23:19:29Z | [
"python",
"linux",
"cygwin",
"debhelper"
] |
Trying to import module with the same name as a built-in module causes an import error | 1,224,741 | <p>I have a module that conflicts with a built-in module. For example, a <code>myapp.email</code> module defined in <code>myapp/email.py</code>.</p>
<p>I can reference <code>myapp.email</code> anywhere in my code without issue. However, I need to reference the built-in email module from my email module.</p>
<pre><c... | 48 | 2009-08-03T21:34:46Z | 1,224,760 | <p>You will want to read about <a href="http://docs.python.org/whatsnew/2.5.html#pep-328-absolute-and-relative-imports">Absolute and Relative Imports</a> which addresses this very problem. Use:</p>
<pre><code>from __future__ import absolute_import
</code></pre>
<p>Using that, any unadorned package name will always re... | 66 | 2009-08-03T21:38:47Z | [
"python",
"python-import"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.