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 |
|---|---|---|---|---|---|---|---|---|---|
Python if else condition error | 1,706,009 | <p>This is my code snippet, but it not execute the way that I want.The first if statement executes successfully if the input is a non-negative/character value, but if it is a negative value it ignores the elif statement. What's the issue.I'm using Python 2.6 </p>
<pre><code>from math import sqrt
import cmath
y = raw... | 1 | 2009-11-10T06:34:25Z | 1,706,026 | <pre><code>elif float(y) < 0:
print "Negative number", cmath.sqrt(float(y))
</code></pre>
<p>Now the correct comparison can take place and <code>cmath.sqrt</code> will work since it needs a float.</p>
| 0 | 2009-11-10T06:40:48Z | [
"python",
"syntax"
] |
Python if else condition error | 1,706,009 | <p>This is my code snippet, but it not execute the way that I want.The first if statement executes successfully if the input is a non-negative/character value, but if it is a negative value it ignores the elif statement. What's the issue.I'm using Python 2.6 </p>
<pre><code>from math import sqrt
import cmath
y = raw... | 1 | 2009-11-10T06:34:25Z | 1,706,028 | <p>The <code>s.isdigit()</code> string method means "string <code>s</code> is one or more characters long and all characters are digits", meaning each character one of <code>0123456789</code>. Note how other characters such as <code>+</code> and <code>-</code> are signally absent from that set;-).</p>
<p>Your <code>e... | 5 | 2009-11-10T06:42:33Z | [
"python",
"syntax"
] |
Python if else condition error | 1,706,009 | <p>This is my code snippet, but it not execute the way that I want.The first if statement executes successfully if the input is a non-negative/character value, but if it is a negative value it ignores the elif statement. What's the issue.I'm using Python 2.6 </p>
<pre><code>from math import sqrt
import cmath
y = raw... | 1 | 2009-11-10T06:34:25Z | 1,706,030 | <p>Why not just :</p>
<pre><code>from math import sqrt
from cmath import sqrt as neg_sqrt
y = raw_input("Enter your number:")
try:
number = float(y)
if number > 0:
print 'Answer is', sqrt(number)
else:
print 'Negative number:', neg_sqrt(number)
except ValueError:
print 'Not a valid ... | 0 | 2009-11-10T06:42:52Z | [
"python",
"syntax"
] |
How do you write a program that interacts with others like banlist for warcraft 3? | 1,706,158 | <p>As in title, what is <a href="http://www.wc3banlist.de/index.php" rel="nofollow">banlist</a> written in, or can be written in? I have a basic knowledge of Python but I don't see a way to get information from a running program.</p>
| 0 | 2009-11-10T07:23:33Z | 1,748,764 | <p>To my knowledge, banlist uses winpcap, an open source library for packet capture and network analysis for the Win32 platforms and "understands" (at least partially) the network traffic between the game running on your computer and Battle.net servers. Regarding Battle.net protocol, there is unofficial documentation a... | 3 | 2009-11-17T13:10:16Z | [
"python",
"security",
"api"
] |
Useful Inheritance in Python resp. Alternative for interfaces | 1,706,167 | <p>Hi as far as I see in Python variables are untyped. So now I want to have a baseclass </p>
<pre><code>class baseClass:
def x():
print "yay"
</code></pre>
<p>and two subClasses</p>
<pre><code>class sub1(baseClass):
def x():
print "sub1"
class sub2(baseClass):
def x():
print "sub2"
</code></pre>
<p>in o... | 1 | 2009-11-10T07:25:56Z | 1,706,185 | <p>Yes, you can do this; however, the syntax to instantiate objects is not "new Class(args)". Simply drop the "new".</p>
<p>Taking a step back, assume you have an object stored in a variable named foo. The compiler will never complain about you doing the following:</p>
<pre>
foo.bar
</pre>
<p>This is true even if th... | 2 | 2009-11-10T07:32:34Z | [
"python",
"inheritance",
"interface"
] |
Useful Inheritance in Python resp. Alternative for interfaces | 1,706,167 | <p>Hi as far as I see in Python variables are untyped. So now I want to have a baseclass </p>
<pre><code>class baseClass:
def x():
print "yay"
</code></pre>
<p>and two subClasses</p>
<pre><code>class sub1(baseClass):
def x():
print "sub1"
class sub2(baseClass):
def x():
print "sub2"
</code></pre>
<p>in o... | 1 | 2009-11-10T07:25:56Z | 1,706,197 | <p>Yes.</p>
<pre><code>c = sub1()
c = sub2()
</code></pre>
<p>But the base class and concept of defining an interface are unnecessary, since python is not statically typed.</p>
<p>EDIT:</p>
<p>To rewrite your code in valid Python:</p>
<pre><code># This space where baseClass was defined intentionally left blank,
#... | 5 | 2009-11-10T07:36:10Z | [
"python",
"inheritance",
"interface"
] |
Useful Inheritance in Python resp. Alternative for interfaces | 1,706,167 | <p>Hi as far as I see in Python variables are untyped. So now I want to have a baseclass </p>
<pre><code>class baseClass:
def x():
print "yay"
</code></pre>
<p>and two subClasses</p>
<pre><code>class sub1(baseClass):
def x():
print "sub1"
class sub2(baseClass):
def x():
print "sub2"
</code></pre>
<p>in o... | 1 | 2009-11-10T07:25:56Z | 1,706,791 | <p>Python doesn't really have "variables". What Python has are names that have objects bound to them.</p>
<pre><code>class X(object):
pass
class Y(object):
pass
class Z(object):
pass
a = X # name "a" bound with class object "X"
print(a is X) # prints True
a = Y
print(a is Y) # prints True
b = Y
prin... | 1 | 2009-11-10T09:56:46Z | [
"python",
"inheritance",
"interface"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 1,706,204 | <p>you can use <a href="http://docs.python.org/library/stdtypes.html#str.startswith">startswith()</a></p>
<p>eg</p>
<pre><code>for line in open("file"):
li=line.strip()
if not li.startswith("#"):
print line.rstrip()
</code></pre>
| 39 | 2009-11-10T07:38:47Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 1,706,334 | <p>I recommend you don't ignore the whole line when you see a <code>#</code> character; just ignore the rest of the line. You can do that easily with a string method function called <code>partition</code>:</p>
<pre><code>with open("filename") as f:
for line in f:
line = line.partition('#')[0]
line... | 26 | 2009-11-10T08:13:19Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 1,708,230 | <p>A more compact version of a filtering expression can also look like this:</p>
<pre><code>for line in (l for l in open(filename) if not l.startswith('#')):
# do something with line
</code></pre>
<p><code>(l for ... )</code> is called "generator expression" which acts here as a wrapping iterator that will filter... | 2 | 2009-11-10T14:08:59Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 1,715,589 | <p>This is the shortest possible form:</p>
<pre><code>for line in open(filename):
if line.startswith('#'):
continue
# PROCESS LINE HERE
</code></pre>
<p>The <code>startswith()</code> method on a string returns True if the string you call it on starts with the string you passed in.</p>
<p>While this is okay i... | 5 | 2009-11-11T14:40:08Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 1,745,815 | <p>I tend to use </p>
<pre><code>for line in lines:
if '#' not in line:
#do something
</code></pre>
<p>This will ignore the whole line, though the answer which includes rpartition has my upvote as it can include any information from before the #</p>
| -1 | 2009-11-17T00:27:07Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 11,129,179 | <p>I've found recently that a generator function does a great job of this. I've used similar functions to skip comment lines, blank lines, etc.</p>
<p>I define my function as</p>
<pre><code>def skip_comments(file):
for line in file:
if not line.strip().startswith('#'):
yield line
</code></pre... | 3 | 2012-06-20T22:36:14Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 27,178,714 | <p>I'm coming at this late, but the problem of handling shell style (or python style) <code>#</code> comments is a very common one. </p>
<p>I've been using some code almost everytime I read a text file.<br>
<strong>Problem is that it doesn't handle quoted or escaped comments properly</strong>. But it works for simpl... | 2 | 2014-11-27T21:13:28Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Python: How to ignore #comment lines when reading in a file | 1,706,198 | <p>In Python, I have just read a line form a text file and I'd like to know how to code to ignore comments with a hash # at the beginning of the line.</p>
<p>I think it should be something like this: </p>
<pre><code>for
if line !contain #
then ...process line
else end for loop
</code></pre>
<p>But I'm n... | 26 | 2009-11-10T07:36:44Z | 28,950,762 | <p>I know that this is an old thread, but this is a generator function that I
use for my own purposes. It strips comments no matter where they
appear in the line, as well as stripping leading/trailing whitespace and
blank lines. The following source text:</p>
<pre><code># Comment line 1
# Comment line 2
# host01 #... | 1 | 2015-03-09T20:01:45Z | [
"python",
"string",
"file-io",
"comments",
"skip"
] |
Understanding Zope internals, from Django eyes | 1,706,309 | <p>I am a newbie to zope and I previously worked on Django for about 2.5 years. So when I first jumped into Zope(v2) (only because my new company is using it since 7 years), I faced these questions. Please help me in understanding them.</p>
<ol>
<li><p>What is the "real" purpose of zodb as such? I know what it does, b... | 7 | 2009-11-10T08:05:26Z | 1,706,464 | <p>I answer without much experience on both, but I had the chance to manipulate both, so I can tell you my opinion on some of your questions.</p>
<blockquote>
<p>1)What is the "real" purpose of zodb
as such? Meaning I know what it does,
but tell me one great thing that zodb
does and a framework like django(whi... | 6 | 2009-11-10T08:48:52Z | [
"python",
"django",
"zope",
"zodb",
"acquisition"
] |
Understanding Zope internals, from Django eyes | 1,706,309 | <p>I am a newbie to zope and I previously worked on Django for about 2.5 years. So when I first jumped into Zope(v2) (only because my new company is using it since 7 years), I faced these questions. Please help me in understanding them.</p>
<ol>
<li><p>What is the "real" purpose of zodb as such? I know what it does, b... | 7 | 2009-11-10T08:05:26Z | 1,707,165 | <p>ZODB is a OO-style database that doesn't need a schema definition. You can simply create (nearly) all kinds of objects, and persist them.</p>
<p>The TTW is sometimes annoying, but you can mount the ZOPE-object-tree using webdav. Then you can edit the templates and scripts using your favorite editor.</p>
<p>ZOPE is... | 2 | 2009-11-10T11:04:52Z | [
"python",
"django",
"zope",
"zodb",
"acquisition"
] |
Understanding Zope internals, from Django eyes | 1,706,309 | <p>I am a newbie to zope and I previously worked on Django for about 2.5 years. So when I first jumped into Zope(v2) (only because my new company is using it since 7 years), I faced these questions. Please help me in understanding them.</p>
<ol>
<li><p>What is the "real" purpose of zodb as such? I know what it does, b... | 7 | 2009-11-10T08:05:26Z | 1,707,894 | <p>First things first: current zope2 versions include all of zope3, too. And if you look at modern zope2 applications like Plone, you'll see that it uses a lot of "zope 3" (now called the "zope tool kit", ZTK) under the hood.</p>
<p>The real purpose of the ZODB: it is one of the few object databases (as opposed to rel... | 15 | 2009-11-10T13:15:42Z | [
"python",
"django",
"zope",
"zodb",
"acquisition"
] |
Understanding Zope internals, from Django eyes | 1,706,309 | <p>I am a newbie to zope and I previously worked on Django for about 2.5 years. So when I first jumped into Zope(v2) (only because my new company is using it since 7 years), I faced these questions. Please help me in understanding them.</p>
<ol>
<li><p>What is the "real" purpose of zodb as such? I know what it does, b... | 7 | 2009-11-10T08:05:26Z | 1,717,147 | <p>A very good reference on ZODB is <a href="http://wiki.zope.org/ZODB/Documentation/guide/index.html" rel="nofollow">ZODB/ZEO programmer's guide</a>. ZODB is not an ORM. Its a true object database. Python objects are persisted inside the database transparently without any worries about how to transform them into a rep... | 5 | 2009-11-11T18:20:13Z | [
"python",
"django",
"zope",
"zodb",
"acquisition"
] |
Understanding Zope internals, from Django eyes | 1,706,309 | <p>I am a newbie to zope and I previously worked on Django for about 2.5 years. So when I first jumped into Zope(v2) (only because my new company is using it since 7 years), I faced these questions. Please help me in understanding them.</p>
<ol>
<li><p>What is the "real" purpose of zodb as such? I know what it does, b... | 7 | 2009-11-10T08:05:26Z | 1,733,045 | <p>On the ZODB:</p>
<p>Another way to ask "What is the real purpose of the ZODB?" is to ask, "Why was the ZODB originally created?"</p>
<p>The answer to that is the project was started very early on, around 1996. This was before the existance of MySQL or PostgreSQL, when miniSQL (a free-to-use but not free software)... | 9 | 2009-11-14T02:39:54Z | [
"python",
"django",
"zope",
"zodb",
"acquisition"
] |
Understanding Zope internals, from Django eyes | 1,706,309 | <p>I am a newbie to zope and I previously worked on Django for about 2.5 years. So when I first jumped into Zope(v2) (only because my new company is using it since 7 years), I faced these questions. Please help me in understanding them.</p>
<ol>
<li><p>What is the "real" purpose of zodb as such? I know what it does, b... | 7 | 2009-11-10T08:05:26Z | 1,735,533 | <p>+1 on Wheat's answer, above: "Zope 2 is really only interesting to learn from a historical perspective". I did Zope dev for a large site for a couple of years, 50% zope 2, 50% zope 3. Even then (this was 2 years ago) we were working to migrate everything off of zope 2. Unless you already have a lot invested in an ex... | 1 | 2009-11-14T20:41:26Z | [
"python",
"django",
"zope",
"zodb",
"acquisition"
] |
Client Digest Authentication Python with URLLIB2 will not remember Authorization Header Information | 1,706,644 | <p>I am trying to use Python to write a client that connects to a custom http server that uses digest authentication. I can connect and pull the first request without problem. Using TCPDUMP (I am on MAC OS X--I am both a MAC and a Python noob) I can see the first request is actually two http requests, as you would ex... | 1 | 2009-11-10T09:29:13Z | 1,717,241 | <p>Although it's not available out of the box, <code>urllib2</code> is flexible enough to add it yourself. Subclass <code>HTTPDigestAuthHandler</code>, hack it (<code>retry_http_digest_auth</code> method I think) to remember authentication information and define an <code>http_request(self, request)</code> method to use... | 1 | 2009-11-11T18:38:49Z | [
"python",
"authentication",
"urllib2",
"digest"
] |
Loading and saving numpy matrix | 1,706,665 | <p>I'm having troubles loading a numpy matrix. I successfully saved it to disk through:</p>
<pre><code>self.q.dump(fileName)
</code></pre>
<p>and now I want to be able to load it. From what I understand, the load command should do the trick:</p>
<pre><code>self.q.load(fileName)
</code></pre>
<p>but it seems not. An... | 1 | 2009-11-10T09:34:20Z | 1,706,864 | <p>help(numpy.ndarray)</p>
<pre><code> | dump(...)
| a.dump(file)
|
| Dump a pickle of the array to the specified file.
| The array can be read back with pickle.load or numpy.load.
|
| Parameters
| ----------
| file : str
| A string naming the dump file.
</c... | 3 | 2009-11-10T10:08:36Z | [
"python",
"numpy"
] |
Uploading multiple files in Django through one form field | 1,706,880 | <p>Is there any custom widget (or a special magic way) to upload multiple files (or a whole folder!) through one form field?
I have tried <a href="http://scompt.com/blog/archives/2007/11/03/multiple-file-uploads-in-django">this multifile widget</a> but it uses many simple FileFileds.</p>
| 7 | 2009-11-10T10:11:13Z | 1,706,884 | <p>No, you can't do that - HTML file inputs don't allow it.</p>
| 3 | 2009-11-10T10:12:52Z | [
"python",
"django",
"forms",
"upload"
] |
Uploading multiple files in Django through one form field | 1,706,880 | <p>Is there any custom widget (or a special magic way) to upload multiple files (or a whole folder!) through one form field?
I have tried <a href="http://scompt.com/blog/archives/2007/11/03/multiple-file-uploads-in-django">this multifile widget</a> but it uses many simple FileFileds.</p>
| 7 | 2009-11-10T10:11:13Z | 1,707,204 | <p>As Daniel said, File Input fields cannot support more than one file. However, there are ways around this using Things like <a href="http://swfupload.org/" rel="nofollow" title="SWFUpload">SWFUpload</a>. How you might integrate that workflow into a Django application, I'm not too sure.</p>
| 3 | 2009-11-10T11:12:24Z | [
"python",
"django",
"forms",
"upload"
] |
Uploading multiple files in Django through one form field | 1,706,880 | <p>Is there any custom widget (or a special magic way) to upload multiple files (or a whole folder!) through one form field?
I have tried <a href="http://scompt.com/blog/archives/2007/11/03/multiple-file-uploads-in-django">this multifile widget</a> but it uses many simple FileFileds.</p>
| 7 | 2009-11-10T10:11:13Z | 6,046,580 | <p><a href="https://github.com/tstone/django-uploadify" rel="nofollow">https://github.com/tstone/django-uploadify</a> is a reusable Django app that integrates <a href="http://uploadify.com" rel="nofollow">http://uploadify.com</a>.</p>
<p>From Uploadify's website: </p>
<blockquote>
<p>Uploadify is a jQuery plugin th... | 3 | 2011-05-18T14:42:50Z | [
"python",
"django",
"forms",
"upload"
] |
Uploading multiple files in Django through one form field | 1,706,880 | <p>Is there any custom widget (or a special magic way) to upload multiple files (or a whole folder!) through one form field?
I have tried <a href="http://scompt.com/blog/archives/2007/11/03/multiple-file-uploads-in-django">this multifile widget</a> but it uses many simple FileFileds.</p>
| 7 | 2009-11-10T10:11:13Z | 10,983,127 | <p>HTML 5 now allows for multiple file uploads in a single form control.</p>
<p><a href="http://www.w3.org/TR/html-markup/input.file.html#input.file.attrs.multiple">http://www.w3.org/TR/html-markup/input.file.html#input.file.attrs.multiple</a></p>
| 9 | 2012-06-11T15:27:59Z | [
"python",
"django",
"forms",
"upload"
] |
How to get interactive input from user and to be able to use arrowkeys while entering input? | 1,706,945 | <p>When I do a raw_input() and enter values, I am not able to use my arrow-keys to change stuff... is there any way for doing that?</p>
<p>Thanx readline module helps in line editing features. How to use the readline module?
Just importing the readline module works!</p>
| 5 | 2009-11-10T10:24:19Z | 1,706,973 | <p>That's not how <code>raw_input()</code> works. It reads a line from the prompt, and then processes it after the newline character.</p>
<p>The docs are pretty clear:
<a href="http://docs.python.org/library/functions.html#raw%5Finput" rel="nofollow">http://docs.python.org/library/functions.html#raw%5Finput</a></p>
<... | 4 | 2009-11-10T10:29:39Z | [
"python"
] |
How to get interactive input from user and to be able to use arrowkeys while entering input? | 1,706,945 | <p>When I do a raw_input() and enter values, I am not able to use my arrow-keys to change stuff... is there any way for doing that?</p>
<p>Thanx readline module helps in line editing features. How to use the readline module?
Just importing the readline module works!</p>
| 5 | 2009-11-10T10:24:19Z | 11,110,661 | <p>Try loading the readline module (import readline). That will make things work for you.</p>
| 8 | 2012-06-19T22:57:55Z | [
"python"
] |
How to get interactive input from user and to be able to use arrowkeys while entering input? | 1,706,945 | <p>When I do a raw_input() and enter values, I am not able to use my arrow-keys to change stuff... is there any way for doing that?</p>
<p>Thanx readline module helps in line editing features. How to use the readline module?
Just importing the readline module works!</p>
| 5 | 2009-11-10T10:24:19Z | 33,675,753 | <p>For those looking for examples, there's a nice introduction to the readline module here:
<a href="https://pymotw.com/2/readline/" rel="nofollow">https://pymotw.com/2/readline/</a></p>
| 2 | 2015-11-12T15:57:43Z | [
"python"
] |
setting up virtualenv for django development on windows, | 1,706,989 | <p>Setting up a virtualenv for the first time, when i try to install MySQL-python using</p>
<pre><code>pip -E <<some virtual env>> install MySQL-python
</code></pre>
<p>i get</p>
<pre><code>File "setup_windows.py", line 7, in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options... | 4 | 2009-11-10T10:33:43Z | 1,707,134 | <p>site.cfg in the same dir as setup.py was looking for the wrong regsitry key, at the end of the file is </p>
<pre><code># The Windows registry key for MySQL.
# This has to be set for Windows builds to work.
# Only change this if you have a different version.
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0
</code><... | 5 | 2009-11-10T10:58:45Z | [
"python",
"mysql",
"windows",
"django",
"virtualenv"
] |
How to print non-ASCII characters in Python | 1,707,065 | <p>I have a problem when I'm printing (or writing to a file) the non-ASCII characters in Python. I've resolved it by overriding the <code>str</code> method in my own objects, and making "x.encode('utf-8')" inside it, where x is a property inside the object.</p>
<p>But, if I receive a third-party object, and I make "st... | 3 | 2009-11-10T10:48:50Z | 1,707,088 | <p>How about you use <code>unicode(object)</code> and define <code>__unicode__</code> method on your classes?</p>
<p>Then you know its unicode and you can encode it anyway you want into to a file.</p>
| 3 | 2009-11-10T10:51:40Z | [
"python",
"extended-ascii"
] |
How to print non-ASCII characters in Python | 1,707,065 | <p>I have a problem when I'm printing (or writing to a file) the non-ASCII characters in Python. I've resolved it by overriding the <code>str</code> method in my own objects, and making "x.encode('utf-8')" inside it, where x is a property inside the object.</p>
<p>But, if I receive a third-party object, and I make "st... | 3 | 2009-11-10T10:48:50Z | 1,707,170 | <p>There is no way to make <code>str()</code> work with Unicode in Python < 3.0.</p>
<p>Use <code>repr(obj)</code> instead of <code>str(obj)</code>. <code>repr()</code> will convert the result to ASCII, properly escaping everything that isn't in the ASCII code range.</p>
<p>Other than that, use a file object which... | 5 | 2009-11-10T11:05:28Z | [
"python",
"extended-ascii"
] |
How to print non-ASCII characters in Python | 1,707,065 | <p>I have a problem when I'm printing (or writing to a file) the non-ASCII characters in Python. I've resolved it by overriding the <code>str</code> method in my own objects, and making "x.encode('utf-8')" inside it, where x is a property inside the object.</p>
<p>But, if I receive a third-party object, and I make "st... | 3 | 2009-11-10T10:48:50Z | 1,707,510 | <p>I would like to say that I've found a solution in Unix systems, exporting a environment var, with this:</p>
<p>export LC_CTYPE="es:ES.UTF-8"</p>
<p>This way, all files are in utf-8, so I can make prints or whatever and it works fine</p>
| 1 | 2009-11-10T12:12:07Z | [
"python",
"extended-ascii"
] |
How to print non-ASCII characters in Python | 1,707,065 | <p>I have a problem when I'm printing (or writing to a file) the non-ASCII characters in Python. I've resolved it by overriding the <code>str</code> method in my own objects, and making "x.encode('utf-8')" inside it, where x is a property inside the object.</p>
<p>But, if I receive a third-party object, and I make "st... | 3 | 2009-11-10T10:48:50Z | 30,007,047 | <p>just paste these two lines at the top of your code</p>
<ol>
<li>#!/usr/local/bin/python</li>
<li># coding: latin-1</li>
</ol>
<p>go to this link for further details <strong><a href="https://www.python.org/dev/peps/pep-0263/" rel="nofollow">https://www.python.org/dev/peps/pep-0263/</a></strong></p>
| 0 | 2015-05-02T20:20:49Z | [
"python",
"extended-ascii"
] |
python app to exe not working on WinSRV2003 | 1,707,323 | <p>I created little app for sending out emails when something is wrong with server. Used py2exe to create exe file. While it is works absolutely fine on Win7 i have problems with running it on WinSRV2003. I do not believe that it has something to do with code itself.
Please see imports below</p>
<pre><code>import pyo... | 2 | 2009-11-10T11:33:16Z | 1,707,348 | <p>I'd say this is a missing DLL's problem. You should check and see the DLL's your application bundles ( or presumes to exist on the target computer ). I think you can do that with the <code>depends.exe</code> that comes with Visual Studio.</p>
<p>EDIT: I just remembered. Make sure you run py2exe with a Python 2.5 in... | 1 | 2009-11-10T11:38:32Z | [
"python",
"windows",
"windows-server-2003",
"py2exe"
] |
python app to exe not working on WinSRV2003 | 1,707,323 | <p>I created little app for sending out emails when something is wrong with server. Used py2exe to create exe file. While it is works absolutely fine on Win7 i have problems with running it on WinSRV2003. I do not believe that it has something to do with code itself.
Please see imports below</p>
<pre><code>import pyo... | 2 | 2009-11-10T11:33:16Z | 1,707,353 | <p>A <a href="http://www.google.com/search?q=%5Fscproxy" rel="nofollow">search on _scproxy</a> seems to indicate that _scproxy is a new module in 2.6. Perhaps somehow Python 2.5 is involved? py2exe is supposed to make a completely self-contained executable, so I don't see how that's possible, though.</p>
<p>Another ... | 1 | 2009-11-10T11:38:55Z | [
"python",
"windows",
"windows-server-2003",
"py2exe"
] |
python app to exe not working on WinSRV2003 | 1,707,323 | <p>I created little app for sending out emails when something is wrong with server. Used py2exe to create exe file. While it is works absolutely fine on Win7 i have problems with running it on WinSRV2003. I do not believe that it has something to do with code itself.
Please see imports below</p>
<pre><code>import pyo... | 2 | 2009-11-10T11:33:16Z | 1,843,080 | <p>Googling for your "this application has failed to start..." message suggests strongly this is a DLL problem, probably with msvcp80.dll and friends. This is a very common occurrence with recent Windows/Python/py2exe given how MS keeps changing MSVCC libraries etc. Different Python versions are linked with different... | 1 | 2009-12-03T21:34:29Z | [
"python",
"windows",
"windows-server-2003",
"py2exe"
] |
python app to exe not working on WinSRV2003 | 1,707,323 | <p>I created little app for sending out emails when something is wrong with server. Used py2exe to create exe file. While it is works absolutely fine on Win7 i have problems with running it on WinSRV2003. I do not believe that it has something to do with code itself.
Please see imports below</p>
<pre><code>import pyo... | 2 | 2009-11-10T11:33:16Z | 2,070,465 | <p>I had a similar problem where COM objects were involved. Maybe that's the case here, too. This <a href="http://www.py2exe.org/index.cgi/IncludingTypelibs" rel="nofollow">description</a> solved my problems. My software would then run on different Windows versions, which it before would not.</p>
| 1 | 2010-01-15T09:11:00Z | [
"python",
"windows",
"windows-server-2003",
"py2exe"
] |
How to disable the OptionParser default help view? | 1,707,380 | <p>I am using the OptionParser from optparse module to parse my command that I get using the raw_input(). When I give a -h it displays the help screen and exits my application. I dont want it to display the help screen or exit the application. How can this be accomplished?
Thanx in advance.</p>
| 2 | 2009-11-10T11:44:47Z | 1,707,433 | <p>set <a href="http://docs.python.org/library/optparse.html#creating-the-parser" rel="nofollow"><code>add_help_option</code></a> to False</p>
<pre><code>parser = optparse.OptionParser(add_help_option=False)
parser.add_option('-h', '--help', help='show this help message')
options, args = parser.parse_args()
if options... | 7 | 2009-11-10T11:54:25Z | [
"python"
] |
How to disable the OptionParser default help view? | 1,707,380 | <p>I am using the OptionParser from optparse module to parse my command that I get using the raw_input(). When I give a -h it displays the help screen and exits my application. I dont want it to display the help screen or exit the application. How can this be accomplished?
Thanx in advance.</p>
| 2 | 2009-11-10T11:44:47Z | 1,707,437 | <p>optparse has a strange penchange for exiting your program, which I think is really unfortunate. You can initialize it like this to prevent it:</p>
<pre><code>oparser = OptionParser(add_help_option=False, ...)
</code></pre>
<p>Note that now you have to handle the <code>-h</code> and <code>--help</code> options you... | 8 | 2009-11-10T11:54:49Z | [
"python"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 1,707,581 | <pre><code>for line in open(name, "r"):
line = line.replace('"', '').strip()
a, b, c, d = map(float, line.split())
</code></pre>
<p>This is kind of bare-bones, and will raise exceptions if (for example) there aren't four values on the line, etc.</p>
| 23 | 2009-11-10T12:23:54Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 1,707,586 | <pre><code>for line in open(fname):
line = line.split()
line[-1] = line[-1].strip('"\n')
floats = [float(i) for i in line]
</code></pre>
<p>another option is to use built-in module, that is <strong>intended</strong> for this task. namely <a href="http://docs.python.org/library/csv.html"><code>csv</code></a... | 9 | 2009-11-10T12:24:25Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 1,707,603 | <p>You can use regexp, try something like this</p>
<pre><code>import re
re.findall("[0-9.]+", file(name).read())
</code></pre>
<p>This will give you a list of all numbers in your file as strings without any quotes.</p>
| 0 | 2009-11-10T12:27:30Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 1,707,614 | <p>Or you can simply replace your line </p>
<pre><code>l = re.split("\s+",string.strip(line)).replace('\"','')
</code></pre>
<p>with this:</p>
<pre><code>l = re.split('[\s"]+',string.strip(line))
</code></pre>
| 6 | 2009-11-10T12:28:50Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 1,707,624 | <p>There's a module you can use from the standard library called <a href="http://doc.python.org/library/shlex.html"><strong><code>shlex</code></strong></a>:</p>
<pre><code>>>> import shlex
>>> print shlex.split('5.6 4.5 6.8 "6.5"')
['5.6', '4.5', '6.8', '6.5']
</code></pre>
| 13 | 2009-11-10T12:31:50Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 12,924,834 | <p>I think the easiest and most efficient thing to do would be to slice it! </p>
<p>From your code:</p>
<pre><code>d = l[3]
returns "6.5"
</code></pre>
<p>so you simply add another statement:</p>
<pre><code>d = d[1:-1]
</code></pre>
<p>now it will return 6.5 without the leading and end double quotes.</p>
<p>viola... | 2 | 2012-10-16T23:10:36Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 13,013,495 | <p>The <code>csv</code> module (standard library) does it automatically, although the docs isn't very specific about <code>skipinitialspace</code></p>
<pre><code>>>> import csv
>>> with open(name, 'rb') as f:
... for row in csv.reader(f, delimiter=' ', skipinitialspace=True):
... pri... | 9 | 2012-10-22T14:25:26Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 30,797,870 | <p>IMHO, the most universal doublequote stripper is this:</p>
<pre><code>In [1]: s = '1 " 1 2" 0 a "3 4 5 " 6'
In [2]: [i[0].strip() for i in csv.reader(s, delimiter=' ') if i != ['', '']]
Out[2]: ['1', '1 2', '0', 'a', '3 4 5', '6']
</code></pre>
| 0 | 2015-06-12T07:45:23Z | [
"python",
"csv",
"strip"
] |
Can Python remove double quotes from a string, when reading in text file? | 1,707,558 | <p>I have some text file like this, with several 5000 lines:</p>
<pre><code>5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
</code></pre>
<p>so the last term is a number between double quotes.</p>
<p>What I want to do is, using Python (if possible), to assign the four columns to double variables. But... | 18 | 2009-11-10T12:20:44Z | 34,936,625 | <p>I used in essence to remove the " in "25" using </p>
<pre><code>Code:
result = result.strip("\"") #remove double quotes characters
</code></pre>
| 2 | 2016-01-21T23:50:43Z | [
"python",
"csv",
"strip"
] |
List all the modules that are part of a python package? | 1,707,709 | <p>Is there a straightforward way to find all the modules that are part of a python package? I've found <a href="http://bytes.com/topic/python/answers/36924-how-get-list-modules-package">this old discussion</a>, which is not really conclusive, but I'd love to have a definite answer before I roll out my own solution bas... | 54 | 2009-11-10T12:47:30Z | 1,707,755 | <p>Here's one way, off the top of my head:</p>
<pre><code>>>> import os
>>> filter(lambda i: type(i) == type(os), [getattr(os, j) for j in dir(os)])
[<module 'UserDict' from '/usr/lib/python2.5/UserDict.pyc'>, <module 'copy_reg' from '/usr/lib/python2.5/copy_reg.pyc'>, <module 'errno' ... | -1 | 2009-11-10T12:54:03Z | [
"python",
"module",
"packages",
"introspection",
"python-import"
] |
List all the modules that are part of a python package? | 1,707,709 | <p>Is there a straightforward way to find all the modules that are part of a python package? I've found <a href="http://bytes.com/topic/python/answers/36924-how-get-list-modules-package">this old discussion</a>, which is not really conclusive, but I'd love to have a definite answer before I roll out my own solution bas... | 54 | 2009-11-10T12:47:30Z | 1,707,786 | <p>Yes, you want something based on <code>pkgutil</code> or similar -- this way you can treat all packages alike regardless if they are in eggs or zips or so (where os.listdir won't help).</p>
<pre><code>import pkgutil
# this is the package we are inspecting -- for example 'email' from stdlib
import email
package = ... | 75 | 2009-11-10T12:58:55Z | [
"python",
"module",
"packages",
"introspection",
"python-import"
] |
List all the modules that are part of a python package? | 1,707,709 | <p>Is there a straightforward way to find all the modules that are part of a python package? I've found <a href="http://bytes.com/topic/python/answers/36924-how-get-list-modules-package">this old discussion</a>, which is not really conclusive, but I'd love to have a definite answer before I roll out my own solution bas... | 54 | 2009-11-10T12:47:30Z | 1,708,706 | <p>The right tool for this job is pkgutil.walk_packages.</p>
<p>To list all the modules on your system:</p>
<pre><code>import pkgutil
for importer, modname, ispkg in pkgutil.walk_packages(path=None, onerror=lambda x: None):
print(modname)
</code></pre>
<p>Be aware that walk_packages imports all subpackages, but ... | 21 | 2009-11-10T15:15:48Z | [
"python",
"module",
"packages",
"introspection",
"python-import"
] |
List all the modules that are part of a python package? | 1,707,709 | <p>Is there a straightforward way to find all the modules that are part of a python package? I've found <a href="http://bytes.com/topic/python/answers/36924-how-get-list-modules-package">this old discussion</a>, which is not really conclusive, but I'd love to have a definite answer before I roll out my own solution bas... | 54 | 2009-11-10T12:47:30Z | 15,723,105 | <p>This works for me:</p>
<pre><code>import types
for key, obj in nltk.__dict__.iteritems():
if type(obj) is types.ModuleType:
print key
</code></pre>
| 3 | 2013-03-30T20:24:30Z | [
"python",
"module",
"packages",
"introspection",
"python-import"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 1,707,851 | <p>You could <a href="http://www.linuxjournal.com/article/8497">embed your Python script in a C program</a> and then <a href="http://www.mathworks.com/support/tech-notes/1600/1605.html">MEX the C program with MATLAB</a> but that might be a lot of work compared dumping the results to a file.</p>
<p>You can call MATLAB ... | 11 | 2009-11-10T13:09:31Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 1,709,660 | <p>I had a similar requirement on my system and this was my solution: </p>
<p>In MATLAB there is a function called perl.m, which allows you to call perl scripts from MATLAB. Depending on which version you are using it will be located somewhere like</p>
<pre><code>C:\Program Files\MATLAB\R2008a\toolbox\matlab\general\... | 34 | 2009-11-10T17:22:51Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 2,650,091 | <p>Since <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="nofollow">Python</a> is a better glue language, it may be easier to call the <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> part of your program from Python instead of vice-versa. </p>
<p>Check out <a href=... | 0 | 2010-04-16T01:48:54Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 5,065,674 | <p>Since <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a> seamlessly integrates with Java, you can use <a href="http://www.jython.org/" rel="nofollow">Jython</a> to write your script and call that from MATLAB (you may have to add a thin pure JKava wrapper to actually call the Jython code). I neve... | 4 | 2011-02-21T12:02:51Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 9,432,280 | <p>I've adapted the <code>perl.m</code> to <code>python.m</code> and attached this for reference for others, but I can't seem to get any output from the Python scripts to be returned to the MATLAB variable :(</p>
<p>Here is my M-file; note I point directly to the Python folder, <code>C:\python27_64</code>, in my code,... | 2 | 2012-02-24T14:23:16Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 9,764,931 | <p>The simplest way to do this is to use <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a>'s <a href="http://www.mathworks.com/help/techdoc/ref/system.html" rel="nofollow">system</a> function. </p>
<p>So basically, you would execute a Python function on MATLAB as you would do on the command promp... | 6 | 2012-03-19T04:09:25Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 10,615,175 | <p>This seems to be a suitable method to "tunnel" functions from <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="nofollow">Python</a> to <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a>:</p>
<p><a href="http://code.google.com/p/python-matlab-wormholes/" rel="nofollo... | 1 | 2012-05-16T08:59:18Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 10,797,152 | <p>Try this MEX file for ACTUALLY calling Python from MATLAB not the other way around as others suggest. It provides fairly decent integration : <a href="http://algoholic.eu/matpy/">http://algoholic.eu/matpy/</a></p>
<p>You can do something like this easily:</p>
<pre><code>[X,Y]=meshgrid(-10:0.1:10,-10:0.1:10);
Z=sin... | 14 | 2012-05-29T10:16:14Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 11,804,197 | <p>As @dgorissen said, Jython is the easiest solution.</p>
<p>Just install Jython from the <a href="http://www.jython.org/downloads.html">homepage</a>.</p>
<p>Then:</p>
<pre><code>javaaddpath('/path-to-your-jython-installation/jython.jar')
import org.python.util.PythonInterpreter;
python = PythonInterpreter; %# ta... | 11 | 2012-08-03T22:37:44Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 14,135,799 | <p>A little known (and little <a href="http://www.mathworks.de/de/help/matlab/ref/matlabunix.html%20documented" rel="nofollow">documented</a>) fact about <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow">MATLAB</a>'s <code>system()</code> function: On unixoid systems it uses whatever interpreter is given in... | 3 | 2013-01-03T09:08:06Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 29,189,167 | <p>With Matlab 2014b python libraries can be called <a href="http://www.mathworks.com/help/matlab/call-python-libraries.html">directly from matlab</a>. A prefix <code>py.</code> is added to all packet names:</p>
<pre><code>wrapped = py.textwrap.wrap(T); % calls textwrap.wrap in python
</code></pre>
| 7 | 2015-03-21T23:17:51Z | [
"python",
"matlab",
"language-interoperability"
] |
Call Python function from MATLAB | 1,707,780 | <p>I need to call a Python function from MATLAB. how can I do this?</p>
| 46 | 2009-11-10T12:57:59Z | 40,006,108 | <p>Starting from Matlab 2014b Python functions can be called directly.
Use prefix py, then module name, and finally function name like so:</p>
<pre><code>result = py.module_name.function_name(parameter1);
</code></pre>
<p>Make sure to add the script to the Python search path when calling from Matlab if you are in a d... | 0 | 2016-10-12T18:43:29Z | [
"python",
"matlab",
"language-interoperability"
] |
Fast way to filter illegal xml unicode chars in python? | 1,707,890 | <p>The <a href="http://www.w3.org/TR/xml11/#charsets" rel="nofollow">XML specification</a> lists a bunch of Unicode characters that are either illegal or "discouraged". Given a string, how can I remove all illegal characters from it?</p>
<p>I came up with the following regular expression, but it's a bit of a mouthful.... | 19 | 2009-11-10T13:15:25Z | 1,707,983 | <p>You could also use unicode's translate method to delete selected codepoints. However, the mapping you have is pretty big (2128 codepoints) and that might make it much slower than just using a regex:</p>
<pre><code>ranges = [(0, 8), (0xb, 0x1f), (0x7f, 0x84), (0x86, 0x9f), (0xd800, 0xdfff), (0xfdd0, 0xfddf), (0xfffe... | 2 | 2009-11-10T13:30:43Z | [
"python",
"xml",
"unicode"
] |
Fast way to filter illegal xml unicode chars in python? | 1,707,890 | <p>The <a href="http://www.w3.org/TR/xml11/#charsets" rel="nofollow">XML specification</a> lists a bunch of Unicode characters that are either illegal or "discouraged". Given a string, how can I remove all illegal characters from it?</p>
<p>I came up with the following regular expression, but it's a bit of a mouthful.... | 19 | 2009-11-10T13:15:25Z | 22,273,639 | <p>Recently we (Trac <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">XmlRpcPlugin</a> maintainers) have been notified of the fact that the regular expression above strips surrogate pairs on Python narrow builds (see <a href="http://trac-hacks.org/ticket/11050#comment:13">th:comment:13:ticket:11050</a>) . An alternati... | 8 | 2014-03-08T18:57:19Z | [
"python",
"xml",
"unicode"
] |
Making sense of Python | 1,708,064 | <p>I am reading the book Programming Collective Intelligence, What exactly the following piece of python code do?</p>
<pre><code> # Add up the squares of all the differences
sum_of_squares=sum([pow(prefs[person1][item]-prefs[person2][item],2)
for item in prefs[person1] if item in prefs[perso... | 0 | 2009-11-10T13:45:36Z | 1,708,099 | <p>First it constructs a list containing the results from:</p>
<pre><code>for each item in prefs for person1:
if that is also an item in the prefs for person2:
find the difference between the number of prefs for that item for the two people
and square it (Math.pow(x,2) is "x squared")
</code></pre>... | 6 | 2009-11-10T13:49:27Z | [
"python"
] |
Making sense of Python | 1,708,064 | <p>I am reading the book Programming Collective Intelligence, What exactly the following piece of python code do?</p>
<pre><code> # Add up the squares of all the differences
sum_of_squares=sum([pow(prefs[person1][item]-prefs[person2][item],2)
for item in prefs[person1] if item in prefs[perso... | 0 | 2009-11-10T13:45:36Z | 1,708,102 | <p>It computes the sum of the squares of the difference between <code>prefs[person1][item]</code> and <code>prefs[person2][item]</code>, for every <code>item</code> in the <code>prefs</code> dictionary for <code>person1</code> that is also in the <code>prefs</code> dictionary for <code>person2</code>.</p>
<p>In other ... | 0 | 2009-11-10T13:49:52Z | [
"python"
] |
Making sense of Python | 1,708,064 | <p>I am reading the book Programming Collective Intelligence, What exactly the following piece of python code do?</p>
<pre><code> # Add up the squares of all the differences
sum_of_squares=sum([pow(prefs[person1][item]-prefs[person2][item],2)
for item in prefs[person1] if item in prefs[perso... | 0 | 2009-11-10T13:45:36Z | 1,708,117 | <pre><code>01 sum_of_squares =
02 sum(
03 [
04 pow(
05 prefs[person1][item]-prefs[person2][item],
06 2
07 )
08 for
09 item
10 in
11 prefs[person1]
12 if
13 item in prefs[person2]
14 ]
15 )
</code></pre>
<p>Sum (line 2) a list, that consists of the values computed... | 1 | 2009-11-10T13:51:59Z | [
"python"
] |
Making sense of Python | 1,708,064 | <p>I am reading the book Programming Collective Intelligence, What exactly the following piece of python code do?</p>
<pre><code> # Add up the squares of all the differences
sum_of_squares=sum([pow(prefs[person1][item]-prefs[person2][item],2)
for item in prefs[person1] if item in prefs[perso... | 0 | 2009-11-10T13:45:36Z | 1,710,052 | <p>This might be a <em>little</em> more readable if the call to pow were replaced with an explicit use of '**' exponentiation operator:</p>
<pre><code>sum_of_squares=sum([(prefs[person1][item]-prefs[person2][item])**2
for item in prefs[person1] if item in prefs[person2]])
</code></pre>
<p>Lifting o... | 2 | 2009-11-10T18:16:22Z | [
"python"
] |
Meaning of using commas and underscores with Python assignment operator? | 1,708,292 | <p>Reading through Peter Norvig's <a href="http://norvig.com/sudoku.html" rel="nofollow">Solving Every Sudoku Puzzle essay</a>, I've encountered a few Python idioms that I've never seen before.</p>
<p>I'm aware that a function can return a tuple/list of values, in which case you can assign multiple variables to the re... | 29 | 2009-11-10T14:16:59Z | 1,708,304 | <p><code>_</code> is like any other variable name but usually it means "I don't care about this variable".</p>
<p>The second question: it is "value unpacking". When a function returns a tuple, you can unpack its elements.</p>
<pre><code>>>> x=("v1", "v2")
>>> a,b = x
>>> print a,b
v1 v2
</... | 13 | 2009-11-10T14:18:27Z | [
"python",
"syntax",
"iterable-unpacking"
] |
Meaning of using commas and underscores with Python assignment operator? | 1,708,292 | <p>Reading through Peter Norvig's <a href="http://norvig.com/sudoku.html" rel="nofollow">Solving Every Sudoku Puzzle essay</a>, I've encountered a few Python idioms that I've never seen before.</p>
<p>I'm aware that a function can return a tuple/list of values, in which case you can assign multiple variables to the re... | 29 | 2009-11-10T14:16:59Z | 1,708,333 | <p><code>d2, = values[s]</code> is just like <code>a,b=f()</code>, except for unpacking 1 element tuples.</p>
<pre><code>>>> T=(1,)
>>> a=T
>>> a
(1,)
>>> b,=T
>>> b
1
>>>
</code></pre>
<p><code>a</code> is tuple, <code>b</code> is an integer.</p>
| 29 | 2009-11-10T14:22:14Z | [
"python",
"syntax",
"iterable-unpacking"
] |
Meaning of using commas and underscores with Python assignment operator? | 1,708,292 | <p>Reading through Peter Norvig's <a href="http://norvig.com/sudoku.html" rel="nofollow">Solving Every Sudoku Puzzle essay</a>, I've encountered a few Python idioms that I've never seen before.</p>
<p>I'm aware that a function can return a tuple/list of values, in which case you can assign multiple variables to the re... | 29 | 2009-11-10T14:16:59Z | 1,708,344 | <p>The _ in the Python shell also refers to the value of the last operation. Hence</p>
<pre><code>>>> 1
1
>>> _
1
</code></pre>
<p>The commas refer to tuple unpacking. What happens is that the return value is a tuple, and so it is unpacked into the variables separated by commas, in the order of the ... | 5 | 2009-11-10T14:24:29Z | [
"python",
"syntax",
"iterable-unpacking"
] |
Meaning of using commas and underscores with Python assignment operator? | 1,708,292 | <p>Reading through Peter Norvig's <a href="http://norvig.com/sudoku.html" rel="nofollow">Solving Every Sudoku Puzzle essay</a>, I've encountered a few Python idioms that I've never seen before.</p>
<p>I'm aware that a function can return a tuple/list of values, in which case you can assign multiple variables to the re... | 29 | 2009-11-10T14:16:59Z | 19,508,178 | <p>You can use the trailing comma in a tuple like this:</p>
<pre><code>>>> (2,)*2
(2, 2)
>>> (2)*2
4
</code></pre>
| 3 | 2013-10-22T02:47:53Z | [
"python",
"syntax",
"iterable-unpacking"
] |
Which DHT implementations are compatible with Python 3.x? | 1,708,315 | <p>Following on from <a href="http://stackoverflow.com/questions/1704646/the-easiest-dht-to-implement">this question about DHTs in Python</a>, my question is the same except that I'm developing on Python 3.x - I only want to know about implementations of the DHT concept which are known to work with Python 3.</p>
<p>Th... | 1 | 2009-11-10T14:20:10Z | 1,716,582 | <p>I don't think you'll get simultaneous 2.6 and 3.x support - that is not what Guido is recommending. To do that they'd have to maintain two equivalent parallel code-lines, because the same code is unlikely to work on both python 2 and 3.</p>
| 1 | 2009-11-11T16:56:37Z | [
"python",
"python-3.x",
"p2p",
"dht"
] |
Use a Descriptor (EDIT: Not a single decorator) for multiple attributes? | 1,708,349 | <p>Python 2.5.4. Fairly new to Python, brand new to decorators as of last night. If I have a class with multiple boolean attributes:</p>
<pre><code>class Foo(object):
_bool1 = True
_bool2 = True
_bool3 = True
#et cetera
def __init__():
self._bool1 = True
self._bool2 = False
... | 0 | 2009-11-10T14:25:03Z | 1,708,419 | <p>Two important things.</p>
<p>First, "class-level" attributes are shared by all instances of the class. Like <code>static</code> in Java. It's not clear from your question if you're really talking about class-level attributes.</p>
<p>Generally, most OO programming is done with instance variables, like this.</p>
... | 2 | 2009-11-10T14:37:09Z | [
"python",
"decorator",
"descriptor"
] |
Use a Descriptor (EDIT: Not a single decorator) for multiple attributes? | 1,708,349 | <p>Python 2.5.4. Fairly new to Python, brand new to decorators as of last night. If I have a class with multiple boolean attributes:</p>
<pre><code>class Foo(object):
_bool1 = True
_bool2 = True
_bool3 = True
#et cetera
def __init__():
self._bool1 = True
self._bool2 = False
... | 0 | 2009-11-10T14:25:03Z | 1,708,470 | <p>You can try using a <a href="http://docs.python.org/reference/datamodel.html#implementing-descriptors" rel="nofollow">descriptor</a>:</p>
<pre><code>class BooleanDescriptor(object):
def __init__(self, attr):
self.attr = attr
def __get__(self, instance, owner):
return getattr(instance, self.at... | 3 | 2009-11-10T14:44:42Z | [
"python",
"decorator",
"descriptor"
] |
Is there code out there to subclass set in Python for big xranges? | 1,708,392 | <p>I'm trying to write some Python code that includes union/intersection of sets that potentially can be very large. Much of the time, these sets will be essentially <code>set(xrange(1<<32))</code> or something of the kind, but often there will be ranges of values that do not belong in the set (say, 'bit 5 cannot... | 4 | 2009-11-10T14:32:04Z | 1,708,407 | <p>If you are using python 3.0, you can subclass collections.Set</p>
| 0 | 2009-11-10T14:34:29Z | [
"python",
"set"
] |
Is there code out there to subclass set in Python for big xranges? | 1,708,392 | <p>I'm trying to write some Python code that includes union/intersection of sets that potentially can be very large. Much of the time, these sets will be essentially <code>set(xrange(1<<32))</code> or something of the kind, but often there will be ranges of values that do not belong in the set (say, 'bit 5 cannot... | 4 | 2009-11-10T14:32:04Z | 1,708,543 | <p>This sounds like it might overlap with linear programming. In linear programming you are trying to find some optimal case where you add constraints to a set of values (typically integers) which initially van be very large. There are various libraries listed at <a href="http://wiki.python.org/moin/NumericAndScienti... | 0 | 2009-11-10T14:54:07Z | [
"python",
"set"
] |
Is there code out there to subclass set in Python for big xranges? | 1,708,392 | <p>I'm trying to write some Python code that includes union/intersection of sets that potentially can be very large. Much of the time, these sets will be essentially <code>set(xrange(1<<32))</code> or something of the kind, but often there will be ranges of values that do not belong in the set (say, 'bit 5 cannot... | 4 | 2009-11-10T14:32:04Z | 1,708,575 | <p>You are trying to make a set containing all the integer values in from 0 to 4,294,967,295. A byte is 8 bits, which gets you to 255. 99.9999940628% of your values are over one byte in size. A crude minimum size for your set, even if you are able to overcome the syntactic issues, is 4 billion bytes, or 4 GB. </p>
... | 1 | 2009-11-10T14:57:34Z | [
"python",
"set"
] |
Is there code out there to subclass set in Python for big xranges? | 1,708,392 | <p>I'm trying to write some Python code that includes union/intersection of sets that potentially can be very large. Much of the time, these sets will be essentially <code>set(xrange(1<<32))</code> or something of the kind, but often there will be ranges of values that do not belong in the set (say, 'bit 5 cannot... | 4 | 2009-11-10T14:32:04Z | 1,708,744 | <p>You say:</p>
<blockquote>
<p>For the most part, the set contents can be expressed algorithmically.</p>
</blockquote>
<p>How about writing a class which presents the entire set API, but determines set inclusion algorithmically. Then with a number of classes which wrap around other sets to perform the union and in... | 3 | 2009-11-10T15:19:41Z | [
"python",
"set"
] |
Is there code out there to subclass set in Python for big xranges? | 1,708,392 | <p>I'm trying to write some Python code that includes union/intersection of sets that potentially can be very large. Much of the time, these sets will be essentially <code>set(xrange(1<<32))</code> or something of the kind, but often there will be ranges of values that do not belong in the set (say, 'bit 5 cannot... | 4 | 2009-11-10T14:32:04Z | 1,709,871 | <p>I would avoid subclassing <code>set</code>, since clearly you can usefully reuse no part of <code>set</code>'s implementation. I would even avoid subclassing <code>collections.Set</code>, since the latter requires you to supply a <code>__len__</code> -- a functionality which you appear not to need otherwise, and ju... | 0 | 2009-11-10T17:52:09Z | [
"python",
"set"
] |
convert decimal to hex python | 1,708,598 | <p>Im building a server in python, i need to convert a decimal value to hex like this :</p>
<p>let's say the packet start by 4 bytes which define the packet lenght :
00 00 00 00
if the len(packet) = 255 we would send :
00 00 00 ff</p>
<p>Now my problem is that sometimes the packet is bigger than 256 as for example 33... | 2 | 2009-11-10T15:00:42Z | 1,708,617 | <pre><code>>>> import struct
>>> struct.pack(">i", 336)
'\x00\x00\x01P'
</code></pre>
<p>The <a href="http://docs.python.org/library/struct"><code>struct</code> module</a> packs and unpacks python values into bytes. The <code>">i"</code> format means big-endian 4-byte integer.</p>
| 8 | 2009-11-10T15:03:39Z | [
"python",
"networking",
"decimal",
"hex"
] |
convert decimal to hex python | 1,708,598 | <p>Im building a server in python, i need to convert a decimal value to hex like this :</p>
<p>let's say the packet start by 4 bytes which define the packet lenght :
00 00 00 00
if the len(packet) = 255 we would send :
00 00 00 ff</p>
<p>Now my problem is that sometimes the packet is bigger than 256 as for example 33... | 2 | 2009-11-10T15:00:42Z | 1,708,669 | <p>What about</p>
<pre><code>"%0.8x" % data
</code></pre>
<p>Sample:</p>
<pre><code>>>> print "%0.8x" % 366
0000016e
>>> print "%0.8x" % 336
00000150
</code></pre>
| 3 | 2009-11-10T15:10:56Z | [
"python",
"networking",
"decimal",
"hex"
] |
Combining two record arrays | 1,708,775 | <p>I have two Numpy record arrays that have exactly the same fields. What is the easiest way to combine them into one (i.e. append one table on to the other)?</p>
| 2 | 2009-11-10T15:25:08Z | 1,708,798 | <pre><code>for i in array1:
array2.append(i)
</code></pre>
<p>Or (if implemented)</p>
<pre><code>array1.extend(array2)
</code></pre>
<p>Now array1 contains also all elements of array2</p>
| 0 | 2009-11-10T15:28:07Z | [
"python",
"numpy",
"recarray"
] |
Combining two record arrays | 1,708,775 | <p>I have two Numpy record arrays that have exactly the same fields. What is the easiest way to combine them into one (i.e. append one table on to the other)?</p>
| 2 | 2009-11-10T15:25:08Z | 1,708,862 | <pre><code>#!/usr/bin/env python
import numpy as np
desc = {'names': ('gender','age','weight'), 'formats': ('S1', 'f4', 'f4')}
a = np.array([('M',64.0,75.0),('F',25.0,60.0)], dtype=desc)
b = np.array([('M',64.0,75.0),('F',25.0,60.0)], dtype=desc)
alen=a.shape[0]
blen=b.shape[0]
a.resize(alen+blen)
a[alen:]=b[:]
</code... | 0 | 2009-11-10T15:37:47Z | [
"python",
"numpy",
"recarray"
] |
Combining two record arrays | 1,708,775 | <p>I have two Numpy record arrays that have exactly the same fields. What is the easiest way to combine them into one (i.e. append one table on to the other)?</p>
| 2 | 2009-11-10T15:25:08Z | 1,708,874 | <p>Use <code>numpy.hstack()</code>:</p>
<pre><code>>>> import numpy
>>> desc = {'names': ('gender','age','weight'), 'formats': ('S1', 'f4', 'f4')}
>>> a = numpy.array([('M',64.0,75.0),('F',25.0,60.0)], dtype=desc)
>>> numpy.hstack((a,a))
array([('M', 64.0, 75.0), ('F', 25.0, 60.0),... | 5 | 2009-11-10T15:39:36Z | [
"python",
"numpy",
"recarray"
] |
Python OCR library or handwritten character recognition engine | 1,708,779 | <p>Could you recommend some python libraries or source code for OCR and handwritten character recognition?</p>
| 8 | 2009-11-10T15:25:43Z | 1,709,223 | <p>Have you tried <a href="http://code.google.com/p/pytesser/">pytesser</a>?</p>
| 7 | 2009-11-10T16:26:32Z | [
"python",
"ocr",
"image-recognition"
] |
Python/Django Model overriding the cleaned data | 1,708,780 | <p>Hello I am currently working on a django project, in one of my Models I have a file upload and image upload, with the parameters of these two fields both are set to blank=True, however there is a stipulatation with this and it is that field can only be blank if one of the two is not, so for example, if the imagefiel... | 1 | 2009-11-10T15:25:55Z | 1,708,918 | <p>You just need to define a custom clean() method on the ModelForm that checks if one or both of the fields is populated.</p>
<pre><code>def clean(self):
file_field = self.cleaned_data.get('file_field')
image_field = self.cleaned_data.get('image_field')
if file_field and image_field:
raise forms.... | 4 | 2009-11-10T15:44:02Z | [
"python",
"django",
"model-view-controller",
"django-models",
"django-forms"
] |
python/scons help: maintaining lists of source files + object files | 1,708,789 | <p>I know next to nothing about Python and I'm using scons. (if you're reading this and know Python but not scons, you can probably help me!)</p>
<p>Could someone help me out and explain how I could have a variable that contains two lists? I'm not sure of the syntax. Is this right?</p>
<pre><code>buildinfo = // how d... | 0 | 2009-11-10T15:27:14Z | 1,708,830 | <p>You could use a <code>dict</code> to make code very similar to your original, but it wouldn't be use dots. Take a look:</p>
<pre><code>buildinfo = dict()
buildinfo['objectFiles'] = []
buildinfo['sourceFiles'] = []
buildinfo['objectFiles'].append("Foo")
buildinfo['sourceFiles'].append("Bar")
</code></pre>
<p>It wo... | 1 | 2009-11-10T15:33:25Z | [
"python",
"scons"
] |
python/scons help: maintaining lists of source files + object files | 1,708,789 | <p>I know next to nothing about Python and I'm using scons. (if you're reading this and know Python but not scons, you can probably help me!)</p>
<p>Could someone help me out and explain how I could have a variable that contains two lists? I'm not sure of the syntax. Is this right?</p>
<pre><code>buildinfo = // how d... | 0 | 2009-11-10T15:27:14Z | 1,708,843 | <pre><code>class BuildInfo(object):
objectFiles = [];
sourceFiles = [];
</code></pre>
<p>which you can create with:</p>
<pre><code>buildInfo = BuildInfo()
</code></pre>
<p>but I don't know about making the appending syntax shorter or cleaner, other than adding some looping over the calls to f(). which adds a d... | 0 | 2009-11-10T15:35:23Z | [
"python",
"scons"
] |
python/scons help: maintaining lists of source files + object files | 1,708,789 | <p>I know next to nothing about Python and I'm using scons. (if you're reading this and know Python but not scons, you can probably help me!)</p>
<p>Could someone help me out and explain how I could have a variable that contains two lists? I'm not sure of the syntax. Is this right?</p>
<pre><code>buildinfo = // how d... | 0 | 2009-11-10T15:27:14Z | 1,708,968 | <p>If you create a separate class (e.g. Oren's BuildInfo) then you can certainly add a method to that class that appends data to both lists.</p>
<pre><code>class BuildInfo(object):
def append(self, data):
self.objectFiles.append(data)
self.sourceFiles.append(data)
</code></pre>
| 1 | 2009-11-10T15:50:08Z | [
"python",
"scons"
] |
python/scons help: maintaining lists of source files + object files | 1,708,789 | <p>I know next to nothing about Python and I'm using scons. (if you're reading this and know Python but not scons, you can probably help me!)</p>
<p>Could someone help me out and explain how I could have a variable that contains two lists? I'm not sure of the syntax. Is this right?</p>
<pre><code>buildinfo = // how d... | 0 | 2009-11-10T15:27:14Z | 1,709,291 | <p>How about something like this:</p>
<pre><code>class BuildInfo(object):
def __init__(self, objectFiles = [], sourceFiles = []):
self.objectFiles = objectFiles
self.sourceFiles = sourceFiles
def append(self, build_info):
self.objectFiles.extend(build_info.objectFiles)
self.sou... | 2 | 2009-11-10T16:33:49Z | [
"python",
"scons"
] |
Python socket receive - incoming packets always have a different size | 1,708,835 | <p>I'm using the SocketServer module for a TCP server.
I'm experiencing some issue here with the <code>recv()</code> function, because the incoming packets always have a different size, so if I specify <code>recv(1024)</code> (I tried with a bigger value, and smaller), it gets stuck after 2 or 3 requests because the pa... | 19 | 2009-11-10T15:34:11Z | 1,708,865 | <p>That's the nature of TCP: the protocol fills up packets (lower layer being IP packets) and sends them. You can have some degree of control over the MTU (Maximum Transfer Unit).</p>
<p>In other words: you must devise a protocol that rides on top of TCP where your "payload delineation" is defined. By "payload deline... | 2 | 2009-11-10T15:38:33Z | [
"python",
"networking",
"timeout",
"recv"
] |
Python socket receive - incoming packets always have a different size | 1,708,835 | <p>I'm using the SocketServer module for a TCP server.
I'm experiencing some issue here with the <code>recv()</code> function, because the incoming packets always have a different size, so if I specify <code>recv(1024)</code> (I tried with a bigger value, and smaller), it gets stuck after 2 or 3 requests because the pa... | 19 | 2009-11-10T15:34:11Z | 1,716,173 | <p>The network is <em>always</em> unpredictable. TCP makes a lot of this random behavior go away for you. One wonderful thing TCP does: it guarantees that the bytes will arrive in the same order. But! It does <em>not</em> guarantee that they will arrive chopped up in the same way. You simply <em>cannot</em> assume... | 25 | 2009-11-11T16:02:59Z | [
"python",
"networking",
"timeout",
"recv"
] |
Python socket receive - incoming packets always have a different size | 1,708,835 | <p>I'm using the SocketServer module for a TCP server.
I'm experiencing some issue here with the <code>recv()</code> function, because the incoming packets always have a different size, so if I specify <code>recv(1024)</code> (I tried with a bigger value, and smaller), it gets stuck after 2 or 3 requests because the pa... | 19 | 2009-11-10T15:34:11Z | 1,806,965 | <p>The answer by Larry Hastings has some great general advice about sockets, but there are a couple of mistakes as it pertains to how the <code>recv(bufsize)</code> method works in the Python socket module.</p>
<p>So, to clarify, since this may be confusing to others looking to this for help:</p>
<ol>
<li>The bufsize... | 84 | 2009-11-27T05:43:38Z | [
"python",
"networking",
"timeout",
"recv"
] |
Python socket receive - incoming packets always have a different size | 1,708,835 | <p>I'm using the SocketServer module for a TCP server.
I'm experiencing some issue here with the <code>recv()</code> function, because the incoming packets always have a different size, so if I specify <code>recv(1024)</code> (I tried with a bigger value, and smaller), it gets stuck after 2 or 3 requests because the pa... | 19 | 2009-11-10T15:34:11Z | 1,830,689 | <p>You can alternatively use recv(x_bytes, socket.MSG_WAITALL), which seems to work only on Unix, and will return exactly x_bytes.</p>
| 9 | 2009-12-02T04:40:21Z | [
"python",
"networking",
"timeout",
"recv"
] |
Automatic font recognition with Python | 1,708,858 | <p>As you may have heard of, there is an online font recognition service call WhatTheFont</p>
<p>I'm curious about the tech behind this tool. I think basically we can seperate this into two parts:</p>
<ol>
<li><p>Generate images from font files of various format, refer to <a href="http://www.fileinfo.com/filetypes/fo... | 3 | 2009-11-10T15:37:36Z | 1,709,106 | <p>As the OP states, there are two parts (and probably also a third part):</p>
<ol>
<li><p>Use <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> to generate <a href="http://www.pythonware.com/library/pil/handbook/imagefont.htm" rel="nofollow">images from fonts</a>.</p></li>
<li><p>Use an image a... | 3 | 2009-11-10T16:11:08Z | [
"python",
"image-processing",
"fonts"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.