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 |
|---|---|---|---|---|---|---|---|---|---|
How do I resize an image using PIL and maintain its aspect ratio? | 273,946 | <p>Is there an obvious way to do this that I'm missing? I'm just trying to make thumbnails.</p>
| 196 | 2008-11-07T23:08:04Z | 12,718,182 | <p>PIL already has the option to crop an image</p>
<pre><code>img = ImageOps.fit(img, size, Image.ANTIALIAS)
</code></pre>
| 16 | 2012-10-03T23:11:39Z | [
"python",
"image",
"python-imaging-library",
"thumbnails"
] |
How do I resize an image using PIL and maintain its aspect ratio? | 273,946 | <p>Is there an obvious way to do this that I'm missing? I'm just trying to make thumbnails.</p>
| 196 | 2008-11-07T23:08:04Z | 16,689,816 | <p>My ugly example.</p>
<p>Function get file like: "pic[0-9a-z].[extension]", resize them to 120x120, moves section to center and save to "ico[0-9a-z].[extension]", works with portrait and landscape:</p>
<pre><code>def imageResize(filepath):
from PIL import Image
file_dir=os.path.split(filepath)
img = Ima... | 1 | 2013-05-22T10:48:36Z | [
"python",
"image",
"python-imaging-library",
"thumbnails"
] |
How do I resize an image using PIL and maintain its aspect ratio? | 273,946 | <p>Is there an obvious way to do this that I'm missing? I'm just trying to make thumbnails.</p>
| 196 | 2008-11-07T23:08:04Z | 30,227,474 | <p>Based in @tomvon, I finished using the following:</p>
<p>Resizing width:</p>
<pre><code>new_width = 680
new_height = new_width * height / width
</code></pre>
<p>Resizing height:</p>
<pre><code>new_height = 680
new_width = new_height * width / height
</code></pre>
<p>Then just:</p>
<pre><code>img = img.resiz... | 6 | 2015-05-14T00:37:06Z | [
"python",
"image",
"python-imaging-library",
"thumbnails"
] |
How do I resize an image using PIL and maintain its aspect ratio? | 273,946 | <p>Is there an obvious way to do this that I'm missing? I'm just trying to make thumbnails.</p>
| 196 | 2008-11-07T23:08:04Z | 32,806,728 | <pre><code>from PIL import Image
from resizeimage import resizeimage
def resize_file(in_file, out_file, size):
with open(in_file) as fd:
image = resizeimage.resize_thumbnail(Image.open(fd), size)
image.save(out_file)
image.close()
resize_file('foo.tif', 'foo_small.jpg', (256, 256))
</code></pre>
... | 2 | 2015-09-27T10:02:19Z | [
"python",
"image",
"python-imaging-library",
"thumbnails"
] |
How do I resize an image using PIL and maintain its aspect ratio? | 273,946 | <p>Is there an obvious way to do this that I'm missing? I'm just trying to make thumbnails.</p>
| 196 | 2008-11-07T23:08:04Z | 36,036,843 | <pre><code>from PIL import Image
img = Image.open('/your iamge path/image.jpg') # image extension *.png,*.jpg
new_width = 200
new_height = 300
img = img.resize((new_width, new_height), Image.ANTIALIAS)
img.save('output image name.png') # format may what u want ,*.png,*jpg,*.gif
</code></pre>
| 2 | 2016-03-16T13:17:46Z | [
"python",
"image",
"python-imaging-library",
"thumbnails"
] |
UTF-8 latin-1 conversion issues, python django | 274,361 | <p>ok so my issue is i have the string '\222\222\223\225' which is stored as latin-1 in the db. What I get from django (by printing it) is the following string, 'ââââ¢' which I assume is the UTF conversion of it. Now I need to pass the string into a function that
does this operation: </p>
<pre><code>strdecrypt... | 3 | 2008-11-08T04:24:45Z | 274,403 | <p>Your first error 'chr() arg not in range(256)' probably means you have underflowed the value, because chr cannot take negative numbers. I don't know what the encryption algorithm is supposed to do when the inputcounter + 33 is more than the actual character representation, you'll have to check what to do in that cas... | 4 | 2008-11-08T05:29:37Z | [
"python",
"django",
"utf-8",
"character-encoding"
] |
UTF-8 latin-1 conversion issues, python django | 274,361 | <p>ok so my issue is i have the string '\222\222\223\225' which is stored as latin-1 in the db. What I get from django (by printing it) is the following string, 'ââââ¢' which I assume is the UTF conversion of it. Now I need to pass the string into a function that
does this operation: </p>
<pre><code>strdecrypt... | 3 | 2008-11-08T04:24:45Z | 274,412 | <p>Well its because its been encrypted with some terrible scheme that just changes the ord() of the character by some request, so the string coming out of the database has been encrypted and this decrypts it. What you supplied above does not seem to work. In the database it is latin-1, django converts it to unicode, ... | 0 | 2008-11-08T05:42:00Z | [
"python",
"django",
"utf-8",
"character-encoding"
] |
UTF-8 latin-1 conversion issues, python django | 274,361 | <p>ok so my issue is i have the string '\222\222\223\225' which is stored as latin-1 in the db. What I get from django (by printing it) is the following string, 'ââââ¢' which I assume is the UTF conversion of it. Now I need to pass the string into a function that
does this operation: </p>
<pre><code>strdecrypt... | 3 | 2008-11-08T04:24:45Z | 274,440 | <p>As Vinko notes, Latin-1 or ISO 8859-1 doesn't have printable characters for the octal string you quote. According to my notes for 8859-1, "C1 Controls (0x80 - 0x9F) are from ISO/IEC 6429:1992. It does not define names for 80, 81, or 99". The code point names are as Vinko lists them:</p>
<pre><code>\222 = 0x92 =&g... | 2 | 2008-11-08T06:08:07Z | [
"python",
"django",
"utf-8",
"character-encoding"
] |
How to copy a file in Python with a progress bar? | 274,493 | <p>When copying large files using <code>shutil.copy()</code>, you get no indication of how the operation is progressing..</p>
<p>I have put together something that works - it uses a simple ProgressBar class (which simple returns a simple ASCII progress bar, as a string), and a loop of <code>open().read()</code> and <c... | 8 | 2008-11-08T07:21:53Z | 274,497 | <p>Two things:</p>
<ul>
<li>I would make the default block size a <em>lot</em> larger than 512. I would start with 16384 and perhaps more.</li>
<li>For modularity, it might be better to have the <code>copy_with_prog</code> function not output the progress bar itself, but call a callback function so the caller can deci... | 14 | 2008-11-08T07:28:43Z | [
"python",
"file-io"
] |
How to copy a file in Python with a progress bar? | 274,493 | <p>When copying large files using <code>shutil.copy()</code>, you get no indication of how the operation is progressing..</p>
<p>I have put together something that works - it uses a simple ProgressBar class (which simple returns a simple ASCII progress bar, as a string), and a loop of <code>open().read()</code> and <c... | 8 | 2008-11-08T07:21:53Z | 275,945 | <p>Overkill? Perhaps. But on almost any system, Linux, Mac, and With a quick wxWidgets install on Windows, you can have the real deal, with pause and cancel buttons in a gui setup. Macs ship with wxWidgets these days, and it's a common package on Linux.</p>
<p>A single file is very quick (it will immediately finish... | 5 | 2008-11-09T14:08:26Z | [
"python",
"file-io"
] |
How to copy a file in Python with a progress bar? | 274,493 | <p>When copying large files using <code>shutil.copy()</code>, you get no indication of how the operation is progressing..</p>
<p>I have put together something that works - it uses a simple ProgressBar class (which simple returns a simple ASCII progress bar, as a string), and a loop of <code>open().read()</code> and <c... | 8 | 2008-11-08T07:21:53Z | 24,737,210 | <p>If you want to use the Windows copy dialog with progress you can use these:</p>
<ul>
<li><a href="https://github.com/tjguk/winshell/" rel="nofollow">https://github.com/tjguk/winshell/</a></li>
<li><a href="https://github.com/frmdstryr/pywinutils" rel="nofollow">https://github.com/frmdstryr/pywinutils</a></li>
</ul>... | 1 | 2014-07-14T13:05:40Z | [
"python",
"file-io"
] |
config_vars.mk missing in default xampp-linux installation | 274,638 | <p>I extracted the xampp package xampp-linux-1.6.7 on a Ubuntu 8.10 system and followed the instuctions from mod_wsgi documentation. I get the error below:</p>
<pre><code>ravi@Ibex:~/mod_wsgi-2.3$ ./configure --with-apxs=/opt/lampp/bin/apxs
checking Apache version... cannot open /opt/lampp/build/config_vars.mk: No s... | 3 | 2008-11-08T11:31:32Z | 7,552,280 | <p>When apxs throws and error complaining about missing config_vars.mk it means that the build directory of Apache is missing. Fox xampp users the solution is to download xampp-dev as well and extract that to the same path.</p>
| 1 | 2011-09-26T08:10:54Z | [
"python",
"apache",
"xampp",
"mod-wsgi"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 275,025 | <p>Try the <a href="http://docs.python.org/2/library/stdtypes.html#str.rstrip">rstrip</a> method.</p>
<pre><code>>>> 'test string\n'.rstrip()
'test string'
</code></pre>
<p>Note that Python's rstrip method strips <em>all</em> kinds of trailing whitespace by default, not just one newline as Perl does with cho... | 963 | 2008-11-08T18:31:53Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 275,401 | <p>The canonical way to strip end-of-line (EOL) characters is to use the string rstrip() method removing any trailing \r or \n. Here are examples for Mac, Windows, and Unix EOL characters.</p>
<pre><code>>>> 'Mac EOL\r'.rstrip('\r\n')
'Mac EOL'
>>> 'Windows EOL\r\n'.rstrip('\r\n')
'Windows EOL'
>... | 100 | 2008-11-09T00:11:21Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 275,659 | <p>And I would say the "pythonic" way to get lines without trailing newline characters is splitlines().</p>
<pre><code>>>> text = "line 1\nline 2\r\nline 3\nline 4"
>>> text.splitlines()
['line 1', 'line 2', 'line 3', 'line 4']
</code></pre>
| 113 | 2008-11-09T05:52:43Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 326,279 | <p>Note that rstrip doesn't act exactly like Perl's chomp() because it doesn't modify the string. That is, in Perl:</p>
<pre><code>$x="a\n";
chomp $x
</code></pre>
<p>results in <code>$x</code> being <code>"a"</code>.</p>
<p>but in Python:</p>
<pre><code>x="a\n"
x.rstrip()
</code></pre>
<p>will mean that the val... | 86 | 2008-11-28T17:31:34Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 1,077,495 | <p>I don't program in Python, but I came across an <a href="http://www.python.org/doc/faq/programming/#is-there-an-equivalent-to-perl-s-chomp-for-removing-trailing-newlines-from-strings" rel="nofollow">FAQ</a> at python.org advocating S.rstrip("\r\n") for python 2.2 or later.</p>
| 12 | 2009-07-03T01:49:19Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 2,396,894 | <p>I might use something like this:</p>
<pre><code>import os
s = s.rstrip(os.linesep)
</code></pre>
<p>I think the problem with <code>rstrip("\n")</code> is that you'll probably want to make sure the line separator is portable. (some antiquated systems are rumored to use <code>"\r\n"</code>). The other gotcha is that... | 39 | 2010-03-07T16:07:27Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 5,764,202 | <p>rstrip doesn't do the same thing as chomp, on so many levels. Read <a href="http://perldoc.perl.org/functions/chomp.html">http://perldoc.perl.org/functions/chomp.html</a> and see that chomp is very complex indeed.</p>
<p>However, my main point is that chomp removes at most 1 line ending, whereas rstrip will remove ... | 14 | 2011-04-23T12:42:25Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 5,803,510 | <p>Careful with <code>"foo".rstrip(os.linesep)</code>: That will only chomp the newline characters for the platform where your Python is being executed. Imagine you're chimping the lines of a Windows file under Linux, for instance:</p>
<pre><code>$ python
Python 2.7.1 (r271:86832, Mar 18 2011, 09:09:48)
[GCC 4.5.0 20... | 17 | 2011-04-27T11:43:20Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 8,327,143 | <p>workaround solution for special case:</p>
<p>if the newline character is the last character (as is the case with most file inputs), then for any element in the collection you can index as follows: </p>
<pre><code>foobar= foobar[:-1]
</code></pre>
<p>to slice out your newline character. </p>
| 7 | 2011-11-30T14:04:19Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 9,507,807 | <pre><code>"line 1\nline 2\r\n...".replace('\n', '').replace('\r', '')
>>> 'line 1line 2...'
</code></pre>
<p>or you could always get geekier with regexps :)</p>
<p>have fun!</p>
| 15 | 2012-02-29T22:40:11Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 16,527,062 | <p>You may use <code>line = line.rstrip('\n')</code>. This will strip all newlines from the end of the string, not just one.</p>
| 35 | 2013-05-13T16:41:22Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 19,317,570 | <p>If your question is to clean up all the line breaks in a multiple line str object (oldstr), you can split it into a list according to the delimiter '\n' and then join this list into a new str(newstr).</p>
<p><code>newstr = "".join(oldstr.split('\n'))</code> </p>
| 6 | 2013-10-11T11:56:21Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 19,531,239 | <p>An <a href="http://docs.python.org/2/library/stdtypes.html#file.next" rel="nofollow">example in Python's documentation</a> simply uses <code>line.strip()</code>.</p>
<p>Perl's <code>chomp</code> function removes one linebreak sequence from the end of a string only if it's actually there.</p>
<p>Here is how I plan ... | 16 | 2013-10-23T01:32:11Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 21,242,117 | <pre><code>import re
r_unwanted = re.compile("[\n\t\r]")
r_unwanted.sub("", your_text)
</code></pre>
| 8 | 2014-01-20T19:07:03Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 26,554,128 | <p>A catch all:</p>
<pre><code>line = line.rstrip('\r|\n')
</code></pre>
| 2 | 2014-10-24T18:34:12Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 27,054,136 | <p>you can use strip:</p>
<pre><code>line = line.strip()
</code></pre>
<p>demo:</p>
<pre><code>>>> "\n\n hello world \n\n".strip()
'hello world'
</code></pre>
| 15 | 2014-11-21T04:29:07Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 27,890,752 | <p>I find it convenient to have be able to get the chomped lines via in iterator, parallel to the way you can get the un-chomped lines from a file object. You can do so with the following code:</p>
<pre><code>def chomped_lines(iter):
for line in iter:
yield line.rstrip("\r\n")
</code></pre>
<p>Sample usag... | 1 | 2015-01-11T18:47:33Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 28,937,424 | <pre><code>s = s.rstrip()
</code></pre>
<p>will remove all newlines at the end of the string <code>s</code>. The assignment is needed because <code>rstrip</code> returns a new string instead of modifying the original string. </p>
| 25 | 2015-03-09T08:02:55Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 32,882,948 | <p>This would replicate exactly perl's chomp (minus behavior on arrays) for "\n" line terminator:</p>
<pre><code>def chomp(x):
if x.endswith("\r\n"): return x[:-2]
if x.endswith("\n"): return x[:-1]
return x[:]
</code></pre>
<p>(Note: it does not modify string 'in place'; it does not strip extra trailing ... | 4 | 2015-10-01T08:33:32Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 33,392,998 | <p>If you are concerned about speed (say you have a looong list of strings) and you know the nature of the newline char, string slicing is actually faster than rstrip. A little test to illustrate this:</p>
<pre><code>import time
loops = 50000000
def method1(loops=loops):
test_string = 'num\n'
t0 = time.time(... | 1 | 2015-10-28T13:56:42Z | [
"python",
"newline"
] |
How can I remove (chomp) a newline in Python? | 275,018 | <p>What is the Python equivalent of Perl's <code>chomp</code> function, which removes the last character of a value?</p>
| 959 | 2008-11-08T18:25:24Z | 37,346,773 | <p>Just use : </p>
<pre><code>line = line.rstrip("\n")
</code></pre>
<p>or</p>
<pre><code>line = line.strip("\n")
</code></pre>
<p>You don't need any of this complicated stuff</p>
| 2 | 2016-05-20T12:29:21Z | [
"python",
"newline"
] |
What is the regular expression for /urlchecker/http://www.google.com | 275,109 | <p>I'm writing a url rewrite in django that when a person goes to <a href="http://mysite.com/urlchecker/http://www.google.com" rel="nofollow">http://mysite.com/urlchecker/http://www.google.com</a> it sends the url: <a href="http://ww.google.com" rel="nofollow">http://ww.google.com</a> to a view as a string variable. ... | 1 | 2008-11-08T20:01:02Z | 275,117 | <p>Try this instead:</p>
<p><code>(r'^urlchecker/(?P<url>.+)$', 'mysite.main.views.urlchecker'),</code></p>
<p>This differs from yours in that:</p>
<ul>
<li>It will take anything after 'urlcheck/', not just "word" characters.</li>
<li>It does not force the url to end in a slash.</li>
</ul>
| 2 | 2008-11-08T20:06:29Z | [
"python",
"regex",
"django"
] |
What is the regular expression for /urlchecker/http://www.google.com | 275,109 | <p>I'm writing a url rewrite in django that when a person goes to <a href="http://mysite.com/urlchecker/http://www.google.com" rel="nofollow">http://mysite.com/urlchecker/http://www.google.com</a> it sends the url: <a href="http://ww.google.com" rel="nofollow">http://ww.google.com</a> to a view as a string variable. ... | 1 | 2008-11-08T20:01:02Z | 275,281 | <p>I just learned something while grazing the Hidden Features of Python thread.
<a href="http://stackoverflow.com/questions/101268/hidden-features-of-python#143636">Python's re compiler has a debug mode</a>! (Who knew? Well, apparently someone did :-) Anyway, it's worth a read.</p>
| 0 | 2008-11-08T22:07:07Z | [
"python",
"regex",
"django"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 275,195 | <p>I found this in the Cheetah source code (<a href="http://www.koders.com/python/fid549827F97513858275EEA43DC0135AC97AEAEF57.aspx" rel="nofollow">here</a>)</p>
<pre><code>htmlCodes = [
['&', '&amp;'],
['<', '&lt;'],
['>', '&gt;'],
['"', '&quot;'],
]
htmlCodesReversed = htmlCo... | 1 | 2008-11-08T20:58:52Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 275,246 | <p>Given the Django use case, there are two answers to this. Here is its <code>django.utils.html.escape</code> function, for reference:</p>
<pre><code>def escape(html):
"""Returns the given HTML with ampersands, quotes and carets encoded."""
return mark_safe(force_unicode(html).replace('&', '&amp;').r... | 89 | 2008-11-08T21:40:37Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 275,463 | <p>Use daniel's solution if the set of encoded characters is relatively restricted.
Otherwise, use one of the numerous HTML-parsing libraries.</p>
<p>I like BeautifulSoup because it can handle malformed XML/HTML :</p>
<p><a href="http://www.crummy.com/software/BeautifulSoup/">http://www.crummy.com/software/BeautifulS... | 20 | 2008-11-09T01:15:21Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 312,538 | <p>See at the bottom of this <a href="http://wiki.python.org/moin/EscapingHtml">page at Python wiki</a>, there are at least 2 options to "unescape" html.</p>
| 8 | 2008-11-23T13:50:40Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 449,169 | <p>For html encoding, there's <strong>cgi.escape</strong> from the standard library:</p>
<pre><code>>> help(cgi.escape)
cgi.escape = escape(s, quote=None)
Replace special characters "&", "<" and ">" to HTML-safe sequences.
If the optional flag quote is true, the quotation mark character (")
... | 75 | 2009-01-16T01:12:53Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 1,619,286 | <p>Daniel's comment as an answer:</p>
<p>"escaping only occurs in Django during template rendering. Therefore, there's no need for an unescape - you just tell the templating engine not to escape. either {{ context_var|safe }} or {% autoescape off %}{{ context_var }}{% endautoescape %}"</p>
| 6 | 2009-10-24T22:04:16Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 3,271,650 | <p>I found a fine function at: <a href="http://snippets.dzone.com/posts/show/4569">http://snippets.dzone.com/posts/show/4569</a></p>
<pre><code>def decodeHtmlentities(string):
import re
entity_re = re.compile("&(#?)(\d{1,5}|\w{1,8});")
def substitute_entity(match):
from htmlentitydefs import n... | 5 | 2010-07-17T13:27:49Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 7,088,472 | <p>With the standard library:</p>
<ul>
<li><p>HTML Escape</p>
<pre><code>try:
from html import escape # python 3.x
except ImportError:
from cgi import escape # python 2.x
print(escape("<"))
</code></pre></li>
<li><p>HTML Unescape</p>
<pre><code>try:
from html import unescape # python 3.4+
except I... | 70 | 2011-08-17T05:51:23Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 8,524,552 | <p>Below is a python function that uses module <code>htmlentitydefs</code>. It is not perfect. The version of <code>htmlentitydefs</code> that I have is incomplete and it assumes that all entities decode to one codepoint which is wrong for entities like <code>&NotEqualTilde;</code>:</p>
<p><a href="http://www.w3... | 0 | 2011-12-15T18:01:24Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 8,593,583 | <p>If anyone is looking for a simple way to do this via the django templates, you can always use filters like this:</p>
<pre><code><html>
{{ node.description|safe }}
</html>
</code></pre>
<p>I had some data coming from a vendor and everything I posted had html tags actually written on the rendered page as... | 3 | 2011-12-21T17:08:31Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 9,468,081 | <p>You can also use django.utils.html.escape</p>
<pre><code>from django.utils.html import escape
something_nice = escape(request.POST['something_naughty'])
</code></pre>
| 1 | 2012-02-27T16:01:44Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 11,273,187 | <p>This is the easiest solution for this problem - </p>
<pre><code>{% autoescape on %}
{{ body }}
{% endautoescape %}
</code></pre>
<p>From <a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs" rel="nofollow">this page</a>.</p>
| 0 | 2012-06-30T09:56:10Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 28,268,163 | <p>Even though this is a really old question, this may work.</p>
<p>Django 1.5.5</p>
<pre><code>In [1]: from django.utils.text import unescape_entities
In [2]: unescape_entities('&lt;img class=&quot;size-medium wp-image-113&quot; style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot; s... | 0 | 2015-02-01T21:31:08Z | [
"python",
"django",
"html-encode"
] |
How do I perform HTML decoding/encoding using Python/Django? | 275,174 | <p>I have a string that is html encoded: </p>
<pre><code>&lt;img class=&quot;size-medium wp-image-113&quot;
style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;
src=&quot;http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt=&quot;&quot; width=&... | 91 | 2008-11-08T20:44:30Z | 31,282,266 | <p>In Python 3.4+:</p>
<pre><code>import html
html.unescape(your_string)
</code></pre>
| 4 | 2015-07-08T01:54:02Z | [
"python",
"django",
"html-encode"
] |
Python ctypes and function calls | 275,207 | <p>My friend produced a small proof-of-concept assembler that worked on x86. I decided to port it for x86_64 as well, but I immediately hit a problem.</p>
<p>I wrote a small piece of program in C, then compiled and objdumped the code. After that I inserted it to my python script, therefore the x86_64 code is correct:<... | 7 | 2008-11-08T21:11:25Z | 275,300 | <p>Does python even allow such usage? I should learn it then...</p>
<p>I think the interpreter doesn't expect any register to be changed. Try saving the registers that you use inside the function if you plan to use your assembler output like this.</p>
<p>Btw, call convention of x86_64 is different than regular x86. Y... | 0 | 2008-11-08T22:21:43Z | [
"python",
"c",
"assembly",
"ctypes",
"x86-64"
] |
Python ctypes and function calls | 275,207 | <p>My friend produced a small proof-of-concept assembler that worked on x86. I decided to port it for x86_64 as well, but I immediately hit a problem.</p>
<p>I wrote a small piece of program in C, then compiled and objdumped the code. After that I inserted it to my python script, therefore the x86_64 code is correct:<... | 7 | 2008-11-08T21:11:25Z | 275,333 | <p>I think you can't freely execute any allocated memory without first setting it as executable. I never tried myself, but you might want to check the unix function <code>mprotect</code>:</p>
<p><a href="http://linux.about.com/library/cmd/blcmdl2_mprotect.htm" rel="nofollow">http://linux.about.com/library/cmd/blcmdl2_... | 4 | 2008-11-08T22:51:24Z | [
"python",
"c",
"assembly",
"ctypes",
"x86-64"
] |
Python ctypes and function calls | 275,207 | <p>My friend produced a small proof-of-concept assembler that worked on x86. I decided to port it for x86_64 as well, but I immediately hit a problem.</p>
<p>I wrote a small piece of program in C, then compiled and objdumped the code. After that I inserted it to my python script, therefore the x86_64 code is correct:<... | 7 | 2008-11-08T21:11:25Z | 275,426 | <p>Done some research with my friend and found out this is a platform-specific issue. We suspect that on some platforms malloc mmaps memory without PROT_EXEC and on others it does.</p>
<p>Therefore it is necessary to change the protection level with mprotect afterwards.</p>
<p>Lame thing, took a while to find out wha... | 6 | 2008-11-09T00:29:39Z | [
"python",
"c",
"assembly",
"ctypes",
"x86-64"
] |
Python ctypes and function calls | 275,207 | <p>My friend produced a small proof-of-concept assembler that worked on x86. I decided to port it for x86_64 as well, but I immediately hit a problem.</p>
<p>I wrote a small piece of program in C, then compiled and objdumped the code. After that I inserted it to my python script, therefore the x86_64 code is correct:<... | 7 | 2008-11-08T21:11:25Z | 275,460 | <p>As <a href="http://stackoverflow.com/questions/275207/python-ctypes-and-function-calls#275333">vincent</a> mentioned, this is due to the allocated page being marked as non executable. Newer processors support this <a href="http://en.wikipedia.org/wiki/NX_bit">functionality</a>, and its used as an added layer of sec... | 7 | 2008-11-09T01:06:14Z | [
"python",
"c",
"assembly",
"ctypes",
"x86-64"
] |
Python ctypes and function calls | 275,207 | <p>My friend produced a small proof-of-concept assembler that worked on x86. I decided to port it for x86_64 as well, but I immediately hit a problem.</p>
<p>I wrote a small piece of program in C, then compiled and objdumped the code. After that I inserted it to my python script, therefore the x86_64 code is correct:<... | 7 | 2008-11-08T21:11:25Z | 1,812,514 | <p>There's simpler approach I've figured only but recently that doesn't involve mprotect. Plainly mmap the executable space for program directly. These days python has a module for doing exactly this, though I didn't find way to get the address of the code. In short you'd allocate memory calling mmap instead of using s... | 0 | 2009-11-28T13:22:43Z | [
"python",
"c",
"assembly",
"ctypes",
"x86-64"
] |
information seemingly coming out of mysqldb incorrectly, python django | 275,541 | <p>In a latin-1 database i have '<code>\222\222\223\225</code>', when I try to pull this field from the django models I get back <code>u'\u2019\u2019\u201c\u2022'</code>.</p>
<pre><code>from django.db import connection ... | 0 | 2008-11-09T03:06:06Z | 276,108 | <p>A little browsing of already-asked questions would have led you to <a href="http://stackoverflow.com/questions/274361/utf-8-latin-1-conversion-issues-python-django">UTF-8 latin-1 conversion issues</a>, which was asked and answered yesterday.</p>
<p>BTW, I couldn't remember the exact title, so I just googled on djan... | 1 | 2008-11-09T16:54:16Z | [
"python",
"mysql",
"django",
"character-encoding"
] |
information seemingly coming out of mysqldb incorrectly, python django | 275,541 | <p>In a latin-1 database i have '<code>\222\222\223\225</code>', when I try to pull this field from the django models I get back <code>u'\u2019\u2019\u201c\u2022'</code>.</p>
<pre><code>from django.db import connection ... | 0 | 2008-11-09T03:06:06Z | 303,448 | <p>Django uses UTF-8, unless you define DEFAULT_CHARSET being something other. Be aware that defining other charset will require you to encode all your templates in this charset and this charset will pop from here to there, like email encoding, in sitemaps and feeds and so on. So, IMO, the best you can do is to go UTF-... | 0 | 2008-11-19T21:34:21Z | [
"python",
"mysql",
"django",
"character-encoding"
] |
Database change underneath SQLObject | 275,572 | <p>I'm starting a web project that likely should be fine with SQLite. I have SQLObject on top of it, but thinking long term here -- if this project should require a more robust (e.g. able to handle high traffic), I will need to have a transition plan ready. My questions:</p>
<ol>
<li>How easy is it to transition fro... | 1 | 2008-11-09T03:46:40Z | 275,587 | <p>I'm not sure I understand the question.</p>
<p>The <a href="http://www.sqlobject.org/SQLObject.html#dbconnection-database-connections" rel="nofollow">SQLObject documentation</a> lists six kinds of connections available. Further, the database connection (or scheme) is specified in a connection string. Changing dat... | 0 | 2008-11-09T04:06:02Z | [
"python",
"mysql",
"database",
"sqlite",
"sqlobject"
] |
Database change underneath SQLObject | 275,572 | <p>I'm starting a web project that likely should be fine with SQLite. I have SQLObject on top of it, but thinking long term here -- if this project should require a more robust (e.g. able to handle high traffic), I will need to have a transition plan ready. My questions:</p>
<ol>
<li>How easy is it to transition fro... | 1 | 2008-11-09T03:46:40Z | 275,676 | <p>Your success with createTable() will depend on your existing underlying table schema / data types. In other words, how well SQLite maps to the database you choose and how SQLObject decides to use your data types.</p>
<p>The safest option may be to create the new database by hand. Then you'll have to deal with dat... | 2 | 2008-11-09T06:20:43Z | [
"python",
"mysql",
"database",
"sqlite",
"sqlobject"
] |
Database change underneath SQLObject | 275,572 | <p>I'm starting a web project that likely should be fine with SQLite. I have SQLObject on top of it, but thinking long term here -- if this project should require a more robust (e.g. able to handle high traffic), I will need to have a transition plan ready. My questions:</p>
<ol>
<li>How easy is it to transition fro... | 1 | 2008-11-09T03:46:40Z | 275,851 | <p>3) Is quite an interesting question. In general, SQLite is pretty useless for web-based stuff. It scales fairly well for size, but scales terribly for concurrency, and so if you are planning to hit it with a few requests at the same time, you will be in trouble.</p>
<p>Now your idea in part 3) of the question is to... | 3 | 2008-11-09T11:53:37Z | [
"python",
"mysql",
"database",
"sqlite",
"sqlobject"
] |
How do you get a thumbnail of a movie using IMDbPy? | 275,683 | <p>Using <a href="http://imdbpy.sourceforge.net">IMDbPy</a> it is painfully easy to access movies from the IMDB site:</p>
<pre><code>import imdb
access = imdb.IMDb()
movie = access.get_movie(3242) # random ID
print "title: %s year: %s" % (movie['title'], movie['year'])
</code></pre>
<p>However I see no way to get t... | 6 | 2008-11-09T06:39:52Z | 275,774 | <p><strong>Note:</strong></p>
<ul>
<li>Not every movie has a cover url. (The random ID in your example doesn't.)</li>
<li>Make sure you're using an up-to-date version of IMDbPy. (IMDb changes, and IMDbPy with it.)</li>
</ul>
<p>...</p>
<pre><code>import imdb
access = imdb.IMDb()
movie = access.get_movie(1132626)
p... | 10 | 2008-11-09T09:34:46Z | [
"python",
"imdb",
"imdbpy"
] |
How do you get a thumbnail of a movie using IMDbPy? | 275,683 | <p>Using <a href="http://imdbpy.sourceforge.net">IMDbPy</a> it is painfully easy to access movies from the IMDB site:</p>
<pre><code>import imdb
access = imdb.IMDb()
movie = access.get_movie(3242) # random ID
print "title: %s year: %s" % (movie['title'], movie['year'])
</code></pre>
<p>However I see no way to get t... | 6 | 2008-11-09T06:39:52Z | 275,826 | <p>Response from the IMDbPy mailing list:</p>
<blockquote>
<p>If present, the url is accessible
through movie['cover url']. Beware
that it could be missing, so you must
first test it with something like:<br />
if 'cover url' in movie:
...</p>
<p>After that, you can use the urllib
module to fe... | 2 | 2008-11-09T11:01:02Z | [
"python",
"imdb",
"imdbpy"
] |
What's the difference between all of the os.popen() methods? | 275,756 | <p>I was looking at the <a href="http://www.python.org/doc/2.5.2/lib/module-popen2.html">Python documentation</a> and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc. </p>
<p>Apart from the fact that some include <em>stderr</em> while others don't, what are the differences betwe... | 7 | 2008-11-09T08:50:12Z | 275,758 | <p>popen2 doesn't capture standard error, popen3 does capture standard error and gives a unique file handle for it. Finally, popen4 captures standard error but includes it in the same file object as standard output.</p>
| 9 | 2008-11-09T08:53:58Z | [
"python",
"subprocess",
"popen"
] |
What's the difference between all of the os.popen() methods? | 275,756 | <p>I was looking at the <a href="http://www.python.org/doc/2.5.2/lib/module-popen2.html">Python documentation</a> and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc. </p>
<p>Apart from the fact that some include <em>stderr</em> while others don't, what are the differences betwe... | 7 | 2008-11-09T08:50:12Z | 275,817 | <p>I would recommend to use the <code>subprocess</code> module which has all the features that these functions have and more.</p>
| 14 | 2008-11-09T10:44:40Z | [
"python",
"subprocess",
"popen"
] |
What's the difference between all of the os.popen() methods? | 275,756 | <p>I was looking at the <a href="http://www.python.org/doc/2.5.2/lib/module-popen2.html">Python documentation</a> and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc. </p>
<p>Apart from the fact that some include <em>stderr</em> while others don't, what are the differences betwe... | 7 | 2008-11-09T08:50:12Z | 275,894 | <p>Jason has it right. To summarize in a way that's easier to see:</p>
<ul>
<li>os.popen() -> stdout</li>
<li>os.popen2() -> (stdin, stdout)</li>
<li>os.popen3() -> (stdin, stdout, stderr)</li>
<li>os.popen4() -> (stdin, stdout_and_stderr)</li>
</ul>
| 12 | 2008-11-09T13:06:46Z | [
"python",
"subprocess",
"popen"
] |
import mechanize module to python script | 275,980 | <p>I tried to import mechanize module to my python script like this,</p>
<p>from mechanize import Browser</p>
<p>But, Google appengine throws HTTP 500 when accessing my script.</p>
<p>To make things more clear, Let me give you the snapshot of my package structure,</p>
<pre><code>root
....mechanize(where all the me... | 4 | 2008-11-09T14:50:26Z | 276,350 | <p>When GAE throws a 500, you can see the actual error in the logs on your admin console. If that doesn't help, paste it here and we'll help further.</p>
<p>Also, does it work on the dev_appserver?</p>
| 0 | 2008-11-09T19:27:31Z | [
"python",
"google-app-engine"
] |
import mechanize module to python script | 275,980 | <p>I tried to import mechanize module to my python script like this,</p>
<p>from mechanize import Browser</p>
<p>But, Google appengine throws HTTP 500 when accessing my script.</p>
<p>To make things more clear, Let me give you the snapshot of my package structure,</p>
<pre><code>root
....mechanize(where all the me... | 4 | 2008-11-09T14:50:26Z | 276,640 | <p>The mechanize main page says:</p>
<blockquote>
<p>mechanize.Browser is a subclass of mechanize.UserAgentBase, which is, in turn, a subclass of urllib2.OpenerDirector</p>
</blockquote>
<p>My understanding is that urllib2 is one of the sandboxed modules in GAE, with its functionality being replaced by the Google-p... | 2 | 2008-11-09T23:09:47Z | [
"python",
"google-app-engine"
] |
import mechanize module to python script | 275,980 | <p>I tried to import mechanize module to my python script like this,</p>
<p>from mechanize import Browser</p>
<p>But, Google appengine throws HTTP 500 when accessing my script.</p>
<p>To make things more clear, Let me give you the snapshot of my package structure,</p>
<pre><code>root
....mechanize(where all the me... | 4 | 2008-11-09T14:50:26Z | 281,012 | <p>Thanks All for the prompt reply.</p>
<p>Here is the log content got from the GAE,</p>
<p>: No module named ClientForm
Traceback (most recent call last):
File "/base/data/home/apps/seoapp/1.28/main.py", line 10, in
import mechanize
File "/base/data/home/apps/seoapp/1.28/mechanize/<strong>init</strong>.py",... | 0 | 2008-11-11T14:25:59Z | [
"python",
"google-app-engine"
] |
import mechanize module to python script | 275,980 | <p>I tried to import mechanize module to my python script like this,</p>
<p>from mechanize import Browser</p>
<p>But, Google appengine throws HTTP 500 when accessing my script.</p>
<p>To make things more clear, Let me give you the snapshot of my package structure,</p>
<pre><code>root
....mechanize(where all the me... | 4 | 2008-11-09T14:50:26Z | 281,097 | <p>I can finally manage with GAE's urlfetch instead of mechanizer. I can able to retrieve the response using the above said utility.</p>
<p>Thanks all for the great timely help.</p>
<p>^Ponmalar</p>
| 0 | 2008-11-11T14:53:08Z | [
"python",
"google-app-engine"
] |
Remote debugging of multi threaded Python Applications | 275,989 | <p>How can I do remote debugging of a multi threaded Python application, running on an Embedded Linux based system, from Windows XP or Vista?</p>
<p>So far I have only come across <a href="http://pyscripter.googlepages.com/" rel="nofollow">PyScripter based remote debugging</a>. How does it perform?</p>
| 1 | 2008-11-09T15:05:23Z | 276,015 | <p>I've never used it except a few quick trial runs, but <a href="http://winpdb.org/" rel="nofollow">winpdb</a> sounds like it does just what you want:</p>
<blockquote>
<p>Winpdb is a platform independent GPL
Python debugger with support for
multiple threads, namespace
modification, embedded debugging,
encry... | 1 | 2008-11-09T15:30:08Z | [
"python",
"remote-debugging"
] |
How to get current CPU and RAM usage in Python? | 276,052 | <p>What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.</p>
<p>There seems to be a few possible ways of extracting that from my search:</p>
<ol>
<li><p>Using a library such as <a href="http://www.psychofx.com/psi/t... | 150 | 2008-11-09T16:04:50Z | 276,164 | <p>I don't believe that there is a well-supported multi-platform library available. Remember that Python itself is written in C so any library is simply going to make a smart decision about which OS-specific code snippet to run, as you suggested above. </p>
| 0 | 2008-11-09T17:25:10Z | [
"python",
"system",
"cpu",
"status",
"ram"
] |
How to get current CPU and RAM usage in Python? | 276,052 | <p>What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.</p>
<p>There seems to be a few possible ways of extracting that from my search:</p>
<ol>
<li><p>Using a library such as <a href="http://www.psychofx.com/psi/t... | 150 | 2008-11-09T16:04:50Z | 276,304 | <p>"... current system status (current CPU, RAM, free disk space, etc.)" And "*nix and Windows platforms" can be a difficult combination to achieve.</p>
<p>The operating systems are fundamentally different in the way they manage these resources. Indeed, they differ in core concepts like defining what counts as syste... | 3 | 2008-11-09T18:50:34Z | [
"python",
"system",
"cpu",
"status",
"ram"
] |
How to get current CPU and RAM usage in Python? | 276,052 | <p>What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.</p>
<p>There seems to be a few possible ways of extracting that from my search:</p>
<ol>
<li><p>Using a library such as <a href="http://www.psychofx.com/psi/t... | 150 | 2008-11-09T16:04:50Z | 276,934 | <p>Here's something I put together a while ago, it's windows only but may help you get part of what you need done.</p>
<p>Derived from:
"for sys available mem"
<a href="http://msdn2.microsoft.com/en-us/library/aa455130.aspx">http://msdn2.microsoft.com/en-us/library/aa455130.aspx</a></p>
<p>"individual process informa... | 7 | 2008-11-10T02:38:51Z | [
"python",
"system",
"cpu",
"status",
"ram"
] |
How to get current CPU and RAM usage in Python? | 276,052 | <p>What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.</p>
<p>There seems to be a few possible ways of extracting that from my search:</p>
<ol>
<li><p>Using a library such as <a href="http://www.psychofx.com/psi/t... | 150 | 2008-11-09T16:04:50Z | 2,468,983 | <p><a href="https://pypi.python.org/pypi/psutil">The psutil library</a> will give you some system information (CPU / Memory usage) on a variety of platforms:</p>
<blockquote>
<p>psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portabl... | 196 | 2010-03-18T10:24:30Z | [
"python",
"system",
"cpu",
"status",
"ram"
] |
How to get current CPU and RAM usage in Python? | 276,052 | <p>What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.</p>
<p>There seems to be a few possible ways of extracting that from my search:</p>
<ol>
<li><p>Using a library such as <a href="http://www.psychofx.com/psi/t... | 150 | 2008-11-09T16:04:50Z | 36,337,011 | <p>You can use psutil or psmem with subprocess
example code </p>
<pre><code>import subprocess
cmd = subprocess.Popen(['sudo','./ps_mem'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out,error = cmd.communicate()
memory = out.splitlines()
</code></pre>
<p>Reference <a href="http://techarena51.com/index.php/how-... | 0 | 2016-03-31T14:57:48Z | [
"python",
"system",
"cpu",
"status",
"ram"
] |
How to get current CPU and RAM usage in Python? | 276,052 | <p>What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.</p>
<p>There seems to be a few possible ways of extracting that from my search:</p>
<ol>
<li><p>Using a library such as <a href="http://www.psychofx.com/psi/t... | 150 | 2008-11-09T16:04:50Z | 38,984,517 | <p>Use the <a href="https://pypi.python.org/pypi/psutil/4.3.0" rel="nofollow">psutil library</a>. For me on Ubuntu, pip installed 0.4.3. You can check your version of psutil by doing </p>
<pre><code>from __future__ import print_function
import psutil
print(psutil.__versiââon__)
</code></pre>
<p>in Python.</p>
... | 0 | 2016-08-16T21:07:35Z | [
"python",
"system",
"cpu",
"status",
"ram"
] |
WCF and Python | 276,184 | <p>Is there any example code of a <a href="http://www.python.org/">cpython</a> (not IronPython) client which can call Windows Communication Foundation (WCF) service?</p>
| 20 | 2008-11-09T17:41:15Z | 276,545 | <p>Even if there is not a specific example of calling WCF from Python, you should be able to make a fully SOAP compliant service with WCF. Then all you have to do is find some examples of how to call a normal SOAP service from Python.</p>
<p>The simplest thing will be to use the BasicHttpBinding in WCF and then you ca... | 0 | 2008-11-09T22:03:59Z | [
"python",
"wcf"
] |
WCF and Python | 276,184 | <p>Is there any example code of a <a href="http://www.python.org/">cpython</a> (not IronPython) client which can call Windows Communication Foundation (WCF) service?</p>
| 20 | 2008-11-09T17:41:15Z | 707,911 | <p>WCF needs to expose functionality through a communication protocol. I think the most commonly used protocol is probably SOAP over HTTP. Let's assume that's
what you're using then.</p>
<p>Take a look at <a href="http://www.diveintopython.net/soap_web_services/index.html">this chapter in Dive Into Python</a>. It ... | 7 | 2009-04-02T00:56:04Z | [
"python",
"wcf"
] |
WCF and Python | 276,184 | <p>Is there any example code of a <a href="http://www.python.org/">cpython</a> (not IronPython) client which can call Windows Communication Foundation (WCF) service?</p>
| 20 | 2008-11-09T17:41:15Z | 822,320 | <p>I do not know of any direct examples, but if the WCF service is REST enabled you could access it through POX (Plain Old XML) via the REST methods/etc (if the service has any). If you are in control of the service you could expose endpoints via REST as well. </p>
| 1 | 2009-05-04T22:07:26Z | [
"python",
"wcf"
] |
WCF and Python | 276,184 | <p>Is there any example code of a <a href="http://www.python.org/">cpython</a> (not IronPython) client which can call Windows Communication Foundation (WCF) service?</p>
| 20 | 2008-11-09T17:41:15Z | 3,000,418 | <p>if you need binary serialized communication over tcp then consider implementing solution like Thrift.</p>
| 1 | 2010-06-08T19:04:43Z | [
"python",
"wcf"
] |
WCF and Python | 276,184 | <p>Is there any example code of a <a href="http://www.python.org/">cpython</a> (not IronPython) client which can call Windows Communication Foundation (WCF) service?</p>
| 20 | 2008-11-09T17:41:15Z | 3,865,315 | <p>I used <a href="/questions/tagged/suds" class="post-tag" title="show questions tagged 'suds'" rel="tag">suds</a>.</p>
<pre><code>from suds.client import Client
print "Connecting to Service..."
wsdl = "http://serviceurl.com/service.svc?WSDL"
client = Client(wsdl)
result = client.service.Method(variable1, variable2)... | 16 | 2010-10-05T15:42:35Z | [
"python",
"wcf"
] |
WCF and Python | 276,184 | <p>Is there any example code of a <a href="http://www.python.org/">cpython</a> (not IronPython) client which can call Windows Communication Foundation (WCF) service?</p>
| 20 | 2008-11-09T17:41:15Z | 36,152,458 | <p>Just to help someone to access WCF SOAP 1.2 service with WS-Addressing using suds.
Main problem is to inject action name in every message.</p>
<p>This example for python 3 and suds port <a href="https://bitbucket.org/jurko/suds" rel="nofollow">https://bitbucket.org/jurko/suds</a>.</p>
<p>Example uses custom authen... | 0 | 2016-03-22T10:53:14Z | [
"python",
"wcf"
] |
What's a cross platform way to play a sound file in python? | 276,266 | <p>I tried playing a .wav file using pyaudio. It works great on windows, but doesn't work in Ubuntu when another device is using sound.</p>
<blockquote>
<p>The error is "IOError: [Errorno
Invalid output device (no default
output device)] -9996</p>
</blockquote>
<p>Is there another library I could try to use? An... | 17 | 2008-11-09T18:28:42Z | 276,322 | <p>Have you looked at pymedia? It looks as easy as this to play a WAV file:</p>
<pre><code>import time, wave, pymedia.audio.sound as sound
f= wave.open('YOUR FILE NAME', 'rb')
sampleRate= f.getframerate()
channels= f.getnchannels()
format= sound.AFMT_S16_LE
snd= sound.Output(sampleRate, channels, format)
s= f.readfram... | 4 | 2008-11-09T19:05:47Z | [
"python",
"cross-platform",
"audio"
] |
What's a cross platform way to play a sound file in python? | 276,266 | <p>I tried playing a .wav file using pyaudio. It works great on windows, but doesn't work in Ubuntu when another device is using sound.</p>
<blockquote>
<p>The error is "IOError: [Errorno
Invalid output device (no default
output device)] -9996</p>
</blockquote>
<p>Is there another library I could try to use? An... | 17 | 2008-11-09T18:28:42Z | 277,274 | <p>You can use <a href="http://wxpython.org/">wxPython</a></p>
<pre><code>sound = wx.Sound('sound.wav')
sound.Play(wx.SOUND_SYNC)
</code></pre>
<p>or</p>
<pre><code>sound.Play(wx.SOUND_ASYNC)
</code></pre>
<p><a href="http://svn.wxwidgets.org/viewvc/wx/wxPython/tags/wxPy-2.8.9.1/wxPython/demo/Sound.py?view=markup">... | 12 | 2008-11-10T07:21:59Z | [
"python",
"cross-platform",
"audio"
] |
What's a cross platform way to play a sound file in python? | 276,266 | <p>I tried playing a .wav file using pyaudio. It works great on windows, but doesn't work in Ubuntu when another device is using sound.</p>
<blockquote>
<p>The error is "IOError: [Errorno
Invalid output device (no default
output device)] -9996</p>
</blockquote>
<p>Is there another library I could try to use? An... | 17 | 2008-11-09T18:28:42Z | 277,429 | <p>I'm not absolutely sure if that fulfills your requirements, but I immediately thought PyGame</p>
<p><a href="http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound" rel="nofollow" title="PyGame Sound Module">http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound</a></p>
<pre><code>from pygame import mi... | 1 | 2008-11-10T09:37:33Z | [
"python",
"cross-platform",
"audio"
] |
What's a cross platform way to play a sound file in python? | 276,266 | <p>I tried playing a .wav file using pyaudio. It works great on windows, but doesn't work in Ubuntu when another device is using sound.</p>
<blockquote>
<p>The error is "IOError: [Errorno
Invalid output device (no default
output device)] -9996</p>
</blockquote>
<p>Is there another library I could try to use? An... | 17 | 2008-11-09T18:28:42Z | 36,284,017 | <p>You can try <a href="http://simpleaudio.readthedocs.org/en/latest/index.html" rel="nofollow">Simpleaudio</a>:</p>
<pre><code>> pip install simpleaudio
</code></pre>
<p>Then:</p>
<pre><code>import simpleaudio as sa
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
play_obj.... | 2 | 2016-03-29T12:16:08Z | [
"python",
"cross-platform",
"audio"
] |
CPU Usage Per Process in Python | 276,281 | <p>Is it possible for me to see the amount of processor usage (% of maximum) that the current, python, app is using?</p>
<p>Scenario:
My host will allow me to run my app as long as it does not consume more then X% of the CPU power, so I would like it to 'keep an eye on itself' and slowdown. So how can I know how muc... | 14 | 2008-11-09T18:35:14Z | 276,289 | <p>The <code>resource</code> module provides <a href="http://www.python.org/doc/2.5.2/lib/node522.html"><code>getrusage</code></a> which can give you the information you need, at least for Unix-like platforms.</p>
<p>Note that CPU usage as a percentage is always measured over a time interval. Essentially, it is the am... | 6 | 2008-11-09T18:40:07Z | [
"python",
"monitoring",
"cpu-usage"
] |
CPU Usage Per Process in Python | 276,281 | <p>Is it possible for me to see the amount of processor usage (% of maximum) that the current, python, app is using?</p>
<p>Scenario:
My host will allow me to run my app as long as it does not consume more then X% of the CPU power, so I would like it to 'keep an eye on itself' and slowdown. So how can I know how muc... | 14 | 2008-11-09T18:35:14Z | 276,295 | <pre><code>>>> import os
>>> os.times()
(1.296875, 0.765625, 0.0, 0.0, 0.0)
>>> print os.times.__doc__
times() -> (utime, stime, cutime, cstime, elapsed_time)
Return a tuple of floating point numbers indicating process times.
</code></pre>
<p>From the (2.5) manual:</p>
<blockquote>
<p... | 23 | 2008-11-09T18:44:10Z | [
"python",
"monitoring",
"cpu-usage"
] |
CPU Usage Per Process in Python | 276,281 | <p>Is it possible for me to see the amount of processor usage (% of maximum) that the current, python, app is using?</p>
<p>Scenario:
My host will allow me to run my app as long as it does not consume more then X% of the CPU power, so I would like it to 'keep an eye on itself' and slowdown. So how can I know how muc... | 14 | 2008-11-09T18:35:14Z | 4,815,145 | <p>Use <code>time.clock()</code> to get the CPU time.
To get the percentage of CPU usage do CPU time elapsed/time elapsed</p>
<p>For example, if CPU time elapsed is 0.2 and time elapsed is 1 then the cpu usage is 20%.</p>
<p>Note:You have to divide by by number of processers you have. If you have 2 i.e. a dual core:<... | 0 | 2011-01-27T10:24:24Z | [
"python",
"monitoring",
"cpu-usage"
] |
CPU Usage Per Process in Python | 276,281 | <p>Is it possible for me to see the amount of processor usage (% of maximum) that the current, python, app is using?</p>
<p>Scenario:
My host will allow me to run my app as long as it does not consume more then X% of the CPU power, so I would like it to 'keep an eye on itself' and slowdown. So how can I know how muc... | 14 | 2008-11-09T18:35:14Z | 6,265,475 | <p>By using <a href="http://code.google.com/p/psutil" rel="nofollow">psutil</a>:</p>
<pre><code>>>> import psutil
>>> p = psutil.Process()
>>> p.cpu_times()
cputimes(user=0.06, system=0.03)
>>> p.cpu_percent(interval=1)
0.0
>>>
</code></pre>
| 12 | 2011-06-07T12:55:38Z | [
"python",
"monitoring",
"cpu-usage"
] |
How to show the visitor a moved web page AND return a 301 redirect HTTP response status code in Django? | 276,286 | <p>When a webpage has moved to a new location, how do I show the moved web page AND return a 301 permanent redirect HTTP response status code in <a href="http://djangoproject.com/" rel="nofollow">Django</a>?</p>
| 0 | 2008-11-09T18:39:37Z | 276,323 | <p>You can't.</p>
<p>301 is an HTTP return code that is directly acted upon by the browser. Many sites handle these two issues by first sending the user to a redirect-er page that tells the user about the change and then X seconds later sends them to the new page. But the redirect-er page <em>must</em> have a 200 code... | 3 | 2008-11-09T19:08:06Z | [
"python",
"django",
"http",
"redirect",
"http-headers"
] |
How to show the visitor a moved web page AND return a 301 redirect HTTP response status code in Django? | 276,286 | <p>When a webpage has moved to a new location, how do I show the moved web page AND return a 301 permanent redirect HTTP response status code in <a href="http://djangoproject.com/" rel="nofollow">Django</a>?</p>
| 0 | 2008-11-09T18:39:37Z | 276,326 | <pre><code> from django import http
return http.HttpResponsePermanentRedirect('/yournewpage.html')
</code></pre>
<p>the browser will get the 301, and go to <code>/yournewpage.html</code> as expected. the other answer is technically correct, in that python is not handling the redirection per se, the browser is. t... | 8 | 2008-11-09T19:13:21Z | [
"python",
"django",
"http",
"redirect",
"http-headers"
] |
Syntax error whenever I put Python code inside a Django template | 276,345 | <p>I'm trying to do the following in my Django template:</p>
<pre><code> {% for embed in embeds %}
{% embed2 = embed.replace("&lt;", "<") %}
{{embed2}}<br />
{% endfor %}
</code></pre>
<p>However, I always get an invalid block or some syntax error when I do anything like that (by t... | 2 | 2008-11-09T19:24:41Z | 276,372 | <p>I am quite sure that Django templates does not support that.
For your replace operation I would look into different filters.</p>
<p>You really should try to keep as much logic as you can in your views and not in the templates.</p>
| 7 | 2008-11-09T19:44:06Z | [
"python",
"django",
"templates",
"django-templates"
] |
Syntax error whenever I put Python code inside a Django template | 276,345 | <p>I'm trying to do the following in my Django template:</p>
<pre><code> {% for embed in embeds %}
{% embed2 = embed.replace("&lt;", "<") %}
{{embed2}}<br />
{% endfor %}
</code></pre>
<p>However, I always get an invalid block or some syntax error when I do anything like that (by t... | 2 | 2008-11-09T19:24:41Z | 276,387 | <p>Django templates use their own syntax, not like <a href="http://en.wikipedia.org/wiki/Kid%5F%28templating%5Flanguage%29" rel="nofollow">Kid</a> or <a href="http://en.wikipedia.org/wiki/Genshi%5F%28templating%5Flanguage%29" rel="nofollow">Genshi</a>.</p>
<p>You have to roll your own <a href="http://docs.djangoprojec... | 2 | 2008-11-09T19:58:50Z | [
"python",
"django",
"templates",
"django-templates"
] |
Syntax error whenever I put Python code inside a Django template | 276,345 | <p>I'm trying to do the following in my Django template:</p>
<pre><code> {% for embed in embeds %}
{% embed2 = embed.replace("&lt;", "<") %}
{{embed2}}<br />
{% endfor %}
</code></pre>
<p>However, I always get an invalid block or some syntax error when I do anything like that (by t... | 2 | 2008-11-09T19:24:41Z | 276,394 | <p>Instead of using a slice assignment to grow a list</p>
<p><code>embed_list[len(embed_list):] = [foo]</code></p>
<p>you should probably just do</p>
<p><code>embed_list.append(foo)</code></p>
<p>But really you should try unescaping html with a library function rather than doing it yourself.</p>
<p>That NoneType e... | 2 | 2008-11-09T20:04:55Z | [
"python",
"django",
"templates",
"django-templates"
] |
Syntax error whenever I put Python code inside a Django template | 276,345 | <p>I'm trying to do the following in my Django template:</p>
<pre><code> {% for embed in embeds %}
{% embed2 = embed.replace("&lt;", "<") %}
{{embed2}}<br />
{% endfor %}
</code></pre>
<p>However, I always get an invalid block or some syntax error when I do anything like that (by t... | 2 | 2008-11-09T19:24:41Z | 276,395 | <p>I don't see why you'd get "NoneType object is not callable". That should mean that somewhere on the line is an expression like "foo(...)", and it means foo is None.</p>
<p>BTW: You are trying to extend the embed_list, and it's easier to do it like this:</p>
<pre><code>embed_list = []
for embed in embeds:
embe... | 3 | 2008-11-09T20:04:59Z | [
"python",
"django",
"templates",
"django-templates"
] |
Syntax error whenever I put Python code inside a Django template | 276,345 | <p>I'm trying to do the following in my Django template:</p>
<pre><code> {% for embed in embeds %}
{% embed2 = embed.replace("&lt;", "<") %}
{{embed2}}<br />
{% endfor %}
</code></pre>
<p>However, I always get an invalid block or some syntax error when I do anything like that (by t... | 2 | 2008-11-09T19:24:41Z | 276,838 | <p>Django's template language is deliberately hobbled. When used by non-programming designers, this is definitely a Good Thing, but there are times when you <em>need</em> to do a little programming. (No, I don't want to argue about that. This has come up several times on django-users and django-dev.)</p>
<p>Two ways t... | 6 | 2008-11-10T01:25:36Z | [
"python",
"django",
"templates",
"django-templates"
] |
Can you achieve a case insensitive 'unique' constraint in Sqlite3 (with Django)? | 276,656 | <p>So let's say I'm using Python 2.5's built-in default sqlite3 and I have a Django model class with the following code:</p>
<pre><code>class SomeEntity(models.Model):
some_field = models.CharField(max_length=50, db_index=True, unique=True)
</code></pre>
<p>I've got the admin interface setup and everything appear... | 11 | 2008-11-09T23:20:13Z | 276,708 | <p>Perhaps you can create and use a custom model field; it would be a subclass of CharField but providing a <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#db_type" rel="nofollow">db_type</a> method returning "text collate nocase"</p>
| 3 | 2008-11-10T00:00:26Z | [
"python",
"django",
"sqlite",
"django-models"
] |
Can you achieve a case insensitive 'unique' constraint in Sqlite3 (with Django)? | 276,656 | <p>So let's say I'm using Python 2.5's built-in default sqlite3 and I have a Django model class with the following code:</p>
<pre><code>class SomeEntity(models.Model):
some_field = models.CharField(max_length=50, db_index=True, unique=True)
</code></pre>
<p>I've got the admin interface setup and everything appear... | 11 | 2008-11-09T23:20:13Z | 471,066 | <p>Yes this can easily be done by adding a unique index to the table with the following command:</p>
<p>CREATE UNIQUE INDEX uidxName ON mytable (myfield COLLATE NOCASE)</p>
<p>If you need case insensitivity for nonASCII letters, you will need to register your own COLLATION with commands similar to the following:</p>
... | 8 | 2009-01-22T22:18:21Z | [
"python",
"django",
"sqlite",
"django-models"
] |
How to import a python file in python script more than once | 276,679 | <p>Is it possible to import a python file more than once in a python script because i run a loop back to my driver file in a function by using the import command but it only works once? thanks</p>
<p><strong>edit:</strong> Resolved myself thanks</p>
| 1 | 2008-11-09T23:40:27Z | 276,692 | <p>The easiest answer is to put the code you are trying to run inside a function like this</p>
<p>(inside your module that you are importing now):</p>
<pre><code>def main():
# All the code that currently does work goes in here
# rather than just in the module
</code></pre>
<p>(The module that does the impor... | 4 | 2008-11-09T23:50:30Z | [
"python"
] |
How to import a python file in python script more than once | 276,679 | <p>Is it possible to import a python file more than once in a python script because i run a loop back to my driver file in a function by using the import command but it only works once? thanks</p>
<p><strong>edit:</strong> Resolved myself thanks</p>
| 1 | 2008-11-09T23:40:27Z | 276,694 | <p>The import statement -- by definition -- only imports once. </p>
<p>You can, if you want, try to use <code>execfile()</code> (or <code>eval()</code>) to execute a separate file more than once. </p>
| 1 | 2008-11-09T23:51:31Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.