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
Is there a wiki processor for Trac to format and colour Python tracebacks?
1,275,401
<p>Understandably many of the tickets we file in Trac contain tracebacks. It would be excellent if these were nicely formatted and syntax highlighted.</p> <p>I've conducted a cursory Google search for a Python traceback wiki processor and have not found any quick hits.</p> <p>I'm happy to roll my own if anyone can re...
4
2009-08-14T00:21:37Z
1,275,531
<p><a href="http://pygments.org/languages/" rel="nofollow">Pygments</a> has support for syntax-coloring Python tracebacks, and there's a <a href="http://trac-hacks.org/wiki/TracPygmentsPlugin" rel="nofollow">trac plugin</a>, but the wiki page claims Trac 0.11 supports Pygments natively.</p>
2
2009-08-14T01:04:39Z
[ "python", "syntax", "trac" ]
Is there a wiki processor for Trac to format and colour Python tracebacks?
1,275,401
<p>Understandably many of the tickets we file in Trac contain tracebacks. It would be excellent if these were nicely formatted and syntax highlighted.</p> <p>I've conducted a cursory Google search for a Python traceback wiki processor and have not found any quick hits.</p> <p>I'm happy to roll my own if anyone can re...
4
2009-08-14T00:21:37Z
1,320,590
<p>Trac 0.11 supports Pygments but doesn't expose the pytb formatting type. Here's a patch against Trac 0.11.3 to add support for Python tracebacks.</p> <pre><code>diff -r 5a0c5e3255b4 mimeview/api.py --- a/mimeview/api.py Tue Aug 11 11:33:45 2009 +1000 +++ b/mimeview/api.py Mon Aug 24 15:13:34 2009 +1000 @@ -348,...
2
2009-08-24T05:16:58Z
[ "python", "syntax", "trac" ]
Is there a wiki processor for Trac to format and colour Python tracebacks?
1,275,401
<p>Understandably many of the tickets we file in Trac contain tracebacks. It would be excellent if these were nicely formatted and syntax highlighted.</p> <p>I've conducted a cursory Google search for a Python traceback wiki processor and have not found any quick hits.</p> <p>I'm happy to roll my own if anyone can re...
4
2009-08-14T00:21:37Z
7,014,002
<p>I don't believe you need that patch. You could specify the shortcode mapping in the <a href="http://trac.edgewall.org/wiki/TracIni#mimeviewer-section" rel="nofollow">trac.ini</a>, but you can also (at least in trac 0.12) just use the mime type directly:</p> <pre><code>{{{ #!text/x-python-traceback &lt;traceback&gt;...
4
2011-08-10T16:03:37Z
[ "python", "syntax", "trac" ]
What is the best way to handle rotating sprites for a top-down view game
1,275,482
<p>I am working on a top-down view 2d game at the moment and I am learning a ton about sprites and sprite handling. My question is how to handle a set of sprites that can be rotated in as many as 32 directions.</p> <p>At the moment a given object has its sprite sheet with all of the animations oriented with the object...
2
2009-08-14T00:47:42Z
1,275,490
<p>You can just rotate the sprites directly by setting the rotate portion of the sprite's transform.</p> <p>For some sample code, check out the Chimp sprite in this <a href="http://www.pygame.org/docs/tut/chimp/ChimpLineByLine.html" rel="nofollow">pygame tutorial</a>. It rotates the sprites when the Chimp is "dizzy"....
2
2009-08-14T00:51:48Z
[ "python", "pygame", "sprite" ]
What is the best way to handle rotating sprites for a top-down view game
1,275,482
<p>I am working on a top-down view 2d game at the moment and I am learning a ton about sprites and sprite handling. My question is how to handle a set of sprites that can be rotated in as many as 32 directions.</p> <p>At the moment a given object has its sprite sheet with all of the animations oriented with the object...
2
2009-08-14T00:47:42Z
1,277,181
<p>The 32 directions for the sprite translate into 32 rotations by 11.25 degrees. </p> <p>You can reduce the number of precalculated images to 8 you only calculate the first 90 degrees (<code>11.25, 22.5, 33.75, 45.0, 56.25, 67.5, 78.75, 90.0</code>) and use the flip operations dynamically. Flips are much faster becau...
4
2009-08-14T10:35:40Z
[ "python", "pygame", "sprite" ]
What is the best way to handle rotating sprites for a top-down view game
1,275,482
<p>I am working on a top-down view 2d game at the moment and I am learning a ton about sprites and sprite handling. My question is how to handle a set of sprites that can be rotated in as many as 32 directions.</p> <p>At the moment a given object has its sprite sheet with all of the animations oriented with the object...
2
2009-08-14T00:47:42Z
1,296,881
<p>Typically you will sacrifice either processor time or memory, and you need to balance between the two. Unless you've got some great limit to your processor or you're computing a lot of expensive stuff, there's no real reason to put all that into the memory. Rotating a few sprites with a transform is cheap enough tha...
1
2009-08-18T22:18:49Z
[ "python", "pygame", "sprite" ]
Python 3 and static typing
1,275,646
<p>I didn't really pay as much attention to Python 3's development as I would have liked, and only just noticed some interesting new syntax changes. Specifically from <a href="http://stackoverflow.com/questions/1269795/unusual-speed-difference-between-python-and-c/1271927#1271927">this SO answer</a> function parameter ...
52
2009-08-14T01:47:26Z
1,275,658
<p>As mentioned in that PEP, static type checking is one of the possible applications that function annotations can be used for, but they're leaving it up to third-party libraries to decide how to do it. That is, there isn't going to be an official implementation in core python.</p> <p>As far as third-party implementa...
14
2009-08-14T01:53:23Z
[ "python", "python-3.x", "static-typing" ]
Python 3 and static typing
1,275,646
<p>I didn't really pay as much attention to Python 3's development as I would have liked, and only just noticed some interesting new syntax changes. Specifically from <a href="http://stackoverflow.com/questions/1269795/unusual-speed-difference-between-python-and-c/1271927#1271927">this SO answer</a> function parameter ...
52
2009-08-14T01:47:26Z
1,276,121
<p>"Static typing" in Python can only be implemented so that the type checking is done in run-time, which means it slows down the application. Therefore you don't want that as a generality. Instead you want some of your methods to check it's inputs. This can be easily done with plain asserts, or with decorators if you ...
13
2009-08-14T05:01:33Z
[ "python", "python-3.x", "static-typing" ]
Python 3 and static typing
1,275,646
<p>I didn't really pay as much attention to Python 3's development as I would have liked, and only just noticed some interesting new syntax changes. Specifically from <a href="http://stackoverflow.com/questions/1269795/unusual-speed-difference-between-python-and-c/1271927#1271927">this SO answer</a> function parameter ...
52
2009-08-14T01:47:26Z
1,276,582
<p>Thanks for reading my code!</p> <p>Indeed, it's not hard to create a generic annotation enforcer in Python. Here's my take:</p> <pre><code>'''Very simple enforcer of type annotations. This toy super-decorator can decorate all functions in a given module that have annotations so that the type of input and output ...
31
2009-08-14T07:53:55Z
[ "python", "python-3.x", "static-typing" ]
Python 3 and static typing
1,275,646
<p>I didn't really pay as much attention to Python 3's development as I would have liked, and only just noticed some interesting new syntax changes. Specifically from <a href="http://stackoverflow.com/questions/1269795/unusual-speed-difference-between-python-and-c/1271927#1271927">this SO answer</a> function parameter ...
52
2009-08-14T01:47:26Z
14,814,818
<p>This is not an answer to question directly, but I found out a Python fork that adds static typing: <a href="http://www.mypy-lang.org/">mypy-lang.org</a>, of course one can't rely on it as it's still small endeavor, but interesting.</p>
12
2013-02-11T15:05:33Z
[ "python", "python-3.x", "static-typing" ]
Python 3 and static typing
1,275,646
<p>I didn't really pay as much attention to Python 3's development as I would have liked, and only just noticed some interesting new syntax changes. Specifically from <a href="http://stackoverflow.com/questions/1269795/unusual-speed-difference-between-python-and-c/1271927#1271927">this SO answer</a> function parameter ...
52
2009-08-14T01:47:26Z
39,145,690
<p>Sure, static typing seems a bit "unpythonic" and I don't use it all the time. But there are cases (e.g. nested classes, as in domain specific language parsing) where it can really speed up your development. </p> <p>Then I prefer using <a href="https://gist.github.com/leycec/3d48cc60e7d5fe8860b077acb067dc54" rel="no...
0
2016-08-25T12:44:30Z
[ "python", "python-3.x", "static-typing" ]
JQuery "get" failure (using Google App Engine on the back-end)
1,275,708
<p>What I am trying to do is pretty simple: yet something has clearly gone awry.</p> <p>On the Front-End:</p> <pre><code>function eval() { var x = 'Unchanged X' $.get("/", { entry: document.getElementById('entry').value }, function(data){ x = data; } ); $("#result").html(x...
1
2009-08-14T02:12:46Z
1,275,713
<p><code>$("#result").html(x);</code> goes in the <code>get()</code> callback</p>
2
2009-08-14T02:16:25Z
[ "javascript", "jquery", "python", "google-app-engine" ]
JQuery "get" failure (using Google App Engine on the back-end)
1,275,708
<p>What I am trying to do is pretty simple: yet something has clearly gone awry.</p> <p>On the Front-End:</p> <pre><code>function eval() { var x = 'Unchanged X' $.get("/", { entry: document.getElementById('entry').value }, function(data){ x = data; } ); $("#result").html(x...
1
2009-08-14T02:12:46Z
1,275,809
<p>If the callback is not running you can try changing the $.get into a $.ajax() call, and adding an error callback, to see if the server is returning an error.</p> <p>Or better yet, check in the "net" panel in firebug to see what the server response is, which might help you track down what the issue is on the back en...
2
2009-08-14T02:48:31Z
[ "javascript", "jquery", "python", "google-app-engine" ]
JQuery "get" failure (using Google App Engine on the back-end)
1,275,708
<p>What I am trying to do is pretty simple: yet something has clearly gone awry.</p> <p>On the Front-End:</p> <pre><code>function eval() { var x = 'Unchanged X' $.get("/", { entry: document.getElementById('entry').value }, function(data){ x = data; } ); $("#result").html(x...
1
2009-08-14T02:12:46Z
1,276,473
<p>First we have the silly mistake:</p> <pre><code>&lt;font size="3" face="Trebuchet MS"&gt;Speak Your Mind:&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;input type="text" size="60" id="entry"/&gt; &lt;img valign="bottom" src='/assets/cognifyup.png' onMouseOver="over()" onMouseOut="out()" onMouseDown="out(); evaluate();"...
1
2009-08-14T07:20:48Z
[ "javascript", "jquery", "python", "google-app-engine" ]
how to access dictionary element in django template?
1,275,735
<p>I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.</p> <pre><code>{% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} &lt;br /&gt; {% endfor %} </code></pre> <p>it raises an exception with ...
110
2009-08-14T02:24:58Z
1,275,751
<p>You need to find (or define) a 'get' template tag, for example, <a href="http://push.cx/2007/django-template-tag-for-dictionary-access">here</a>.</p>
9
2009-08-14T02:30:39Z
[ "python", "django" ]
how to access dictionary element in django template?
1,275,735
<p>I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.</p> <pre><code>{% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} &lt;br /&gt; {% endfor %} </code></pre> <p>it raises an exception with ...
110
2009-08-14T02:24:58Z
1,275,805
<p>Ideally, you would create a method on the choice object that found itself in votes, or create a relationship between the models. A template tag that performed the dictionary lookup would work, too.</p>
3
2009-08-14T02:46:44Z
[ "python", "django" ]
how to access dictionary element in django template?
1,275,735
<p>I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.</p> <pre><code>{% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} &lt;br /&gt; {% endfor %} </code></pre> <p>it raises an exception with ...
110
2009-08-14T02:24:58Z
1,275,999
<p>To echo / extend upon Jeff's comment, what I think you should aim for is simply a property in your Choice class that calculates the number of votes associated with that object: </p> <pre><code> class Choice(models.Model): text = models.CharField(max_length=200) def calculateVotes(self): ...
40
2009-08-14T04:07:47Z
[ "python", "django" ]
how to access dictionary element in django template?
1,275,735
<p>I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.</p> <pre><code>{% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} &lt;br /&gt; {% endfor %} </code></pre> <p>it raises an exception with ...
110
2009-08-14T02:24:58Z
1,724,201
<p>you can use the dot notation:</p> <blockquote> <p>Dot lookups can be summarized like this: when the template system encounters a dot in a variable name, it tries the following lookups, in this order:</p> <ul> <li>Dictionary lookup (e.g., foo["bar"])</li> <li>Attribute lookup (e.g., foo.bar)</li> ...
121
2009-11-12T18:01:40Z
[ "python", "django" ]
how to access dictionary element in django template?
1,275,735
<p>I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.</p> <pre><code>{% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} &lt;br /&gt; {% endfor %} </code></pre> <p>it raises an exception with ...
110
2009-08-14T02:24:58Z
6,285,769
<pre><code>choices = {'key1':'val1', 'key2':'val2'} </code></pre> <p>Here's the template:</p> <pre> &lt;ul&gt; {% for key, value in choices.items %} &lt;li&gt;{{key}} - {{value}}&lt;/li&gt; {% endfor %} &lt;/ul&gt; </pre> <p>Basically, <code>.items</code> is a Django keyword that splits a dictionary into a list ...
180
2011-06-08T21:59:02Z
[ "python", "django" ]
how to access dictionary element in django template?
1,275,735
<p>I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.</p> <pre><code>{% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} &lt;br /&gt; {% endfor %} </code></pre> <p>it raises an exception with ...
110
2009-08-14T02:24:58Z
37,053,330
<p><a href="https://github.com/telminov/sw-django-utils/blob/master/djutils/templatetags/djutils.py" rel="nofollow">django_template_filter</a> filter name get_value_from_dict</p> <pre><code>{{ your_dict|get_value_from_dict:your_key }} </code></pre>
0
2016-05-05T14:32:36Z
[ "python", "django" ]
how to access dictionary element in django template?
1,275,735
<p>I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.</p> <pre><code>{% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} &lt;br /&gt; {% endfor %} </code></pre> <p>it raises an exception with ...
110
2009-08-14T02:24:58Z
38,530,067
<p>Similar to the answer by @russian_spy :</p> <pre><code>&lt;ul&gt; {% for choice in choices.items %} &lt;li&gt;{{choice.0}} - {{choice.1}}&lt;/li&gt; {% endfor %} &lt;/ul&gt; </code></pre> <p>This might be suitable for breaking down more complex dictionaries.</p>
0
2016-07-22T15:19:35Z
[ "python", "django" ]
Executes Fine In Jail Shell but not in Browser
1,276,497
<p>My python script executes fine in Jail shell, putting out html which I can pipe to an html file. When I look at the file, it's exactly what I want. However when I try to run the file from a browser I get a 500 error. According to the instructions at <a href="http://imgseekweb.sourceforge.net/install.html" rel="no...
0
2009-08-14T07:27:40Z
1,280,412
<p>My hoster resolved the issue. It turns out I'm working in a Windows environment with Microsoft Expression 2.0 HTML editor. The code needed to be converted to a UNIX environment with dos2unix which is installed in the hoster environment and can be accessed from the shell...Thanks for reading this thread to any who ...
0
2009-08-14T21:54:01Z
[ "python", "browser", "scripting" ]
Take screenshots **quickly** from python
1,276,616
<p>A <code>PIL.Image.grab() </code> takes about 0.5 seconds. That's just to get data from the screen to my app, without any processing on my part. <a href="http://www.fraps.com/" rel="nofollow">FRAPS</a>, on the other hand, can take screenshots up to 30 FPS. Is there any way for me to do the same from a Python program?...
4
2009-08-14T08:08:31Z
1,276,664
<p>If you want fast screenshots, you must use a lower level API, like DirectX or GTK. There are Python wrappers for those, like <a href="http://directpython.sourceforge.net/" rel="nofollow">DirectPython</a> and <a href="http://www.pygtk.org/" rel="nofollow">PyGTK</a>. Some samples I've found follow:</p> <ul> <li><p><a...
1
2009-08-14T08:25:02Z
[ "python", "image", "optimization", "performance", "screen-scraping" ]
Stripping everything but alphanumeric chars from a string in Python
1,276,764
<p>What is the best way to strip all non alphanumeric characters from a string, using Python?</p> <p>The solutions presented in the <a href="http://stackoverflow.com/questions/840948">PHP variant of this question</a> will probably work with some minor adjustments, but don't seem very 'pythonic' to me.</p> <p>For the ...
142
2009-08-14T08:54:47Z
1,276,774
<p>Regular expressions to the rescue:</p> <pre><code>import re re.sub(r'\W+', '', your_string) </code></pre>
116
2009-08-14T08:57:37Z
[ "python", "string" ]
Stripping everything but alphanumeric chars from a string in Python
1,276,764
<p>What is the best way to strip all non alphanumeric characters from a string, using Python?</p> <p>The solutions presented in the <a href="http://stackoverflow.com/questions/840948">PHP variant of this question</a> will probably work with some minor adjustments, but don't seem very 'pythonic' to me.</p> <p>For the ...
142
2009-08-14T08:54:47Z
1,276,782
<p>How about:</p> <pre><code>def ExtractAlphanumeric(InputString): from string import ascii_letters, digits return "".join([ch for ch in InputString if ch in (ascii_letters + digits)]) </code></pre> <p>This works by using list comprehension to produce a list of the characters in <code>InputString</code> if th...
8
2009-08-14T08:58:39Z
[ "python", "string" ]
Stripping everything but alphanumeric chars from a string in Python
1,276,764
<p>What is the best way to strip all non alphanumeric characters from a string, using Python?</p> <p>The solutions presented in the <a href="http://stackoverflow.com/questions/840948">PHP variant of this question</a> will probably work with some minor adjustments, but don't seem very 'pythonic' to me.</p> <p>For the ...
142
2009-08-14T08:54:47Z
1,276,804
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; string = "Kl13@£$%[};'\"" &gt;&gt;&gt; pattern = re.compile('\W') &gt;&gt;&gt; string = re.sub(pattern, '', string) &gt;&gt;&gt; print string Kl13 </code></pre>
6
2009-08-14T09:01:22Z
[ "python", "string" ]
Stripping everything but alphanumeric chars from a string in Python
1,276,764
<p>What is the best way to strip all non alphanumeric characters from a string, using Python?</p> <p>The solutions presented in the <a href="http://stackoverflow.com/questions/840948">PHP variant of this question</a> will probably work with some minor adjustments, but don't seem very 'pythonic' to me.</p> <p>For the ...
142
2009-08-14T08:54:47Z
1,276,811
<p>You could try:</p> <pre><code>print ''.join(ch for ch in some_string if ch.isalnum()) </code></pre>
14
2009-08-14T09:02:28Z
[ "python", "string" ]
Stripping everything but alphanumeric chars from a string in Python
1,276,764
<p>What is the best way to strip all non alphanumeric characters from a string, using Python?</p> <p>The solutions presented in the <a href="http://stackoverflow.com/questions/840948">PHP variant of this question</a> will probably work with some minor adjustments, but don't seem very 'pythonic' to me.</p> <p>For the ...
142
2009-08-14T08:54:47Z
1,277,047
<p>I just timed some functions out of curiosity. In these tests I'm removing non-alphanumeric characters from the string <code>string.printable</code> (part of the built-in <code>string</code> module).</p> <pre><code>$ python -m timeit -s \ "import string" \ "''.join(ch for ch in string.printable if ch.isal...
160
2009-08-14T10:03:32Z
[ "python", "string" ]
Stripping everything but alphanumeric chars from a string in Python
1,276,764
<p>What is the best way to strip all non alphanumeric characters from a string, using Python?</p> <p>The solutions presented in the <a href="http://stackoverflow.com/questions/840948">PHP variant of this question</a> will probably work with some minor adjustments, but don't seem very 'pythonic' to me.</p> <p>For the ...
142
2009-08-14T08:54:47Z
1,280,823
<p>Use the <strong>str.translate()</strong> method.</p> <p>Presuming you will be doing this often:</p> <p>(1) Once, create a string containing all the characters you wish to delete:</p> <pre><code>delchars = ''.join(c for c in map(chr, range(256)) if not c.isalnum()) </code></pre> <p>(2) Whenever you want to scrunc...
52
2009-08-15T00:33:48Z
[ "python", "string" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,277,175
<p>I compile it in <code>/usr/local</code> without any issues whatsoever.</p> <p>Install Python, libxml2, libxslt and then lxml. You might need setuptools installed too.</p>
-4
2009-08-14T10:33:46Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,277,258
<p>Have you tried with easy_install? </p> <ul> <li><a href="http://peak.telecommunity.com/DevCenter/EasyInstall" rel="nofollow">http://peak.telecommunity.com/DevCenter/EasyInstall</a></li> </ul> <p>I don't own a Mac so I can't test it, but easy_install is almost considered the standard way to install python modules, ...
-2
2009-08-14T10:57:49Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,277,326
<p>Try installing Cython and installing from source, easy_install does fail. I haven't tried on my mac yet though.</p> <p>Failing that the ports version isn't that ancient. You can see the dependencies, some of which had to be updated for my Linux build of lxml.</p> <p>info py25-lxml py25-lxml @2.1.5 (python, devel)<...
0
2009-08-14T11:15:46Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,277,327
<p>This is quite up to date - march 2009: <a href="http://lsimons.wordpress.com/2008/08/31/how-to-install-lxml-python-module-on-mac-os-105-leopard/" rel="nofollow">http://lsimons.wordpress.com/2008/08/31/how-to-install-lxml-python-module-on-mac-os-105-leopard/</a></p>
0
2009-08-14T11:15:50Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,277,421
<p>Thanks to @jessenoller on Twitter I have an answer that fits my needs - you can compile lxml with static dependencies, hence avoiding messing with the libxml2 that ships with OS X. Here's what worked for me:</p> <pre><code>cd /tmp curl -O http://lxml.de/files/lxml-3.6.0.tgz tar -xzvf lxml-3.6.0.tgz cd lxml-3.6.0 p...
33
2009-08-14T11:40:39Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,277,425
<p>This worked for me in the past <a href="http://muffinresearch.co.uk/archives/2009/03/05/install-lxml-on-osx/" rel="nofollow">install lxml on osx</a></p>
1
2009-08-14T11:41:46Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,333,631
<p>Easy_install <em>can</em> work using this:</p> <p>STATIC_DEPS=true easy_install 'lxml>=2.2beta4'</p> <p>you may <em>then</em> need to run, depending on permissions;</p> <p>STATIC_DEPS=true sudo easy_install 'lxml>=2.2beta4'</p> <p>see <a href="http://muffinresearch.co.uk/archives/2009/03/05/install-lxml-on-osx/...
5
2009-08-26T10:05:27Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
1,542,110
<p>lxml is <a href="http://code.activestate.com/pypm/lxml/" rel="nofollow">included</a> in the <a href="http://docs.activestate.com/activepython/2.7/pypm.html" rel="nofollow">pypm</a> repository:</p> <pre><code>$ pypm install lxml </code></pre>
0
2009-10-09T06:27:38Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
5,785,013
<p>I've had excellent luck with <a href="http://mxcl.github.com/homebrew/">Homebrew</a> to install the <code>libxml2</code> dependency:</p> <pre><code>brew install libxml2 </code></pre> <p>Homebrew doesn't seem to have <code>libxslt</code> available, but I've not yet had a need for XSLT. YMMV.</p> <p>Once you have t...
16
2011-04-26T01:32:08Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
6,545,556
<p>This worked for me (10.6.8):</p> <pre><code>sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml </code></pre>
30
2011-07-01T08:38:34Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
7,850,559
<p>I had this working fine with Snow Lepoard but after I upgraded to Lion I had to symlink gcc-4.2 to gcc. Running sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml was looking for gcc-4.2 instead of gcc.</p>
1
2011-10-21T14:06:12Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
10,323,988
<p>To install with up to date versions of libxml2 and libxslt: </p> <pre><code>ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true pip install lxml </code></pre> <p>To install with specific versions of libraries:</p> <pre><code>ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSI...
0
2012-04-25T21:21:11Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
19,303,920
<p>This worked for me on 10.8.5</p> <ol> <li>Install Xcode from Mac App Store</li> <li>Xcode -> Preferences -> Downloads -> Command Line Tools</li> <li>Install homebrew using</li> <li><code>ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"</code></li> <li><code>brew install libxml2</code></li> <li><code>...
2
2013-10-10T18:52:08Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
21,501,469
<p>On <strong>OS X 10.9.1</strong> the suggested answer above errors out during install -- following changes had to be made:</p> <pre><code>cd /tmp curl -o lxml-3.3.0.tgz http://lxml.de/files/lxml-3.3.0.tgz tar -xzvf lxml-3.3.0.tgz cd lxml-3.3.0 python setup.py build --static-deps --libxml2-version=2.8.0 --li...
3
2014-02-01T17:54:12Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
24,543,380
<p>A lot of pain went into this for an outdated 10.6.8 os x but here it goes for anyone running Snow Leopard! </p> <p>First you have to install a different version of libxml2 from homebrew and install --with-python. You can do this by typing in the following commands.</p> <pre><code>brew update brew edit libxml2 </co...
0
2014-07-03T00:55:04Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
33,181,756
<p>I'm using OSX 10.11 El Capitan and Homebrew. Using <code>pip install lxml</code> would give me "fatal error: 'libxml/xmlversion.h' file not found" and "failed with error code 1" blah blah.</p> <p>According to the <a href="http://lxml.de/installation.html" rel="nofollow">official website</a>, I should use <code>STAT...
1
2015-10-17T01:24:15Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
How do you install lxml on OS X Leopard without using MacPorts or Fink?
1,277,124
<p>I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?</p> <p>Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.</p>
34
2009-08-14T10:22:27Z
34,777,511
<p>using homebrew (0.9.5) on el capitan (10.11.1) the following worked for me:</p> <pre><code>brew install libxml2 LD_FLAGS=-L/usr/local/opt/libxml2/lib CPPFLAGS=-I/usr/local/opt/libxml2/include/libxml2 pip install lxml </code></pre>
2
2016-01-13T21:36:49Z
[ "python", "osx", "shell", "lxml", "osx-leopard" ]
Python: zip-like function that pads to longest length?
1,277,278
<p>Is there a built-in function that works like <code>zip()</code> but that will pad the results so that the length of the resultant list is the length of the <em>longest</em> input rather than the <em>shortest</em> input?</p> <pre><code>&gt;&gt;&gt; a=['a1'] &gt;&gt;&gt; b=['b1','b2','b3'] &gt;&gt;&gt; c=['c1','c2'] ...
70
2009-08-14T11:04:09Z
1,277,286
<p>For Python 2.6x use <code>itertools</code> module's <a href="http://docs.python.org/library/itertools.html#itertools.izip_longest"><code>izip_longest</code></a>.</p> <p>For Python 3 use <a href="http://docs.python.org/3.1/library/itertools.html#itertools.zip_longest"><code>zip_longest</code></a> instead (no leading...
41
2009-08-14T11:06:13Z
[ "python", "list", "zip" ]
Python: zip-like function that pads to longest length?
1,277,278
<p>Is there a built-in function that works like <code>zip()</code> but that will pad the results so that the length of the resultant list is the length of the <em>longest</em> input rather than the <em>shortest</em> input?</p> <pre><code>&gt;&gt;&gt; a=['a1'] &gt;&gt;&gt; b=['b1','b2','b3'] &gt;&gt;&gt; c=['c1','c2'] ...
70
2009-08-14T11:04:09Z
1,277,311
<p>You can either use <a href="https://docs.python.org/2/library/itertools.html#itertools.izip_longest"><code>itertools.izip_longest</code></a> (Python 2.6+), or you can use <code>map</code> with <code>None</code>. It is a little known <a href="https://docs.python.org/2/library/functions.html#map">feature of <code>map<...
98
2009-08-14T11:10:44Z
[ "python", "list", "zip" ]
How can I pass my locals and access the variables directly from another function?
1,277,519
<p>Let's say I have this :</p> <pre><code> def a(dict): locals().update(dict) print size def b(): size = 20 f(locals()) </code></pre> <p>What do I have to do to access the <code>size</code> variable directly from the <code>a</code> function? I know of :</p> <pre><code> size = dict["size"] </code></pre> <p>...
3
2009-08-14T12:08:57Z
1,277,538
<pre><code>print size </code></pre> <p>cannot work, because "size" is not known when the code is compiled. Your code will work if you change it like this:</p> <pre><code>def a(dict): locals().update(dict) print locals()["size"] def b(): size = 20 a(locals()) </code></pre> <p>But as the comment to yo...
0
2009-08-14T12:18:27Z
[ "python", "variables", "function", "language-features" ]
How can I pass my locals and access the variables directly from another function?
1,277,519
<p>Let's say I have this :</p> <pre><code> def a(dict): locals().update(dict) print size def b(): size = 20 f(locals()) </code></pre> <p>What do I have to do to access the <code>size</code> variable directly from the <code>a</code> function? I know of :</p> <pre><code> size = dict["size"] </code></pre> <p>...
3
2009-08-14T12:08:57Z
1,277,564
<p>Is this helping you somehow?</p> <pre><code>def print_size(size=None): print(size) dict = {'size': 'XXL'} print_size(**dict) </code></pre>
0
2009-08-14T12:23:42Z
[ "python", "variables", "function", "language-features" ]
How can I pass my locals and access the variables directly from another function?
1,277,519
<p>Let's say I have this :</p> <pre><code> def a(dict): locals().update(dict) print size def b(): size = 20 f(locals()) </code></pre> <p>What do I have to do to access the <code>size</code> variable directly from the <code>a</code> function? I know of :</p> <pre><code> size = dict["size"] </code></pre> <p>...
3
2009-08-14T12:08:57Z
1,277,683
<p>You can use closures to access the scope of another function:</p> <pre><code>def b(): def a(): print size size = 20 a() </code></pre> <p>The trick is to stack functions which belongs together in each other. This way the inner function a can access the local variables of the outer function b.</p> <p>Bu...
1
2009-08-14T12:51:38Z
[ "python", "variables", "function", "language-features" ]
How can I pass my locals and access the variables directly from another function?
1,277,519
<p>Let's say I have this :</p> <pre><code> def a(dict): locals().update(dict) print size def b(): size = 20 f(locals()) </code></pre> <p>What do I have to do to access the <code>size</code> variable directly from the <code>a</code> function? I know of :</p> <pre><code> size = dict["size"] </code></pre> <p>...
3
2009-08-14T12:08:57Z
1,278,351
<p>The Python compiler optimizes access to local variables by recognizing at compile time whether the barenames a function is accessing are local (i.e., barenames assigned or otherwise bound within the function). So if you code:</p> <pre><code>def lv1(d): locals().update(d) print zap </code></pre> <p>the compiler...
9
2009-08-14T14:54:55Z
[ "python", "variables", "function", "language-features" ]
python subprocess module: looping over stdout of child process
1,277,866
<p>I have some commands which I am running using the subprocess module. I then want to loop over the lines of the output. The documentation says do not do data_stream.stdout.read which I am not but I may be doing something which calls that. I am looping over the output like this:</p> <pre><code>for line in data_str...
4
2009-08-14T13:34:20Z
1,277,980
<p><code>data_stream.stdout</code> is a standard output <strong>handle</strong>. you shouldn't be looping over it. <a href="http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate" rel="nofollow"><code>communicate</code></a> returns tuple of <code>(stdoutdata, stderr)</code>. this <code>stdoutdata</...
0
2009-08-14T13:54:15Z
[ "python", "subprocess" ]
python subprocess module: looping over stdout of child process
1,277,866
<p>I have some commands which I am running using the subprocess module. I then want to loop over the lines of the output. The documentation says do not do data_stream.stdout.read which I am not but I may be doing something which calls that. I am looping over the output like this:</p> <pre><code>for line in data_str...
4
2009-08-14T13:34:20Z
1,278,000
<p>You have to worry about deadlocks if you're <strong>communicating</strong> with your subprocess, i.e. if you're writing to stdin as well as reading from stdout. Because these pipes may be cached, doing this kind of two-way communication is very much a no-no:</p> <pre><code>data_stream = Popen(mycmd, stdin=PIPE, std...
6
2009-08-14T13:57:35Z
[ "python", "subprocess" ]
python subprocess module: looping over stdout of child process
1,277,866
<p>I have some commands which I am running using the subprocess module. I then want to loop over the lines of the output. The documentation says do not do data_stream.stdout.read which I am not but I may be doing something which calls that. I am looping over the output like this:</p> <pre><code>for line in data_str...
4
2009-08-14T13:34:20Z
1,278,211
<p>SilentGhost's/chrispy's answers are OK if you have a small to moderate amount of output from your subprocess. Sometimes, though, there may be a lot of output - too much to comfortably buffer in memory. In such a case, the thing to do is <code>start()</code> the process, and spawn a couple of threads - one to read <c...
3
2009-08-14T14:33:29Z
[ "python", "subprocess" ]
python subprocess module: looping over stdout of child process
1,277,866
<p>I have some commands which I am running using the subprocess module. I then want to loop over the lines of the output. The documentation says do not do data_stream.stdout.read which I am not but I may be doing something which calls that. I am looping over the output like this:</p> <pre><code>for line in data_str...
4
2009-08-14T13:34:20Z
1,278,245
<p>The two answer have caught the gist of the issue pretty well: don't mix writing something to the subprocess, reading something from it, writing again, etc -- the pipe's buffering means you're at risk of a deadlock. If you can, write everything you need to write to the subprocess FIRST, close that pipe, and only THEN...
6
2009-08-14T14:38:51Z
[ "python", "subprocess" ]
Python and dictionary like object
1,277,881
<p>I need a python 3.1 deep update function for dictionaries (a function that will recursively update child dictionaries that are inside a parent dictionary).</p> <p>But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore I want to avoid using <...
10
2009-08-14T13:37:53Z
1,277,918
<p>use <code>isinstance</code>, there is nothing wrong with it and it's routinely used in code requiring recursion.</p> <p>If by dictionary-like you mean the object's class inherit from the <code>dict</code>, <code>isinstance</code> will also return <code>True</code>.</p> <pre><code>&gt;&gt;&gt; class A(dict): pa...
1
2009-08-14T13:43:29Z
[ "python", "dictionary", "duck-typing" ]
Python and dictionary like object
1,277,881
<p>I need a python 3.1 deep update function for dictionaries (a function that will recursively update child dictionaries that are inside a parent dictionary).</p> <p>But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore I want to avoid using <...
10
2009-08-14T13:37:53Z
1,277,936
<p>Duck typing is where you do what you want to do, and deal with the fallout if your objects don't behave the way you expected them to.</p> <p>You want to check if something is dict-like, and update it if it is, right? Just call the object's update method, and handle the Exception you get if there is no such method.<...
1
2009-08-14T13:45:06Z
[ "python", "dictionary", "duck-typing" ]
Python and dictionary like object
1,277,881
<p>I need a python 3.1 deep update function for dictionaries (a function that will recursively update child dictionaries that are inside a parent dictionary).</p> <p>But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore I want to avoid using <...
10
2009-08-14T13:37:53Z
1,278,070
<p>Check out the (new in 3.x) abstract base classes (ABC's) in the collections module:</p> <p><a href="http://docs.python.org/3.1/library/collections.html">http://docs.python.org/3.1/library/collections.html</a></p> <p>I would consider checking with isinstance against Mapping like in the following:</p> <pre><code>&g...
11
2009-08-14T14:08:58Z
[ "python", "dictionary", "duck-typing" ]
Python and dictionary like object
1,277,881
<p>I need a python 3.1 deep update function for dictionaries (a function that will recursively update child dictionaries that are inside a parent dictionary).</p> <p>But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore I want to avoid using <...
10
2009-08-14T13:37:53Z
1,278,292
<p>If you also have to handle custom classes that behave like dictionaries but aren't subclassed from dict, you can use getattr to get the function you require.</p> <pre><code># loop # ... more code someObject = getObject(..) try: getattr(someObject, "update")("someValue") except AttributeError: # Wasn't a typ...
0
2009-08-14T14:45:47Z
[ "python", "dictionary", "duck-typing" ]
Python and dictionary like object
1,277,881
<p>I need a python 3.1 deep update function for dictionaries (a function that will recursively update child dictionaries that are inside a parent dictionary).</p> <p>But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore I want to avoid using <...
10
2009-08-14T13:37:53Z
1,279,829
<p>Well, to update recursively a dictionary, you must call the 'items' method to iterate on it.</p> <p>So I suggest, you just do :</p> <pre><code>try : for key, value in data.items() : # recursive call except AttributeError : # handling the trouble </code></pre>
1
2009-08-14T19:47:54Z
[ "python", "dictionary", "duck-typing" ]
Python and dictionary like object
1,277,881
<p>I need a python 3.1 deep update function for dictionaries (a function that will recursively update child dictionaries that are inside a parent dictionary).</p> <p>But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore I want to avoid using <...
10
2009-08-14T13:37:53Z
24,437,844
<p>I like to check for the '<strong>__setitem__</strong>' magic method... this that is what allows the foo['bar'] = baz behavior.</p> <pre><code>if getattr(obj, '__setattr__'): obj[key] = val </code></pre> <p>Here is the <a href="https://docs.python.org/2/reference/datamodel.html#emulating-container-types" rel="n...
0
2014-06-26T18:40:42Z
[ "python", "dictionary", "duck-typing" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
1,277,937
<pre><code>filter(lambda n: isinstance(n, int), [1,2,"three"]) </code></pre>
0
2009-08-14T13:45:28Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
1,277,940
<p>List comprehensions.</p> <pre><code>list_2 = [num for num in list_1 if isinstance(num, (int,float))] </code></pre>
12
2009-08-14T13:46:19Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
1,277,943
<pre><code>list_2 = [i for i in list_1 if isinstance(i, (int, float))] </code></pre>
0
2009-08-14T13:46:51Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
1,277,949
<pre><code>list_2 = [i for i in list_1 if isinstance(i, (int, float))] </code></pre>
2
2009-08-14T13:47:54Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
1,277,966
<pre><code>&gt;&gt;&gt; [ i for i in list_1 if not str(i).replace(" ","").isalpha() ] [1, 123131.13099999999, 9.9999999999999995e-07, 34.124512352650001] </code></pre>
-1
2009-08-14T13:51:54Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
1,277,993
<p>This should be the most efficent and shortest:</p> <pre><code>import operator filter(operator.isNumberType, list_1) </code></pre> <p>Edit: this in python 3000:</p> <pre><code>import numbers [x for x in list_1 if isinstance(x, numbers.Number)] </code></pre>
13
2009-08-14T13:56:52Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
1,281,993
<p>for short of SilentGhost way</p> <pre><code>list_2 = [i for i in list_1 if isinstance(i, (int, float))] </code></pre> <p>to</p> <pre><code>list_2 = [i for i in list_1 if not isinstance(i, str)] </code></pre>
-1
2009-08-15T14:20:37Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
34,065,821
<p>I think the easiest way is:</p> <pre><code>[s for s in myList if s.isdigit()] </code></pre> <p>Hope it helps!</p>
0
2015-12-03T12:14:45Z
[ "python" ]
Is there a way to output the numbers only from a python list?
1,277,914
<p>Simple Question:</p> <pre><code>list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ] </code></pre> <p>I want to create a <code>list_2</code> such that it only contains the numbers:</p> <pre><code>list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ] </code><...
5
2009-08-14T13:42:47Z
39,723,833
<p>All solutions proposed work only if the numbers inside the list are already converted to the appropriate type (<code>int</code>, <code>float</code>).</p> <p>I found myself with a list coming from the <code>fetchall</code> function of <code>sqlite3</code>. All elements there were formated as <code>str</code>, even i...
0
2016-09-27T11:45:53Z
[ "python" ]
Updating profile with python-twitter
1,278,192
<p>I am trying to update my Profile info via <a href="http://code.google.com/p/python-twitter/" rel="nofollow">python-twitter module</a>.</p> <pre><code>&gt;&gt;&gt; api = twitter.Api(username="username", password="password") &gt;&gt;&gt; user = api.GetUser(user="username") &gt;&gt;&gt; user.SetLocation('New Location'...
0
2009-08-14T14:31:48Z
1,278,284
<p>I don't believe that the python-twitter module currently supports updating a profile. SetLocation will only update your local user object that GetUser has returned.</p> <p>It would be relatively trivial to add support for this to the module though. Have a look at this method:</p> <p><a href="http://apiwiki.twitter...
1
2009-08-14T14:45:15Z
[ "python", "api", "twitter" ]
Updating profile with python-twitter
1,278,192
<p>I am trying to update my Profile info via <a href="http://code.google.com/p/python-twitter/" rel="nofollow">python-twitter module</a>.</p> <pre><code>&gt;&gt;&gt; api = twitter.Api(username="username", password="password") &gt;&gt;&gt; user = api.GetUser(user="username") &gt;&gt;&gt; user.SetLocation('New Location'...
0
2009-08-14T14:31:48Z
2,266,068
<p>This are the set*profile* methods from User:</p> <pre><code>SetProfileBackgroundColor(self, profile_background_color) SetProfileBackgroundImageUrl(self, profile_background_image_url) SetProfileBackgroundTile(self, profile_background_tile) Set the boolean flag for whether to tile the profile background image. ...
0
2010-02-15T13:05:00Z
[ "python", "api", "twitter" ]
How to eliminate last digit from each of the top lines
1,278,664
<pre><code>&gt;Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA ATATTATAGCGCGCGCGCGGATATATATATATATATATATT &gt;Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT &gt;Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG </code></pre> <p>NOW,I would like to remove the last digit from each of th...
1
2009-08-14T15:52:28Z
1,278,687
<pre><code>if line.startswith('&gt;Sequence'): line = line[:-2] # trim 2 characters from the end of the string </code></pre> <p>or if there could be more than one digit after the period:</p> <pre><code>if line.startswith('&gt;Sequence'): dot_pos = line.rfind('.') # find position of rightmost period line = line[...
4
2009-08-14T15:57:51Z
[ "python", "file" ]
How to eliminate last digit from each of the top lines
1,278,664
<pre><code>&gt;Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA ATATTATAGCGCGCGCGCGGATATATATATATATATATATT &gt;Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT &gt;Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG </code></pre> <p>NOW,I would like to remove the last digit from each of th...
1
2009-08-14T15:52:28Z
1,278,690
<p>map <code>"".join(line.split('.')[:-1])</code> to each line of the file.</p>
2
2009-08-14T15:58:11Z
[ "python", "file" ]
How to eliminate last digit from each of the top lines
1,278,664
<pre><code>&gt;Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA ATATTATAGCGCGCGCGCGGATATATATATATATATATATT &gt;Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT &gt;Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG </code></pre> <p>NOW,I would like to remove the last digit from each of th...
1
2009-08-14T15:52:28Z
1,278,691
<pre><code>import fileinput import re for line in fileinput.input(inplace=True, backup='.bak'): line = line.rstrip() if line.startswith('&gt;'): line = re.sub(r'\.\d$', '', line) print line </code></pre> <p>many details can be changed depending on details of the processing you want, which you have not clear...
7
2009-08-14T15:58:29Z
[ "python", "file" ]
How to eliminate last digit from each of the top lines
1,278,664
<pre><code>&gt;Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA ATATTATAGCGCGCGCGCGGATATATATATATATATATATT &gt;Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT &gt;Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG </code></pre> <p>NOW,I would like to remove the last digit from each of th...
1
2009-08-14T15:52:28Z
1,278,695
<pre><code>import re trimmedtext = re.sub(r'(\d+\.\d+)\.\d', '$1', text) </code></pre> <p>Should do it. Somewhat simpler than searching for start characters (and it won't effect your DNA chains)</p>
4
2009-08-14T15:59:03Z
[ "python", "file" ]
How to eliminate last digit from each of the top lines
1,278,664
<pre><code>&gt;Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA ATATTATAGCGCGCGCGCGGATATATATATATATATATATT &gt;Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT &gt;Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG </code></pre> <p>NOW,I would like to remove the last digit from each of th...
1
2009-08-14T15:52:28Z
1,278,764
<p>Here's a short script. Run it like: <code>script [filename to clean]</code>. Lots of error handling omitted.</p> <p>It operates using generators, so it should work fine on huge files as well.</p> <pre><code>import sys import os def clean_line(line): if line.startswith("&gt;"): return line.rstrip()[:-2...
1
2009-08-14T16:13:19Z
[ "python", "file" ]
How to eliminate last digit from each of the top lines
1,278,664
<pre><code>&gt;Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA ATATTATAGCGCGCGCGCGGATATATATATATATATATATT &gt;Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT &gt;Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG </code></pre> <p>NOW,I would like to remove the last digit from each of th...
1
2009-08-14T15:52:28Z
1,278,956
<pre><code>import re input_file = open('in') output_file = open('out', 'w') for line in input_file: line = re.sub(r'(\d+[.]\d+)[.]\d+', r'\1', line) output_file.write(line) </code></pre>
0
2009-08-14T16:54:01Z
[ "python", "file" ]
Python When I catch an exception, how do I get the type, file, and line number?
1,278,705
<p>Catching an exception that would print like this:</p> <pre><code>Traceback (most recent call last): File "c:/tmp.py", line 1, in &lt;module&gt; 4 / 0 ZeroDivisionError: integer division or modulo by zero </code></pre> <p>I want to format it into:</p> <pre><code>ZeroDivisonError, tmp.py, 1 </code></pre>
115
2009-08-14T16:02:14Z
1,278,740
<pre><code>import sys, os try: raise NotImplementedError("No error") except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno) </code></pre>
161
2009-08-14T16:09:05Z
[ "python", "exception", "exception-handling", "stack-trace" ]
Python When I catch an exception, how do I get the type, file, and line number?
1,278,705
<p>Catching an exception that would print like this:</p> <pre><code>Traceback (most recent call last): File "c:/tmp.py", line 1, in &lt;module&gt; 4 / 0 ZeroDivisionError: integer division or modulo by zero </code></pre> <p>I want to format it into:</p> <pre><code>ZeroDivisonError, tmp.py, 1 </code></pre>
115
2009-08-14T16:02:14Z
16,046,900
<p><a href="http://jserv.sayya.org/misc/use_source_luke.png">Source</a> (Py v2.7.3) for <a href="http://hg.python.org/cpython/file/8dffb76faacc/Lib/traceback.py#l130">traceback.format_exception()</a> and called/related functions helps greatly. Embarrassingly, I always forget to <a href="http://catb.org/jargon/html/U/U...
22
2013-04-16T20:55:32Z
[ "python", "exception", "exception-handling", "stack-trace" ]
How do I detect missing fields in a CSV file in a Pythonic way?
1,278,749
<p>I'm trying to parse a CSV file using Python's <code>csv</code> module (specifically, the <code>DictReader</code> class). Is there a Pythonic way to detect empty or missing fields and throw an error?</p> <p>Here's a sample file using the following headers: NAME, LABEL, VALUE</p> <pre><code>foo,bar,baz yes,no x,y,z...
7
2009-08-14T16:10:36Z
1,278,779
<p>Something like this?</p> <pre><code>... for row in reader: for column, value in row.items(): if value is None or value == "": # raise Error, using value of column to say which field is missing </code></pre> <p>You may be able to use 'if not value:' as your test instead of the more explicit ...
1
2009-08-14T16:15:11Z
[ "python", "error-handling", "csv" ]
How do I detect missing fields in a CSV file in a Pythonic way?
1,278,749
<p>I'm trying to parse a CSV file using Python's <code>csv</code> module (specifically, the <code>DictReader</code> class). Is there a Pythonic way to detect empty or missing fields and throw an error?</p> <p>Here's a sample file using the following headers: NAME, LABEL, VALUE</p> <pre><code>foo,bar,baz yes,no x,y,z...
7
2009-08-14T16:10:36Z
1,278,792
<pre><code>if any(row[key] in (None, "") for key in row): # raise error </code></pre> <p><strong>Edit</strong>: Even better:</p> <pre><code>if any(val in (None, "") for val in row.itervalues()): # raise error </code></pre>
13
2009-08-14T16:17:55Z
[ "python", "error-handling", "csv" ]
How do I detect missing fields in a CSV file in a Pythonic way?
1,278,749
<p>I'm trying to parse a CSV file using Python's <code>csv</code> module (specifically, the <code>DictReader</code> class). Is there a Pythonic way to detect empty or missing fields and throw an error?</p> <p>Here's a sample file using the following headers: NAME, LABEL, VALUE</p> <pre><code>foo,bar,baz yes,no x,y,z...
7
2009-08-14T16:10:36Z
1,278,797
<p>Since <code>None</code> and empty strings both evaluate to <code>False</code>, you should consider this:</p> <pre><code>for row in reader: for header in HEADERS: if not row[header]: # raise error </code></pre> <p>Note that, unlike some other answers, you will still have the option of raisin...
2
2009-08-14T16:18:38Z
[ "python", "error-handling", "csv" ]
How do I detect missing fields in a CSV file in a Pythonic way?
1,278,749
<p>I'm trying to parse a CSV file using Python's <code>csv</code> module (specifically, the <code>DictReader</code> class). Is there a Pythonic way to detect empty or missing fields and throw an error?</p> <p>Here's a sample file using the following headers: NAME, LABEL, VALUE</p> <pre><code>foo,bar,baz yes,no x,y,z...
7
2009-08-14T16:10:36Z
1,278,896
<p>This code will provide, for each row, a list of field names which are not present (or are empty) for that row. You could then provide a more detailed exception, such as "Missing fields: foo, baz".</p> <pre><code>def missing(row): return [h for h in HEADERS if not row.get(h)] for row in reader: m = missing(...
1
2009-08-14T16:39:14Z
[ "python", "error-handling", "csv" ]
How do I detect missing fields in a CSV file in a Pythonic way?
1,278,749
<p>I'm trying to parse a CSV file using Python's <code>csv</code> module (specifically, the <code>DictReader</code> class). Is there a Pythonic way to detect empty or missing fields and throw an error?</p> <p>Here's a sample file using the following headers: NAME, LABEL, VALUE</p> <pre><code>foo,bar,baz yes,no x,y,z...
7
2009-08-14T16:10:36Z
1,278,903
<p>If you use matplotlib.mlab.csv2rec, it already saves the content of the file into an array and raise an error if one of the values is missing.</p> <pre><code>&gt;&gt;&gt; from matplotlib.mlab import csv2rec &gt;&gt;&gt; content_array = csv2rec('file.txt') IndexError: list index out of range </code></pre> <p>The pr...
0
2009-08-14T16:39:56Z
[ "python", "error-handling", "csv" ]
How do unit tests work in django-tagging, because I want mine to run like that?
1,279,032
<p>Few times while browsing <code>tests</code> dir in various Django apps I stumbled across <code>models.py</code> and <code>settings.py</code> files (in <code>django-tagging</code> for example). </p> <p>But there's no code to be found that syncs test models or applies custom test settings - but tests make use of them...
0
2009-08-14T17:13:45Z
1,279,096
<p>You mean, "How do I write unit tests in Django?" Check the <a href="http://docs.djangoproject.com/en/dev/topics/testing/" rel="nofollow">documentation on testing</a>.</p> <p>When I've done it, I wrote unit tests in a test/ subdirectory. Make sure the directory has an empty __init__.py file. You may also need a mode...
0
2009-08-14T17:26:25Z
[ "python", "django", "unit-testing" ]
How do unit tests work in django-tagging, because I want mine to run like that?
1,279,032
<p>Few times while browsing <code>tests</code> dir in various Django apps I stumbled across <code>models.py</code> and <code>settings.py</code> files (in <code>django-tagging</code> for example). </p> <p>But there's no code to be found that syncs test models or applies custom test settings - but tests make use of them...
0
2009-08-14T17:13:45Z
1,283,400
<p>If you want to run the tests in <code>django-tagging</code>, you can try:</p> <blockquote> <p>django-admin.py test --settings=tagging.tests.settings</p> </blockquote> <p>Basically, it uses doctests which are in the <code>tests.py</code> file inside the <code>tests</code> package/directory. The tests use the set...
1
2009-08-16T03:29:26Z
[ "python", "django", "unit-testing" ]
Python and regex
1,279,087
<p>i have to parse need string. Here is command I execute in Linux console:</p> <pre><code>amixer get Master |grep Mono: </code></pre> <p>And get, for example, </p> <pre><code>Mono: Playback 61 [95%] [-3.00dB] [on] </code></pre> <p>Then i test it from python-console:</p> <pre><code>import re,os print re.search( ur...
0
2009-08-14T17:25:01Z
1,279,095
<p><code>os.system()</code> returns the exit code from the application, not the text output of the application.</p> <p>You should read up on the <a href="http://docs.python.org/library/subprocess.html" rel="nofollow"><code>subprocess</code></a> Python module; it will do what you need.</p>
7
2009-08-14T17:26:25Z
[ "python", "regex" ]
Python and regex
1,279,087
<p>i have to parse need string. Here is command I execute in Linux console:</p> <pre><code>amixer get Master |grep Mono: </code></pre> <p>And get, for example, </p> <pre><code>Mono: Playback 61 [95%] [-3.00dB] [on] </code></pre> <p>Then i test it from python-console:</p> <pre><code>import re,os print re.search( ur...
0
2009-08-14T17:25:01Z
1,279,107
<p>How to run a process and get the output:</p> <p><a href="http://docs.python.org/library/popen2.html" rel="nofollow">http://docs.python.org/library/popen2.html</a></p>
0
2009-08-14T17:28:02Z
[ "python", "regex" ]
Python and regex
1,279,087
<p>i have to parse need string. Here is command I execute in Linux console:</p> <pre><code>amixer get Master |grep Mono: </code></pre> <p>And get, for example, </p> <pre><code>Mono: Playback 61 [95%] [-3.00dB] [on] </code></pre> <p>Then i test it from python-console:</p> <pre><code>import re,os print re.search( ur...
0
2009-08-14T17:25:01Z
1,279,115
<p>Instead of using <code>os.system()</code>, use the <code>subprocess</code> module:</p> <pre><code>from subprocess import Popen, PIPE p = Popen("amixer get Master | grep Mono:", shell = True, stdout = PIPE) stdout = p.stdout.read() print re.search( ur"(?&lt;=\[)[0-9]{1,3}", stdout).group() </code></pre>
1
2009-08-14T17:30:24Z
[ "python", "regex" ]
What's the regex for removing dots in acronyms but not in domain names?
1,279,110
<p>I want to remove dots in acronyms but not in domain names in a python string. For example, I want the string</p> <pre><code>'a.b.c. test@test.com http://www.test.com' </code></pre> <p>to become</p> <pre><code>'abc test@test.com http://www.test.com' </code></pre> <p>The closest regex I made so far is</p> <pre><...
1
2009-08-14T17:28:58Z
1,279,152
<p>I suggest you split the string at '@' (or whatever character makes sense), do the substitution on the first part, then put the string back together. I think that will show the intent of the code better than a complex regexp. Something like this, perhaps:</p> <pre><code>string='a.b.c. test@test.com http://www.test.c...
2
2009-08-14T17:37:46Z
[ "python", "regex" ]
What's the regex for removing dots in acronyms but not in domain names?
1,279,110
<p>I want to remove dots in acronyms but not in domain names in a python string. For example, I want the string</p> <pre><code>'a.b.c. test@test.com http://www.test.com' </code></pre> <p>to become</p> <pre><code>'abc test@test.com http://www.test.com' </code></pre> <p>The closest regex I made so far is</p> <pre><...
1
2009-08-14T17:28:58Z
1,279,162
<p>You could simply remove DOTS that don't have two [a-z] letters (or more) ahead of them:</p> <pre><code>\.(?![a-zA-Z]{2}) </code></pre> <p>But that will of course also remove the first DOT from the following address:</p> <p>name.i@foo.bar</p> <p>You could fix that by doing:</p> <pre><code>\.(?![a-zA-Z]{2}|[^\s@]...
2
2009-08-14T17:39:49Z
[ "python", "regex" ]
What's the regex for removing dots in acronyms but not in domain names?
1,279,110
<p>I want to remove dots in acronyms but not in domain names in a python string. For example, I want the string</p> <pre><code>'a.b.c. test@test.com http://www.test.com' </code></pre> <p>to become</p> <pre><code>'abc test@test.com http://www.test.com' </code></pre> <p>The closest regex I made so far is</p> <pre><...
1
2009-08-14T17:28:58Z
1,279,163
<p>If your data is always formatted like this then why not split your data into 3 parts by splitting on the space.</p> <p>Then it's pretty trivial to remove the periods from the first element and use join to remerge the parts.</p>
5
2009-08-14T17:40:06Z
[ "python", "regex" ]
What's the regex for removing dots in acronyms but not in domain names?
1,279,110
<p>I want to remove dots in acronyms but not in domain names in a python string. For example, I want the string</p> <pre><code>'a.b.c. test@test.com http://www.test.com' </code></pre> <p>to become</p> <pre><code>'abc test@test.com http://www.test.com' </code></pre> <p>The closest regex I made so far is</p> <pre><...
1
2009-08-14T17:28:58Z
1,279,417
<p>Not as elegant as a simple <code>re.sub()</code>, but try this:</p> <pre><code>import re s='a.b.c. test@test.com http://www.test.com' m=re.search('(.*?)(([a-zA-Z]\.){2,})(.*)', s) if m: replacement=''.join(m.group(2).split('.')) s=m.group(1)+replacement+m.group(4) print s </code></pre> <p>It assumes tha...
0
2009-08-14T18:30:24Z
[ "python", "regex" ]
What's the regex for removing dots in acronyms but not in domain names?
1,279,110
<p>I want to remove dots in acronyms but not in domain names in a python string. For example, I want the string</p> <pre><code>'a.b.c. test@test.com http://www.test.com' </code></pre> <p>to become</p> <pre><code>'abc test@test.com http://www.test.com' </code></pre> <p>The closest regex I made so far is</p> <pre><...
1
2009-08-14T17:28:58Z
1,280,397
<p>The following worked for me (with thanks to Bart for his answer):</p> <pre><code>re.sub('\.(?!(\S[^. ])|\d)', '', s) </code></pre> <p>This will not remove a dot if it is the first character in a word or acronym. </p>
1
2009-08-14T21:49:47Z
[ "python", "regex" ]
What's the regex for removing dots in acronyms but not in domain names?
1,279,110
<p>I want to remove dots in acronyms but not in domain names in a python string. For example, I want the string</p> <pre><code>'a.b.c. test@test.com http://www.test.com' </code></pre> <p>to become</p> <pre><code>'abc test@test.com http://www.test.com' </code></pre> <p>The closest regex I made so far is</p> <pre><...
1
2009-08-14T17:28:58Z
1,280,754
<p>A non-regex way:</p> <pre><code>&gt;&gt;&gt; S = 'a.b.c. test@test.com http://www.test.com' &gt;&gt;&gt; ' '.join(w if '@' in w or ':' in w else w.replace('.', '') for w in S.split()) 'abc test@test.com http://www.test.com' </code></pre> <p>(Requires spaces to split on, though - so if you had something like commas...
1
2009-08-15T00:00:57Z
[ "python", "regex" ]
Controlling Django ModelForm output
1,279,221
<p>I've got a Model in Django, example code below (not my actual code):</p> <pre><code>class Department(models.Model): name = models.CharField(max_length=100) abbreviation = models.CharField(max_length=4) </code></pre> <p>Let's say I do the following in the Django shell:</p> <pre><code>&gt;&gt;&gt; Departmen...
6
2009-08-14T17:49:06Z
1,279,291
<blockquote> <p>How can I change the way these items are sorted in the ModelForm code, or in the Model code, rather than in the template?</p> </blockquote> <p>One thing you can do is add an <a href="http://docs.djangoproject.com/en/dev/ref/models/options/#ordering"><code>ordering</code></a> <a href="http://docs.djan...
9
2009-08-14T18:04:31Z
[ "python", "django", "django-templates", "django-forms" ]
Controlling Django ModelForm output
1,279,221
<p>I've got a Model in Django, example code below (not my actual code):</p> <pre><code>class Department(models.Model): name = models.CharField(max_length=100) abbreviation = models.CharField(max_length=4) </code></pre> <p>Let's say I do the following in the Django shell:</p> <pre><code>&gt;&gt;&gt; Departmen...
6
2009-08-14T17:49:06Z
1,280,441
<p>mipadi has shown you how to modify the ordering for your Department model, and this is reflected in the form widget.</p> <p>However, if you only wanted to change the ordering for that widget, and leave the model's default ordering as something else, you could do this:</p> <pre><code>class CourseForm(ModelForm): ...
1
2009-08-14T22:04:06Z
[ "python", "django", "django-templates", "django-forms" ]
BytesIO with python v2.5
1,279,244
<p><strong>Question:</strong></p> <p>How do I get a byte stream that works like StringIO for Python 2.5?</p> <p><strong>Application:</strong></p> <p>I'm converting a PDF to text, but don't want to save a file to the hard disk.</p> <p><strong>Other Thoughts:</strong></p> <p>I figured I could use StringIO, but there...
1
2009-08-14T17:54:01Z
1,279,251
<p>In Python 2.x, "string" means "bytes", and "unicode" means "string". You should use the <code>StringIO</code> or <code>cStringIO</code> modules. The mode will depend on which kind of data you pass in as the buffer parameter.</p>
4
2009-08-14T17:55:49Z
[ "python", "stringio", "bytesio" ]