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
What's the quickest way for a Ruby programmer to pick up Python?
846,139
<p>I've been programming Ruby pretty extensively for the past four years or so, and I'm extremely comfortable with the language. For no particular reason, I've decided to learn some Python this week. Is there a specific book, tutorial, or reference that would be well-suited to someone coming from a nearly-identical lan...
10
2009-05-10T21:25:18Z
846,168
<p>After running through some tutorials on-line (the ones posted so far look pretty good), find a current Ruby project you've done (or are working on) and re-write it in Python. I've used this technique to transition from various languages, and it's helped enormously.</p>
3
2009-05-10T21:37:33Z
[ "python", "ruby" ]
I get "parent_id may not be NULL" when creating my Django model
846,298
<p>I'm creating my own <code>Group</code> model; I'm not referring to the builtin <code>Group</code> model. I want each hroup to be a member of another group (it's parent), but there is the one "top" group that doesn't have a parent group.</p> <p>The admin interface won't let me create a group without entering a paren...
4
2009-05-10T23:19:12Z
846,858
<p>I created the database before I added <strong><code>blank=True, null=True</code></strong> to the <strong><code>parent</code></strong> field definition. syncdb can't deal with that type of change, so Django wasn't picking up on my changes.</p> <p>I deleted my database and let syncdb create another and it worked fine...
6
2009-05-11T05:48:28Z
[ "python", "database", "django", "models" ]
I get "parent_id may not be NULL" when creating my Django model
846,298
<p>I'm creating my own <code>Group</code> model; I'm not referring to the builtin <code>Group</code> model. I want each hroup to be a member of another group (it's parent), but there is the one "top" group that doesn't have a parent group.</p> <p>The admin interface won't let me create a group without entering a paren...
4
2009-05-10T23:19:12Z
18,942,663
<p>Django evolution would get you out of this kind of problem without dropping your complete database </p>
0
2013-09-22T10:08:31Z
[ "python", "database", "django", "models" ]
Snapshot Movies
846,343
<p>I'm currently learning Python and have taken up several small projects to help learn the language. Are there currently any libraries (possibly PythonMagick) out there that are capable of extracting snapshots from .wmv, .avi, .mpg, or other movie formats with only command-line options (no GUI)? And if so, can anyon...
1
2009-05-11T00:07:07Z
846,373
<p>A quick search in google revealed <a href="http://pymedia.org/tut/" rel="nofollow">pymedia</a>. It supports avi, dvd, wma, ...</p> <p>Here is an <a href="http://pymedia.org/tut/src/dump%5Fvideo.py.html" rel="nofollow">example</a> on how to get snapshots from videos</p>
1
2009-05-11T00:36:22Z
[ "python", "screenshot", "snapshot", "movie" ]
Snapshot Movies
846,343
<p>I'm currently learning Python and have taken up several small projects to help learn the language. Are there currently any libraries (possibly PythonMagick) out there that are capable of extracting snapshots from .wmv, .avi, .mpg, or other movie formats with only command-line options (no GUI)? And if so, can anyon...
1
2009-05-11T00:07:07Z
846,392
<p>Additionally, if the CLI situation is not mandatory <a href="http://www.pyglet.org" rel="nofollow">Pyglet</a> is exceptionally easy to use to load movies, images, etc. and is very well documented.</p>
0
2009-05-11T00:48:18Z
[ "python", "screenshot", "snapshot", "movie" ]
Problem installing pyscopg2 on Mac OS X
846,383
<p>I have downloaded the latest build of pyscopg2 and have tried to build and install it using the directions provided. However i always get an error saying that 'w' is undeclared. Does anybody have any experience with this? </p>
3
2009-05-11T00:41:23Z
846,403
<p>This is an error that crops up when the build tools cannot find your Postgresql libraries. It means one of three things:</p> <ol> <li><p>You don't have postgresql installed on your system. If so, download and build postgres, or download a pre-built psycopg2 binary for OS X.</p></li> <li><p>You have postgresql insta...
11
2009-05-11T00:55:08Z
[ "python", "database", "django", "osx" ]
Problem installing pyscopg2 on Mac OS X
846,383
<p>I have downloaded the latest build of pyscopg2 and have tried to build and install it using the directions provided. However i always get an error saying that 'w' is undeclared. Does anybody have any experience with this? </p>
3
2009-05-11T00:41:23Z
6,702,874
<p>using MacPorts on Snow Leopard</p> <pre><code>pg_config=/opt/local/lib/postgresql90/bin/pg_config </code></pre>
3
2011-07-15T05:03:02Z
[ "python", "database", "django", "osx" ]
Problem installing pyscopg2 on Mac OS X
846,383
<p>I have downloaded the latest build of pyscopg2 and have tried to build and install it using the directions provided. However i always get an error saying that 'w' is undeclared. Does anybody have any experience with this? </p>
3
2009-05-11T00:41:23Z
26,741,878
<p>I needed to install the psycopg2 library only in a virtualenv without adding it to the root python and I didn't want to fully install postgreSQL on my local machine so I came up with this solution which seems to work really well. </p> <ol> <li><p>Download the postgres.app from <a href="http://postgresapp.com" rel=...
0
2014-11-04T18:00:36Z
[ "python", "database", "django", "osx" ]
Is there a mod_python for Apache HTTP Server 2.2 and Python 2.6 or 3.0?
846,420
<p>I poked around the <a href="http://www.modpython.org/" rel="nofollow">mod_python website</a> and I only found the files for Python 2.5 and earlier for Apache HTTP Server 2.2. I Googled around a little, without significant luck. Any suggestions?</p>
2
2009-05-11T01:12:37Z
846,430
<p>Use mod_wsgi.</p> <p>mod_python has been stagnant for a while now. Most of the effort for python web apps has been going into mod_wsgi.</p>
9
2009-05-11T01:17:51Z
[ "python", "apache2", "mod-python" ]
Modelling a swiss tournament in Django
846,485
<p>I'm trying to create models that represent a <a href="http://en.wikipedia.org/wiki/Swiss%5Ftournament" rel="nofollow">swiss tournament</a>, with multiple rounds. Each round everyone will be paired up with another player, except in the case where there is an odd player out, when one player will get a bye. </p> <p>I ...
2
2009-05-11T01:55:17Z
846,511
<p>I think you should have just a single player list and not split it into player1 and player2, those can be constructed when a round is set up.</p> <p>Your player class could include a list of players they have played, and the last player on that list would be the current player they are facing. When you pick the nex...
1
2009-05-11T02:13:36Z
[ "python", "django", "django-models" ]
Modelling a swiss tournament in Django
846,485
<p>I'm trying to create models that represent a <a href="http://en.wikipedia.org/wiki/Swiss%5Ftournament" rel="nofollow">swiss tournament</a>, with multiple rounds. Each round everyone will be paired up with another player, except in the case where there is an odd player out, when one player will get a bye. </p> <p>I ...
2
2009-05-11T01:55:17Z
846,870
<p>You can refactor your TournamentPairing class to be more "round" centric to aid in making queries.</p> <p>CHOICES = ( ('n', 'Normal'), ('b', 'Bye'), )</p> <pre><code>class Round(models.Model): number = models.IntegerField() round_type = models.CharField(max_length=1, default="n", choice...
5
2009-05-11T05:55:21Z
[ "python", "django", "django-models" ]
A ListView of checkboxes in PyQt
846,684
<p>I want to display a QListView where each item is a checkbox with some label. The checkboxes should be visible at all times. One way I can think of is using a custom delegate and QAbstractListModel. Are there simpler ways? Can you provide the simplest snippet that does this?</p> <p>Thanks in advance</p>
9
2009-05-11T04:02:36Z
854,535
<p>See my reply to your question on the PyQt mailing list:</p> <p><a href="http://www.riverbankcomputing.com/pipermail/pyqt/2009-May/023002.html">http://www.riverbankcomputing.com/pipermail/pyqt/2009-May/023002.html</a></p> <p>Summary: You need to use the ItemIsUserCheckable flag and CheckStateRole role.</p>
9
2009-05-12T19:49:48Z
[ "python", "qt", "pyqt", "qitemdelegate", "qlistview" ]
A ListView of checkboxes in PyQt
846,684
<p>I want to display a QListView where each item is a checkbox with some label. The checkboxes should be visible at all times. One way I can think of is using a custom delegate and QAbstractListModel. Are there simpler ways? Can you provide the simplest snippet that does this?</p> <p>Thanks in advance</p>
9
2009-05-11T04:02:36Z
855,938
<p>I ended up using the method provided by <a href="http://stackoverflow.com/users/61047/david-boddie">David Boddie</a> in the PyQt mailing list. Here's a working snippet based on his code:</p> <pre><code>from PyQt4.QtCore import * from PyQt4.QtGui import * import sys from random import randint app = QApplication(sy...
21
2009-05-13T03:34:00Z
[ "python", "qt", "pyqt", "qitemdelegate", "qlistview" ]
Read Unicode characters from command-line arguments in Python 2.x on Windows
846,850
<p>I want my Python script to be able to read Unicode command line arguments in Windows. But it appears that sys.argv is a string encoded in some local encoding, rather than Unicode. How can I read the command line in full Unicode?</p> <p>Example code: <code>argv.py</code></p> <pre><code>import sys first_arg = sys.a...
24
2009-05-11T05:44:02Z
846,873
<p>The command line might be in Windows encoding. Try decoding the arguments into <code>unicode</code> objects:</p> <pre><code>args = [unicode(x, "iso-8859-9") for x in sys.argv] </code></pre>
0
2009-05-11T05:57:07Z
[ "python", "windows", "command-line", "unicode", "python-2.x" ]
Read Unicode characters from command-line arguments in Python 2.x on Windows
846,850
<p>I want my Python script to be able to read Unicode command line arguments in Windows. But it appears that sys.argv is a string encoded in some local encoding, rather than Unicode. How can I read the command line in full Unicode?</p> <p>Example code: <code>argv.py</code></p> <pre><code>import sys first_arg = sys.a...
24
2009-05-11T05:44:02Z
846,877
<p>Try this:</p> <pre><code>import sys print repr(sys.argv[1].decode('UTF-8')) </code></pre> <p>Maybe you have to substitute <code>CP437</code> or <code>CP1252</code> for <code>UTF-8</code>. You should be able to infer the proper encoding name from the registry key <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Co...
2
2009-05-11T05:58:33Z
[ "python", "windows", "command-line", "unicode", "python-2.x" ]
Read Unicode characters from command-line arguments in Python 2.x on Windows
846,850
<p>I want my Python script to be able to read Unicode command line arguments in Windows. But it appears that sys.argv is a string encoded in some local encoding, rather than Unicode. How can I read the command line in full Unicode?</p> <p>Example code: <code>argv.py</code></p> <pre><code>import sys first_arg = sys.a...
24
2009-05-11T05:44:02Z
846,931
<p>Here is a solution that is just what I'm looking for, making a call to the Windows <code>GetCommandLineArgvW </code> function:<br> <a href="http://code.activestate.com/recipes/572200/">Get sys.argv with Unicode characters under Windows</a> (from ActiveState)</p> <p>But I've made several changes, to simplify its usa...
24
2009-05-11T06:21:59Z
[ "python", "windows", "command-line", "unicode", "python-2.x" ]
Read Unicode characters from command-line arguments in Python 2.x on Windows
846,850
<p>I want my Python script to be able to read Unicode command line arguments in Windows. But it appears that sys.argv is a string encoded in some local encoding, rather than Unicode. How can I read the command line in full Unicode?</p> <p>Example code: <code>argv.py</code></p> <pre><code>import sys first_arg = sys.a...
24
2009-05-11T05:44:02Z
847,114
<p>Dealing with encodings is very confusing.</p> <p>I <em>believe</em> if your inputing data via the commandline it will encode the data as whatever your system encoding is and is not unicode. (Even copy/paste should do this)</p> <p>So it should be correct to decode into unicode using the system encoding:</p> <pre><...
10
2009-05-11T07:45:24Z
[ "python", "windows", "command-line", "unicode", "python-2.x" ]
Parsing in Python: what's the most efficient way to supress/normalize strings?
846,869
<p>I'm parsing a source file, and I want to "suppress" strings. What I mean by this is transform every string like "bla bla bla +/*" to something like "string" that is deterministic and does not contain any characters that may confuse my parser, because I don't care about the value of the strings. One of the issues her...
0
2009-05-11T05:55:03Z
846,886
<p>Option 1: To sanitize Python source code, try the built-in <a href="http://docs.python.org/library/tokenize.html" rel="nofollow">tokenize</a> module. It can correctly find strings and other tokens in any Python source file.</p> <p>Option 3: Use <a href="http://pygments.org/languages/" rel="nofollow">pygments</a> wi...
4
2009-05-11T06:01:22Z
[ "python", "string", "parsing" ]
Parsing in Python: what's the most efficient way to supress/normalize strings?
846,869
<p>I'm parsing a source file, and I want to "suppress" strings. What I mean by this is transform every string like "bla bla bla +/*" to something like "string" that is deterministic and does not contain any characters that may confuse my parser, because I don't care about the value of the strings. One of the issues her...
0
2009-05-11T05:55:03Z
846,900
<p>Nowhere do you mention that you take an approach using a <a href="http://en.wikipedia.org/wiki/Lexical%5Fanalysis" rel="nofollow">lexer</a> and <a href="http://en.wikipedia.org/wiki/Parsing" rel="nofollow">parser</a>. If in fact you do not, have a look at e.g. the <a href="http://docs.python.org/library/tokenize.htm...
1
2009-05-11T06:06:40Z
[ "python", "string", "parsing" ]
Parsing in Python: what's the most efficient way to supress/normalize strings?
846,869
<p>I'm parsing a source file, and I want to "suppress" strings. What I mean by this is transform every string like "bla bla bla +/*" to something like "string" that is deterministic and does not contain any characters that may confuse my parser, because I don't care about the value of the strings. One of the issues her...
0
2009-05-11T05:55:03Z
846,905
<p><strong>Use a dedicated parser for each language</strong> — especially since people have already done that work for you. Most of the languages you mentioned have a grammar.</p>
1
2009-05-11T06:08:02Z
[ "python", "string", "parsing" ]
Is Twisted an httplib2/socket replacement?
846,950
<p>Many python libraries, even recently written ones, use httplib2 or the socket interface to perform networking tasks.</p> <p>Those are obviously easier to code on than Twisted due to their blocking nature, but I think this is a drawback when integrating them with other code, especially GUI one. If you want scalabili...
6
2009-05-11T06:30:44Z
846,984
<p>See <a href="http://stackoverflow.com/questions/80617/asychronous-programming-in-python-twisted">asychronous-programming-in-python-twisted</a>, you'll have to decide if depending on a non-standard (external) library fits your needs. Note the answer by <a href="http://stackoverflow.com/users/13564/glyph">@Glyph</a>, ...
5
2009-05-11T06:46:53Z
[ "python", "networking", "sockets", "twisted", "httplib2" ]
Is Twisted an httplib2/socket replacement?
846,950
<p>Many python libraries, even recently written ones, use httplib2 or the socket interface to perform networking tasks.</p> <p>Those are obviously easier to code on than Twisted due to their blocking nature, but I think this is a drawback when integrating them with other code, especially GUI one. If you want scalabili...
6
2009-05-11T06:30:44Z
847,014
<ol> <li>Should new networking code (with the exception of small command line tools) be written with Twisted? <ul> <li>Maybe. It really depends. Sometimes its just easy enough to wrap the blocking calls in their own thread. Twisted is good for large scale network code.</li> </ul></li> <li>Would you mix Twisted, http2li...
0
2009-05-11T06:58:25Z
[ "python", "networking", "sockets", "twisted", "httplib2" ]
Python equivalent of perl's dbi/DBD::Proxy access? (Perl DBI/DBD::Proxy for Python)
847,032
<p>I have a Perl script that interfaces with an existing database (type of database is unknown) through the DBI module, that I would like to access in python 2.6 on WinXP.</p> <p>The Perl code is:</p> <pre><code>use DBI; my $DSN = "DBI:Proxy:hostname=some.dot.com;port=12345;dsn=DBI:XXXX:ZZZZZ"; my $dbh = DBI-&gt;conn...
0
2009-05-11T07:08:27Z
847,190
<p>Your python script doesn't have to be a line by line translation of your Perl script.</p> <p>Why not just use the Python <a href="http://www.python.org/dev/peps/pep-0249/" rel="nofollow">DB-API</a> compatible module for the database you want to access? For MySQL, use <a href="http://mysql-python.sourceforge.net/My...
5
2009-05-11T08:26:00Z
[ "python", "perl", "odbc", "dbi" ]
Python equivalent of perl's dbi/DBD::Proxy access? (Perl DBI/DBD::Proxy for Python)
847,032
<p>I have a Perl script that interfaces with an existing database (type of database is unknown) through the DBI module, that I would like to access in python 2.6 on WinXP.</p> <p>The Perl code is:</p> <pre><code>use DBI; my $DSN = "DBI:Proxy:hostname=some.dot.com;port=12345;dsn=DBI:XXXX:ZZZZZ"; my $dbh = DBI-&gt;conn...
0
2009-05-11T07:08:27Z
852,703
<p><a href="http://www.sqlalchemy.org/" rel="nofollow">sqlalchemy</a> is pretty nice.</p>
0
2009-05-12T13:13:43Z
[ "python", "perl", "odbc", "dbi" ]
Importing a python module to .net - "No module named signal"
847,109
<p>I'm trying to import a Python module in a C# code like this:</p> <pre><code> var setup = Python.CreateRuntimeSetup(null); var runtime = new ScriptRuntime(setup); var engine = Python.GetEngine(runtime); var module = engine.ImportModule("mymodule"); </code></pre> <p>but I get an error ...
1
2009-05-11T07:43:22Z
847,230
<p>The 'signal' module is used to handle all that has to do with ... you guessed it: signals. There are special "messages" that the OS send to a process to tell it something: eg. Break, Kill, Terminate, etc... The exact set of message are generally OS specific, but as the <a href="http://docs.python.org/library/signal....
1
2009-05-11T08:44:30Z
[ ".net", "python", "ironpython" ]
Is there an ipython equivalent for erlang?
847,151
<p>Coming from Python I am looking for some "easy to try out" shell like Python has with <code>ipython</code> (preferably with Emacs support). In the Erlang shell you always have to first compile (<code>c(...)</code>) which slows down the experimental phase very much.</p>
5
2009-05-11T08:07:52Z
847,576
<p>Yes it is :) <a href="http://erlang.org/doc/man/escript.html" rel="nofollow">http://erlang.org/doc/man/escript.html</a></p> <pre><code>$ cat /tmp/test #!/usr/bin/env escript main(_) -&gt; io:format("Hello World!\n"). $ chmod +x /tmp/test $ /tmp/test Hello World! </code></pre>
3
2009-05-11T10:43:10Z
[ "python", "emacs", "erlang", "ipython" ]
Is there an ipython equivalent for erlang?
847,151
<p>Coming from Python I am looking for some "easy to try out" shell like Python has with <code>ipython</code> (preferably with Emacs support). In the Erlang shell you always have to first compile (<code>c(...)</code>) which slows down the experimental phase very much.</p>
5
2009-05-11T08:07:52Z
860,807
<p>It should be fairly easy to build a module the starts a process to autoload code changes into your shell. Erlang actually has built in support for this kind of thing. So anytime you have recompiled the code it gets loaded into your shell automatically thus eliminating the need to type c('module.erl'). yourself. You ...
1
2009-05-13T22:49:06Z
[ "python", "emacs", "erlang", "ipython" ]
Is there an ipython equivalent for erlang?
847,151
<p>Coming from Python I am looking for some "easy to try out" shell like Python has with <code>ipython</code> (preferably with Emacs support). In the Erlang shell you always have to first compile (<code>c(...)</code>) which slows down the experimental phase very much.</p>
5
2009-05-11T08:07:52Z
24,341,588
<p>IErlang is an Erlang language kernel for IPython. It allows users to use IPython's Notebook frontend, except where IPython executes python code, IErlang can execute erlang code and compile and execute erlang modules.</p> <p><a href="https://github.com/robbielynch/ierlang" rel="nofollow">https://github.com/robbielyn...
1
2014-06-21T12:27:21Z
[ "python", "emacs", "erlang", "ipython" ]
User-defined derived data in Django
847,201
<p>How do I let my users apply their own custom formula to a table of data to derive new fields?</p> <p>I am working on a <a href="http://www.djangoproject.com" rel="nofollow">Django</a> application which is going to store and process a lot of data for subscribed users on the open web. Think 100-10,000 sensor readings...
2
2009-05-11T08:32:27Z
847,223
<p>Another user asked a <a href="http://stackoverflow.com/questions/28124/calculating-user-defined-formulas-with-c">similar question</a> in C. In that post, Warren suggested that the formula could be parsed and converted from </p> <pre><code>(a + c) / b </code></pre> <p>Into <a href="http://en.wikipedia.org/wiki/Rev...
0
2009-05-11T08:41:14Z
[ "python", "django", "user-defined-functions" ]
User-defined derived data in Django
847,201
<p>How do I let my users apply their own custom formula to a table of data to derive new fields?</p> <p>I am working on a <a href="http://www.djangoproject.com" rel="nofollow">Django</a> application which is going to store and process a lot of data for subscribed users on the open web. Think 100-10,000 sensor readings...
2
2009-05-11T08:32:27Z
847,408
<p>I would work out what operations you want to support [+,-,*,/,(,),etc] and develop client side (javascript) to edit and apply those values to new fields of the data. I don't see the need to do any of this server-side and you will end up with a more responsive and enjoyable user experience as a result.</p> <p>If you...
2
2009-05-11T09:44:18Z
[ "python", "django", "user-defined-functions" ]
User-defined derived data in Django
847,201
<p>How do I let my users apply their own custom formula to a table of data to derive new fields?</p> <p>I am working on a <a href="http://www.djangoproject.com" rel="nofollow">Django</a> application which is going to store and process a lot of data for subscribed users on the open web. Think 100-10,000 sensor readings...
2
2009-05-11T08:32:27Z
847,566
<p>Depends on who your clients are.</p> <p>If this is "open to the public" on the WWW, you have to parse expressions yourself. You can use the Python compiler to compile Python syntax. You can also invent your own compiler for a subset of Python syntax. There are lots of examples; start with the <a href="http://www...
2
2009-05-11T10:41:43Z
[ "python", "django", "user-defined-functions" ]
Cross-platform way of getting temp directory in Python
847,850
<p>Is there a cross-platform way of getting the path to the <em><code>temp</code></em> directory in Python 2.6? </p> <p>For example, under Linux that would be <code>/tmp</code>, while under XP <code>C:\Documents and settings\[user]\Application settings\Temp</code>.</p> <p>Thanks!</p>
123
2009-05-11T12:21:46Z
847,866
<p>That would be the <a href="http://docs.python.org/library/tempfile.html">tempfile</a> module.</p> <p>It has functions to get the temporary directory, and also has some shortcuts to create temporary files and directories in it, either named or unnamed.</p> <p>Example:</p> <pre><code>import tempfile print tempfile...
189
2009-05-11T12:25:18Z
[ "python", "cross-platform", "temporary-directory" ]
Cross-platform way of getting temp directory in Python
847,850
<p>Is there a cross-platform way of getting the path to the <em><code>temp</code></em> directory in Python 2.6? </p> <p>For example, under Linux that would be <code>/tmp</code>, while under XP <code>C:\Documents and settings\[user]\Application settings\Temp</code>.</p> <p>Thanks!</p>
123
2009-05-11T12:21:46Z
847,874
<p>This should do what you want:</p> <pre><code>print tempfile.gettempdir() </code></pre> <p>For me on my Windows box, I get:</p> <pre><code>c:\temp </code></pre> <p>and on my Linux box I get:</p> <pre><code>/tmp </code></pre>
35
2009-05-11T12:27:30Z
[ "python", "cross-platform", "temporary-directory" ]
Cross-platform way of getting temp directory in Python
847,850
<p>Is there a cross-platform way of getting the path to the <em><code>temp</code></em> directory in Python 2.6? </p> <p>For example, under Linux that would be <code>/tmp</code>, while under XP <code>C:\Documents and settings\[user]\Application settings\Temp</code>.</p> <p>Thanks!</p>
123
2009-05-11T12:21:46Z
37,147,950
<p>Taking the important bit from @nosklo's <a href="http://stackoverflow.com/a/847866/623735">answer</a> and adding a semi-private sandbox dir:</p> <pre><code>import os from tempfile import gettempdir tmp = os.path.join(gettempdir(), '.{}'.format(hash(os.times()))) os.makedirs(tmp) </code></pre> <p>That way you can e...
0
2016-05-10T20:04:20Z
[ "python", "cross-platform", "temporary-directory" ]
How to write a vb.net code to compile C/C++ programs?
847,860
<p>I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ pro...
1
2009-05-11T12:24:35Z
847,878
<p>Look at the <code>System.IO</code> namespace for clues as to how you go about loading the contents of a file into a text box. In particular, the <code>File</code> class.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.io.file.aspx" rel="nofollow">System.IO.File Class</a></p> <p>Look at the <code>Sys...
2
2009-05-11T12:29:40Z
[ "c#", "c++", "python", "c", "vb.net" ]
How to write a vb.net code to compile C/C++ programs?
847,860
<p>I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ pro...
1
2009-05-11T12:24:35Z
847,883
<p>Compiling can be done by calling cl.exe which comes with Visual Studio. Of course you could also use GCC instead.</p>
1
2009-05-11T12:31:04Z
[ "c#", "c++", "python", "c", "vb.net" ]
How do I upload pickled data to django FileField?
847,904
<p>I would like to store large dataset generated in Python in a Django model. My idea was to pickle the data to a string and upload it to FileField of my model. My django model is:</p> <pre><code>#models.py from django.db import models class Data(models.Model): label = models.CharField(max_length=30) file = m...
4
2009-05-11T12:36:38Z
847,913
<p>Might you not be better off storing your data in a text field? It's not a file upload, after all.</p>
0
2009-05-11T12:40:01Z
[ "python", "django", "file", "upload", "pickle" ]
How do I upload pickled data to django FileField?
847,904
<p>I would like to store large dataset generated in Python in a Django model. My idea was to pickle the data to a string and upload it to FileField of my model. My django model is:</p> <pre><code>#models.py from django.db import models class Data(models.Model): label = models.CharField(max_length=30) file = m...
4
2009-05-11T12:36:38Z
848,176
<p>In you database the <em>file</em> attribute is just a path to the file. So, since you are not doing an actual upload you need to store the file on the disk and then save the path in database.</p> <pre><code>f = open(filename, 'w') pickle.dump(somedata, f) f.close() data_entry.file=filename data_entry.save() </code>...
1
2009-05-11T13:46:38Z
[ "python", "django", "file", "upload", "pickle" ]
How do I upload pickled data to django FileField?
847,904
<p>I would like to store large dataset generated in Python in a Django model. My idea was to pickle the data to a string and upload it to FileField of my model. My django model is:</p> <pre><code>#models.py from django.db import models class Data(models.Model): label = models.CharField(max_length=30) file = m...
4
2009-05-11T12:36:38Z
848,606
<p>I've never done this, but based on reading a bit of the relevant code, I'd start by looking into creating an instance of django.core.files.base.ContentFile and assigning that as the value of the field.</p>
0
2009-05-11T15:21:23Z
[ "python", "django", "file", "upload", "pickle" ]
How do I upload pickled data to django FileField?
847,904
<p>I would like to store large dataset generated in Python in a Django model. My idea was to pickle the data to a string and upload it to FileField of my model. My django model is:</p> <pre><code>#models.py from django.db import models class Data(models.Model): label = models.CharField(max_length=30) file = m...
4
2009-05-11T12:36:38Z
848,737
<p>Based on the answers to the questions I came up with the following solution:</p> <pre><code>from django.core.files.base import ContentFile import pickle content = pickle.dumps(somedata) fid = ContentFile(content) data_entry.file.save(filename, fid) fid.close() </code></pre> <p>All of it is done on the server side...
8
2009-05-11T15:48:04Z
[ "python", "django", "file", "upload", "pickle" ]
How do I upload pickled data to django FileField?
847,904
<p>I would like to store large dataset generated in Python in a Django model. My idea was to pickle the data to a string and upload it to FileField of my model. My django model is:</p> <pre><code>#models.py from django.db import models class Data(models.Model): label = models.CharField(max_length=30) file = m...
4
2009-05-11T12:36:38Z
1,097,239
<p><strong>NOTE: <em>See other answers and comments below</em></strong> - old info and broken links removed (can't delete a once-accepted answer).</p> <p>Marty Alchin has a section on this in chapter 3 of Pro Django, <a href="http://ericholscher.com/blog/2009/jan/21/review-pro-django-marty-alchin/" rel="nofollow">revi...
-3
2009-07-08T10:21:40Z
[ "python", "django", "file", "upload", "pickle" ]
Measure Path Length in Blender Script?
848,499
<p>In Blender (v2.48), how can I determine the length of a path (in Blender units) from a Python script?</p> <p>The value is available from the GUI: With the path selected, the Editing panel contains a <em>PrintLen</em> button. The length appears to the right when the button is pressed.</p> <p>How can I obtain this v...
0
2009-05-11T14:53:59Z
953,202
<p>The best idea I've found is to create a mesh from the path and sum the length of the segments (edges).</p> <pre><code>import Blender def get_length(path): """ Return the length (in Blender distance units) of the path. """ mesh = Blender.Mesh.New() mesh.getFromObject(path) return sum(edge.l...
1
2009-06-04T21:25:10Z
[ "python", "blender" ]
Python M2Crypto EC Support
848,508
<p>M2Crypto provides EC support for ECDSA/ECDH. I have installed OpenSSL 0.9.8i which contains support for EC. However when I run "from M2Crypto import EC,BIO" I get error saying EC_init() failed. So I added debug to print m2.OPENSSL_VERSION_TEXT value. It gets printed as "OpenSSL 0.9.7 19 Feb 2003". This version of Op...
2
2009-05-11T14:55:46Z
848,795
<p>Possibly its looking up shared libs libssl.so and libcrypto.so and finding the old ones in /usr/lib if you add the new_path to the top of /etc/ld.so.conf so it gets searched first it would work. But this might break other OpenSSL applications expecting old OpenSSL.</p>
0
2009-05-11T16:03:21Z
[ "python", "m2crypto" ]
Python M2Crypto EC Support
848,508
<p>M2Crypto provides EC support for ECDSA/ECDH. I have installed OpenSSL 0.9.8i which contains support for EC. However when I run "from M2Crypto import EC,BIO" I get error saying EC_init() failed. So I added debug to print m2.OPENSSL_VERSION_TEXT value. It gets printed as "OpenSSL 0.9.7 19 Feb 2003". This version of Op...
2
2009-05-11T14:55:46Z
1,192,236
<p>Some Linux distros, for example Fedora and Redhat, disable EC due to patent concerns.</p> <p>If you build OpenSSL yourself, there are a few options you may need to specify for build_ext in addition to --openssl: --library-dirs and --include-dirs. See for example the m2crypto <a href="http://svn.osafoundation.org/ch...
2
2009-07-28T06:33:19Z
[ "python", "m2crypto" ]
Python M2Crypto EC Support
848,508
<p>M2Crypto provides EC support for ECDSA/ECDH. I have installed OpenSSL 0.9.8i which contains support for EC. However when I run "from M2Crypto import EC,BIO" I get error saying EC_init() failed. So I added debug to print m2.OPENSSL_VERSION_TEXT value. It gets printed as "OpenSSL 0.9.7 19 Feb 2003". This version of Op...
2
2009-05-11T14:55:46Z
39,173,448
<p>Please file a problem report at <a href="https://gitlab.com/m2crypto/m2crypto/issues/new" rel="nofollow">https://gitlab.com/m2crypto/m2crypto/issues/new</a> and your OS, version of Python, locations and versions of all OpenSSL libraries on your system, version of your compiler, and please attach <strong>complete</st...
0
2016-08-26T19:25:56Z
[ "python", "m2crypto" ]
Writing/parsing a fixed width file using Python
848,537
<p>I'm a newbie to Python and I'm looking at using it to write some hairy EDI stuff that our supplier requires.</p> <p>Basically they need an 80-character fixed width text file, with certain "chunks" of the field with data and others left blank. I have the documentation so I know what the length of each "chunk" is. ...
11
2009-05-11T15:01:36Z
848,607
<p>It's a little difficult to parse your question, but I'm gathering that you are receiving a file or file-like-object, reading it, and replacing some of the values with some business logic results. Is this correct?</p> <p>The simplest way to overcome string immutability is to write a new string:</p> <pre><code># Wo...
0
2009-05-11T15:21:24Z
[ "python", "parsing", "edi" ]
Writing/parsing a fixed width file using Python
848,537
<p>I'm a newbie to Python and I'm looking at using it to write some hairy EDI stuff that our supplier requires.</p> <p>Basically they need an 80-character fixed width text file, with certain "chunks" of the field with data and others left blank. I have the documentation so I know what the length of each "chunk" is. ...
11
2009-05-11T15:01:36Z
848,661
<p>You don't need to assign to slices, just build the string using <a href="http://docs.python.org/library/stdtypes.html#string-formatting-operations"><code>% formatting</code></a>.</p> <p>An example with a fixed format for 3 data items:</p> <pre><code>&gt;&gt;&gt; fmt="%4s%10s%10s" &gt;&gt;&gt; fmt % (1,"ONE",2) ' ...
15
2009-05-11T15:32:37Z
[ "python", "parsing", "edi" ]
Writing/parsing a fixed width file using Python
848,537
<p>I'm a newbie to Python and I'm looking at using it to write some hairy EDI stuff that our supplier requires.</p> <p>Basically they need an 80-character fixed width text file, with certain "chunks" of the field with data and others left blank. I have the documentation so I know what the length of each "chunk" is. ...
11
2009-05-11T15:01:36Z
848,663
<p>Hopefully I understand what you're looking for: some way to conveniently identify each part of the line by a simple variable, but output it padded to the correct width?</p> <p>The snippet below may give you what you want</p> <pre><code>class FixWidthFieldLine(object): fields = (('foo', 10), ('ba...
6
2009-05-11T15:32:45Z
[ "python", "parsing", "edi" ]
Writing/parsing a fixed width file using Python
848,537
<p>I'm a newbie to Python and I'm looking at using it to write some hairy EDI stuff that our supplier requires.</p> <p>Basically they need an 80-character fixed width text file, with certain "chunks" of the field with data and others left blank. I have the documentation so I know what the length of each "chunk" is. ...
11
2009-05-11T15:01:36Z
848,668
<p>You can convert the string to a list and do the slice manipulation.</p> <pre><code>&gt;&gt;&gt; text = list("some text") &gt;&gt;&gt; text[0:4] = list("fine") &gt;&gt;&gt; text ['f', 'i', 'n', 'e', ' ', 't', 'e', 'x', 't'] &gt;&gt;&gt; text[0:4] = list("all") &gt;&gt;&gt; text ['a', 'l', 'l', ' ', 't', 'e', 'x', 't...
0
2009-05-11T15:33:43Z
[ "python", "parsing", "edi" ]
Writing/parsing a fixed width file using Python
848,537
<p>I'm a newbie to Python and I'm looking at using it to write some hairy EDI stuff that our supplier requires.</p> <p>Basically they need an 80-character fixed width text file, with certain "chunks" of the field with data and others left blank. I have the documentation so I know what the length of each "chunk" is. ...
11
2009-05-11T15:01:36Z
848,672
<p>It is easy to write function to "modify" string.</p> <pre><code>def change(string, start, end, what): length = end - start if len(what)&lt;length: what = what + " "*(length-len(what)) return string[0:start]+what[0:length]+string[end:] </code></pre> <p>Usage:</p> <pre><code>test_string = 'This is test ...
0
2009-05-11T15:34:17Z
[ "python", "parsing", "edi" ]
Writing/parsing a fixed width file using Python
848,537
<p>I'm a newbie to Python and I'm looking at using it to write some hairy EDI stuff that our supplier requires.</p> <p>Basically they need an 80-character fixed width text file, with certain "chunks" of the field with data and others left blank. I have the documentation so I know what the length of each "chunk" is. ...
11
2009-05-11T15:01:36Z
848,698
<p>You can use <a href="http://docs.python.org/library/string.html#string.ljust">justify</a> functions to left-justify, right-justify and center a string in a field of given width.</p> <pre><code>'hi'.ljust(10) -&gt; 'hi ' </code></pre>
7
2009-05-11T15:37:43Z
[ "python", "parsing", "edi" ]
Writing/parsing a fixed width file using Python
848,537
<p>I'm a newbie to Python and I'm looking at using it to write some hairy EDI stuff that our supplier requires.</p> <p>Basically they need an 80-character fixed width text file, with certain "chunks" of the field with data and others left blank. I have the documentation so I know what the length of each "chunk" is. ...
11
2009-05-11T15:01:36Z
23,917,443
<p>I used Jarret Hardie's example and modified it slightly. This allows for selection of type of text alignment(left, right or centered.)</p> <pre><code>class FixedWidthFieldLine(object): def __init__(self, fields, justify = 'L'): """ Returns line from list containing tuples of field values and lengths. Ac...
0
2014-05-28T16:47:25Z
[ "python", "parsing", "edi" ]
Javascript graphing library to draw a region
848,604
<p>As a keen windsurfer, I'm interested in how windy the next few weeks are going to be. To that end, I've been writing a little app to scrape a popular weather site (personal use only - not relaying the information or anything) and collate the data into a single graph so that I can easily see when's going to be worth ...
2
2009-05-11T15:20:58Z
848,659
<p>Take a look at the <a href="http://code.google.com/apis/visualization/documentation/gallery/areachart.html" rel="nofollow">Google chart API's</a>. They make this sort of thing pretty easy. Without some example code, I would have a hard time giving you an example, but Google has nice one on the docs.</p>
1
2009-05-11T15:32:25Z
[ "javascript", "python", "django", "graph", "screen-scraping" ]
Javascript graphing library to draw a region
848,604
<p>As a keen windsurfer, I'm interested in how windy the next few weeks are going to be. To that end, I've been writing a little app to scrape a popular weather site (personal use only - not relaying the information or anything) and collate the data into a single graph so that I can easily see when's going to be worth ...
2
2009-05-11T15:20:58Z
848,870
<p>You should check out Dojo. It looks like it'd be pretty easy for you to do, just plot the bottom line with the same fill color as the background. That should get you the effect you're going for.</p> <p><a href="http://dojocampus.org/explorer/#Dojox_Charting_2D" rel="nofollow">http://dojocampus.org/explorer/#Dojox_C...
1
2009-05-11T16:19:07Z
[ "javascript", "python", "django", "graph", "screen-scraping" ]
Javascript graphing library to draw a region
848,604
<p>As a keen windsurfer, I'm interested in how windy the next few weeks are going to be. To that end, I've been writing a little app to scrape a popular weather site (personal use only - not relaying the information or anything) and collate the data into a single graph so that I can easily see when's going to be worth ...
2
2009-05-11T15:20:58Z
849,098
<p>I'd use open flash chart, you just have to create a JSON with the data and then you've to all the flashy coolness in your page....</p> <p><a href="http://teethgrinder.co.uk/open-flash-chart-2/" rel="nofollow">http://teethgrinder.co.uk/open-flash-chart-2/</a></p>
0
2009-05-11T17:19:15Z
[ "javascript", "python", "django", "graph", "screen-scraping" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
849,113
<p><strong>plain "no".</strong></p> <p>You've pretty much reached maximum disk speed.</p> <p>I mean, you could <a href="http://docs.python.org/library/mmap.html" rel="nofollow">mmap</a> the file, or read it in binary chunks, and use <code>.count('\n')</code> or something. But that is unlikely to give major improvemen...
5
2009-05-11T17:22:22Z
[ "python", "linux", "performance", "text-files" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
849,146
<p>If you assume that a disk can read 60MB/s you'd need 6000 / 60 = 100 seconds, which is 1 minute 40 seconds. I don't think that you can get any faster because the disk is the bottleneck.</p>
4
2009-05-11T17:30:53Z
[ "python", "linux", "performance", "text-files" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
849,153
<p>as others have said - "no"</p> <p>Almost all of your time is spent waiting for IO. If this is something that you need to do more than once, <em>and</em> you have a machine with tons of ram, you could keep the file in memory. If your machine has 16GB of ram, you'll have 8GB available at /dev/shm to play with.</p> <...
1
2009-05-11T17:33:33Z
[ "python", "linux", "performance", "text-files" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
849,510
<p>You can't get any faster than the maximum disk read speed.</p> <p>In order to reach the maximum disk speed you can use the following two tips:</p> <ol> <li>Read the file in with a big buffer. This can either be coded "manually" or simply by using io.BufferedReader ( available in python2.6+ ).</li> <li>Do the newli...
1
2009-05-11T18:53:41Z
[ "python", "linux", "performance", "text-files" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
849,521
<p>Note that Python I/O is implemented in C, so there is not much luck speeding it up further.</p>
1
2009-05-11T18:55:30Z
[ "python", "linux", "performance", "text-files" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
849,645
<p><strong>Throw hardware at the problem.</strong></p> <p>As gs pointed out, your bottleneck is the hard disk transfer rate. So, no you can't use a better algorithm to improve your time, but you can buy a faster hard drive.</p> <p><strong>Edit:</strong> Another good point by gs; you could also use a <a href="http://...
11
2009-05-11T19:24:57Z
[ "python", "linux", "performance", "text-files" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
849,842
<p>The trick is not to make electrons move faster (that's hard to do) but to get more work done per unit of time.</p> <p>First, be sure your 6GB file read is I/O bound, not CPU bound.</p> <p>If It's I/O bound, consider the "Fan-Out" design pattern.</p> <ul> <li><p>A parent process spawns a bunch of children.</p></li...
6
2009-05-11T20:06:39Z
[ "python", "linux", "performance", "text-files" ]
Is it possible to speed-up python IO?
849,058
<p>Consider this python program:</p> <pre><code>import sys lc = 0 for line in open(sys.argv[1]): lc = lc + 1 print lc, sys.argv[1] </code></pre> <p>Running it on my 6GB text file, it completes in ~ 2minutes.</p> <p>Question: <strong>is it possible to go faster?</strong></p> <p>Note that the same time is requi...
8
2009-05-11T17:06:46Z
861,105
<p>2 minutes sounds about right to read an entire 6gb file. Theres not really much you can do to the algorithm or the OS to speed things up. I think you have two options:</p> <ol> <li><p>Throw money at the problem and get better hardware. Probably the best option if this project is for your job.</p></li> <li><p>Don't ...
1
2009-05-14T00:54:28Z
[ "python", "linux", "performance", "text-files" ]
How to limit the maximum value of a numeric field in a Django model?
849,142
<p>Django has various numeric fields available for use in models, e.g. <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield">DecimalField</a> and <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#positiveintegerfield">PositiveIntegerField</a>. Although the former can be restricte...
87
2009-05-11T17:29:57Z
849,177
<p>There are two ways to do this. One is to use form validation to never let any number over 50 be entered by a user. <a href="http://docs.djangoproject.com/en/dev/ref/forms/validation/">Form validation docs</a>.</p> <p>If there is no user involved in the process, or you're not using a form to enter data, then you'll ...
9
2009-05-11T17:39:52Z
[ "python", "django", "django-models", "numbers" ]
How to limit the maximum value of a numeric field in a Django model?
849,142
<p>Django has various numeric fields available for use in models, e.g. <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield">DecimalField</a> and <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#positiveintegerfield">PositiveIntegerField</a>. Although the former can be restricte...
87
2009-05-11T17:29:57Z
849,426
<p>You could also create a custom model field type - see <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#howto-custom-model-fields">http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#howto-custom-model-fields</a></p> <p>In this case, you could 'inherit' from the built-in IntegerFi...
95
2009-05-11T18:31:21Z
[ "python", "django", "django-models", "numbers" ]
How to limit the maximum value of a numeric field in a Django model?
849,142
<p>Django has various numeric fields available for use in models, e.g. <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield">DecimalField</a> and <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#positiveintegerfield">PositiveIntegerField</a>. Although the former can be restricte...
87
2009-05-11T17:29:57Z
4,047,378
<p>I had this very same problem; here was my solution:</p> <pre><code>SCORE_CHOICES = zip( range(1,n), range(1,n) ) score = models.IntegerField(choices=SCORE_CHOICES, blank=True) </code></pre>
41
2010-10-28T21:38:25Z
[ "python", "django", "django-models", "numbers" ]
How to limit the maximum value of a numeric field in a Django model?
849,142
<p>Django has various numeric fields available for use in models, e.g. <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield">DecimalField</a> and <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#positiveintegerfield">PositiveIntegerField</a>. Although the former can be restricte...
87
2009-05-11T17:29:57Z
12,026,867
<p>You can use <a href="https://docs.djangoproject.com/en/dev/ref/validators/#built-in-validators">Django's built-in validators</a>—</p> <pre><code>from django.db.models import IntegerField, Model from django.core.validators import MaxValueValidator, MinValueValidator class CoolModelBro(Model): limited_integer_...
144
2012-08-19T13:32:39Z
[ "python", "django", "django-models", "numbers" ]
How to limit the maximum value of a numeric field in a Django model?
849,142
<p>Django has various numeric fields available for use in models, e.g. <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield">DecimalField</a> and <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#positiveintegerfield">PositiveIntegerField</a>. Although the former can be restricte...
87
2009-05-11T17:29:57Z
12,027,012
<pre><code>from django.db import models from django.core.validators import MinValueValidator, MaxValueValidator size = models.IntegerField(validators=[MinValueValidator(0), MaxValueValidator(5)]) </code></pre>
47
2012-08-19T13:54:25Z
[ "python", "django", "django-models", "numbers" ]
How to limit the maximum value of a numeric field in a Django model?
849,142
<p>Django has various numeric fields available for use in models, e.g. <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield">DecimalField</a> and <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#positiveintegerfield">PositiveIntegerField</a>. Although the former can be restricte...
87
2009-05-11T17:29:57Z
25,900,058
<p>Here is the best solution if you want some extra flexibility and don't want to change your model field. Just add this custom validator:</p> <pre><code>#Imports from django.core.exceptions import ValidationError class validate_range_or_null(object): compare = lambda self, a, b, c: a &gt; c or a &lt; b ...
0
2014-09-17T20:45:53Z
[ "python", "django", "django-models", "numbers" ]
Getting the name of document that used to launch the application bundle on OS X
849,172
<p>When writing an OS X Bundle application (.app), how can I get the name of the document that caused the application to be launched?</p> <p>Say I've associated .abcd with MyApp, when I click on foo.abcd MyApp is launched. How can I get the foo.abcd from inside MyApp? (Command line arguments only contain the process i...
2
2009-05-11T17:39:09Z
849,284
<p>In general, these are handled through <em>Apple Events</em>. Specifically, your application will receive an <em>open document</em> event. How you would handle it depends on what type of application you are writing.</p> <p>If you're writing a document-based app, this is easy: the document controller receives an <cod...
1
2009-05-11T18:01:57Z
[ "python", "osx" ]
Getting the name of document that used to launch the application bundle on OS X
849,172
<p>When writing an OS X Bundle application (.app), how can I get the name of the document that caused the application to be launched?</p> <p>Say I've associated .abcd with MyApp, when I click on foo.abcd MyApp is launched. How can I get the foo.abcd from inside MyApp? (Command line arguments only contain the process i...
2
2009-05-11T17:39:09Z
1,004,487
<p>It looks like you need a GUI toolkit for that, there is an example in <a href="http://svn.python.org/view/python/trunk/Lib/idlelib/macosxSupport.py?revision=HEAD&amp;view=markup" rel="nofollow">idlelib/macosxSupport.py</a></p> <pre><code>def doOpenFile(*args): for fn in args: flist.open(fn) # The comma...
1
2009-06-17T00:01:38Z
[ "python", "osx" ]
Standard non-code resource location for python packages
849,334
<p>This should be a common scenario, but could not find any relevant post yet..</p> <p>I plan to deploy a Python library (I guess the same applies to regular applications) which makes use of some images and other resource files. What is the standard location for such items? I imagine, for project <code>Foo</code>, the...
4
2009-05-11T18:13:14Z
849,446
<p>This question is somewhat incomplete, because a proper answer would depend on the underlying operating system, as each has its own modus operandi. In linux (and most unix based OSs) for example /usr/share/foo or /usr/local/share/foo would be the standard. In OS X you can do the same, but I would think "/Library/Appl...
2
2009-05-11T18:37:35Z
[ "python", "resources", "location", "package", "shared" ]
Standard non-code resource location for python packages
849,334
<p>This should be a common scenario, but could not find any relevant post yet..</p> <p>I plan to deploy a Python library (I guess the same applies to regular applications) which makes use of some images and other resource files. What is the standard location for such items? I imagine, for project <code>Foo</code>, the...
4
2009-05-11T18:13:14Z
849,795
<p>The <em>standard</em> location is where your standard libs goes. But it doesn't sound to me from what you've written, that you'll want your python lib there. I think you should try out <a href="http://pypi.python.org/pypi/virtualenv#what-it-does" rel="nofollow">Virtualenv</a>.</p> <p>If you don't want to go through...
0
2009-05-11T19:58:44Z
[ "python", "resources", "location", "package", "shared" ]
Standard non-code resource location for python packages
849,334
<p>This should be a common scenario, but could not find any relevant post yet..</p> <p>I plan to deploy a Python library (I guess the same applies to regular applications) which makes use of some images and other resource files. What is the standard location for such items? I imagine, for project <code>Foo</code>, the...
4
2009-05-11T18:13:14Z
849,803
<p>We put non .py files in <code>/opt/foo/foo-1.2/...</code></p> <p>Except, of course, for static media that is served by Apache, that goes to <code>/var/www/html/foo/foo-1.1/media/...</code></p> <p>Except, of course, for customer-specific configuration files. They go to <code>/var/opt/customer/foo/...</code></p> <...
2
2009-05-11T20:01:23Z
[ "python", "resources", "location", "package", "shared" ]
How do I enumerate() over a list of tuples in Python?
849,369
<p>I've got some code like this:</p> <pre><code>letters = [('a', 'A'), ('b', 'B')] i = 0 for (lowercase, uppercase) in letters: print "Letter #%d is %s/%s" % (i, lowercase, uppercase) i += 1 </code></pre> <p>I've been told that there's an enumerate() function that can take care of the "i" variable for me:</p>...
25
2009-05-11T18:20:13Z
849,388
<p>This is a neat way to do it:</p> <pre><code>letters = [('a', 'A'), ('b', 'B')] for i, (lowercase, uppercase) in enumerate(letters): print "Letter #%d is %s/%s" % (i, lowercase, uppercase) </code></pre>
60
2009-05-11T18:23:36Z
[ "python", "list", "enumerate" ]
How do I enumerate() over a list of tuples in Python?
849,369
<p>I've got some code like this:</p> <pre><code>letters = [('a', 'A'), ('b', 'B')] i = 0 for (lowercase, uppercase) in letters: print "Letter #%d is %s/%s" % (i, lowercase, uppercase) i += 1 </code></pre> <p>I've been told that there's an enumerate() function that can take care of the "i" variable for me:</p>...
25
2009-05-11T18:20:13Z
849,705
<p>This is how I'd do it:</p> <pre><code>import itertools letters = [('a', 'A'), ('b', 'B')] for i, lower, upper in zip(itertools.count(),*zip(*letters)): print "Letter #%d is %s/%s" % (i, lower, upper) </code></pre> <p>EDIT: unpacking becomes redundant. This is a more compact way, which might work or not depend...
3
2009-05-11T19:39:31Z
[ "python", "list", "enumerate" ]
How do I enumerate() over a list of tuples in Python?
849,369
<p>I've got some code like this:</p> <pre><code>letters = [('a', 'A'), ('b', 'B')] i = 0 for (lowercase, uppercase) in letters: print "Letter #%d is %s/%s" % (i, lowercase, uppercase) i += 1 </code></pre> <p>I've been told that there's an enumerate() function that can take care of the "i" variable for me:</p>...
25
2009-05-11T18:20:13Z
13,805,621
<p>You can do this way too:</p> <pre><code>letters = [('a', 'A'), ('b', 'B')] for i, letter in enumerate(letters): print "Letter #%d is %s/%s" % (i, letter[0], letter[1]) </code></pre>
0
2012-12-10T17:05:52Z
[ "python", "list", "enumerate" ]
Deploying Python via CGI
849,384
<p>How do I deploy a Python project to a webserver that supports Python via CGI? I'm well versed in PHP, but do not understand CGI's relation to Python in the deployment process.</p> <p>Any resource links are appreciated.</p> <p>The web host in question is GoDaddy.</p>
1
2009-05-11T18:22:12Z
849,472
<p>To actually answer your question about deploying python as CGI (while it does not make a lot of sense on a high activity system - there are occasions where it does the job just fine) you just make sure that your files are executable, have the correct extension and then follow <a href="http://www.cs.virginia.edu/~lab...
0
2009-05-11T18:44:17Z
[ "python" ]
Deploying Python via CGI
849,384
<p>How do I deploy a Python project to a webserver that supports Python via CGI? I'm well versed in PHP, but do not understand CGI's relation to Python in the deployment process.</p> <p>Any resource links are appreciated.</p> <p>The web host in question is GoDaddy.</p>
1
2009-05-11T18:22:12Z
849,579
<p>Generally, we use <a href="http://code.google.com/p/modwsgi/" rel="nofollow">mod_wsgi</a> to make a Python application respond to CGI. </p> <p>PHP has a special role -- the language runtime IS a CGI application.</p> <p>Python does not have this special role. Python -- by default -- is not a CGI application. It ...
3
2009-05-11T19:12:27Z
[ "python" ]
django template includes
849,463
<p>I'm having an issue with django templates at the moment. I have 3 template files basically:</p> <ul> <li>Base</li> <li>story_list</li> <li>story_detail</li> </ul> <p>Story_list and _detail extend Base, and that works perfectly fine. However, list and detail share some code that extend the base template for my side...
3
2009-05-11T18:41:24Z
849,530
<p>If there is common code between the story templates that isn't needed site-wide, I'd create a <code>story_base</code> (extending the original <code>base</code>) and have my story templates extend that.</p>
6
2009-05-11T18:58:14Z
[ "python", "django", "django-templates" ]
django template includes
849,463
<p>I'm having an issue with django templates at the moment. I have 3 template files basically:</p> <ul> <li>Base</li> <li>story_list</li> <li>story_detail</li> </ul> <p>Story_list and _detail extend Base, and that works perfectly fine. However, list and detail share some code that extend the base template for my side...
3
2009-05-11T18:41:24Z
849,559
<p>You have an <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#include" rel="nofollow">{% include %}</a> tag for this.</p>
0
2009-05-11T19:07:32Z
[ "python", "django", "django-templates" ]
django template includes
849,463
<p>I'm having an issue with django templates at the moment. I have 3 template files basically:</p> <ul> <li>Base</li> <li>story_list</li> <li>story_detail</li> </ul> <p>Story_list and _detail extend Base, and that works perfectly fine. However, list and detail share some code that extend the base template for my side...
3
2009-05-11T18:41:24Z
849,574
<p>Generally, using <code>include</code>s is not the answer with Django templates. Let me answer your question on several fronts.</p> <p>First, let me address the sidebar.</p> <ul> <li><p><strong>Are nearly all the common pages going to be using that sidebar?</strong> Put it in <code>Base</code>. Don't override those...
16
2009-05-11T19:11:25Z
[ "python", "django", "django-templates" ]
django template includes
849,463
<p>I'm having an issue with django templates at the moment. I have 3 template files basically:</p> <ul> <li>Base</li> <li>story_list</li> <li>story_detail</li> </ul> <p>Story_list and _detail extend Base, and that works perfectly fine. However, list and detail share some code that extend the base template for my side...
3
2009-05-11T18:41:24Z
14,425,036
<pre><code>{% include xxx.html %} </code></pre> <p>This tag works.</p> <p>An alternative way is to use filter. Filter calls a function for rendering, template can be used while rendering.</p>
0
2013-01-20T13:33:27Z
[ "python", "django", "django-templates" ]
Performing Photoshop's "Luminosity" filter programmatically
849,654
<p>I have two JPEG's and would like to overlay one on the other with the same results as the "Luminosity" mode available in Photoshop (and Fireworks). You can read more about Luminosity mode here: <a href="http://www.adobetutorialz.com/articles/662/1/Photoshop%92s-Luminosity-Mode" rel="nofollow">http://www.adobetutori...
3
2009-05-11T19:27:12Z
849,687
<p>The Gimp would be another option - it has a scripting interface ans a python api - here is an article on <a href="http://gimpology.com/submission/view/luminosity%5Fmasking%5Fthe%5Flight%5Fside/" rel="nofollow">luminosity and the Gimp</a>. Not sure if it is the same effect you are going for though.</p>
0
2009-05-11T19:36:31Z
[ "php", "python", "image", "image-processing", "python-imaging-library" ]
Performing Photoshop's "Luminosity" filter programmatically
849,654
<p>I have two JPEG's and would like to overlay one on the other with the same results as the "Luminosity" mode available in Photoshop (and Fireworks). You can read more about Luminosity mode here: <a href="http://www.adobetutorialz.com/articles/662/1/Photoshop%92s-Luminosity-Mode" rel="nofollow">http://www.adobetutori...
3
2009-05-11T19:27:12Z
849,694
<p>First you need to understand what Photoshop does.</p> <p>It preserves under layer perceptual color information and replaces it's luminosity with the top layer's perceptual luminosity information. To do that, you need to convert the images to the right color space.</p> <p>Here is the shoping list of things you will...
5
2009-05-11T19:37:30Z
[ "php", "python", "image", "image-processing", "python-imaging-library" ]
Performing Photoshop's "Luminosity" filter programmatically
849,654
<p>I have two JPEG's and would like to overlay one on the other with the same results as the "Luminosity" mode available in Photoshop (and Fireworks). You can read more about Luminosity mode here: <a href="http://www.adobetutorialz.com/articles/662/1/Photoshop%92s-Luminosity-Mode" rel="nofollow">http://www.adobetutori...
3
2009-05-11T19:27:12Z
849,715
<p>In pseudo-code:</p> <pre><code>foreach rgb_pixel1, rgb_pixel2 in image1, image2 { hsl1 = RgbToHsl(rgb_pixel1); hsl2 = RgbToHsl(rgb_pixel2); hsl3 = hsl(hsl1.h, hsl1.s, hsl2.l); output_rgb = HslToRgb(hsl3); } </code></pre> <p>Conversion from rgb to hsl and back is <a href="http://www.geekymonkey.com/...
1
2009-05-11T19:41:58Z
[ "php", "python", "image", "image-processing", "python-imaging-library" ]
Performing Photoshop's "Luminosity" filter programmatically
849,654
<p>I have two JPEG's and would like to overlay one on the other with the same results as the "Luminosity" mode available in Photoshop (and Fireworks). You can read more about Luminosity mode here: <a href="http://www.adobetutorialz.com/articles/662/1/Photoshop%92s-Luminosity-Mode" rel="nofollow">http://www.adobetutori...
3
2009-05-11T19:27:12Z
849,725
<p>You could have a look at the <a href="http://opencv.willowgarage.com/wiki/" rel="nofollow">OpenCV</a> image processing library. It has Python bindings and handles a lot of these lower level image manipulation tasks for you, or at least makes them easier.</p>
0
2009-05-11T19:44:39Z
[ "php", "python", "image", "image-processing", "python-imaging-library" ]
Performing Photoshop's "Luminosity" filter programmatically
849,654
<p>I have two JPEG's and would like to overlay one on the other with the same results as the "Luminosity" mode available in Photoshop (and Fireworks). You can read more about Luminosity mode here: <a href="http://www.adobetutorialz.com/articles/662/1/Photoshop%92s-Luminosity-Mode" rel="nofollow">http://www.adobetutori...
3
2009-05-11T19:27:12Z
850,091
<p>I don't know about this specific filter but I can tell you how to follow Coincoin steps in <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a>. I didn't actually run the code, but you can use it as a reference:</p> <p>Load both the source and target JPEGs</p> <pre><code>from PIL import Image i...
1
2009-05-11T21:07:00Z
[ "php", "python", "image", "image-processing", "python-imaging-library" ]
Simple threading in Python 2.6 using thread.start_new_thread()
849,674
<p>I'm following a tutorial on simple threading. They give this example and when I try to use it I'm getting unintelligible errors from the interpreter. Can you please tell me why this isn't working? I'm on WinXP SP3 w/ Python 2.6 current</p> <pre><code>import thread def myfunction(mystring,*args): print mystring...
11
2009-05-11T19:32:17Z
849,698
<p>I tried it in Python 2.5 on a mac, after changing </p> <pre><code>except Exception as errtxt: </code></pre> <p>to</p> <pre><code>except Exception, errtxt: </code></pre> <p>The program did not throw an exception but also did not print anything. Not sure if that is helpful, but I do find it curious...</p>
-1
2009-05-11T19:38:35Z
[ "python", "multithreading", "python-2.6" ]
Simple threading in Python 2.6 using thread.start_new_thread()
849,674
<p>I'm following a tutorial on simple threading. They give this example and when I try to use it I'm getting unintelligible errors from the interpreter. Can you please tell me why this isn't working? I'm on WinXP SP3 w/ Python 2.6 current</p> <pre><code>import thread def myfunction(mystring,*args): print mystring...
11
2009-05-11T19:32:17Z
849,700
<p>When I ran this code in Python 2.6 it worked, is it possible you have open threads already that are locked on the function? I recommend closing Python completely, checking your running processes to make sure nothing of yours is running and try again.</p>
-1
2009-05-11T19:38:51Z
[ "python", "multithreading", "python-2.6" ]
Simple threading in Python 2.6 using thread.start_new_thread()
849,674
<p>I'm following a tutorial on simple threading. They give this example and when I try to use it I'm getting unintelligible errors from the interpreter. Can you please tell me why this isn't working? I'm on WinXP SP3 w/ Python 2.6 current</p> <pre><code>import thread def myfunction(mystring,*args): print mystring...
11
2009-05-11T19:32:17Z
849,759
<p>The problem is that your main thread has quit before your new thread has time to finish. The solution is to wait at your main thread.</p> <pre><code>import thread, time def myfunction(mystring,*args): print mystring if __name__ == '__main__': try: thread.start_new_thread(myfunction,('MyStringHe...
22
2009-05-11T19:53:08Z
[ "python", "multithreading", "python-2.6" ]
Simple threading in Python 2.6 using thread.start_new_thread()
849,674
<p>I'm following a tutorial on simple threading. They give this example and when I try to use it I'm getting unintelligible errors from the interpreter. Can you please tell me why this isn't working? I'm on WinXP SP3 w/ Python 2.6 current</p> <pre><code>import thread def myfunction(mystring,*args): print mystring...
11
2009-05-11T19:32:17Z
849,896
<p>You need to wait until your Thread finishes its work, so you have to use Thread.join() :</p> <pre><code>from threading import Thread def myfunction(mystring,*args): print mystring if __name__ == '__main__': try: t = Thread(None,myfunction,None,('MyStringHere',1)) t.start() t.join(...
14
2009-05-11T20:19:04Z
[ "python", "multithreading", "python-2.6" ]
Simple threading in Python 2.6 using thread.start_new_thread()
849,674
<p>I'm following a tutorial on simple threading. They give this example and when I try to use it I'm getting unintelligible errors from the interpreter. Can you please tell me why this isn't working? I'm on WinXP SP3 w/ Python 2.6 current</p> <pre><code>import thread def myfunction(mystring,*args): print mystring...
11
2009-05-11T19:32:17Z
20,633,107
<pre><code>import thread def myfunction(mystring,*args): print mystring if __name__ == '__main__': try: thread.start_new_thread(myfunction,('MyStringHere',1)) except Exception as errtxt: print errtxt while 1: pass </code></pre> <p>Put while loop at last then it will work for you.<...
0
2013-12-17T11:38:56Z
[ "python", "multithreading", "python-2.6" ]
Is there a way to set multiple defaults on a Python dict using another dict?
849,806
<p>Suppose I've got two dicts in Python:</p> <pre><code>mydict = { 'a': 0 } defaults = { 'a': 5, 'b': 10, 'c': 15 } </code></pre> <p>I want to be able to expand <code>mydict</code> using the default values from <code>defaults</code>, such that 'a' remains the same but 'b' and 'c' are filled in. I know a...
7
2009-05-11T20:01:46Z
849,831
<pre><code>defaults.update(mydict) </code></pre>
0
2009-05-11T20:05:26Z
[ "python", "dictionary" ]
Is there a way to set multiple defaults on a Python dict using another dict?
849,806
<p>Suppose I've got two dicts in Python:</p> <pre><code>mydict = { 'a': 0 } defaults = { 'a': 5, 'b': 10, 'c': 15 } </code></pre> <p>I want to be able to expand <code>mydict</code> using the default values from <code>defaults</code>, such that 'a' remains the same but 'b' and 'c' are filled in. I know a...
7
2009-05-11T20:01:46Z
849,849
<p>Couldnt you make mydict be a copy of default, That way, mydict would have all the correct values to start with?</p> <pre><code>mydict = default.copy() </code></pre>
7
2009-05-11T20:07:05Z
[ "python", "dictionary" ]
Is there a way to set multiple defaults on a Python dict using another dict?
849,806
<p>Suppose I've got two dicts in Python:</p> <pre><code>mydict = { 'a': 0 } defaults = { 'a': 5, 'b': 10, 'c': 15 } </code></pre> <p>I want to be able to expand <code>mydict</code> using the default values from <code>defaults</code>, such that 'a' remains the same but 'b' and 'c' are filled in. I know a...
7
2009-05-11T20:01:46Z
849,856
<p>If you don't mind creating a new dictionary in the process, this will do the trick:</p> <pre><code>newdict = dict(defaults) newdict.update(mydict) </code></pre> <p>Now <code>newdict</code> contains what you need.</p>
3
2009-05-11T20:08:06Z
[ "python", "dictionary" ]
Is there a way to set multiple defaults on a Python dict using another dict?
849,806
<p>Suppose I've got two dicts in Python:</p> <pre><code>mydict = { 'a': 0 } defaults = { 'a': 5, 'b': 10, 'c': 15 } </code></pre> <p>I want to be able to expand <code>mydict</code> using the default values from <code>defaults</code>, such that 'a' remains the same but 'b' and 'c' are filled in. I know a...
7
2009-05-11T20:01:46Z
849,877
<p>You can do this the same way Python's collections.DefaultDict works:</p> <pre><code>class MultiDefaultDict(dict): def __init__(self, defaults, **kwargs): self.defaults = defaults self.update(kwargs) def __missing__(self, key): return self.defaults[key] &gt;&gt;&gt; mydict2 = MultiDe...
5
2009-05-11T20:11:44Z
[ "python", "dictionary" ]
Is there a way to set multiple defaults on a Python dict using another dict?
849,806
<p>Suppose I've got two dicts in Python:</p> <pre><code>mydict = { 'a': 0 } defaults = { 'a': 5, 'b': 10, 'c': 15 } </code></pre> <p>I want to be able to expand <code>mydict</code> using the default values from <code>defaults</code>, such that 'a' remains the same but 'b' and 'c' are filled in. I know a...
7
2009-05-11T20:01:46Z
850,402
<p>Personally I like to append the dictionary object. It works mostly like a dictionary except that you have to create the object first.</p> <pre><code>class d_dict(dict): 'Dictionary object with easy defaults.' def __init__(self,defaults={}): self.setdefault(defaults) def setdefault(sel...
0
2009-05-11T22:36:35Z
[ "python", "dictionary" ]
Python -- Regex -- How to find a string between two sets of strings
849,912
<p>Consider the following:</p> <pre><code>&lt;div id=hotlinklist&gt; &lt;a href="foo1.com"&gt;Foo1&lt;/a&gt; &lt;div id=hotlink&gt; &lt;a href="/"&gt;Home&lt;/a&gt; &lt;/div&gt; &lt;div id=hotlink&gt; &lt;a href="/extract"&gt;Extract&lt;/a&gt; &lt;/div&gt; &lt;div id=hotlink&gt; &lt;a href="/si...
5
2009-05-11T20:23:49Z
849,950
<p>Don't use a regex. Use <a href="http://www.crummy.com/software/BeautifulSoup/">BeautfulSoup</a>, an HTML parser.</p> <pre><code>from BeautifulSoup import BeautifulSoup html = \ """ &lt;div id=hotlinklist&gt; &lt;a href="foo1.com"&gt;Foo1&lt;/a&gt; &lt;div id=hotlink&gt; &lt;a href="/"&gt;Home&lt;/a&gt; &...
14
2009-05-11T20:32:41Z
[ "python", "regex", "string", "tags" ]
Python -- Regex -- How to find a string between two sets of strings
849,912
<p>Consider the following:</p> <pre><code>&lt;div id=hotlinklist&gt; &lt;a href="foo1.com"&gt;Foo1&lt;/a&gt; &lt;div id=hotlink&gt; &lt;a href="/"&gt;Home&lt;/a&gt; &lt;/div&gt; &lt;div id=hotlink&gt; &lt;a href="/extract"&gt;Extract&lt;/a&gt; &lt;/div&gt; &lt;div id=hotlink&gt; &lt;a href="/si...
5
2009-05-11T20:23:49Z
849,971
<p>Parsing HTML with regular expression is a bad idea!</p> <p>Think about the following piece of html</p> <pre><code>&lt;a&gt;&lt;/a &gt; &lt;!-- legal html, but won't pass your regex --&gt; &lt;a href="/sitemap"&gt;Sitemap&lt;!-- proof that a&gt;b iff ab&gt;1 --&gt;&lt;/a&gt; </code></pre> <p>There are many more s...
6
2009-05-11T20:37:51Z
[ "python", "regex", "string", "tags" ]