title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
FOSS HTML to PDF in Python, .Net or command line? | 597,348 | <p>I have google as much as I possible, checked stackoverflow several times, and yet I can not find a good <strong>html to pdf converter</strong> that can handle css. Is there a free and open source solution (even for commercial usage)? There are many solutions, with huge variety of price ranges, but I was looking fo... | 0 | 2009-02-28T01:56:26Z | 597,368 | <p>The fact that you're asking about C#/.NET makes me guess you're on a Windows platform, so this may not work for you, but I've had decent success using <a href="http://user.it.uu.se/~jan/html2ps.html" rel="nofollow"><strong>html2ps</strong></a> in conjunction with <a href="http://pages.cs.wisc.edu/~ghost/doc/AFPL/6.5... | 1 | 2009-02-28T02:12:59Z | [
"c#",
".net",
"python",
"html-to-pdf"
] |
FOSS HTML to PDF in Python, .Net or command line? | 597,348 | <p>I have google as much as I possible, checked stackoverflow several times, and yet I can not find a good <strong>html to pdf converter</strong> that can handle css. Is there a free and open source solution (even for commercial usage)? There are many solutions, with huge variety of price ranges, but I was looking fo... | 0 | 2009-02-28T01:56:26Z | 597,840 | <p>You can also try different approach like using virtual printers.</p>
| 0 | 2009-02-28T10:32:41Z | [
"c#",
".net",
"python",
"html-to-pdf"
] |
FOSS HTML to PDF in Python, .Net or command line? | 597,348 | <p>I have google as much as I possible, checked stackoverflow several times, and yet I can not find a good <strong>html to pdf converter</strong> that can handle css. Is there a free and open source solution (even for commercial usage)? There are many solutions, with huge variety of price ranges, but I was looking fo... | 0 | 2009-02-28T01:56:26Z | 2,589,983 | <p>I have had stunning success using the 'PISA' xhtml2pdf tool found here: <a href="http://www.xhtml2pdf.com/" rel="nofollow">http://www.xhtml2pdf.com/</a></p>
<p>Don't be scared off by the 'xhtml' part, it accepts a large range of html input, and produces PDFs according to CSS, including CSS print extensions.</p>
| 0 | 2010-04-07T04:24:09Z | [
"c#",
".net",
"python",
"html-to-pdf"
] |
How to create MS Paint clone with Python and pygame | 597,369 | <p>As I see it, there are two ways to handle mouse events to draw a picture.</p>
<p>The first is to detect when the mouse moves and draw a line to where the mouse is, shown <a href="http://www.cs.iupui.edu/~aharris/pygame/ch05/paint.py">here</a>. However, the problem with this is that with a large brush size, many g... | 9 | 2009-02-28T02:13:08Z | 597,401 | <p>Why not do both?</p>
<p>Draw a circle at each endpoint and a line between the two.</p>
<p><strong>EDIT</strong> rofl, just couldn't stop myself. </p>
<p>Actually, you don't want to use pygame.draw.line because it cheats. It fills a 1 pixel wide row or column (depending on angle of attack) of pixels. If you do ... | 11 | 2009-02-28T02:50:16Z | [
"python",
"mouse",
"pygame",
"draw",
"paint"
] |
How to create MS Paint clone with Python and pygame | 597,369 | <p>As I see it, there are two ways to handle mouse events to draw a picture.</p>
<p>The first is to detect when the mouse moves and draw a line to where the mouse is, shown <a href="http://www.cs.iupui.edu/~aharris/pygame/ch05/paint.py">here</a>. However, the problem with this is that with a large brush size, many g... | 9 | 2009-02-28T02:13:08Z | 5,690,387 | <p>For the first problem, you need have a background, even if its just a color. I had the same problem with a replica pong game i made. Here is an example of a replica paint program I made, left click to draw, right click to erase, click on the color image to choose a color, and up button to clear screen:</p>
<pre><co... | 1 | 2011-04-16T23:31:12Z | [
"python",
"mouse",
"pygame",
"draw",
"paint"
] |
How to create MS Paint clone with Python and pygame | 597,369 | <p>As I see it, there are two ways to handle mouse events to draw a picture.</p>
<p>The first is to detect when the mouse moves and draw a line to where the mouse is, shown <a href="http://www.cs.iupui.edu/~aharris/pygame/ch05/paint.py">here</a>. However, the problem with this is that with a large brush size, many g... | 9 | 2009-02-28T02:13:08Z | 5,900,836 | <p>Not blitting at each loop step can improve the speed of the drawing (using this code adapted from the previous one allow to remove lag problem on my machine)</p>
<pre><code>import pygame, random
screen = pygame.display.set_mode((800,600))
draw_on = False
last_pos = (0, 0)
color = (255, 128, 0)
radius = 10
def ro... | 2 | 2011-05-05T16:04:42Z | [
"python",
"mouse",
"pygame",
"draw",
"paint"
] |
How to concisely cascade through multiple regex statements in Python | 597,476 | <p>My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this:</p>... | 6 | 2009-02-28T04:06:31Z | 597,485 | <p>Hmm... you could use something with the <strong><code>with</code></strong> construct... um</p>
<pre><code>class rewrapper()
def __init__(self, pattern, target):
something
def __enter__(self):
something
def __exit__(self):
something
with rewrapper("regex1", string) as match:
... | 0 | 2009-02-28T04:24:22Z | [
"python",
"regex",
"coding-style"
] |
How to concisely cascade through multiple regex statements in Python | 597,476 | <p>My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this:</p>... | 6 | 2009-02-28T04:06:31Z | 597,487 | <p>Are the manipulations for each regex similar? If so, try this:</p>
<pre><code>for regex in ('regex1', 'regex2', 'regex3', 'regex4'):
match = re.match(regex, string)
if match:
# Manipulate match.group(n)
return result
</code></pre>
| 0 | 2009-02-28T04:25:47Z | [
"python",
"regex",
"coding-style"
] |
How to concisely cascade through multiple regex statements in Python | 597,476 | <p>My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this:</p>... | 6 | 2009-02-28T04:06:31Z | 597,492 | <p>Here your regexs and matches are not repeated twice:</p>
<pre><code>match = re.match('regex1', string)
if match:
# do stuff
return
match = re.match('regex2', string)
if match:
# do stuff
return
</code></pre>
| 0 | 2009-02-28T04:30:40Z | [
"python",
"regex",
"coding-style"
] |
How to concisely cascade through multiple regex statements in Python | 597,476 | <p>My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this:</p>... | 6 | 2009-02-28T04:06:31Z | 597,493 | <p>Generally speaking, in these sorts of situations, you want to make the code "data driven". That is, put the important information in a container, and loop through it.</p>
<p>In your case, the important information is (string, function) pairs.</p>
<pre><code>import re
def fun1():
print('fun1')
def fun2():
... | 21 | 2009-02-28T04:31:57Z | [
"python",
"regex",
"coding-style"
] |
How to concisely cascade through multiple regex statements in Python | 597,476 | <p>My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this:</p>... | 6 | 2009-02-28T04:06:31Z | 597,557 | <p>Similar question from back in september: <a href="http://stackoverflow.com/questions/122277">How do you translate this regular-expression idiom from Perl into Python?</a></p>
<p>Using global variables in a module maybe not the best way to do it, but converting it into a class:</p>
<pre><code>import re
class Re(ob... | 6 | 2009-02-28T05:32:56Z | [
"python",
"regex",
"coding-style"
] |
How to concisely cascade through multiple regex statements in Python | 597,476 | <p>My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this:</p>... | 6 | 2009-02-28T04:06:31Z | 602,524 | <p>I had the same problem as yours. Here´s my solution:</p>
<pre><code>import re
regexp = {
'key1': re.compile(r'regexp1'),
'key2': re.compile(r'regexp2'),
'key3': re.compile(r'regexp3'),
# ...
}
def test_all_regexp(string):
for key, pattern in regexp.items():
m = pattern.match(string)
... | 2 | 2009-03-02T14:27:29Z | [
"python",
"regex",
"coding-style"
] |
How to concisely cascade through multiple regex statements in Python | 597,476 | <p>My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this:</p>... | 6 | 2009-02-28T04:06:31Z | 6,164,807 | <pre><code>class RegexStore(object):
_searches = None
def __init__(self, pat_list):
# build RegEx searches
self._searches = [(name,re.compile(pat, re.VERBOSE)) for
name,pat in pat_list]
def match( self, text ):
match_all = ((x,y.match(text)) for x,y in self._searches... | 0 | 2011-05-28T22:46:01Z | [
"python",
"regex",
"coding-style"
] |
Why Jython behaves inconsistently when tested with PyStone? | 597,483 | <p>I've been playing recently with Jython and decided to do some quick and dirty benchmarking with pystone. In order to have a reference, I first tested cPython 2.6, with an increasing numbers of loops (I thought this may be relevant as Jython should start to profit from the JIT only after some time).</p>
<pre><code>(... | 2 | 2009-02-28T04:21:10Z | 597,509 | <p>I'm pretty sure that the results can be improved by tweaking the JVM configuration (JRuby is using quite a few interesting flags for doing it) and I'm also pretty sure that the garbage collection can be tuned.
If you are very interested in this benchmark here is a good resource for configuring your VM: <a href="http... | 1 | 2009-02-28T04:54:15Z | [
"java",
"python",
"performance",
"jython",
"benchmarking"
] |
Why Jython behaves inconsistently when tested with PyStone? | 597,483 | <p>I've been playing recently with Jython and decided to do some quick and dirty benchmarking with pystone. In order to have a reference, I first tested cPython 2.6, with an increasing numbers of loops (I thought this may be relevant as Jython should start to profit from the JIT only after some time).</p>
<pre><code>(... | 2 | 2009-02-28T04:21:10Z | 597,905 | <p>This might be a bug in jython 2.5b1. You should consider reporting it back to the jython team. I have just run the pystone benchmark on my MacBook with the current stable release of jython (2.2.1) and I get slow but consistent results:</p>
<pre><code>mo$ ~/Coding/Jython/jython2.2.1/jython pystone.py 50000
Pystone(1... | 2 | 2009-02-28T11:42:32Z | [
"java",
"python",
"performance",
"jython",
"benchmarking"
] |
Why Jython behaves inconsistently when tested with PyStone? | 597,483 | <p>I've been playing recently with Jython and decided to do some quick and dirty benchmarking with pystone. In order to have a reference, I first tested cPython 2.6, with an increasing numbers of loops (I thought this may be relevant as Jython should start to profit from the JIT only after some time).</p>
<pre><code>(... | 2 | 2009-02-28T04:21:10Z | 602,574 | <p>my bench on a XP_Win32_PC :</p>
<pre><code>C:\jython\jython2.5b1>bench "50000"
C:\jython\jython2.5b1>jython Lib\test\pystone.py "50000"
Pystone(1.1) time for 50000 passes = 1.73489
This machine benchmarks at 28820.2 pystones/second
C:\jython\jython2.5b1>bench "100000"
C:\jython\jython2.5b1>jython Lib... | 1 | 2009-03-02T14:44:58Z | [
"java",
"python",
"performance",
"jython",
"benchmarking"
] |
Why Jython behaves inconsistently when tested with PyStone? | 597,483 | <p>I've been playing recently with Jython and decided to do some quick and dirty benchmarking with pystone. In order to have a reference, I first tested cPython 2.6, with an increasing numbers of loops (I thought this may be relevant as Jython should start to profit from the JIT only after some time).</p>
<pre><code>(... | 2 | 2009-02-28T04:21:10Z | 608,604 | <p>The same results from my laptop running Ubuntu Jaunty, with JRE 1.6.0_12-b04:</p>
<pre>nathell@breeze:/usr/lib/python2.5/test$ python pystone.py 500000
Pystone(1.1) time for 500000 passes = 12.98
This machine benchmarks at 38520.8 pystones/second
nathell@breeze:/usr/lib/python2.5/test$ python pystone.py 1000000
Py... | 2 | 2009-03-03T22:58:52Z | [
"java",
"python",
"performance",
"jython",
"benchmarking"
] |
Why Jython behaves inconsistently when tested with PyStone? | 597,483 | <p>I've been playing recently with Jython and decided to do some quick and dirty benchmarking with pystone. In order to have a reference, I first tested cPython 2.6, with an increasing numbers of loops (I thought this may be relevant as Jython should start to profit from the JIT only after some time).</p>
<pre><code>(... | 2 | 2009-02-28T04:21:10Z | 714,212 | <p>Benchmarking a runtime environment as complex as the JVM is hard. Even excluding the JIT and GC, you've got a big heap, memory layout and cache variation between runs.</p>
<p>One thing that helps with Jython is simply running the benchmark more than once in a single VM session: once to warm up the JIT and one or m... | 2 | 2009-04-03T14:41:15Z | [
"java",
"python",
"performance",
"jython",
"benchmarking"
] |
How can i use TurboMail 3 together with TurboGears 2 | 598,019 | <p>Hy,
I want to use TurboMail3 (<a href="http://www.python-turbomail.org/wiki/3.0/BetaRelease" rel="nofollow">website</a>) together with a TurboGears 2(<a href="http://www.turbogears.org/2.0/" rel="nofollow">website</a>) project. Which files to I have to modify to include TurboMail into my TurboGears project? Everythi... | 1 | 2009-02-28T13:23:42Z | 600,090 | <p>The integration is currently the same as for Pylons. There is a ticket for a TG2 specific integration which is currently in our bug tracker. If you really want answers for that topic, please ask in the turbomail google group: <a href="http://groups.google.com/group/turbomail-devel" rel="nofollow">http://groups.googl... | 1 | 2009-03-01T16:51:28Z | [
"python",
"email",
"turbogears"
] |
How can i use TurboMail 3 together with TurboGears 2 | 598,019 | <p>Hy,
I want to use TurboMail3 (<a href="http://www.python-turbomail.org/wiki/3.0/BetaRelease" rel="nofollow">website</a>) together with a TurboGears 2(<a href="http://www.turbogears.org/2.0/" rel="nofollow">website</a>) project. Which files to I have to modify to include TurboMail into my TurboGears project? Everythi... | 1 | 2009-02-28T13:23:42Z | 1,310,195 | <p>This might help you along: <a href="http://www.5dollarwhitebox.org/drupal/node/92" rel="nofollow">Getting TurboMail to work with TurboGears 2.0</a></p>
| 0 | 2009-08-21T05:19:34Z | [
"python",
"email",
"turbogears"
] |
Why does @foo.setter in Python not work for me? | 598,077 | <p>So, I'm playing with decorators in Python 2.6, and I'm having some trouble getting them to work. Here is my class file:</p>
<pre><code>class testDec:
@property
def x(self):
print 'called getter'
return self._x
@x.setter
def x(self, value):
print 'called setter'
se... | 102 | 2009-02-28T14:33:50Z | 598,090 | <p>You need to use new-style classes which you do by deriving your class from object:</p>
<pre><code>class testDec(object):
....
</code></pre>
<p>Then it should work.</p>
| 22 | 2009-02-28T14:43:22Z | [
"python",
"decorator",
"new-style-class"
] |
Why does @foo.setter in Python not work for me? | 598,077 | <p>So, I'm playing with decorators in Python 2.6, and I'm having some trouble getting them to work. Here is my class file:</p>
<pre><code>class testDec:
@property
def x(self):
print 'called getter'
return self._x
@x.setter
def x(self, value):
print 'called setter'
se... | 102 | 2009-02-28T14:33:50Z | 598,092 | <p>You seem to be using <a href="https://docs.python.org/2/glossary.html#term-classic-class">classic old-style classes</a>. In order for <a href="https://docs.python.org/2/library/functions.html#property">properties</a> to work correctly you need to use <a href="https://docs.python.org/2/glossary.html#term-new-style-cl... | 213 | 2009-02-28T14:43:40Z | [
"python",
"decorator",
"new-style-class"
] |
Why does @foo.setter in Python not work for me? | 598,077 | <p>So, I'm playing with decorators in Python 2.6, and I'm having some trouble getting them to work. Here is my class file:</p>
<pre><code>class testDec:
@property
def x(self):
print 'called getter'
return self._x
@x.setter
def x(self, value):
print 'called setter'
se... | 102 | 2009-02-28T14:33:50Z | 17,395,735 | <p>Just a note for other people who stumble here looking for this exception: both functions need to have the same name. Naming the methods as follows will result in an exception:</p>
<pre><code>@property
def x(self): pass
@x.setter
def x_setter(self, value): pass
</code></pre>
<p>Instead give both methods the same n... | 34 | 2013-06-30T23:20:33Z | [
"python",
"decorator",
"new-style-class"
] |
Why does @foo.setter in Python not work for me? | 598,077 | <p>So, I'm playing with decorators in Python 2.6, and I'm having some trouble getting them to work. Here is my class file:</p>
<pre><code>class testDec:
@property
def x(self):
print 'called getter'
return self._x
@x.setter
def x(self, value):
print 'called setter'
se... | 102 | 2009-02-28T14:33:50Z | 28,464,787 | <p>In case anybody comes here from google, in addition to the above answers I would like to add that this needs careful attention when invoking the setter from the <code>__init__</code> method of your class based on <a href="http://stackoverflow.com/a/3942118/808734">this answer</a>
Specifically:</p>
<pre><code>class ... | 3 | 2015-02-11T21:23:33Z | [
"python",
"decorator",
"new-style-class"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 598,168 | <p>You might find this post helpful: <a href="http://paltman.com/2008/jan/18/try-except-performance-in-python-a-simple-test/"><strong>Try / Except Performance in Python: A Simple Test</strong></a> where Patrick Altman did some simple testing to see what the performance is in various scenarios pre-conditional checking (... | 24 | 2009-02-28T15:40:15Z | [
"python",
"performance",
"exception-handling"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 598,189 | <p>I am a python beginner as well. While I cannot say why exactly Exception handling has been called cheap in the context of that answer, here are my thoughts:</p>
<p>Note that checking with if-elif-else has to evaluate a condition every time. Exception handling, including the search for an exception handler occurs on... | 4 | 2009-02-28T15:48:52Z | [
"python",
"performance",
"exception-handling"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 598,217 | <p>What are static versus dynamic calls and returns, and why do you think that calls and returns are any different in Python depending on if you are doing it in a try/except block? Even if you aren't catching an exception, Python still has to handle the call possibly raising something, so it doesn't make a difference t... | 1 | 2009-02-28T16:03:45Z | [
"python",
"performance",
"exception-handling"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 598,219 | <p>With Python, it is easy to check different possibilities for speed - get to know the <a href="http://docs.python.org/library/timeit.html#module-timeit" rel="nofollow">timeit module</a> :</p>
<blockquote>
<p>... example session (using the command line) that compare the cost of using hasattr() vs. try/except to tes... | 8 | 2009-02-28T16:04:16Z | [
"python",
"performance",
"exception-handling"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 598,221 | <p>Don't sweat the small stuff. You've already picked one of the slower scripting languages out there, so trying to optimize down to the opcode is not going to help you much. The reason to choose an interpreted, dynamic language like Python is to optimize your time, not the CPU's.</p>
<p>If you use common language i... | 33 | 2009-02-28T16:05:27Z | [
"python",
"performance",
"exception-handling"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 598,227 | <p>"Can someone explain this to me?"</p>
<p>Depends. </p>
<p>Here's one explanation, but it's not helpful. Your question stems from your assumptions. Since the real world conflicts with your assumptions, it must mean your assumptions are wrong. Not much of an explanation, but that's why you're asking.</p>
<p>"Ex... | 9 | 2009-02-28T16:07:32Z | [
"python",
"performance",
"exception-handling"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 598,559 | <p>Putting aside the performance measurements that others have said, the guiding principle is often structured as "it is easier to ask forgiveness than ask permission" vs. "look before you leap."</p>
<p>Consider these two snippets:</p>
<pre><code># Look before you leap
if not os.path.exists(filename):
raise SomeE... | 20 | 2009-02-28T19:50:34Z | [
"python",
"performance",
"exception-handling"
] |
Cheap exception handling in Python? | 598,157 | <p>I read in an earlier <a href="http://stackoverflow.com/questions/576988/python-specific-antipatterns/577731#577731">answer</a> that exception handling is cheap in Python so we shouldn't do pre-conditional checking.</p>
<p>I have not heard of this before, but I'm relatively new to Python. Exception handling means a ... | 22 | 2009-02-28T15:30:19Z | 600,628 | <p>The general message, as S.Lott said, is that try/except <em>doesn't hurt</em> so you should feel free to use it whenever it seems appropriate.</p>
<p>This debate is often called "LBYL vs EAFP" â that's "look before you leap" vs "easier to ask forgiveness than permission". <a href="http://en.wikipedia.org/wiki/Al... | 1 | 2009-03-01T21:56:02Z | [
"python",
"performance",
"exception-handling"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 598,333 | <p>Just my experience, take it with a grain of salt.</p>
<p>My preference for a couple of open-source libraries that I author is for independence from additional libs as much as possible. Reason being, not only am I on the hook for distribution of additional libraries along with mine, I'm also obliged to update my ap... | 1 | 2009-02-28T17:16:29Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 598,343 | <p>Can't you just rely on a certain version of those dependencies? E.g. in Python with <a href="http://peak.telecommunity.com/DevCenter/setuptools" rel="nofollow">setuptools</a> you can specify which exact version it needs or even give some conditions like <= > etc. This of course only applies to Python and on the s... | 3 | 2009-02-28T17:24:01Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 598,397 | <p>I favor bundling dependencies, <em>if</em> it's not feasible to use a system for automatic dependency resolution (i.e. setuptools), and <em>if</em> you can do it without introducing version conflicts. You still have to consider your application and your audience; serious developers or enthusiasts are more likely to... | 8 | 2009-02-28T18:03:58Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 598,599 | <p>I always include all dependancies for my web applications. Not only does this make installation simpler, the application remains stable and working the way you expect it to even when other components on the system are upgraded.</p>
| 1 | 2009-02-28T20:14:12Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 598,614 | <p>Beware reproducing the classic Windows DLL hell. By all means minimize the number of dependencies: ideally, just depend on your language and its framework, nothing else, if you can.</p>
<p>After all, preserving hard disk space is hardly the objective any more, so users need not care about having multiple copies. Al... | 1 | 2009-02-28T20:19:48Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 603,778 | <p>For Linux, don't even think about bundling. You aren't smarter than the package manager or the packagers, and each distribution takes approach their own way - they won't be happy if you attempt to go your way. At best, they won't bother with packaging your app, which isn't great.</p>
<p>Keep in mind that in Linux, ... | 2 | 2009-03-02T20:05:06Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 603,843 | <p>If you're producing software for an end-user, the goal is to let the customer use your software. Anything that stands in the way is counter-productive. If they have to download dependencies themselves, there's a possibility that they'll decide to avoid your software instead. You can't control whether libraries will ... | 3 | 2009-03-02T20:20:52Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
When is it (not) appropriate to bundle dependencies with an application? | 598,299 | <p><strong>Summary</strong></p>
<p>I recently had a conversation with the creator of a framework that one of my applications depends on. During that conversation he mentioned as a sort of aside that it would make my life simpler if I just bundled his framework with my application and delivered to the end user a versi... | 12 | 2009-02-28T16:59:37Z | 609,861 | <p>An important point seems to have been forgotten in the Cons of bundling libraries/frameworks/etc with the application: security updates.</p>
<p>Most Web frameworks are full of security holes and require frequent patching. Any library, anyway, may have to be upgraded one day or the other for a security bug.</p>
<p>... | 2 | 2009-03-04T09:32:22Z | [
"python",
"dependencies",
"distribution",
"packaging"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 598,405 | <p>You should add a <code>__eq__</code> and a <code>__hash__</code> method to your <code>Data</code> class, it could check if the <code>__dict__</code> attributes are equal (same properties) and then if their values are equal, too.</p>
<p>If you did that, you can use</p>
<pre><code>test = Data()
test.n = 5
found = t... | 1 | 2009-02-28T18:10:38Z | [
"python"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 598,407 | <p>You can get a list of <em>all</em> matching elements with a list comprehension:</p>
<pre><code>[x for x in myList if x.n == 30] # list of all elements with .n==30
</code></pre>
<p>If you simply want to determine if the list contains <em>any</em> element that matches and do it (relatively) efficiently, you can do<... | 45 | 2009-02-28T18:11:05Z | [
"python"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 598,415 | <pre><code>[x for x in myList if x.n == 30] # list of all matches
any(x.n == 30 for x in myList) # if there is any matches
[i for i,x in enumerate(myList) if x.n == 30] # indices of all matches
def first(iterable, default=None):
for item in iterable:
return item
return default
f... | 20 | 2009-02-28T18:19:28Z | [
"python"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 598,417 | <p>Just for completeness, let's not forget the Simplest Thing That Could Possibly Work:</p>
<pre><code>for i in list:
if i.n == 5:
# do something with it
print "YAY! Found one!"
</code></pre>
| 32 | 2009-02-28T18:20:01Z | [
"python"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 598,424 | <pre><code>filter(lambda x: x.n == 5, myList)
</code></pre>
| 18 | 2009-02-28T18:22:06Z | [
"python"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 598,427 | <p>You can use <code>in</code> to look for an item in a collection, and a list comprehension to extract the field you are interested in. This (works for lists, sets, tuples, and anything that defines <code>__contains__</code> or <code>__getitem__</code>). </p>
<pre><code>if 5 in [data.n for data in myList]:
print ... | 7 | 2009-02-28T18:23:29Z | [
"python"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 598,602 | <p><strong>Simple, Elegant, and Powerful:</strong></p>
<p>A generator expression in conjuction with a builtin⦠(python 2.5+)</p>
<pre><code>any(x for x in mylist if x.n == 10)
</code></pre>
<p>Uses the Python <a href="http://docs.python.org/2/library/functions.html#any"><code>any()</code></a> builtin, which is def... | 31 | 2009-02-28T20:15:28Z | [
"python"
] |
Searching a list of objects in Python | 598,398 | <p>Let's assume I'm creating a simple class to work similar to a C-style struct, to just hold data elements. I'm trying to figure out how to search the list of objects for objects with a certain attribute. Below is a trivial example to illustrate what I'm trying to do.</p>
<p>For instance:</p>
<pre><code>class Data... | 32 | 2009-02-28T18:06:20Z | 599,045 | <p>Consider using a dictionary:</p>
<pre><code>myDict = {}
for i in range(20):
myDict[i] = i * i
print(5 in myDict)
</code></pre>
| 3 | 2009-03-01T01:14:25Z | [
"python"
] |
Calling function defined in exe | 598,569 | <p>I need to know a way to call a function defined in the exe from a python script.
I know how to call entire exe from py file.</p>
| 3 | 2009-02-28T19:55:21Z | 598,571 | <p>Unless the said executable takes command line arguments which will specify which function to use, I don't think this is possible.</p>
<p>With that being said, if you created the EXE, command line arguments are a good way to implement the functionality you're looking for.</p>
| 0 | 2009-02-28T19:57:59Z | [
"python"
] |
Calling function defined in exe | 598,569 | <p>I need to know a way to call a function defined in the exe from a python script.
I know how to call entire exe from py file.</p>
| 3 | 2009-02-28T19:55:21Z | 598,582 | <p>Unless your EXE is a COM object, or specifically exports certain functions like a dll does, then this is not possible. </p>
<p>For the COM method take a look at these resources:</p>
<ul>
<li><a href="http://oreilly.com/catalog/9781565926219/" rel="nofollow">Python Programming On Win32</a> book, by Mark Hammond a... | 6 | 2009-02-28T20:04:04Z | [
"python"
] |
Calling function defined in exe | 598,569 | <p>I need to know a way to call a function defined in the exe from a python script.
I know how to call entire exe from py file.</p>
| 3 | 2009-02-28T19:55:21Z | 598,585 | <p>Not sure if it is for windows. But you can treat an exe like a dll (if functions are exported). And they can be used by other programs.</p>
| 1 | 2009-02-28T20:05:16Z | [
"python"
] |
What SHOULDN'T Django's admin interface be used for? | 598,577 | <p>I've been applying Django's automatic administration capabilities to some applications who had previously been very difficult to administer. I'm thinking of a lot of ways to apply it to other applications we use (including using it to replace some internal apps altogether). Before I go overboard though, is there a... | 4 | 2009-02-28T20:00:03Z | 598,580 | <p>User-specific privileges. I myself had been trying to work it into that-- some of the new (and at least at the time, undocumented) features (from newforms-admin) make it actually possible. Depending on how fine you want the control to be, though, you can end up getting very, very deep into the Django/admin internals... | 7 | 2009-02-28T20:03:46Z | [
"python",
"django",
"administration"
] |
What SHOULDN'T Django's admin interface be used for? | 598,577 | <p>I've been applying Django's automatic administration capabilities to some applications who had previously been very difficult to administer. I'm thinking of a lot of ways to apply it to other applications we use (including using it to replace some internal apps altogether). Before I go overboard though, is there a... | 4 | 2009-02-28T20:00:03Z | 599,054 | <p>Generally, you shouldn't use the admin for access by people you don't really trust. Even though there's plenty of flexibility in terms of locking things down and controlling access (much more so since Django 1.0), the admin is still designed on the assumption that the people using it are trusted members of your staf... | 5 | 2009-03-01T01:28:57Z | [
"python",
"django",
"administration"
] |
AppEngine: Query datastore for records with <missing> value | 598,605 | <p>I created a new property for my db model in the Google App Engine Datastore.</p>
<p>Old:</p>
<pre><code>class Logo(db.Model):
name = db.StringProperty()
image = db.BlobProperty()
</code></pre>
<p>New:</p>
<pre><code>class Logo(db.Model):
name = db.StringProperty()
image = db.BlobProperty()
is_approved ... | 20 | 2009-02-28T20:16:28Z | 598,975 | <p>According to the App Engine documentation on <a href="http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Introducing%5FIndexes">Queries and Indexes</a>, there is a distinction between entities that have <em>no</em> value for a property, and those that have a <em>null</em> value for it; and... | 30 | 2009-03-01T00:26:57Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
AppEngine: Query datastore for records with <missing> value | 598,605 | <p>I created a new property for my db model in the Google App Engine Datastore.</p>
<p>Old:</p>
<pre><code>class Logo(db.Model):
name = db.StringProperty()
image = db.BlobProperty()
</code></pre>
<p>New:</p>
<pre><code>class Logo(db.Model):
name = db.StringProperty()
image = db.BlobProperty()
is_approved ... | 20 | 2009-02-28T20:16:28Z | 8,599,897 | <p>Maybe this has changed, but I am able to filter records based on <strong>null</strong> fields.</p>
<p>When I try the GQL query <code>SELECT * FROM Contact WHERE demo=NULL</code>, it returns only records for which the demo field is missing.</p>
<p>According to the doc <a href="http://code.google.com/appengine/docs/... | 2 | 2011-12-22T05:49:05Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
Where is the function get_example_data in matplotlib? It seems to be missing but its in examples/tutorials | 598,626 | <p>Looking at this tutorial here: <a href="http://matplotlib.sourceforge.net/plot%5Fdirective/mpl%5Fexamples/pylab%5Fexamples/finance%5Fwork2.py" rel="nofollow">link text</a> it references matplotlib.get_example_data('goog.npy'). I get an error when I run this, and furthermore I can't even find the mpl-data/ folder in ... | 2 | 2009-02-28T20:28:37Z | 598,653 | <p>It's defined in <code>__init__.py</code> (around line 490), if that's what you're asking.</p>
<p>-- MarkusQ</p>
<p>P.S. The <code>mpl_data/</code> directory is there too (both of them are in the top level directory). Are you sure you've got a good / complete installation?</p>
| 1 | 2009-02-28T20:45:37Z | [
"python",
"graph",
"visualization",
"matplotlib"
] |
Where is the function get_example_data in matplotlib? It seems to be missing but its in examples/tutorials | 598,626 | <p>Looking at this tutorial here: <a href="http://matplotlib.sourceforge.net/plot%5Fdirective/mpl%5Fexamples/pylab%5Fexamples/finance%5Fwork2.py" rel="nofollow">link text</a> it references matplotlib.get_example_data('goog.npy'). I get an error when I run this, and furthermore I can't even find the mpl-data/ folder in ... | 2 | 2009-02-28T20:28:37Z | 9,392,115 | <p>I just had a similar (the same?) problem for Ubuntu 10.04 (Python 2.6.5, MPL 0.99.1.1).</p>
<p>There was no <code>get_sample_data</code>, however a <code>get_example_data</code> in <code>/usr/lib/pymodules/python2.6/matplotlib/__init__.py</code> which didn't really work. The directory <code>/usr/local/lib/python2.6... | 0 | 2012-02-22T09:26:26Z | [
"python",
"graph",
"visualization",
"matplotlib"
] |
External classes in Python | 598,668 | <p>I'm just beginning Python, and I'd like to use an external RSS class. Where do I put that class and how do I import it? I'd like to eventually be able to share python programs.</p>
| 4 | 2009-02-28T20:54:02Z | 598,674 | <pre><code>from [module] import [classname]
</code></pre>
<p>Where the module is somewhere on your python path.</p>
| 1 | 2009-02-28T20:55:38Z | [
"python",
"python-module",
"python-import"
] |
External classes in Python | 598,668 | <p>I'm just beginning Python, and I'd like to use an external RSS class. Where do I put that class and how do I import it? I'd like to eventually be able to share python programs.</p>
| 4 | 2009-02-28T20:54:02Z | 598,685 | <p>About modules and packages:</p>
<ul>
<li><p>a module is a file ending with <code>.py</code>. You can put your class in such a file. As said by Andy, it needs to be in your python path (<code>PYTHONPATH</code>). Usually you will put the additional module in the same directory as your script is though which can be di... | 1 | 2009-02-28T21:03:26Z | [
"python",
"python-module",
"python-import"
] |
External classes in Python | 598,668 | <p>I'm just beginning Python, and I'd like to use an external RSS class. Where do I put that class and how do I import it? I'd like to eventually be able to share python programs.</p>
| 4 | 2009-02-28T20:54:02Z | 598,686 | <p><strong>About the <code>import</code> statement:</strong></p>
<p>(a good writeup is at <a href="http://effbot.org/zone/import-confusion.htm">http://effbot.org/zone/import-confusion.htm</a> and the python tutorial goes into detail at <a href="http://docs.python.org/tutorial/modules.html">http://docs.python.org/tutor... | 12 | 2009-02-28T21:03:54Z | [
"python",
"python-module",
"python-import"
] |
External classes in Python | 598,668 | <p>I'm just beginning Python, and I'd like to use an external RSS class. Where do I put that class and how do I import it? I'd like to eventually be able to share python programs.</p>
| 4 | 2009-02-28T20:54:02Z | 598,720 | <p>I don't really like answering so late, but I'm not entirely satisfied with the existing answers.</p>
<blockquote>
<p>I'm just beginning Python, and I'd like to use an external RSS class. Where do I put that class and how do I import it?</p>
</blockquote>
<p>You put it in a python file, and give the python file a... | 2 | 2009-02-28T21:32:13Z | [
"python",
"python-module",
"python-import"
] |
External classes in Python | 598,668 | <p>I'm just beginning Python, and I'd like to use an external RSS class. Where do I put that class and how do I import it? I'd like to eventually be able to share python programs.</p>
| 4 | 2009-02-28T20:54:02Z | 15,196,925 | <p>If you want to store your RSS file in a different place use sys.append("") and pout the module in that directory and use
import or from import *</p>
| 0 | 2013-03-04T07:55:03Z | [
"python",
"python-module",
"python-import"
] |
How to match a text node then follow parent nodes using XPath | 598,722 | <p>I'm trying to parse some HTML with XPath. Following the simplified XML example below, I want to match the string 'Text 1', then grab the contents of the relevant <code>content</code> node.</p>
<pre><code><doc>
<block>
<title>Text 1</title>
<content>Stuff I want</... | 14 | 2009-02-28T21:33:20Z | 598,732 | <p>Do you want that?</p>
<pre><code>//title[text()='Text 1']/../content/text()
</code></pre>
| 22 | 2009-02-28T21:40:19Z | [
"python",
"html",
"xpath",
"lxml"
] |
How to match a text node then follow parent nodes using XPath | 598,722 | <p>I'm trying to parse some HTML with XPath. Following the simplified XML example below, I want to match the string 'Text 1', then grab the contents of the relevant <code>content</code> node.</p>
<pre><code><doc>
<block>
<title>Text 1</title>
<content>Stuff I want</... | 14 | 2009-02-28T21:33:20Z | 599,061 | <p><strong>Use</strong>:</p>
<pre><code>string(/*/*/title[. = 'Text 1']/following-sibling::content)
</code></pre>
<p><strong>This represents at least two improvements</strong> as compared to the currently accepted solution of Johannes WeiÃ:</p>
<ol>
<li><p><strong>The very expensive abbreviation "//"</strong> (usua... | 15 | 2009-03-01T01:37:19Z | [
"python",
"html",
"xpath",
"lxml"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 598,824 | <p>You can use a regular expression to remove all the tags:</p>
<pre><code>>>> import re
>>> s = 'blah blah <a href="blah">link</a>'
>>> re.sub('<[^>]*>', '', s)
'blah blah link'
</code></pre>
| 7 | 2009-02-28T22:43:17Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 598,838 | <p>Try <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>. Throw away everything except the text.</p>
| 3 | 2009-02-28T22:52:16Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 598,881 | <pre><code>>>> import re
>>> s = 'blah blah <a href="blah">link</a>'
>>> q = re.compile(r'<.*?>', re.IGNORECASE)
>>> re.sub(q, '', s)
'blah blah link'
</code></pre>
| 0 | 2009-02-28T23:23:36Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 599,080 | <p>When your regular expression solution hits a wall, try this super easy (and reliable) <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> program.</p>
<pre><code>from BeautifulSoup import BeautifulSoup
html = "<a> Keep me </a>"
soup = BeautifulSoup(html)
text_parts = soup.findAll... | 18 | 2009-03-01T02:00:18Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 599,924 | <p>There is also a small library called <a href="http://pypi.python.org/pypi/stripogram">stripogram</a> which can be used to strip away some or all HTML tags.</p>
<p>You can use it like this:</p>
<pre><code>from stripogram import html2text, html2safehtml
# Only allow <b>, <a>, <i>, <br>, and &... | 10 | 2009-03-01T14:45:46Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 600,252 | <p><a href="http://www.aaronsw.com/2002/html2text/" rel="nofollow">html2text</a> will do something like this.</p>
| 2 | 2009-03-01T18:38:03Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 600,471 | <p>Regexs, BeautifulSoup, html2text <strong>don't work</strong> if an attribute has <strong>'<code>></code>'</strong> in it. See <a href="http://stackoverflow.com/questions/94528/is-u003e-greater-than-sign-allowed-inside-an-html-element-attribute-value">Is â>â (U+003E GREATER-THAN SIGN) allowed inside an html-el... | 5 | 2009-03-01T20:42:41Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 11,266,485 | <p>I just wrote this. I need it. It uses html2text and takes a file path, although I would prefer a URL. The output of html2text is stored in TextFromHtml2Text.text
print it, store it, feed it to your pet canary.</p>
<pre><code>import html2text
class TextFromHtml2Text:
def __init__(self, url = ''):
if url... | 1 | 2012-06-29T17:41:43Z | [
"python",
"string"
] |
Python HTML removal | 598,817 | <p>How can I remove all HTML from a string in Python? For example, how can I turn:</p>
<pre><code>blah blah <a href="blah">link</a>
</code></pre>
<p>into</p>
<pre><code>blah blah link
</code></pre>
<p>Thanks!</p>
| 6 | 2009-02-28T22:39:55Z | 14,464,562 | <p>There's a simple way to this:</p>
<pre><code>def remove_html_markup(s):
tag = False
quote = False
out = ""
for c in s:
if c == '<' and not quote:
tag = True
elif c == '>' and not quote:
tag = False
elif (c == '"' or c == "'")... | 1 | 2013-01-22T17:31:08Z | [
"python",
"string"
] |
Working with MySQL booleans in python | 598,879 | <p>I am querying a MySQL database in python and selecting a boolean value -- so the response from MySQL is either the string 'True' or 'False'. I would like to execute further code based on the boolean value from MySQL. </p>
<p>E.g.</p>
<pre><code>data = 'False' # assume this is what was returned by MySQL.
if data:
... | 2 | 2009-02-28T23:22:02Z | 598,882 | <p>Boolean in MySQL is TINYINT(1). Checking for 1 or 0 might work</p>
| 2 | 2009-02-28T23:24:17Z | [
"python",
"mysql",
"boolean"
] |
Working with MySQL booleans in python | 598,879 | <p>I am querying a MySQL database in python and selecting a boolean value -- so the response from MySQL is either the string 'True' or 'False'. I would like to execute further code based on the boolean value from MySQL. </p>
<p>E.g.</p>
<pre><code>data = 'False' # assume this is what was returned by MySQL.
if data:
... | 2 | 2009-02-28T23:22:02Z | 598,963 | <p>If the column is always one of the actual strings <code>"False"</code> or <code>"True"</code> (as opposed to integers or something) then I'd recommend some variation on:</p>
<pre><code>value = {'False' : False, 'True' : True}[data]
</code></pre>
| 1 | 2009-03-01T00:19:40Z | [
"python",
"mysql",
"boolean"
] |
Working with MySQL booleans in python | 598,879 | <p>I am querying a MySQL database in python and selecting a boolean value -- so the response from MySQL is either the string 'True' or 'False'. I would like to execute further code based on the boolean value from MySQL. </p>
<p>E.g.</p>
<pre><code>data = 'False' # assume this is what was returned by MySQL.
if data:
... | 2 | 2009-02-28T23:22:02Z | 599,022 | <p>If your db connection doesn't know how to transform the values for you, then you need to use a better one. This should not be something you need to do yourself. If these are not actual booleans, but just an int column you only store 0 or 1 in, then you should fix your schema. Alternatively, if you always get the val... | 2 | 2009-03-01T00:56:37Z | [
"python",
"mysql",
"boolean"
] |
Working with MySQL booleans in python | 598,879 | <p>I am querying a MySQL database in python and selecting a boolean value -- so the response from MySQL is either the string 'True' or 'False'. I would like to execute further code based on the boolean value from MySQL. </p>
<p>E.g.</p>
<pre><code>data = 'False' # assume this is what was returned by MySQL.
if data:
... | 2 | 2009-02-28T23:22:02Z | 600,044 | <p>Your solution is actually quite OK, but there are alternatives:</p>
<p>If you are using Python 2.5 or higher, you can shorten the if statement:</p>
<pre><code>print 'Success' if data == 'True' else 'Fail'
</code></pre>
<p>If you are finding yourself repeating the check often, you might consider writing a function... | 0 | 2009-03-01T16:28:36Z | [
"python",
"mysql",
"boolean"
] |
Working with MySQL booleans in python | 598,879 | <p>I am querying a MySQL database in python and selecting a boolean value -- so the response from MySQL is either the string 'True' or 'False'. I would like to execute further code based on the boolean value from MySQL. </p>
<p>E.g.</p>
<pre><code>data = 'False' # assume this is what was returned by MySQL.
if data:
... | 2 | 2009-02-28T23:22:02Z | 601,295 | <p>You can find the place MySQLDdb converts the values in the converters.py file in the MySQLdb directory.</p>
<p>here's the snippet dealing with bool:</p>
<pre><code>conversions = {
...
types.BooleanType: Bool2Str,
...
}
</code></pre>
<p>And the Bool2Str function:</p>
<pre><code>def Bool2Str(s, d): ret... | 2 | 2009-03-02T04:43:23Z | [
"python",
"mysql",
"boolean"
] |
Working with MySQL booleans in python | 598,879 | <p>I am querying a MySQL database in python and selecting a boolean value -- so the response from MySQL is either the string 'True' or 'False'. I would like to execute further code based on the boolean value from MySQL. </p>
<p>E.g.</p>
<pre><code>data = 'False' # assume this is what was returned by MySQL.
if data:
... | 2 | 2009-02-28T23:22:02Z | 14,554,324 | <p>This handles the way it's returned by MySQLdb.</p>
<pre><code>if data == '\x01':
print 'Success'
else:
print 'Fail'
</code></pre>
| 0 | 2013-01-28T01:37:21Z | [
"python",
"mysql",
"boolean"
] |
Difference between class (Python) and struct (C) | 598,931 | <p>I'm new to python. I've studied C and I noticed that that the C structure (struct) seemed to have the same task as "class" in python. So what is, conceptually, the difference? </p>
| 1 | 2009-03-01T00:03:43Z | 598,937 | <p>Aside from numerous technical differences between how they're implemented, they serve roughly the same purpose: the organization of data. </p>
<p>The big difference is that in Python (and other object oriented languages such as C++, Java, or C#), a class can also have functions associated with it that operate only ... | 8 | 2009-03-01T00:08:08Z | [
"python",
"c"
] |
Difference between class (Python) and struct (C) | 598,931 | <p>I'm new to python. I've studied C and I noticed that that the C structure (struct) seemed to have the same task as "class" in python. So what is, conceptually, the difference? </p>
| 1 | 2009-03-01T00:03:43Z | 598,941 | <p>Classes typically have methods (which are mostly just functions) associated with them, whereas C structs don't. You'll probably want to learn about what object-oriented programming is, if you want to make effective use of classes in Python (or any other object-oriented language, like Java or C++).</p>
<p>Of course,... | 3 | 2009-03-01T00:09:14Z | [
"python",
"c"
] |
Difference between class (Python) and struct (C) | 598,931 | <p>I'm new to python. I've studied C and I noticed that that the C structure (struct) seemed to have the same task as "class" in python. So what is, conceptually, the difference? </p>
| 1 | 2009-03-01T00:03:43Z | 598,945 | <p>Without taking pages and pages to go into the details, think of a C struct as a way to organize data, while a Python (or C++ or Objective-C) "class" is a way to organize not only your data, but the operations for that data. A Python "class," for example, can inherit from other objects, to give you an interator for t... | 5 | 2009-03-01T00:10:30Z | [
"python",
"c"
] |
Difference between class (Python) and struct (C) | 598,931 | <p>I'm new to python. I've studied C and I noticed that that the C structure (struct) seemed to have the same task as "class" in python. So what is, conceptually, the difference? </p>
| 1 | 2009-03-01T00:03:43Z | 598,955 | <p>Structs encapsulate data.</p>
<p>Classes encapsulate behavior and data.</p>
| 18 | 2009-03-01T00:16:32Z | [
"python",
"c"
] |
Difference between class (Python) and struct (C) | 598,931 | <p>I'm new to python. I've studied C and I noticed that that the C structure (struct) seemed to have the same task as "class" in python. So what is, conceptually, the difference? </p>
| 1 | 2009-03-01T00:03:43Z | 599,017 | <p>One thing that hasn't been mentioned is that C structs are value types, whereas Python classes are reference types.</p>
<p>For example, consider this statement:</p>
<pre><code>var1 = var2
</code></pre>
<p>If var1 and var2 were C structs, then that statement would copy the contents of var2 into var1. That's <stron... | 5 | 2009-03-01T00:52:41Z | [
"python",
"c"
] |
What's the best technology for connecting from linux to MS SQL Server using python? ODBC? | 598,979 | <p>By best, I mean most-common, easiest to setup, free. Performance doesn't matter.</p>
| 5 | 2009-03-01T00:29:11Z | 598,986 | <p>I'm just learning Python myself, but it seems like there are Python libraries that look more like Java JDBC drivers. Google found these articles about <a href="http://www.ibm.com/developerworks/opensource/library/os-pythonsqlo/" rel="nofollow">SQLObject</a> and <a href="http://www.oracle.com/technology/pub/articles... | 0 | 2009-03-01T00:32:52Z | [
"python"
] |
What's the best technology for connecting from linux to MS SQL Server using python? ODBC? | 598,979 | <p>By best, I mean most-common, easiest to setup, free. Performance doesn't matter.</p>
| 5 | 2009-03-01T00:29:11Z | 598,988 | <p><a href="http://pymssql.sourceforge.net/" rel="nofollow">pymssql</a>, the simple MS SQL Python extension module.</p>
| 2 | 2009-03-01T00:33:49Z | [
"python"
] |
What's the best technology for connecting from linux to MS SQL Server using python? ODBC? | 598,979 | <p>By best, I mean most-common, easiest to setup, free. Performance doesn't matter.</p>
| 5 | 2009-03-01T00:29:11Z | 598,993 | <p>You may find this topic helpful:</p>
<p><a href="http://stackoverflow.com/questions/289978/whats-the-simplest-way-to-access-mssql-with-python-or-ironpython">http://stackoverflow.com/questions/289978/whats-the-simplest-way-to-access-mssql-with-python-or-ironpython</a></p>
| 2 | 2009-03-01T00:36:48Z | [
"python"
] |
What's the best technology for connecting from linux to MS SQL Server using python? ODBC? | 598,979 | <p>By best, I mean most-common, easiest to setup, free. Performance doesn't matter.</p>
| 5 | 2009-03-01T00:29:11Z | 599,833 | <p>I decided that pyodbc was the best fit. Very simple, stable, supported:<br />
<a href="http://code.google.com/p/pyodbc/" rel="nofollow">http://code.google.com/p/pyodbc/</a></p>
| 3 | 2009-03-01T13:38:49Z | [
"python"
] |
What's the best technology for connecting from linux to MS SQL Server using python? ODBC? | 598,979 | <p>By best, I mean most-common, easiest to setup, free. Performance doesn't matter.</p>
| 5 | 2009-03-01T00:29:11Z | 601,276 | <p><a href="http://www.freetds.org/" rel="nofollow">FreeTDS</a></p>
| 1 | 2009-03-02T04:30:41Z | [
"python"
] |
How can I manually register distributions with pkg_resources? | 599,205 | <p>I'm trying to get a package installed on Google App Engine. The package relies rather extensively on <code>pkg_resources</code>, but there's no way to run <code>setup.py</code> on App Engine.</p>
<p>There's no platform-specific code in the source, however, so it's no problem to just zip up the source and include t... | 1 | 2009-03-01T03:40:26Z | 676,517 | <p>Yes, for setuptools-based libraries you'll need to deploy the library's "Egg" metadata along with it. The easiest way I've found is to deploy a whole <a href="http://pypi.python.org/pypi/virtualenv/1.3.3" rel="nofollow">virtualenv</a> environment containing your project and the required libraries.</p>
<p>I did thi... | 1 | 2009-03-24T08:19:40Z | [
"python",
"google-app-engine",
"setuptools",
"pkg-resources"
] |
How can I manually register distributions with pkg_resources? | 599,205 | <p>I'm trying to get a package installed on Google App Engine. The package relies rather extensively on <code>pkg_resources</code>, but there's no way to run <code>setup.py</code> on App Engine.</p>
<p>There's no platform-specific code in the source, however, so it's no problem to just zip up the source and include t... | 1 | 2009-03-01T03:40:26Z | 744,882 | <p>On your local development system, run <code>python setup.py bdist_egg</code>, which will create a Zip archive with the necessary metadata included. Add it to your <code>sys.path</code>, and it should work properly.</p>
| 0 | 2009-04-13T18:24:17Z | [
"python",
"google-app-engine",
"setuptools",
"pkg-resources"
] |
How can I manually register distributions with pkg_resources? | 599,205 | <p>I'm trying to get a package installed on Google App Engine. The package relies rather extensively on <code>pkg_resources</code>, but there's no way to run <code>setup.py</code> on App Engine.</p>
<p>There's no platform-specific code in the source, however, so it's no problem to just zip up the source and include t... | 1 | 2009-03-01T03:40:26Z | 2,164,138 | <p>Create a setup.py for the package just as you would normally, and then use "setup.py sdist --formats=zip" to build your source zip. The built source zip will include an .egg-info metadata directory, which will then be findable by pkg_resources. Alternately, you can use bdist_egg for all your packages.</p>
| 0 | 2010-01-29T18:15:48Z | [
"python",
"google-app-engine",
"setuptools",
"pkg-resources"
] |
Authentication Required - Problems Establishing AIM OSCAR Session using Python | 599,218 | <p>I'm writing a simple python script that will interface with the AIM servers using the <a href="http://dev.aol.com/aim/oscar/" rel="nofollow">OSCAR protocol</a>. It includes a somewhat complex handshake protocol. You essentially have to send a GET request to a specific URL, receive XML or JSON encoded reply, extract ... | 1 | 2009-03-01T03:52:58Z | 644,921 | <p>URI Encode your digest?</p>
<p>-moxford</p>
| 0 | 2009-03-13T23:00:37Z | [
"python",
"json",
"aim"
] |
Authentication Required - Problems Establishing AIM OSCAR Session using Python | 599,218 | <p>I'm writing a simple python script that will interface with the AIM servers using the <a href="http://dev.aol.com/aim/oscar/" rel="nofollow">OSCAR protocol</a>. It includes a somewhat complex handshake protocol. You essentially have to send a GET request to a specific URL, receive XML or JSON encoded reply, extract ... | 1 | 2009-03-01T03:52:58Z | 1,005,063 | <p>Try using <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/oscar.py" rel="nofollow">Twisted's OSCAR support</a> instead of writing your own? It hasn't seen a lot of maintenance, but I believe it works.</p>
| 1 | 2009-06-17T04:03:55Z | [
"python",
"json",
"aim"
] |
How to pass information using an HTTP redirect (in Django) | 599,280 | <p>I have a view that accepts a form submission and updates a model.</p>
<p>After updating the model, I want to redirect to another page, and I want a message such as "Field X successfully updated" to appear on this page.</p>
<p>How can I "pass" this message to the other page? HttpResponseRedirect only accepts a <a h... | 19 | 2009-03-01T05:02:13Z | 599,319 | <p>Can you just pass the message as a query param oon the URL to which you're redirecting? It's not terribly RESTy, but it ought to work:</p>
<pre><code>return HttpResponseRedirect('/polls/%s/results/?message=Updated" % p.id)
</code></pre>
<p>and have that view check for a message param, scrub it for nasties, and di... | 0 | 2009-03-01T05:40:29Z | [
"python",
"django",
"http"
] |
How to pass information using an HTTP redirect (in Django) | 599,280 | <p>I have a view that accepts a form submission and updates a model.</p>
<p>After updating the model, I want to redirect to another page, and I want a message such as "Field X successfully updated" to appear on this page.</p>
<p>How can I "pass" this message to the other page? HttpResponseRedirect only accepts a <a h... | 19 | 2009-03-01T05:02:13Z | 599,704 | <p>This is a built-in feature of Django, called "messages"</p>
<p>See <a href="http://docs.djangoproject.com/en/dev/topics/auth/#messages">http://docs.djangoproject.com/en/dev/topics/auth/#messages</a></p>
<p>From the documentation:</p>
<blockquote>
<p>A message is associated with a User.
There's no concept of e... | 11 | 2009-03-01T11:56:07Z | [
"python",
"django",
"http"
] |
How to pass information using an HTTP redirect (in Django) | 599,280 | <p>I have a view that accepts a form submission and updates a model.</p>
<p>After updating the model, I want to redirect to another page, and I want a message such as "Field X successfully updated" to appear on this page.</p>
<p>How can I "pass" this message to the other page? HttpResponseRedirect only accepts a <a h... | 19 | 2009-03-01T05:02:13Z | 600,593 | <p>You can use django-flashcookie app
<a href="http://bitbucket.org/offline/django-flashcookie/wiki/Home">http://bitbucket.org/offline/django-flashcookie/wiki/Home</a></p>
<p>it can send multiple messages and have unlimited types of messages. Lets say you want one message type for warning and one for error messages, ... | 8 | 2009-03-01T21:41:14Z | [
"python",
"django",
"http"
] |
How to pass information using an HTTP redirect (in Django) | 599,280 | <p>I have a view that accepts a form submission and updates a model.</p>
<p>After updating the model, I want to redirect to another page, and I want a message such as "Field X successfully updated" to appear on this page.</p>
<p>How can I "pass" this message to the other page? HttpResponseRedirect only accepts a <a h... | 19 | 2009-03-01T05:02:13Z | 607,585 | <p>While all suggestions so far work, I would suggest going with Ry4an's (pass it in the request URL) - just change the actual text to a coded text within a predefined set of text messages. </p>
<p>Two advantages here:</p>
<ol>
<li>Less chance of something hacking through your scrubbing of bad content</li>
<li>You ca... | 0 | 2009-03-03T18:34:01Z | [
"python",
"django",
"http"
] |
How to pass information using an HTTP redirect (in Django) | 599,280 | <p>I have a view that accepts a form submission and updates a model.</p>
<p>After updating the model, I want to redirect to another page, and I want a message such as "Field X successfully updated" to appear on this page.</p>
<p>How can I "pass" this message to the other page? HttpResponseRedirect only accepts a <a h... | 19 | 2009-03-01T05:02:13Z | 1,912,778 | <p>Take a look at Django's messages framework. <a href="http://docs.djangoproject.com/en/dev/ref/contrib/messages/#ref-contrib-messages" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/contrib/messages/#ref-contrib-messages</a></p>
| 0 | 2009-12-16T06:49:38Z | [
"python",
"django",
"http"
] |
How to pass information using an HTTP redirect (in Django) | 599,280 | <p>I have a view that accepts a form submission and updates a model.</p>
<p>After updating the model, I want to redirect to another page, and I want a message such as "Field X successfully updated" to appear on this page.</p>
<p>How can I "pass" this message to the other page? HttpResponseRedirect only accepts a <a h... | 19 | 2009-03-01T05:02:13Z | 1,912,876 | <p>There is a lot of solutions</p>
<p>1 Use Django-trunk version - it support sending messages to Anonymous Users</p>
<p>2 Sessions</p>
<pre><code>def view1(request):
request.session['message'] = 'Hello view2!'
return HttpResponseRedirect('/view2/')
def view2(request):
return HttpResponse(request.sessi... | 2 | 2009-12-16T07:11:51Z | [
"python",
"django",
"http"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.