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
MySQL "incorrect string value" error when save unicode string in Django
2,108,824
<p>I got strange error message when tried to save first_name, last_name to Django's auth_user model.</p> <p><strong>Failed examples</strong></p> <pre><code>user = User.object.create_user(username, email, password) user.first_name = u'Rytis' user.last_name = u'Slatkevičius' user.save() &gt;&gt;&gt; Incorrect string v...
104
2010-01-21T11:34:22Z
11,597,447
<p>If you have this problem here's a python script to change all the columns of your mysql database automatically.</p> <pre><code>#! /usr/bin/env python import MySQLdb host = "localhost" passwd = "passwd" user = "youruser" dbname = "yourdbname" db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname) cur...
54
2012-07-22T02:46:53Z
[ "python", "mysql", "django", "unicode", "utf-8" ]
MySQL "incorrect string value" error when save unicode string in Django
2,108,824
<p>I got strange error message when tried to save first_name, last_name to Django's auth_user model.</p> <p><strong>Failed examples</strong></p> <pre><code>user = User.object.create_user(username, email, password) user.first_name = u'Rytis' user.last_name = u'Slatkevičius' user.save() &gt;&gt;&gt; Incorrect string v...
104
2010-01-21T11:34:22Z
20,349,552
<p>None of these answers solved the problem for me. The root cause being: </p> <p><strong>You cannot store 4-byte characters in MySQL with the utf-8 character set.</strong></p> <p>MySQL has a <a href="http://dev.mysql.com/doc/refman/5.6/en/charset-unicode-utf8.html">3 byte limit on utf-8 characters</a> (yes, it's wac...
56
2013-12-03T11:11:42Z
[ "python", "mysql", "django", "unicode", "utf-8" ]
MySQL "incorrect string value" error when save unicode string in Django
2,108,824
<p>I got strange error message when tried to save first_name, last_name to Django's auth_user model.</p> <p><strong>Failed examples</strong></p> <pre><code>user = User.object.create_user(username, email, password) user.first_name = u'Rytis' user.last_name = u'Slatkevičius' user.save() &gt;&gt;&gt; Incorrect string v...
104
2010-01-21T11:34:22Z
23,792,645
<p>If it's a new project, I'd just drop the database, and create a new one with a proper charset:</p> <pre><code>CREATE DATABASE &lt;dbname&gt; CHARACTER SET utf8; </code></pre>
8
2014-05-21T19:57:05Z
[ "python", "mysql", "django", "unicode", "utf-8" ]
parsing a text string for dates - not the standard convert problem!
2,109,014
<p>Does anyone know of a library - ideally Python, that can have a stab at pulling dates out of text?</p> <p>"Shall we go to the library today" -> 21 Jan 10 "Starting on the 1st of January" -> 1 Jan 10 "Anytime between 3nd and 5th of Feb 2009" -> 3 Feb 09, 5 Feb 09</p> <p>It's a tough problem and probably why I hav...
2
2010-01-21T12:07:38Z
2,109,058
<p>Looks like this module is what you are looking for: <a href="http://code.google.com/p/parsedatetime/" rel="nofollow">parsedatetime</a></p>
4
2010-01-21T12:15:03Z
[ "python", "parsing" ]
parsing a text string for dates - not the standard convert problem!
2,109,014
<p>Does anyone know of a library - ideally Python, that can have a stab at pulling dates out of text?</p> <p>"Shall we go to the library today" -> 21 Jan 10 "Starting on the 1st of January" -> 1 Jan 10 "Anytime between 3nd and 5th of Feb 2009" -> 3 Feb 09, 5 Feb 09</p> <p>It's a tough problem and probably why I hav...
2
2010-01-21T12:07:38Z
2,135,619
<p>Thanks for the contributions - in the end I followed up one of the comments, that led to pyparsing, which led to the beginnings of a solution. many thanks all.</p> <p>Have posted the work in progress, two pyparsing snippets of code here <a href="http://pbjots.blogspot.com/2010/01/using-pyparsing-to-extract-dates-f...
1
2010-01-25T21:04:20Z
[ "python", "parsing" ]
parsing a text string for dates - not the standard convert problem!
2,109,014
<p>Does anyone know of a library - ideally Python, that can have a stab at pulling dates out of text?</p> <p>"Shall we go to the library today" -> 21 Jan 10 "Starting on the 1st of January" -> 1 Jan 10 "Anytime between 3nd and 5th of Feb 2009" -> 3 Feb 09, 5 Feb 09</p> <p>It's a tough problem and probably why I hav...
2
2010-01-21T12:07:38Z
2,135,649
<p>The <a href="http://pyparsing.wikispaces.com" rel="nofollow">PyParsing</a> site has a little bonus script for <a href="http://pyparsing.wikispaces.com/UnderDevelopment#toc0" rel="nofollow">parsing time expressions</a>. I would say that is worth a look for you!</p> <p>Edit: I see you already ended up there as I was ...
2
2010-01-25T21:10:40Z
[ "python", "parsing" ]
IPython doesn't work in Django shell
2,109,075
<p>I've just recently switched over to using 64-bit Python 2.6.1 on Mac OS X 10.6 (Snow Leopard). IPython won't work with Django anymore, but IPython works from the command-line. </p> <p>The error says:</p> <pre><code> shell = IPython.Shell.IPShell(argv=[]) AttributeError: 'module' object has no attribute 'Shell' ...
17
2010-01-21T12:17:39Z
2,113,242
<p>Does this work when you run it from Python interactive console?</p> <pre><code>import IPython; IPython.Shell </code></pre>
0
2010-01-21T21:57:05Z
[ "python", "django", "osx-snow-leopard" ]
IPython doesn't work in Django shell
2,109,075
<p>I've just recently switched over to using 64-bit Python 2.6.1 on Mac OS X 10.6 (Snow Leopard). IPython won't work with Django anymore, but IPython works from the command-line. </p> <p>The error says:</p> <pre><code> shell = IPython.Shell.IPShell(argv=[]) AttributeError: 'module' object has no attribute 'Shell' ...
17
2010-01-21T12:17:39Z
4,263,207
<p>I got the same problem, and solved this issue by applying the patches for the Django bug. - <a href="http://stackoverflow.com/questions/4262938/ipython-doesnt-find-the-shell-ipshell-class">IPython doesn't find the Shell.IPShell class </a></p>
0
2010-11-24T03:23:02Z
[ "python", "django", "osx-snow-leopard" ]
IPython doesn't work in Django shell
2,109,075
<p>I've just recently switched over to using 64-bit Python 2.6.1 on Mac OS X 10.6 (Snow Leopard). IPython won't work with Django anymore, but IPython works from the command-line. </p> <p>The error says:</p> <pre><code> shell = IPython.Shell.IPShell(argv=[]) AttributeError: 'module' object has no attribute 'Shell' ...
17
2010-01-21T12:17:39Z
7,712,122
<p>IPython 0.11 has a different API, for which a fix exists in the last Django versions.</p> <p>For older Django versions, you can use IPython 0.10, which does work:</p> <pre><code>pip install ipython==0.10 </code></pre>
28
2011-10-10T11:30:01Z
[ "python", "django", "osx-snow-leopard" ]
Creating very large images using Python Image Library
2,109,109
<p>I'm trying to create a very large image (25000x25000) by pasting together many smaller images. Upon calling Image.new() with such large dimensions, python runs out of memory and I get a MemoryError.</p> <p>Is there a way to write out an image like this incrementally, without having the whole thing resident in RAM?...
11
2010-01-21T12:27:31Z
2,109,238
<p>Check if your system runs out of virtual memory when you do this. If it does, try adding more. That way, you offload the entire problem onto the virtual memory subsystem, which might be quicker.</p>
0
2010-01-21T12:47:49Z
[ "python", "python-imaging-library" ]
Creating very large images using Python Image Library
2,109,109
<p>I'm trying to create a very large image (25000x25000) by pasting together many smaller images. Upon calling Image.new() with such large dimensions, python runs out of memory and I get a MemoryError.</p> <p>Is there a way to write out an image like this incrementally, without having the whole thing resident in RAM?...
11
2010-01-21T12:27:31Z
2,109,260
<p>Not too suprising you're running out of memory; that image will take over 2gig in memory and depending on the system you're using your OS might not be able to allocate enough virtual memory to python to run it, regardless of your actual RAM.</p> <p>You are definitely going to need to write it out incrementally. If ...
2
2010-01-21T12:50:54Z
[ "python", "python-imaging-library" ]
Creating very large images using Python Image Library
2,109,109
<p>I'm trying to create a very large image (25000x25000) by pasting together many smaller images. Upon calling Image.new() with such large dimensions, python runs out of memory and I get a MemoryError.</p> <p>Is there a way to write out an image like this incrementally, without having the whole thing resident in RAM?...
11
2010-01-21T12:27:31Z
2,110,073
<p>mayby You could try out OIIO python bindings that was created by one of the GSoC student? OpenImageIO itself can read big images using small memory - but I didn't use it by myself</p> <p>OIIO: <a href="http://openimageio.org" rel="nofollow">http://openimageio.org</a> How to use python bindings: <a href="http://open...
0
2010-01-21T14:51:45Z
[ "python", "python-imaging-library" ]
Creating very large images using Python Image Library
2,109,109
<p>I'm trying to create a very large image (25000x25000) by pasting together many smaller images. Upon calling Image.new() with such large dimensions, python runs out of memory and I get a MemoryError.</p> <p>Is there a way to write out an image like this incrementally, without having the whole thing resident in RAM?...
11
2010-01-21T12:27:31Z
2,121,558
<p>Use numpy.memmap and the png module.</p>
-1
2010-01-23T00:47:47Z
[ "python", "python-imaging-library" ]
Creating very large images using Python Image Library
2,109,109
<p>I'm trying to create a very large image (25000x25000) by pasting together many smaller images. Upon calling Image.new() with such large dimensions, python runs out of memory and I get a MemoryError.</p> <p>Is there a way to write out an image like this incrementally, without having the whole thing resident in RAM?...
11
2010-01-21T12:27:31Z
2,124,486
<p>You may try to use <a href="http://www.gdal.org" rel="nofollow">GDAL</a> library. It provides bindings to Python. Here is combined <a href="http://www.gdal.org/gdal_tutorial.html" rel="nofollow">tutorial</a> presenting how to read and write images using C++, C and Python APIs Depending on GDAL operations and functio...
3
2010-01-23T19:57:06Z
[ "python", "python-imaging-library" ]
Creating very large images using Python Image Library
2,109,109
<p>I'm trying to create a very large image (25000x25000) by pasting together many smaller images. Upon calling Image.new() with such large dimensions, python runs out of memory and I get a MemoryError.</p> <p>Is there a way to write out an image like this incrementally, without having the whole thing resident in RAM?...
11
2010-01-21T12:27:31Z
2,144,991
<p>It's just a matter of understanding the binary file format. Compressed formats are going to be more difficult.</p> <p>Assuming you want a bitmap/DIB, this code:</p> <pre><code>#incremental_write_bmp.py import binascii data=''' 0h -2 -42 4D -"BM" -Magic Number (unsigned integer 66, 77) 2h -4 -46 00 00 00 -70 Byte...
2
2010-01-27T06:32:18Z
[ "python", "python-imaging-library" ]
Matplotlib in Python - Drawing shapes and animating them
2,109,265
<p>So I'm representing a token ring network (doing the simulation in SimPy), I'm a totally newbie to matplotlib, but I was told that it'd be really good for representing my simulation visually.</p> <p>So I googled around and found out how to draw shapes and lines - using add_patch and add_line respectively to the axes...
5
2010-01-21T12:52:32Z
2,109,388
<p>The core technique is to update the data of the elements being rendered using set_data. Then call draw(). See if your circle and line elements have set_data functions. Otherwise you can use <a href="http://mayavi.sourceforge.net/docs/guide/ch04.html" rel="nofollow">pyvtk</a>. The other option is to render and save t...
1
2010-01-21T13:12:32Z
[ "python", "networking", "matplotlib", "simulation" ]
Matplotlib in Python - Drawing shapes and animating them
2,109,265
<p>So I'm representing a token ring network (doing the simulation in SimPy), I'm a totally newbie to matplotlib, but I was told that it'd be really good for representing my simulation visually.</p> <p>So I googled around and found out how to draw shapes and lines - using add_patch and add_line respectively to the axes...
5
2010-01-21T12:52:32Z
2,111,567
<p>Replicating your image using the plot method:</p> <pre><code>from pylab import * points = [] points.append((-0.25, -1.0)) points.append((0.7, -0.7)) points.append((1,0)) points.append((0.7,1)) points.append((-0.25,1.2)) points.append((-1,0.5)) points.append((-1,-0.5)) points.append((-0.25, -1.0)) a_line = plot(*z...
4
2010-01-21T17:55:24Z
[ "python", "networking", "matplotlib", "simulation" ]
Matplotlib in Python - Drawing shapes and animating them
2,109,265
<p>So I'm representing a token ring network (doing the simulation in SimPy), I'm a totally newbie to matplotlib, but I was told that it'd be really good for representing my simulation visually.</p> <p>So I googled around and found out how to draw shapes and lines - using add_patch and add_line respectively to the axes...
5
2010-01-21T12:52:32Z
4,337,037
<p>It sounds like Mark has the answer you were looking for, but if you decide to go with whatnick's approach and build an animation from individual pngs, here is the code to implement Amit's suggestion to use mencoder (from <a href="http://en.wikibooks.org/wiki/Mplayer" rel="nofollow">http://en.wikibooks.org/wiki/Mplay...
1
2010-12-02T16:05:12Z
[ "python", "networking", "matplotlib", "simulation" ]
Creating a FeaturedContent feature in Django using contenttypes
2,109,281
<p>I'm using the contenttypes framework to create a "featured content" feature on my site. I've basically done this by defining a model like so:</p> <pre><code>class FeaturedContent(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = gener...
1
2010-01-21T12:55:08Z
2,109,810
<p>You will need to create a stackedinline admin, for each of your models that need this option in the admin.</p> <p>Something like the following:</p> <pre><code>class ObjectInline(admin.StackedInline): model = YourFancyModelthatisFeatured extra = 0 class FancyModelAdmin(admin.ModelAdmin): inlines = [Obj...
0
2010-01-21T14:16:36Z
[ "python", "django", "django-models" ]
Django - How to model this correctly?
2,109,293
<p>I want to model the following situation. I have a table of items, and a table of players, and a player can have many items and have multiple copies of the same item. I can easily model the player having multiple items:</p> <pre><code>class Item(models.Model): name = models.CharField(max_length = 200, blank = Fa...
1
2010-01-21T12:57:29Z
2,109,376
<p>Use an <a href="http://docs.djangoproject.com/en/1.1/topics/db/models/#extra-fields-on-many-to-many-relationships" rel="nofollow">explicit <code>through</code> table</a> with a <code>quantity</code> field.</p>
5
2010-01-21T13:11:12Z
[ "python", "django", "model" ]
Django - How to model this correctly?
2,109,293
<p>I want to model the following situation. I have a table of items, and a table of players, and a player can have many items and have multiple copies of the same item. I can easily model the player having multiple items:</p> <pre><code>class Item(models.Model): name = models.CharField(max_length = 200, blank = Fa...
1
2010-01-21T12:57:29Z
2,110,813
<p>If the items are non-unique you can use a PlayerItem model and define it as a <a href="http://docs.djangoproject.com/en/1.1/topics/db/models/#extra-fields-on-many-to-many-relationships" rel="nofollow">through model</a> as Daniel Roseman suggested. To avoid saving the same item twice you can use <code>unique_together...
1
2010-01-21T16:19:22Z
[ "python", "django", "model" ]
Renaming a file on a remote file server in C# / Python
2,109,988
<p>I need to rename a whole heap of files on a Windows file server - I don't mind what language I use really as long it's quick and easy!</p> <p>I know it's basic but just to clarify - in pseudo-code...</p> <pre><code>server = login (fileserver, creds) foreach (file in server.navigateToDir(dir)) rename(file) </c...
2
2010-01-21T14:39:58Z
2,110,103
<p>Use \\servername\sharename\somefile.foo for filenames - provided you have access to connect to it and are running on windows.</p> <p>You could also map up a network drive and treat it as any other local drive (y:\sharename\somefile.foo)</p>
1
2010-01-21T14:55:43Z
[ "c#", "python", "file", "rename", "fileserver" ]
Renaming a file on a remote file server in C# / Python
2,109,988
<p>I need to rename a whole heap of files on a Windows file server - I don't mind what language I use really as long it's quick and easy!</p> <p>I know it's basic but just to clarify - in pseudo-code...</p> <pre><code>server = login (fileserver, creds) foreach (file in server.navigateToDir(dir)) rename(file) </c...
2
2010-01-21T14:39:58Z
2,110,367
<p>The following renames a file in each of the sub-directories of the folder path given. It renames the file from the given filename (eg."blah.txt") to foldername+extension.</p> <p>NB. Z can be either a local or network drive (ie. if folder is on file server map network drive to it).</p> <p>For example from a shell.....
0
2010-01-21T15:27:20Z
[ "c#", "python", "file", "rename", "fileserver" ]
Renaming a file on a remote file server in C# / Python
2,109,988
<p>I need to rename a whole heap of files on a Windows file server - I don't mind what language I use really as long it's quick and easy!</p> <p>I know it's basic but just to clarify - in pseudo-code...</p> <pre><code>server = login (fileserver, creds) foreach (file in server.navigateToDir(dir)) rename(file) </c...
2
2010-01-21T14:39:58Z
2,113,192
<p>You could also use PSEXEC to execute the code remotely on the server if you need the performance of locally executed code. See <a href="http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx" rel="nofollow">http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx</a></p>
1
2010-01-21T21:47:56Z
[ "c#", "python", "file", "rename", "fileserver" ]
Renaming a file on a remote file server in C# / Python
2,109,988
<p>I need to rename a whole heap of files on a Windows file server - I don't mind what language I use really as long it's quick and easy!</p> <p>I know it's basic but just to clarify - in pseudo-code...</p> <pre><code>server = login (fileserver, creds) foreach (file in server.navigateToDir(dir)) rename(file) </c...
2
2010-01-21T14:39:58Z
2,124,737
<p>Have a look at <a href="http://code.google.com/p/pyfilesystem/source/browse/trunk/docs/getting_started.rst" rel="nofollow">pyfilesytem</a>, it provides a consistent interface for local and remote filesystems.</p>
1
2010-01-23T21:08:45Z
[ "c#", "python", "file", "rename", "fileserver" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
2,110,291
<p>I guess you could do something based on <a href="http://en.wikipedia.org/wiki/Levenshtein_distance" rel="nofollow">Levenshtein distance</a>, but there's no real way to do this automatically - without creating a fairly complex rules-based system.</p> <p>Unless you can define a rules system that can work out for any ...
4
2010-01-21T15:16:42Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
2,110,341
<p>This is not a complete solutions but one thought I had:</p> <pre><code>class DJ(models.Model): #other fields, no alias! class DJAlias(models.Model): dj = models.ForeignKey(DJ) </code></pre> <p>This would allow you to have several Aliases for the same dj.</p> <p>But still you will need to find a proper wa...
1
2010-01-21T15:23:13Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
2,110,348
<p>From the examples you give, it sounds like you have more a natural language problem than an exact matching problem. Given that natural language matching is inexact by nature you're unlikely to come up with a perfect solution. </p> <ul> <li>String distance doesn't really work, as strings that are algorithmically clo...
3
2010-01-21T15:24:19Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
2,110,553
<p>You could try to solve this problem for this instance only (replacing the "&amp;" with "&amp;" and "DJ" with "Disk jokey" or ignore "DJ" etc..). If your table only contains DJ's you could set up a bunch of rules like those. If your table contains more diverse stuff you will have to go with a more structural approac...
1
2010-01-21T15:47:02Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
2,110,663
<p>I think this is more of a social problem than a programming problem. Any sort of programatic solution to natural language processing like this is going to be buggy and error prone. It's very hard to distinguish things that are close, but legitimately different from the sort of undesired duplicates that you're talk...
2
2010-01-21T16:01:17Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
2,115,973
<p>First of all of course the programming task (NLP etc. as mentioned) is interesting. But as mentioned it's overkill aiming to perfect that.</p> <p>But the other view is as mentioned ("social"), who enters the data, who views it, how long and how correct should it be? So it's a naming convention issue and reminds me ...
1
2010-01-22T08:36:01Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
2,123,685
<p>How about changing the model so "alias" to be list of keys to other table that looks like this (skipping small words like "the", "and", etc.): 1 => Above; 2 => Beyond; 3 => Disk; 4 => Jokey;</p> <p>Then when you want to insert new record just check how many of the significant words from the title are already in the...
1
2010-01-23T15:47:13Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
13,275,867
<p>Looks like <a href="https://github.com/seatgeek/fuzzywuzzy" rel="nofollow">fuzzywuzzy</a> is a perfect match to your needs.</p> <p><a href="http://seatgeek.com/blog/dev/fuzzywuzzy-fuzzy-string-matching-in-python" rel="nofollow">This article</a> explains the reason it was set up, which very closely matches your requ...
0
2012-11-07T18:28:32Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Merging duplicates in a list? - Question is more complex than it seems
2,110,238
<p>So I have a huge list of entries in a DB (<strong>MySql</strong>)</p> <p>I'm using <strong>Python</strong> and <strong>Django</strong> in the creation of my web application.</p> <p>This is the base Django model I'm using:</p> <pre><code>class DJ(models.Model): alias = models.CharField(max_length=255) #oth...
4
2010-01-21T15:10:51Z
13,286,968
<p>If you're only after artist names or generally media related names it might be much better to just use the API of last.fm or echonest as they already have a huge rule set and a huge database to settle on.</p>
0
2012-11-08T10:15:54Z
[ "python", "mysql", "django", "sqlalchemy", "django-orm" ]
Hooking into django views
2,110,399
<p>Simple question. I have bunch of django views. Is there a way to tell django that for each view, use <code>foo(view)</code> instead? Example:</p> <p>Instead of writing</p> <pre><code>@foo @bar @baz def view(request): # do something </code></pre> <p>all the time, I'd like to have</p> <pre><code>def view(reque...
0
2010-01-21T15:30:06Z
2,110,978
<p>I don't know why you want to do this. I don't know either why you don't want to use decorators. But you could use this ugly (and likely error prone) hack as a start:</p> <pre><code>def view(request): pass view.markers = ['some', 'markers'] </code></pre> <p>some other place:</p> <pre><code>from app import view...
1
2010-01-21T16:42:12Z
[ "python", "django", "hook", "django-views" ]
Hooking into django views
2,110,399
<p>Simple question. I have bunch of django views. Is there a way to tell django that for each view, use <code>foo(view)</code> instead? Example:</p> <p>Instead of writing</p> <pre><code>@foo @bar @baz def view(request): # do something </code></pre> <p>all the time, I'd like to have</p> <pre><code>def view(reque...
0
2010-01-21T15:30:06Z
2,112,184
<p>Depending on what you want to do (or achieve), you can write a <a href="http://docs.djangoproject.com/en/1.1/topics/http/middleware/#writing-your-own-middleware" rel="nofollow">custom middelware</a> and implement the method <code>process_view</code> (and/or any other method that you need):</p> <blockquote> <p><co...
2
2010-01-21T19:26:53Z
[ "python", "django", "hook", "django-views" ]
A good django search app? — How to perform fuzzy search with Haystack?
2,110,411
<p>I'm using django-haystack at the moment with apache-solr as the backend.</p> <p>Problem is I cannot get the app to perform the search functionality I'm looking for</p> <ol> <li><p>Searching for sub-parts in a word</p> <blockquote> <p>eg. Searching for "buntu" does not give me "ubuntu"</p> </blockquote></li> <l...
4
2010-01-21T15:31:17Z
2,110,763
<p>This is really about how you pass the query back to Haystack (and therefore to Solr). You can do a 'fuzzy' search in Solr/Lucene by using a <code>~</code> after the word:</p> <pre><code>ubuntu~ </code></pre> <p>would return both <code>buntu</code> and <code>ubantu</code>. See the <a href="http://lucene.apache.org/...
9
2010-01-21T16:13:46Z
[ "python", "django", "solr", "django-haystack", "fuzzy-search" ]
why is __init__ module in django project loaded twice
2,110,545
<p>I put </p> <pre><code>print 'Hello world!' </code></pre> <p>into <code>__init__.py</code> in my django project. When I run <code>./manage.py runserver</code> now, I get</p> <pre><code>gruszczy@gruszczy-laptop:~/Programy/project$ ./manage.py runserver Hello world! Hello world! Validating models... 0 errors found <...
8
2010-01-21T15:45:32Z
2,110,584
<p>It should be loaded only once... <em>per process</em>. I'm guessing that <code>manage.py</code> forks, and that two separate processes are launched. Could you print the result of <code>os.getpid()</code>?</p>
19
2010-01-21T15:51:26Z
[ "python", "django" ]
why is __init__ module in django project loaded twice
2,110,545
<p>I put </p> <pre><code>print 'Hello world!' </code></pre> <p>into <code>__init__.py</code> in my django project. When I run <code>./manage.py runserver</code> now, I get</p> <pre><code>gruszczy@gruszczy-laptop:~/Programy/project$ ./manage.py runserver Hello world! Hello world! Validating models... 0 errors found <...
8
2010-01-21T15:45:32Z
2,113,436
<p>One simple way of finding out would be to raise an exception. Perhaps something like this in your <strong>init</strong>.py:</p> <pre><code>import os if os.path.isfile('/tmp/once.log'): raise Exception open('/tmp/once.log','w').write('first time') </code></pre> <p>Then you can inspect the traceback.</p>
0
2010-01-21T22:26:00Z
[ "python", "django" ]
Getting invalid image error in Django, but PIL is installed and passes all tests
2,110,588
<p>So I've finally successfully installed PIL (after many difficulties) on RHEL5 with Django (development version) and Python 2.6 installed at /opt/python2.6.</p> <p>Running selftest.py shows that everything appears to be installed correctly:</p> <pre><code>$ python2.6 selftest.py 57 tests passed. </code></pre> <p>...
3
2010-01-21T15:51:45Z
2,111,229
<p>My impression of the PIL JPEG problem is that it's almost always a system configuration problem.</p> <p>You built and configured PIL and tested with that version and it worked. So, my guess is that Django is pulling in a different PIL, probably one built without JPEG support or that can't find libjpeg.</p> <p>You...
0
2010-01-21T17:12:49Z
[ "python", "django", "python-imaging-library", "django-models" ]
Getting invalid image error in Django, but PIL is installed and passes all tests
2,110,588
<p>So I've finally successfully installed PIL (after many difficulties) on RHEL5 with Django (development version) and Python 2.6 installed at /opt/python2.6.</p> <p>Running selftest.py shows that everything appears to be installed correctly:</p> <pre><code>$ python2.6 selftest.py 57 tests passed. </code></pre> <p>...
3
2010-01-21T15:51:45Z
2,188,547
<p>See possible answer in:</p> <p><a href="http://stackoverflow.com/questions/2173103/is-it-possible-to-control-which-libraries-apache-uses">http://stackoverflow.com/questions/2173103/is-it-possible-to-control-which-libraries-apache-uses</a></p> <p>Referencing here so can still get bounty if awarded. :-)</p>
2
2010-02-02T23:22:18Z
[ "python", "django", "python-imaging-library", "django-models" ]
Python zipfile hangs when writing
2,110,739
<p>I am trying to use the <a href="http://docs.python.org/library/zipfile.html" rel="nofollow">zipfile</a> module in Python to create simple zip files:</p> <pre><code>import zipfile files = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h') zip_file_name = 'zipfile_test.zip' zfh = zipfile.ZipFile(zip_file_name, 'w') for file ...
3
2010-01-21T16:11:17Z
2,110,777
<p>You're putting <em>the zip file</em> into the zip file:</p> <pre><code>zfh.write(zip_file_name) </code></pre> <p>Should be:</p> <pre><code>zfh.write(file) </code></pre>
9
2010-01-21T16:15:02Z
[ "python", "zipfile" ]
Cleaning up nested for loops in python
2,110,753
<p>I have this code:</p> <pre><code>def GetSteamAccts(): #Get list of steam logins on this computer. templist = [] Steamapp_Folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\", "C:\\Program Files\\Steam\\steamapps\\"] #Check both of these directories. for SF_i in range(len(Steamapp_Folders)): ...
1
2010-01-21T16:12:24Z
2,110,844
<pre><code>for i in range(len(somelist)): something( somelist[i] ) </code></pre> <p>should be written as</p> <pre><code>for x in somelist: something( x ) </code></pre> <p>Also you can write everything much shorter:</p> <pre><code>def GetSteamAccts(): Steamapp_Folders = [f for f in ("C:\\Program Files (x...
9
2010-01-21T16:22:38Z
[ "python" ]
Cleaning up nested for loops in python
2,110,753
<p>I have this code:</p> <pre><code>def GetSteamAccts(): #Get list of steam logins on this computer. templist = [] Steamapp_Folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\", "C:\\Program Files\\Steam\\steamapps\\"] #Check both of these directories. for SF_i in range(len(Steamapp_Folders)): ...
1
2010-01-21T16:12:24Z
2,110,849
<blockquote> <p>And: Do lists in for loops always have to be traversed like:</p> <p>for x in range(len(somelist)): or is there something shorter than using range(len( ?</p> </blockquote> <p>Sure there is, if you want to access the item only and you are not interested in its index you could do this:</p> <...
5
2010-01-21T16:23:13Z
[ "python" ]
Cleaning up nested for loops in python
2,110,753
<p>I have this code:</p> <pre><code>def GetSteamAccts(): #Get list of steam logins on this computer. templist = [] Steamapp_Folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\", "C:\\Program Files\\Steam\\steamapps\\"] #Check both of these directories. for SF_i in range(len(Steamapp_Folders)): ...
1
2010-01-21T16:12:24Z
2,110,851
<p>You should lose the idea that a for loop always iterates over numbers from zero to something, like in other languages. You're just traversing lists, so use the for loop like this:</p> <pre><code>def GetSteamAccts(): templist = [] Steamapp_Folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\", "C:\\Progra...
4
2010-01-21T16:23:25Z
[ "python" ]
Cleaning up nested for loops in python
2,110,753
<p>I have this code:</p> <pre><code>def GetSteamAccts(): #Get list of steam logins on this computer. templist = [] Steamapp_Folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\", "C:\\Program Files\\Steam\\steamapps\\"] #Check both of these directories. for SF_i in range(len(Steamapp_Folders)): ...
1
2010-01-21T16:12:24Z
2,110,971
<p>I'd suggest something like this:</p> <pre><code>def check_subfolder(*args): for folder in args: for root, dirs, _ in os.walk(folder): return [os.path.join(root, i) for i in dirs] # since only 1 will ever exist </code></pre> <p>it's just saves on all those <code>if</code> statements. Of ...
0
2010-01-21T16:41:14Z
[ "python" ]
Cleaning up nested for loops in python
2,110,753
<p>I have this code:</p> <pre><code>def GetSteamAccts(): #Get list of steam logins on this computer. templist = [] Steamapp_Folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\", "C:\\Program Files\\Steam\\steamapps\\"] #Check both of these directories. for SF_i in range(len(Steamapp_Folders)): ...
1
2010-01-21T16:12:24Z
2,110,973
<p>As others have mentioned, removing the assumption about integer indexes removes a large amount of the complexity. </p> <p>Going a bit further, you can replace patterns where you build up a list by appending in a for loop with a <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="...
2
2010-01-21T16:41:42Z
[ "python" ]
Test Suite unittest
2,110,842
<p>I have a test suite and I am trying to get it to work with the tests I have created. The test work if I run them individually but I want to run them all in a test suite. The code below show the test suite created:</p> <pre><code>import unittest def suite(): modules_to_test = ('TestAbsoluteMove', 'TestContinuou...
1
2010-01-21T16:22:21Z
2,110,886
<p><a href="https://nose.readthedocs.org/en/latest/" rel="nofollow" title="Nose">Nose</a> makes this sort of thing a no-brainer. It will auto-detect your tests and run them as a suite. (You can also run specific tests by passing it a flag.)</p>
2
2010-01-21T16:29:28Z
[ "python", "unit-testing", "testing", "test-suite" ]
Test Suite unittest
2,110,842
<p>I have a test suite and I am trying to get it to work with the tests I have created. The test work if I run them individually but I want to run them all in a test suite. The code below show the test suite created:</p> <pre><code>import unittest def suite(): modules_to_test = ('TestAbsoluteMove', 'TestContinuou...
1
2010-01-21T16:22:21Z
2,110,904
<p>TestAbsoluteMove is a class, and it needs to come from somewhere. Wherever your AbsoluteMoveTestSuite class is defined, you need to import TestAbsoluteMove.</p>
2
2010-01-21T16:31:25Z
[ "python", "unit-testing", "testing", "test-suite" ]
Test Suite unittest
2,110,842
<p>I have a test suite and I am trying to get it to work with the tests I have created. The test work if I run them individually but I want to run them all in a test suite. The code below show the test suite created:</p> <pre><code>import unittest def suite(): modules_to_test = ('TestAbsoluteMove', 'TestContinuou...
1
2010-01-21T16:22:21Z
2,110,941
<p><code>unittest</code> is a bit of a pain to use like this. I would very much reommend that you follow Alison's advice a look at <code>nose</code> or use my personal favourite Python testing tool <a href="http://codespeak.net/py/dist/test/" rel="nofollow">py.test</a>. Just create functions following a specific naming...
0
2010-01-21T16:37:06Z
[ "python", "unit-testing", "testing", "test-suite" ]
Test Suite unittest
2,110,842
<p>I have a test suite and I am trying to get it to work with the tests I have created. The test work if I run them individually but I want to run them all in a test suite. The code below show the test suite created:</p> <pre><code>import unittest def suite(): modules_to_test = ('TestAbsoluteMove', 'TestContinuou...
1
2010-01-21T16:22:21Z
17,994,611
<p>this is how I create my testsuite (loadTestFromTestCase detects your tests automatically)</p> <pre><code>def suite(): """ returns all the testcases in this module """ return TestLoader().loadTestsFromTestCase(AbsoluteMoveTestSuite) </code></pre> <p>and to run them all at once I have a suite that incorporat...
1
2013-08-01T12:51:02Z
[ "python", "unit-testing", "testing", "test-suite" ]
File indexing (using Binary trees?) in Python
2,110,843
<h2>Background</h2> <p>I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). </p...
4
2010-01-21T16:22:28Z
2,110,912
<p>The physical storage access time will tend to dominate anything you do. When you profile, you'll find that the <code>read()</code> is where you spend most of your time.</p> <p>To reduce the time spent waiting for I/O, your best bet is compression.</p> <p>Create a huge ZIP archive of all of your files. One <code>...
1
2010-01-21T16:31:41Z
[ "python", "algorithm", "indexing", "binary-tree" ]
File indexing (using Binary trees?) in Python
2,110,843
<h2>Background</h2> <p>I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). </p...
4
2010-01-21T16:22:28Z
2,110,919
<p>Why reinvent the wheel? By all means, index the files, but use <a href="http://whoosh.ca/" rel="nofollow">Whoosh</a>, or <a href="http://lucene.apache.org/pylucene/" rel="nofollow">Lucene</a>, etc.</p> <p>Edit: you hadn't stated your performance requirements at the time I posted this answer. You're not going to be ...
5
2010-01-21T16:32:54Z
[ "python", "algorithm", "indexing", "binary-tree" ]
File indexing (using Binary trees?) in Python
2,110,843
<h2>Background</h2> <p>I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). </p...
4
2010-01-21T16:22:28Z
2,111,067
<p>If the data is already organized in fields, it doesn't sound like a text searching/indexing problem. It sounds like tabular data that would be well-served by a database.</p> <p>Script the file data into a database, index as you see fit, and query the data in any complex way the database supports.</p> <p>That is un...
1
2010-01-21T16:52:01Z
[ "python", "algorithm", "indexing", "binary-tree" ]
File indexing (using Binary trees?) in Python
2,110,843
<h2>Background</h2> <p>I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). </p...
4
2010-01-21T16:22:28Z
2,111,105
<p>There are a number of file-based DBMSes designed for the sort of data you describe. One of the most widely used is <a href="http://www.oracle.com/technology/products/berkeley-db/index.html" rel="nofollow">Berkeley DB</a>. It's open source, now owned by Oracle, and comes in C and Java flavors (with Python and other l...
1
2010-01-21T16:56:34Z
[ "python", "algorithm", "indexing", "binary-tree" ]
File indexing (using Binary trees?) in Python
2,110,843
<h2>Background</h2> <p>I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). </p...
4
2010-01-21T16:22:28Z
12,805,622
<p>sqlite3 is fast, small, part of python (so nothing to install) and provides indexing of columns. It writes to files, so you wouldn't need to install a database system.</p>
1
2012-10-09T17:53:00Z
[ "python", "algorithm", "indexing", "binary-tree" ]
Looping over datasets in Python
2,111,072
<p>I'm trying to write a Python script that will perform the same action on multiple databases. There are too many for me to input them by hand, so I'd like to write a script that will loop over them. Right now, I've gotten as far as the following before getting stuck:</p> <pre><code>countylist = ['01001','01002','010...
0
2010-01-21T16:52:24Z
2,111,085
<p>Simple concatenation will do:</p> <pre><code>for item in countylist: file_2 = 'F:\\file' + item + '.shp' output_2 = 'F:\\output' + item + '.shp' </code></pre>
1
2010-01-21T16:54:55Z
[ "python", "string" ]
Looping over datasets in Python
2,111,072
<p>I'm trying to write a Python script that will perform the same action on multiple databases. There are too many for me to input them by hand, so I'd like to write a script that will loop over them. Right now, I've gotten as far as the following before getting stuck:</p> <pre><code>countylist = ['01001','01002','010...
0
2010-01-21T16:52:24Z
2,111,088
<p>How about:</p> <pre><code>countylist = ['01001','01002','01003','01004'] for item in countylist: # Local variables... file_1 = "F:\\file1.shp" file_2 = "F:\\file%s.shp" % countylist output_2 = "F:\\output%s.shp" % countylist </code></pre>
0
2010-01-21T16:55:21Z
[ "python", "string" ]
Looping over datasets in Python
2,111,072
<p>I'm trying to write a Python script that will perform the same action on multiple databases. There are too many for me to input them by hand, so I'd like to write a script that will loop over them. Right now, I've gotten as far as the following before getting stuck:</p> <pre><code>countylist = ['01001','01002','010...
0
2010-01-21T16:52:24Z
2,111,090
<pre><code>countylist = ['01001','01002','01003','01004'] file_1 = "F:\\file1.shp" for item in countylist: file_2 = "F:\\file%s.shp" % item output_2 = "F:\\output%s.shp" % item # Here, I do my commands that are dependent on # the name of the file changing. # Here, outside of the loop, file_2 and output...
3
2010-01-21T16:55:29Z
[ "python", "string" ]
Looping over datasets in Python
2,111,072
<p>I'm trying to write a Python script that will perform the same action on multiple databases. There are too many for me to input them by hand, so I'd like to write a script that will loop over them. Right now, I've gotten as far as the following before getting stuck:</p> <pre><code>countylist = ['01001','01002','010...
0
2010-01-21T16:52:24Z
2,111,161
<p>Nobody's used this variation yet, how about the <a href="http://docs.python.org/library/stdtypes.html#str.format" rel="nofollow">format method</a> for strings...</p> <pre><code>countylist = ['01001','01002','01003','01004'] for item in countylist: file_1 = "F:\\file1.shp" file_2 = "F:\\file{0}.shp".format(item)...
0
2010-01-21T17:04:10Z
[ "python", "string" ]
create a grayscale image
2,111,150
<p>I am reading binary data from one file that specifies intensity values across x and y coordinates (not a open-source image format) and want to convert it to a PNG image (or other widely supported format). I have the data loaded into an array (using the array module) where each element is a integer from 0 to 255. To ...
5
2010-01-21T17:02:15Z
2,111,194
<p>There are several ways to do this, but if you already have the data in memory, look into using <code>Image.frombuffer</code> or <code>Image.fromstring</code> using the <code>'L'</code> mode (for 8-bit greyscale data).</p>
2
2010-01-21T17:08:19Z
[ "python", "python-imaging-library" ]
create a grayscale image
2,111,150
<p>I am reading binary data from one file that specifies intensity values across x and y coordinates (not a open-source image format) and want to convert it to a PNG image (or other widely supported format). I have the data loaded into an array (using the array module) where each element is a integer from 0 to 255. To ...
5
2010-01-21T17:02:15Z
2,111,195
<p>Would im.putpixel(xy, colour) be what you are looking for?</p>
0
2010-01-21T17:08:29Z
[ "python", "python-imaging-library" ]
create a grayscale image
2,111,150
<p>I am reading binary data from one file that specifies intensity values across x and y coordinates (not a open-source image format) and want to convert it to a PNG image (or other widely supported format). I have the data loaded into an array (using the array module) where each element is a integer from 0 to 255. To ...
5
2010-01-21T17:02:15Z
2,111,223
<p>When you create the new image, give it the mode L:</p> <pre><code>im = Image.new('L', size) im.putdata([x1, x2, x3, ...]) </code></pre> <p>Where data is a list of values not tuples.</p>
6
2010-01-21T17:12:12Z
[ "python", "python-imaging-library" ]
Selecting specific column in each row from array
2,111,163
<p>I am trying to select specific column elements for each row of a numpy array. For example, in the following example:</p> <pre><code>In [1]: a = np.random.random((3,2)) Out[1]: array([[ 0.75670668, 0.1283942 ], [ 0.51326555, 0.59378083], [ 0.03219789, 0.53612603]]) </code></pre> <p>I would like to...
4
2010-01-21T17:04:25Z
2,111,309
<p>You can use:</p> <pre><code>a[np.arange(3), (0,1,0)] </code></pre> <p>in your example above.</p>
6
2010-01-21T17:22:25Z
[ "python", "numpy" ]
Selecting specific column in each row from array
2,111,163
<p>I am trying to select specific column elements for each row of a numpy array. For example, in the following example:</p> <pre><code>In [1]: a = np.random.random((3,2)) Out[1]: array([[ 0.75670668, 0.1283942 ], [ 0.51326555, 0.59378083], [ 0.03219789, 0.53612603]]) </code></pre> <p>I would like to...
4
2010-01-21T17:04:25Z
2,144,048
<p>This isn't an answer so much as an attempt to document this a bit. For the answer above, we would have:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; A = np.array(range(6)) &gt;&gt;&gt; A array([0, 1, 2, 3, 4, 5]) &gt;&gt;&gt; A.shape = (3,2) &gt;&gt;&gt; A array([[0, 1], [2, 3], [4, 5]...
2
2010-01-27T01:50:53Z
[ "python", "numpy" ]
Selecting specific column in each row from array
2,111,163
<p>I am trying to select specific column elements for each row of a numpy array. For example, in the following example:</p> <pre><code>In [1]: a = np.random.random((3,2)) Out[1]: array([[ 0.75670668, 0.1283942 ], [ 0.51326555, 0.59378083], [ 0.03219789, 0.53612603]]) </code></pre> <p>I would like to...
4
2010-01-21T17:04:25Z
13,294,675
<p>OK, just to clarify here, lets do a simple example</p> <pre><code>A=diag(arange(0,10,1)) </code></pre> <p>gives</p> <pre><code>array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0, 0,...
3
2012-11-08T17:43:00Z
[ "python", "numpy" ]
How to build 64-bit Python on OS X 10.6 -- ONLY 64 bit, no Universal nonsense
2,111,283
<p>I just want to build this on my development machine -- the binary install from Python.org is still 32 bits and installing extensions (MySQLdb, for example) is driving me nuts with trying to figure out the proper flags for each and every extension.</p> <p>Clarification: I did NOT replace the system Python, I just in...
6
2010-01-21T17:19:36Z
2,111,435
<p>If you happen to be using <a href="http://www.macports.org/">MacPorts</a>, it's as simple as specifying the variant that tells it not to compile Universal, like so:</p> <pre><code>sudo port install python26 -universal </code></pre> <p>You can view available variants using the <code>variants</code> command:</p> <p...
11
2010-01-21T17:36:52Z
[ "python", "osx", "64bit", "osx-snow-leopard", "x86-64" ]
How to build 64-bit Python on OS X 10.6 -- ONLY 64 bit, no Universal nonsense
2,111,283
<p>I just want to build this on my development machine -- the binary install from Python.org is still 32 bits and installing extensions (MySQLdb, for example) is driving me nuts with trying to figure out the proper flags for each and every extension.</p> <p>Clarification: I did NOT replace the system Python, I just in...
6
2010-01-21T17:19:36Z
2,112,151
<p>The simplest solution is pull <em>everything</em> you need from MacPorts:</p> <pre><code>$ sudo port selfupdate $ sudo port install python26 +no_tkinter -universal py26-mysqldb -universal </code></pre> <p>That will install python2.6, the MySQLdb adapter, and the necessary MySQL client libraries. I suggest adding ...
5
2010-01-21T19:21:37Z
[ "python", "osx", "64bit", "osx-snow-leopard", "x86-64" ]
How to build 64-bit Python on OS X 10.6 -- ONLY 64 bit, no Universal nonsense
2,111,283
<p>I just want to build this on my development machine -- the binary install from Python.org is still 32 bits and installing extensions (MySQLdb, for example) is driving me nuts with trying to figure out the proper flags for each and every extension.</p> <p>Clarification: I did NOT replace the system Python, I just in...
6
2010-01-21T17:19:36Z
3,033,906
<p>Once you do get 64-bit Python setup using the methods outlined above above, I also found this <a href="http://asmeurersympy.wordpress.com/2009/11/13/how-to-get-both-32-bit/" rel="nofollow">blog post by Aaron Meurer</a> helpful for verifying that Python is in fact installed as 64-bit. The post also talks about runnin...
3
2010-06-13T21:03:37Z
[ "python", "osx", "64bit", "osx-snow-leopard", "x86-64" ]
How to build 64-bit Python on OS X 10.6 -- ONLY 64 bit, no Universal nonsense
2,111,283
<p>I just want to build this on my development machine -- the binary install from Python.org is still 32 bits and installing extensions (MySQLdb, for example) is driving me nuts with trying to figure out the proper flags for each and every extension.</p> <p>Clarification: I did NOT replace the system Python, I just in...
6
2010-01-21T17:19:36Z
3,033,916
<p>Always macports... sheesh</p> <p>This is what I did:</p> <pre><code>~: wget http://python.org/ftp/python/2.6.5/Python-2.6.5.tar.bz2 ~: tar xjf Python-2.6.5.tar.bz2 ~: cd Python-2.6.5 ~: ./configure ./configure MACOSX_DEPLOYMENT_TARGET=10.6 --enable-framework --with-universal-archs="64-bit" CFLAGS="-arch x86_64" LD...
5
2010-06-13T21:09:51Z
[ "python", "osx", "64bit", "osx-snow-leopard", "x86-64" ]
Django auth without "auth_*" tables
2,111,432
<p>We would like to use our own tables for user management instead of the Django "auth" tables. We already have database tables that include all of the relevant information our application needs but it isn't in the Django format. We would prefer not to have the information duplicated in two tables.</p> <p>We would lik...
4
2010-01-21T17:36:18Z
32,612,527
<p>I think you want to implement a <a href="https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#substituting-a-custom-user-model" rel="nofollow">custom user model</a>. That integrates nicely with the rest of django.contrib.auth and allows you to write it against a legacy user table. You need to do this wit...
0
2015-09-16T15:12:35Z
[ "python", "django", "authentication" ]
What's the best practice for handling single-value tuples in Python?
2,111,759
<p>I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particular...
6
2010-01-21T18:22:22Z
2,111,811
<p>for your first problem you could check if the return value is tuple using </p> <pre><code>type(r) is tuple #alternative isinstance(r, tuple) # one-liner def as_tuple(r): return [ tuple([r]), r ][type(r) is tuple] </code></pre> <p>the second thing i like to use <code>tuple([1])</code>. think it is a matter of taste...
0
2010-01-21T18:29:56Z
[ "python", "tuples" ]
What's the best practice for handling single-value tuples in Python?
2,111,759
<p>I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particular...
6
2010-01-21T18:22:22Z
2,111,825
<p>Rather than checking for a length of 1, I'd use the isinstance built-in instead.</p> <pre><code>&gt;&gt;&gt; isinstance('a_str', tuple) False &gt;&gt;&gt; isinstance(('str1', 'str2', 'str3'), tuple) True </code></pre>
1
2010-01-21T18:31:50Z
[ "python", "tuples" ]
What's the best practice for handling single-value tuples in Python?
2,111,759
<p>I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particular...
6
2010-01-21T18:22:22Z
2,111,832
<p>For your first problem, I'm not really sure if this is the best answer, but I think you need to check yourself whether the returned value is a string or tuple and act accordingly. </p> <p>As for your second problem, any variable can be turned into a single valued tuple by placing a <code>,</code> next to it:</p> <...
6
2010-01-21T18:33:15Z
[ "python", "tuples" ]
What's the best practice for handling single-value tuples in Python?
2,111,759
<p>I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particular...
6
2010-01-21T18:22:22Z
2,111,864
<p>You need to somehow test for the type, if it's a string or a tuple. I'd do it like this:</p> <pre><code>keywords = library.get_keywords() if not isinstance(keywords, tuple): keywords = (keywords,) # Note the comma for keyword in keywords: do_your_thang(keyword) </code></pre>
11
2010-01-21T18:37:04Z
[ "python", "tuples" ]
What's the best practice for handling single-value tuples in Python?
2,111,759
<p>I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particular...
6
2010-01-21T18:22:22Z
2,111,899
<p>Your <code>tuple_maker</code> doesn't do what you think it does. An equivalent definition of <code>tuple maker</code> to yours is</p> <pre><code>def tuple_maker(input): return input </code></pre> <p>What you're seeing is that <code>tuple_maker("a string")</code> returns a string, while <code>tuple_maker(["str1...
1
2010-01-21T18:42:25Z
[ "python", "tuples" ]
What's the best practice for handling single-value tuples in Python?
2,111,759
<p>I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particular...
6
2010-01-21T18:22:22Z
2,112,088
<p>Is it absolutely necessary that it returns tuples, or will any iterable do?</p> <pre><code>import collections def iterate(keywords): if not isinstance(keywords, collections.Iterable): yield keywords else: for keyword in keywords: yield keyword for keyword in iterate(library.get...
1
2010-01-21T19:12:43Z
[ "python", "tuples" ]
What's the best practice for handling single-value tuples in Python?
2,111,759
<p>I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particular...
6
2010-01-21T18:22:22Z
2,113,291
<p>There's always monkeypatching!</p> <pre><code># Store a reference to the real library function really_get_keywords = library.get_keywords # Define out patched version of the function, which uses the real # version above, adjusting its return value as necessary def patched_get_keywords(): """Make sure we always...
2
2010-01-21T22:03:23Z
[ "python", "tuples" ]
Problem when using python logging in django and unicode
2,111,765
<p>totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a <strong>unicode</strong>()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could ...
7
2010-01-21T18:22:58Z
2,112,485
<p>I don't understand what it is you don't understand, if you see what I mean. Your middle paragraph: </p> <blockquote> <p>So, my understanding is that the list starts to generate itself and does repr() on all its elements and they return their values - in this case it should be 's2 | ÅÄÖÖ', then the list presen...
0
2010-01-21T20:10:10Z
[ "python", "django", "logging", "unicode", "decoding" ]
Problem when using python logging in django and unicode
2,111,765
<p>totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a <strong>unicode</strong>()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could ...
7
2010-01-21T18:22:58Z
2,112,545
<p>I can't reproduce your problem with a simple test:</p> <pre> Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> group = u'Luleå' >>> logging.warning('Group: %s', group) WARNING:root:Group: Luleå >>> ...
1
2010-01-21T20:18:49Z
[ "python", "django", "logging", "unicode", "decoding" ]
Problem when using python logging in django and unicode
2,111,765
<p>totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a <strong>unicode</strong>()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could ...
7
2010-01-21T18:22:58Z
2,116,284
<p>I ended following advice as answered and going over all code and doing list comprehension or similar when trying to log a set/list/dict/django queryset. So adapting and adding things like this solved it for me:</p> <pre><code>logging.debug(u"new groups: %s" % [unicode(g) for g in list_of_groups]) </code></pre> <p>...
0
2010-01-22T09:36:30Z
[ "python", "django", "logging", "unicode", "decoding" ]
Problem when using python logging in django and unicode
2,111,765
<p>totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a <strong>unicode</strong>()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could ...
7
2010-01-21T18:22:58Z
2,779,255
<p>Try to use this code in the top of your views.py</p> <pre><code>#-*- coding: utf-8 -*- ... </code></pre>
1
2010-05-06T07:30:10Z
[ "python", "django", "logging", "unicode", "decoding" ]
Problem when using python logging in django and unicode
2,111,765
<p>totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a <strong>unicode</strong>()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could ...
7
2010-01-21T18:22:58Z
3,455,890
<p>have you tried manually making any result unicode?</p> <pre><code>logging.debug(u'new groups %s' % unicode(list_of_groups("UTF-8")) </code></pre>
0
2010-08-11T06:42:54Z
[ "python", "django", "logging", "unicode", "decoding" ]
Problem when using python logging in django and unicode
2,111,765
<p>totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a <strong>unicode</strong>()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could ...
7
2010-01-21T18:22:58Z
3,731,817
<p>Here's my test code:</p> <pre><code>#-*- coding: utf-8 -*- class Wrap: def __init__(self, s): self.s = s def __repr__(self): return repr(self.s) def __unicode__(self): return unicode(self.s) def __str__(self): return...
2
2010-09-17T00:11:55Z
[ "python", "django", "logging", "unicode", "decoding" ]
Problem when using python logging in django and unicode
2,111,765
<p>totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a <strong>unicode</strong>()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could ...
7
2010-01-21T18:22:58Z
12,533,050
<p>I encountered the same issues: see <a href="http://hustoknow.blogspot.com/2012/09/unicode-quirks-in-django.html" rel="nofollow">http://hustoknow.blogspot.com/2012/09/unicode-quirks-in-django.html</a>.</p> <p>You can declare a <strong>str</strong>() method to override the Django default behavior, which will help to ...
0
2012-09-21T14:58:24Z
[ "python", "django", "logging", "unicode", "decoding" ]
Math functions as well as flags
2,111,945
<pre><code>from django.db import models from django.contrib.auth.models import User class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 30) lot_no = models.CharField(max_length = 30) inventory = models.IntegerField() commited = mo...
1
2010-01-21T18:49:08Z
2,112,443
<p>I don't understand your last sentence, but for the rest of it, showing a calculated field in the admin list_display is easy - just create a method on the model or the admin. In your case, the easiest thing is to drop the existing 'available' field and use a model method marked as a property.</p> <pre><code>@propert...
0
2010-01-21T20:04:55Z
[ "python", "django-admin" ]
Math functions as well as flags
2,111,945
<pre><code>from django.db import models from django.contrib.auth.models import User class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 30) lot_no = models.CharField(max_length = 30) inventory = models.IntegerField() commited = mo...
1
2010-01-21T18:49:08Z
2,112,906
<p>for example if reorder is &lt;= available than the reorder integerfield would come up as a red flag saying you need to reorder or something of the sort.</p>
0
2010-01-21T21:06:32Z
[ "python", "django-admin" ]
Am I doing these unit tests right?
2,112,014
<p>I'm new to unit tests for my own projects, so this is my first attempt to write a unit test from scratch. I'm using python, and the unittest module. The TodoList class being tested here is a wrapper for actual lists, with a few extra methods for stuff like saving to disc. It also defines a few methods for getting it...
2
2010-01-21T19:01:33Z
2,112,349
<p>I think that you are going in the right way. But I will send some suggestions;</p> <ul> <li>Move the <code>self.testdata.close()</code> from <code>setUp()</code> to the <code>tearDown()</code> function.</li> <li>Surround the others open/close with try/finally blocks. So, if a file didn't open with success it will b...
2
2010-01-21T19:50:57Z
[ "python", "unit-testing" ]
Am I doing these unit tests right?
2,112,014
<p>I'm new to unit tests for my own projects, so this is my first attempt to write a unit test from scratch. I'm using python, and the unittest module. The TodoList class being tested here is a wrapper for actual lists, with a few extra methods for stuff like saving to disc. It also defines a few methods for getting it...
2
2010-01-21T19:01:33Z
2,112,352
<p>No, it doesn't quite look like you are. Unit tests should be small, fast, and uncomplicated. Doing 'complicated' tests (anything that relies on an external database, file system, configuration, environment, or really anything outside the test itself and the code being tested) is valuable, but shouldn't be a part of ...
1
2010-01-21T19:51:21Z
[ "python", "unit-testing" ]
How to encrypt a string in Python and decrypt that same string in PHP?
2,112,274
<p>I have a string that I would like to encrypt in Python, store it as a cookie, then in a PHP file I'd like to retrieve that cookie, and decrypt it in PHP. How would I go about doing this?</p> <hr> <p>I appreciate the fast responses.</p> <p>All cookie talk aside, lets just say I want to encrypt a string in Python a...
4
2010-01-21T19:38:58Z
2,112,306
<p>Well, my first thought would be to use a web server that uses SSL and set the cookie's secure property to true, meaning that it will only be served over SSL connections.</p> <p>However, I'm aware that this probably isn't what you're looking for.</p>
0
2010-01-21T19:44:24Z
[ "php", "python" ]
How to encrypt a string in Python and decrypt that same string in PHP?
2,112,274
<p>I have a string that I would like to encrypt in Python, store it as a cookie, then in a PHP file I'd like to retrieve that cookie, and decrypt it in PHP. How would I go about doing this?</p> <hr> <p>I appreciate the fast responses.</p> <p>All cookie talk aside, lets just say I want to encrypt a string in Python a...
4
2010-01-21T19:38:58Z
2,112,319
<p>Use a standard encryption scheme. The implementation is going to be equivalent in either language.</p> <p><a href="http://en.wikipedia.org/wiki/RSA">RSA</a> is available (via third party libraries) in both languages, if you need asymmetric key crypto. So is <a href="http://en.wikipedia.org/wiki/Advanced_Encryptio...
7
2010-01-21T19:46:39Z
[ "php", "python" ]
How to encrypt a string in Python and decrypt that same string in PHP?
2,112,274
<p>I have a string that I would like to encrypt in Python, store it as a cookie, then in a PHP file I'd like to retrieve that cookie, and decrypt it in PHP. How would I go about doing this?</p> <hr> <p>I appreciate the fast responses.</p> <p>All cookie talk aside, lets just say I want to encrypt a string in Python a...
4
2010-01-21T19:38:58Z
2,112,331
<p>If you're not talking about <strong>encryption</strong> but <strong>encoding</strong> to make sure the contents make it through safely regardless of quoting issues, special characters, and line breaks, I think base64 encoding is your best bet. PHP has base64_encode / decode() out of the box, and I'm sure Python has,...
1
2010-01-21T19:48:08Z
[ "php", "python" ]
How to encrypt a string in Python and decrypt that same string in PHP?
2,112,274
<p>I have a string that I would like to encrypt in Python, store it as a cookie, then in a PHP file I'd like to retrieve that cookie, and decrypt it in PHP. How would I go about doing this?</p> <hr> <p>I appreciate the fast responses.</p> <p>All cookie talk aside, lets just say I want to encrypt a string in Python a...
4
2010-01-21T19:38:58Z
2,112,415
<p>There is a good example here:<br> <a href="http://www.codekoala.com/blog/2009/aes-encryption-python-using-pycrypto/">http://www.codekoala.com/blog/2009/aes-encryption-python-using-pycrypto/</a></p> <p>Other links that may help:<br> <a href="http://www.phpclasses.org/browse/package/4238.html">http://www.phpclasses.o...
5
2010-01-21T20:02:09Z
[ "php", "python" ]
Python 2.x vs 3.x Speed
2,112,298
<p>I'm a PhD student and use Python to write the code I use for my research. My workflow often consists of making a small change to the code, running the program, seeing whether the results improved, and repeating the process. Because of this, I find myself spending more time waiting for my program to run than I do ...
35
2010-01-21T19:43:17Z
2,112,332
<p>I can't answer the root of your question, but if you read anything regarding the sluggish performance of the io module please disregard it. The were definitely performance issues in Python 3.0, but they were largely resolved in Python 3.1.</p>
2
2010-01-21T19:48:50Z
[ "python", "performance" ]
Python 2.x vs 3.x Speed
2,112,298
<p>I'm a PhD student and use Python to write the code I use for my research. My workflow often consists of making a small change to the code, running the program, seeing whether the results improved, and repeating the process. Because of this, I find myself spending more time waiting for my program to run than I do ...
35
2010-01-21T19:43:17Z
2,112,375
<p><a href="https://web.archive.org/web/20131028122438/http://mikewatkins.ca/2008/12/06/python-3-performance-a-red-herring/" rel="nofollow">This article (archive.org)</a> said that there were a few points where Python 3.0 was actually slower than Python 2.6, though I think many of these issues were resolved. That bein...
22
2010-01-21T19:54:43Z
[ "python", "performance" ]
Python 2.x vs 3.x Speed
2,112,298
<p>I'm a PhD student and use Python to write the code I use for my research. My workflow often consists of making a small change to the code, running the program, seeing whether the results improved, and repeating the process. Because of this, I find myself spending more time waiting for my program to run than I do ...
35
2010-01-21T19:43:17Z
2,112,731
<p>Right now, speed on Python 3 is more or less the same as Python 2... If you're looking for speed, it's not on Python 3 vs Python 2 but in other tools like Psyco, Cython, etc...</p> <p><strong>But,</strong> very recently, there have arisen plans to merge Unladen Swallow, the Google project to implement a JIT over Py...
5
2010-01-21T20:43:07Z
[ "python", "performance" ]
Python 2.x vs 3.x Speed
2,112,298
<p>I'm a PhD student and use Python to write the code I use for my research. My workflow often consists of making a small change to the code, running the program, seeing whether the results improved, and repeating the process. Because of this, I find myself spending more time waiting for my program to run than I do ...
35
2010-01-21T19:43:17Z
2,112,852
<p>I have phylogenetics analysis that takes a long time to run, and uses about a half-dozen python scripts as well as other bioinformatics software (muscle, clustal, blast, even R!). I use temp files to save intermediate results and a master script with the subprocess module to glue all the pieces together. It's easy...
2
2010-01-21T20:58:54Z
[ "python", "performance" ]
Python 2.x vs 3.x Speed
2,112,298
<p>I'm a PhD student and use Python to write the code I use for my research. My workflow often consists of making a small change to the code, running the program, seeing whether the results improved, and repeating the process. Because of this, I find myself spending more time waiting for my program to run than I do ...
35
2010-01-21T19:43:17Z
2,115,650
<p>Try refining the algorithms or changing the data structures used. That's usually the best way to get an increase in performance.</p>
3
2010-01-22T07:12:55Z
[ "python", "performance" ]
In Python in Google App Engine, how do you capture output produced by the print statement?
2,112,396
<p>I am working in the Google Application Engine environment where I am loading doctests and python code from strings to test Python homework assignments. My basic implementation (<a href="http://stackoverflow.com/questions/1310254/what-is-the-best-way-to-create-a-python-object-when-you-have-the-class-implementa">Provi...
0
2010-01-21T19:58:17Z
2,112,456
<p>For this problem I like to capture the string output directly. Inside your function I would use something like:</p> <pre><code>import StringIO, sys # create file-like string to capture output codeOut = StringIO.StringIO() # capture output and errors sys.stdout = codeOut err = '' try : exec code in code_na...
4
2010-01-21T20:07:47Z
[ "python", "google-app-engine" ]
In Python in Google App Engine, how do you capture output produced by the print statement?
2,112,396
<p>I am working in the Google Application Engine environment where I am loading doctests and python code from strings to test Python homework assignments. My basic implementation (<a href="http://stackoverflow.com/questions/1310254/what-is-the-best-way-to-create-a-python-object-when-you-have-the-class-implementa">Provi...
0
2010-01-21T19:58:17Z
2,113,221
<p>I think <a href="http://stackoverflow.com/questions/2112396/in-python-in-google-app-engine-how-do-you-capture-output-produced-by-the-print-s/2112456#2112456">Hooked has the right answer</a>, but I think you'd be better off storing the value of <code>sys.stdout</code> before you modify it and restoring <em>that</em> ...
5
2010-01-21T21:52:40Z
[ "python", "google-app-engine" ]